Chromium Code Reviews| Index: src/core/SkGlyphCache.cpp |
| diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp |
| old mode 100644 |
| new mode 100755 |
| index 2b1b62b839641d2825795ff42472ffe8519c030c..04761d05956e9acd29f1ad1b9c3105c4f682e263 |
| --- a/src/core/SkGlyphCache.cpp |
| +++ b/src/core/SkGlyphCache.cpp |
| @@ -9,6 +9,7 @@ |
| #include "SkGlyphCache.h" |
| #include "SkGlyphCache_Globals.h" |
| +#include "SkDistanceFieldGen.h" |
| #include "SkGraphics.h" |
| #include "SkPaint.h" |
| #include "SkPath.h" |
| @@ -358,6 +359,43 @@ const SkPath* SkGlyphCache::findPath(const SkGlyph& glyph) { |
| return glyph.fPath; |
| } |
| +const void* SkGlyphCache::findDistanceField(const SkGlyph& glyph) { |
| + if (glyph.fWidth > 0 && glyph.fWidth < kMaxGlyphWidth) { |
| + if (NULL == glyph.fDistanceField) { |
| + size_t size = SkComputeDistanceFieldSize(glyph.fWidth, glyph.fHeight); |
| + if (size == 0) { |
| + return NULL; |
| + } |
|
robertphillips
2014/04/11 14:13:00
this->?
jvanverth1
2014/04/11 17:54:14
Done.
|
| + const void* image = findImage(glyph); |
| + // now generate the distance field |
|
robertphillips
2014/04/11 14:13:00
NULL != ?
jvanverth1
2014/04/11 17:54:14
Done.
|
| + if (image) { |
| + const_cast<SkGlyph&>(glyph).fDistanceField = fGlyphAlloc.alloc(size, |
| + SkChunkAlloc::kReturnNil_AllocFailType); |
|
robertphillips
2014/04/11 14:13:00
NULL != ?
jvanverth1
2014/04/11 17:54:14
Done.
|
| + if (glyph.fDistanceField) { |
| + SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
| + if (SkMask::kA8_Format == maskFormat) { |
| + // make the distance field from the image |
| + SkGenerateDistanceFieldFromA8Image((unsigned char*)glyph.fDistanceField, |
| + (unsigned char*)glyph.fImage, |
|
robertphillips
2014/04/11 14:13:00
overlength
jvanverth1
2014/04/11 17:54:14
Done.
|
| + glyph.fWidth, glyph.fHeight, glyph.rowBytes()); |
| + fMemoryUsed += size; |
| + } else if (SkMask::kBW_Format == maskFormat) { |
| + // make the distance field from the image |
| + SkGenerateDistanceFieldFromBWImage((unsigned char*)glyph.fDistanceField, |
| + (unsigned char*)glyph.fImage, |
|
robertphillips
2014/04/11 14:13:00
overlength
jvanverth1
2014/04/11 17:54:14
Done.
|
| + glyph.fWidth, glyph.fHeight, glyph.rowBytes()); |
| + fMemoryUsed += size; |
| + } else { |
| + fGlyphAlloc.unalloc(glyph.fDistanceField); |
| + const_cast<SkGlyph&>(glyph).fDistanceField = NULL; |
| + } |
| + } |
| + } |
| + } |
| + } |
| + return glyph.fDistanceField; |
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| bool SkGlyphCache::getAuxProcData(void (*proc)(void*), void** dataPtr) const { |
| @@ -649,6 +687,9 @@ void SkGlyphCache::validate() const { |
| if (glyph->fImage) { |
| SkASSERT(fGlyphAlloc.contains(glyph->fImage)); |
| } |
| + if (glyph->fDistanceField) { |
| + SkASSERT(fGlyphAlloc.contains(glyph->fDistanceField)); |
| + } |
| } |
| #endif |
| } |