BUG=skia:
(mtklein from here on)
No public API changes.
TBR=reed@google.com
Review URL: https://codereview.chromium.org/939123002
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 50fe1f4..5f02662 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -24,7 +24,7 @@
struct SkDeviceProperties;
class SkReadBuffer;
class SkWriteBuffer;
-struct SkGlyph;
+class SkGlyph;
struct SkRect;
class SkGlyphCache;
class SkImageFilter;
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index f40c1bb..b6738e2 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1534,7 +1534,7 @@
fPaint = &pnt;
if (cache->isSubpixel()) {
- fHalfSampleX = fHalfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits);
+ fHalfSampleX = fHalfSampleY = SkGlyph::kSubpixelRound;
} else {
fHalfSampleX = fHalfSampleY = SK_FixedHalf;
}
diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h
index 9abefa8..4a9acbf 100644
--- a/src/core/SkGlyph.h
+++ b/src/core/SkGlyph.h
@@ -13,6 +13,7 @@
#include "SkMask.h"
class SkPath;
+class SkGlyphCache;
// needs to be != to any valid SkMask::Format
#define MASK_FORMAT_UNKNOWN (0xFF)
@@ -20,12 +21,23 @@
#define kMaxGlyphWidth (1<<13)
-struct SkGlyph {
+class SkGlyph {
+ enum {
+ kSubBits = 2,
+ kSubMask = ((1 << kSubBits) - 1),
+ kSubShift = 24, // must be large enough for glyphs and unichars
+ kCodeMask = ((1 << kSubShift) - 1),
+ // relative offsets for X and Y subpixel bits
+ kSubShiftX = kSubBits,
+ kSubShiftY = 0
+ };
+
+ public:
+ static const SkFixed kSubpixelRound = SK_FixedHalf >> SkGlyph::kSubBits;
void* fImage;
SkPath* fPath;
SkFixed fAdvanceX, fAdvanceY;
- uint32_t fID;
uint16_t fWidth, fHeight;
int16_t fTop, fLeft;
@@ -33,12 +45,12 @@
int8_t fRsbDelta, fLsbDelta; // used by auto-kerning
int8_t fForceBW;
- void init(uint32_t id) {
- fID = id;
- fImage = NULL;
- fPath = NULL;
- fMaskFormat = MASK_FORMAT_UNKNOWN;
- fForceBW = 0;
+ void initWithGlyphID(uint32_t glyph_id) {
+ this->initCommon(MakeID(glyph_id));
+ }
+
+ void initGlyphIdFrom(const SkGlyph& glyph) {
+ this->initCommon(glyph.fID);
}
/**
@@ -94,18 +106,22 @@
*/
void zeroMetrics();
- enum {
- kSubBits = 2,
- kSubMask = ((1 << kSubBits) - 1),
- kSubShift = 24, // must be large enough for glyphs and unichars
- kCodeMask = ((1 << kSubShift) - 1),
- // relative offsets for X and Y subpixel bits
- kSubShiftX = kSubBits,
- kSubShiftY = 0
- };
+ void toMask(SkMask* mask) const;
+
+ private:
+ // TODO(herb) remove friend statement after SkGlyphCache cleanup.
+ friend class SkGlyphCache;
+
+ void initCommon(uint32_t id) {
+ fID = id;
+ fImage = NULL;
+ fPath = NULL;
+ fMaskFormat = MASK_FORMAT_UNKNOWN;
+ fForceBW = 0;
+ }
static unsigned ID2Code(uint32_t id) {
- return id & kCodeMask;
+ return (id & kCodeMask);
}
static unsigned ID2SubX(uint32_t id) {
@@ -134,11 +150,11 @@
x = FixedToSub(x);
y = FixedToSub(y);
return (x << (kSubShift + kSubShiftX)) |
- (y << (kSubShift + kSubShiftY)) |
- code;
+ (y << (kSubShift + kSubShiftY)) |
+ code;
}
- void toMask(SkMask* mask) const;
+ uint32_t fID;
};
#endif
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 57c54bf..f0fd859 100755
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -314,7 +314,7 @@
glyph = (SkGlyph*)fGlyphAlloc.alloc(sizeof(SkGlyph),
SkChunkAlloc::kThrow_AllocFailType);
- glyph->init(id);
+ glyph->initCommon(id);
*fGlyphArray.insert(hi) = glyph;
if (kJustAdvance_MetricsType == mtype) {
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index a3ff95c..e3b5d80 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -482,7 +482,7 @@
SkMask::kARGB32_Format != origGlyph.fMaskFormat);
if (fMaskFilter) { // restore the prefilter bounds
- tmpGlyph.init(origGlyph.fID);
+ tmpGlyph.initGlyphIdFrom(origGlyph);
// need the original bounds, sans our maskfilter
SkMaskFilter* mf = fMaskFilter;
diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h
index 4677635..02b3a76 100644
--- a/src/core/SkScalerContext.h
+++ b/src/core/SkScalerContext.h
@@ -14,7 +14,7 @@
#include "SkPaint.h"
#include "SkTypeface.h"
-struct SkGlyph;
+class SkGlyph;
class SkDescriptor;
class SkMaskFilter;
class SkPathEffect;
diff --git a/src/fonts/SkTestScalerContext.cpp b/src/fonts/SkTestScalerContext.cpp
index b9aa6c7..fc1f945 100644
--- a/src/fonts/SkTestScalerContext.cpp
+++ b/src/fonts/SkTestScalerContext.cpp
@@ -117,7 +117,7 @@
}
void SkTestTypeface::getAdvance(SkGlyph* glyph) {
- glyph->fAdvanceX = fTestFont->fWidths[SkGlyph::ID2Code(glyph->fID)];
+ glyph->fAdvanceX = fTestFont->fWidths[glyph->getGlyphID()];
glyph->fAdvanceY = 0;
}
@@ -126,12 +126,12 @@
}
void SkTestTypeface::getMetrics(SkGlyph* glyph) {
- glyph->fAdvanceX = fTestFont->fWidths[SkGlyph::ID2Code(glyph->fID)];
+ glyph->fAdvanceX = fTestFont->fWidths[glyph->getGlyphID()];
glyph->fAdvanceY = 0;
}
void SkTestTypeface::getPath(const SkGlyph& glyph, SkPath* path) {
- *path = *fTestFont->fPaths[SkGlyph::ID2Code(glyph.fID)];
+ *path = *fTestFont->fPaths[glyph.getGlyphID()];
}
void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const {
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index 30c9205..2345ac1 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -140,7 +140,7 @@
SkFixed fyMask = ~0;
SkFixed halfSampleX, halfSampleY;
if (cache->isSubpixel()) {
- halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits);
+ halfSampleX = halfSampleY = SkGlyph::kSubpixelRound;
SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(viewMatrix);
if (kX_SkAxisAlignment == baseline) {
fyMask = 0;
diff --git a/src/gpu/GrPathRendering.cpp b/src/gpu/GrPathRendering.cpp
index c7f2d9d..456f6d8 100644
--- a/src/gpu/GrPathRendering.cpp
+++ b/src/gpu/GrPathRendering.cpp
@@ -30,7 +30,7 @@
void generatePath(int glyphID, SkPath* out) SK_OVERRIDE {
SkGlyph skGlyph;
- skGlyph.init(SkGlyph::MakeID(glyphID));
+ skGlyph.initWithGlyphID(glyphID);
fScalerContext->getMetrics(&skGlyph);
fScalerContext->getPath(skGlyph, out);
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 7d39da2..67927fd 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -1580,17 +1580,17 @@
{
GLYPHMETRICS gm;
- DWORD total_size = GetGlyphOutlineW(fDDC, glyph.fID, flags, &gm, BUFFERSIZE, glyphbuf->get(), &fMat22);
+ DWORD total_size = GetGlyphOutlineW(fDDC, glyph.getGlyphID(), flags, &gm, BUFFERSIZE, glyphbuf->get(), &fMat22);
// Sometimes GetGlyphOutlineW returns a number larger than BUFFERSIZE even if BUFFERSIZE > 0.
// It has been verified that this does not involve a buffer overrun.
if (GDI_ERROR == total_size || total_size > BUFFERSIZE) {
// GDI_ERROR because the BUFFERSIZE was too small, or because the data was not accessible.
// When the data is not accessable GetGlyphOutlineW fails rather quickly,
// so just try to get the size. If that fails then ensure the data is accessible.
- total_size = GetGlyphOutlineW(fDDC, glyph.fID, flags, &gm, 0, NULL, &fMat22);
+ total_size = GetGlyphOutlineW(fDDC, glyph.getGlyphID(), flags, &gm, 0, NULL, &fMat22);
if (GDI_ERROR == total_size) {
LogFontTypeface::EnsureAccessible(this->getTypeface());
- total_size = GetGlyphOutlineW(fDDC, glyph.fID, flags, &gm, 0, NULL, &fMat22);
+ total_size = GetGlyphOutlineW(fDDC, glyph.getGlyphID(), flags, &gm, 0, NULL, &fMat22);
if (GDI_ERROR == total_size) {
// GetGlyphOutlineW is known to fail for some characters, such as spaces.
// In these cases, just return that the glyph does not have a shape.
@@ -1600,10 +1600,10 @@
glyphbuf->reset(total_size);
- DWORD ret = GetGlyphOutlineW(fDDC, glyph.fID, flags, &gm, total_size, glyphbuf->get(), &fMat22);
+ DWORD ret = GetGlyphOutlineW(fDDC, glyph.getGlyphID(), flags, &gm, total_size, glyphbuf->get(), &fMat22);
if (GDI_ERROR == ret) {
LogFontTypeface::EnsureAccessible(this->getTypeface());
- ret = GetGlyphOutlineW(fDDC, glyph.fID, flags, &gm, total_size, glyphbuf->get(), &fMat22);
+ ret = GetGlyphOutlineW(fDDC, glyph.getGlyphID(), flags, &gm, total_size, glyphbuf->get(), &fMat22);
if (GDI_ERROR == ret) {
SkASSERT(false);
return 0;
diff --git a/src/ports/SkScalerContext_win_dw.h b/src/ports/SkScalerContext_win_dw.h
index 12ca5d5..5c13eab 100644
--- a/src/ports/SkScalerContext_win_dw.h
+++ b/src/ports/SkScalerContext_win_dw.h
@@ -15,7 +15,7 @@
#include <dwrite.h>
-struct SkGlyph;
+class SkGlyph;
class SkDescriptor;
class SkScalerContext_DW : public SkScalerContext {