aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text
diff options
context:
space:
mode:
authorGravatar joel.liang <joel.liang@arm.com>2016-12-18 20:24:12 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-12-18 20:24:12 -0800
commit64b70b096ac20833d9737758a4bd5f2a51078bc4 (patch)
tree553c812c4460798e4cc28496a0e234adf6f87638 /src/gpu/text
parent57845a7264ef5183258ec23ffe77c25ec967c755 (diff)
Generate Signed Distance Field directly from vector path
Diffstat (limited to 'src/gpu/text')
-rw-r--r--src/gpu/text/GrAtlasGlyphCache.cpp59
1 files changed, 41 insertions, 18 deletions
diff --git a/src/gpu/text/GrAtlasGlyphCache.cpp b/src/gpu/text/GrAtlasGlyphCache.cpp
index 803dbb48e1..b466ca88d2 100644
--- a/src/gpu/text/GrAtlasGlyphCache.cpp
+++ b/src/gpu/text/GrAtlasGlyphCache.cpp
@@ -14,6 +14,7 @@
#include "SkString.h"
#include "SkDistanceFieldGen.h"
+#include "GrDistanceFieldGenFromVector.h"
bool GrAtlasGlyphCache::initAtlas(GrMaskFormat format) {
int index = MaskFormatToAtlasIndex(format);
@@ -320,29 +321,51 @@ static bool get_packed_glyph_df_image(SkGlyphCache* cache, const SkGlyph& glyph,
int width, int height, void* dst) {
SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width);
SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height);
- const void* image = cache->findImage(glyph);
- if (nullptr == image) {
+
+#ifndef SK_USE_LEGACY_DISTANCE_FIELDS
+ const SkPath* path = cache->findPath(glyph);
+ if (nullptr == path) {
return false;
}
+
// now generate the distance field
SkASSERT(dst);
- SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat);
- if (SkMask::kA8_Format == maskFormat) {
- // make the distance field from the image
- SkGenerateDistanceFieldFromA8Image((unsigned char*)dst,
- (unsigned char*)image,
- glyph.fWidth, glyph.fHeight,
- glyph.rowBytes());
- } else if (SkMask::kBW_Format == maskFormat) {
- // make the distance field from the image
- SkGenerateDistanceFieldFromBWImage((unsigned char*)dst,
- (unsigned char*)image,
- glyph.fWidth, glyph.fHeight,
- glyph.rowBytes());
- } else {
- return false;
- }
+ SkMatrix drawMatrix;
+ drawMatrix.setTranslate((SkScalar)-glyph.fLeft, (SkScalar)-glyph.fTop);
+
+ // Generate signed distance field directly from SkPath
+ bool succeed = GrGenerateDistanceFieldFromPath((unsigned char*)dst,
+ *path, drawMatrix,
+ width, height, width * sizeof(unsigned char));
+
+ if (!succeed) {
+#endif
+ const void* image = cache->findImage(glyph);
+ if (nullptr == image) {
+ return false;
+ }
+ // now generate the distance field
+ SkASSERT(dst);
+ SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat);
+ if (SkMask::kA8_Format == maskFormat) {
+ // make the distance field from the image
+ SkGenerateDistanceFieldFromA8Image((unsigned char*)dst,
+ (unsigned char*)image,
+ glyph.fWidth, glyph.fHeight,
+ glyph.rowBytes());
+ } else if (SkMask::kBW_Format == maskFormat) {
+ // make the distance field from the image
+ SkGenerateDistanceFieldFromBWImage((unsigned char*)dst,
+ (unsigned char*)image,
+ glyph.fWidth, glyph.fHeight,
+ glyph.rowBytes());
+ } else {
+ return false;
+ }
+#ifndef SK_USE_LEGACY_DISTANCE_FIELDS
+ }
+#endif
return true;
}