diff options
-rw-r--r-- | gn/core.gni | 1 | ||||
-rw-r--r-- | src/core/SkGlyph.cpp | 101 | ||||
-rw-r--r-- | src/core/SkGlyph.h | 77 | ||||
-rw-r--r-- | src/core/SkScalerContext.cpp | 31 | ||||
-rw-r--r-- | src/ports/SkScalerContext_win_dw.cpp | 2 |
5 files changed, 107 insertions, 105 deletions
diff --git a/gn/core.gni b/gn/core.gni index 922aa35c46..ddf324b5b2 100644 --- a/gn/core.gni +++ b/gn/core.gni @@ -156,6 +156,7 @@ skia_core_sources = [ "$_src/core/SkGeometry.h", "$_src/core/SkGlobalInitialization_core.cpp", "$_src/core/SkGlyph.h", + "$_src/core/SkGlyph.cpp", "$_src/core/SkGlyphCache.cpp", "$_src/core/SkGlyphCache.h", "$_src/core/SkGlyphCache_Globals.h", diff --git a/src/core/SkGlyph.cpp b/src/core/SkGlyph.cpp new file mode 100644 index 0000000000..3b72ac5a96 --- /dev/null +++ b/src/core/SkGlyph.cpp @@ -0,0 +1,101 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkGlyph.h" + +void SkGlyph::initWithGlyphID(SkPackedGlyphID glyph_id) { + fID = glyph_id; + fImage = nullptr; + fPathData = nullptr; + fMaskFormat = MASK_FORMAT_UNKNOWN; + fForceBW = 0; +} + +void SkGlyph::toMask(SkMask* mask) const { + SkASSERT(mask); + + mask->fImage = (uint8_t*)fImage; + mask->fBounds.set(fLeft, fTop, fLeft + fWidth, fTop + fHeight); + mask->fRowBytes = this->rowBytes(); + mask->fFormat = static_cast<SkMask::Format>(fMaskFormat); +} + +void SkGlyph::zeroMetrics() { + fAdvanceX = 0; + fAdvanceY = 0; + fWidth = 0; + fHeight = 0; + fTop = 0; + fLeft = 0; + fRsbDelta = 0; + fLsbDelta = 0; +} + +static size_t bits_to_bytes(size_t bits) { + return (bits + 7) >> 3; +} + +static size_t format_rowbytes(int width, SkMask::Format format) { + switch (format) { + case SkMask::kBW_Format: + return bits_to_bytes(width); + case SkMask::kA8_Format: + case SkMask::k3D_Format: + return SkAlign4(width); + case SkMask::kARGB32_Format: + return width * sizeof(uint32_t); + case SkMask::kLCD16_Format: + return SkAlign4(width * sizeof(uint16_t)); + default: + SK_ABORT("Unknown mask format."); + break; + } + return 0; +} + +static size_t format_alignment(SkMask::Format format) { + switch (format) { + case SkMask::kBW_Format: + case SkMask::kA8_Format: + case SkMask::k3D_Format: + return alignof(uint8_t); + case SkMask::kARGB32_Format: + return alignof(uint32_t); + case SkMask::kLCD16_Format: + return alignof(uint16_t); + default: + SK_ABORT("Unknown mask format."); + break; + } + return 0; +} + +size_t SkGlyph::allocImage(SkArenaAlloc* alloc) { + auto size = this->computeImageSize(); + auto format = static_cast<SkMask::Format>(fMaskFormat); + fImage = alloc->makeBytesAlignedTo(size, format_alignment(format)); + + return size; +} + +size_t SkGlyph::rowBytes() const { + return format_rowbytes(fWidth, (SkMask::Format)fMaskFormat); +} + +size_t SkGlyph::rowBytesUsingFormat(SkMask::Format format) const { + return format_rowbytes(fWidth, format); +} + +size_t SkGlyph::computeImageSize() const { + size_t size = this->rowBytes() * fHeight; + + if (fMaskFormat == SkMask::k3D_Format) { + size *= 3; + } + + return size; +} diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h index b54635277b..44d141d34d 100644 --- a/src/core/SkGlyph.h +++ b/src/core/SkGlyph.h @@ -155,81 +155,12 @@ public: int8_t fRsbDelta, fLsbDelta; // used by auto-kerning int8_t fForceBW; - void initWithGlyphID(SkPackedGlyphID glyph_id) { - fID = glyph_id; - fImage = nullptr; - fPathData = nullptr; - fMaskFormat = MASK_FORMAT_UNKNOWN; - fForceBW = 0; - } - - static size_t BitsToBytes(size_t bits) { - return (bits + 7) >> 3; - } - - /** - * Compute the rowbytes for the specified width and mask-format. - */ - static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) { - unsigned rb = width; - switch (format) { - case SkMask::kBW_Format: - rb = BitsToBytes(rb); - break; - case SkMask::kA8_Format: - rb = SkAlign4(rb); - break; - case SkMask::k3D_Format: - rb = SkAlign4(rb); - break; - case SkMask::kARGB32_Format: - rb <<= 2; - break; - case SkMask::kLCD16_Format: - rb = SkAlign4(rb << 1); - break; - default: - SK_ABORT("Unknown mask format."); - break; - } - return rb; - } + void initWithGlyphID(SkPackedGlyphID glyph_id); - size_t allocImage(SkArenaAlloc* alloc) { - size_t allocSize; - switch (static_cast<SkMask::Format>(fMaskFormat)) { - case SkMask::kBW_Format: - allocSize = BitsToBytes(fWidth) * fHeight; - fImage = alloc->makeArrayDefault<char>(allocSize); - break; - case SkMask::kA8_Format: - allocSize = SkAlign4(fWidth) * fHeight; - fImage = alloc->makeArrayDefault<char>(allocSize); - break; - case SkMask::k3D_Format: - allocSize = SkAlign4(fWidth) * fHeight * 3; - fImage = alloc->makeArrayDefault<char>(allocSize); - break; - case SkMask::kARGB32_Format: - allocSize = fWidth * fHeight; - fImage = alloc->makeArrayDefault<uint32_t>(fWidth * fHeight); - allocSize *= sizeof(uint32_t); - break; - case SkMask::kLCD16_Format: - allocSize = SkAlign2(fWidth) * fHeight; - fImage = alloc->makeArrayDefault<uint16_t>(allocSize); - allocSize *= sizeof(uint16_t); - break; - default: - SK_ABORT("Unknown mask format."); - break; - } - return allocSize; - } + size_t allocImage(SkArenaAlloc* alloc) ; - unsigned rowBytes() const { - return ComputeRowBytes(fWidth, (SkMask::Format)fMaskFormat); - } + size_t rowBytes() const; + size_t rowBytesUsingFormat(SkMask::Format format) const; bool isJustAdvance() const { return MASK_FORMAT_JUST_ADVANCE == fMaskFormat; diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index 6d5984abdf..b8778282e2 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -29,37 +29,6 @@ #include "SkTextFormatParams.h" #include "SkWriteBuffer.h" -void SkGlyph::toMask(SkMask* mask) const { - SkASSERT(mask); - - mask->fImage = (uint8_t*)fImage; - mask->fBounds.set(fLeft, fTop, fLeft + fWidth, fTop + fHeight); - mask->fRowBytes = this->rowBytes(); - mask->fFormat = static_cast<SkMask::Format>(fMaskFormat); -} - -size_t SkGlyph::computeImageSize() const { - const size_t size = this->rowBytes() * fHeight; - - switch (fMaskFormat) { - case SkMask::k3D_Format: - return 3 * size; - default: - return size; - } -} - -void SkGlyph::zeroMetrics() { - fAdvanceX = 0; - fAdvanceY = 0; - fWidth = 0; - fHeight = 0; - fTop = 0; - fLeft = 0; - fRsbDelta = 0; - fLsbDelta = 0; -} - /////////////////////////////////////////////////////////////////////////////// #ifdef SK_DEBUG diff --git a/src/ports/SkScalerContext_win_dw.cpp b/src/ports/SkScalerContext_win_dw.cpp index 5f2ff66d48..d66c87a07d 100644 --- a/src/ports/SkScalerContext_win_dw.cpp +++ b/src/ports/SkScalerContext_win_dw.cpp @@ -859,7 +859,7 @@ void SkScalerContext_DW::generateColorGlyphImage(const SkGlyph& glyph) { SkDraw draw; draw.fDst = SkPixmap(SkImageInfo::MakeN32(glyph.fWidth, glyph.fHeight, kPremul_SkAlphaType), glyph.fImage, - glyph.ComputeRowBytes(glyph.fWidth, SkMask::Format::kARGB32_Format)); + glyph.rowBytesUsingFormat(SkMask::Format::kARGB32_Format)); draw.fMatrix = &matrix; draw.fRC = &rc; |