diff options
author | Herb Derby <herb@google.com> | 2018-03-12 16:02:29 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-14 02:12:42 +0000 |
commit | ba321b601782b4dd7cd060506dcc222ccdaac408 (patch) | |
tree | 772434d5ca67d1fc37dcc63ef5bc266b3a992ff1 /src/core/SkGlyph.cpp | |
parent | cefa808f3f237434139ce5fbbbbaf34cbc90e368 (diff) |
Cleanup size calculations in SkGlyph
BUG=skia:7515
Change-Id: Ie9d255a93ecff86ce018f8510332bdb280ec575e
Reviewed-on: https://skia-review.googlesource.com/113863
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core/SkGlyph.cpp')
-rw-r--r-- | src/core/SkGlyph.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
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; +} |