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>
This commit is contained in:
parent
cefa808f3f
commit
ba321b6017
@ -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",
|
||||
|
101
src/core/SkGlyph.cpp
Normal file
101
src/core/SkGlyph.cpp
Normal file
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
void initWithGlyphID(SkPackedGlyphID glyph_id);
|
||||
|
||||
static size_t BitsToBytes(size_t bits) {
|
||||
return (bits + 7) >> 3;
|
||||
}
|
||||
size_t allocImage(SkArenaAlloc* alloc) ;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user