Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Unified Diff: src/gpu/GrTextStrike.cpp

Issue 227593010: Move distance field generation to the glyph cache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move GrFontScaler back to public interface Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.cpp ('k') | src/gpu/SkGrFontScaler.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrTextStrike.cpp
diff --git a/src/gpu/GrTextStrike.cpp b/src/gpu/GrTextStrike.cpp
index 65ead0f0bbf08268d7247e5c8cb95cbaeaa9aaaa..29d1b91e8e2f65ef475a751f304828118cd9dedb 100644
--- a/src/gpu/GrTextStrike.cpp
+++ b/src/gpu/GrTextStrike.cpp
@@ -214,10 +214,6 @@ void GrFontCache::dump() const {
static int gCounter;
#endif
-// this acts as the max magnitude for the distance field,
-// as well as the pad we need around the glyph
-#define DISTANCE_FIELD_RANGE 4
-
/*
The text strike is specific to a given font/style/matrix setup, which is
represented by the GrHostFontScaler object we are given in getGlyph().
@@ -260,20 +256,17 @@ GrTextStrike::~GrTextStrike() {
GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed,
GrFontScaler* scaler) {
SkIRect bounds;
- if (!scaler->getPackedGlyphBounds(packed, &bounds)) {
- return NULL;
+ if (fUseDistanceField) {
+ if (!scaler->getPackedGlyphDFBounds(packed, &bounds)) {
+ return NULL;
+ }
+ } else {
+ if (!scaler->getPackedGlyphBounds(packed, &bounds)) {
+ return NULL;
+ }
}
GrGlyph* glyph = fPool.alloc();
- // expand bounds to hold full distance field data
- // + room for bilerp
- int pad = DISTANCE_FIELD_RANGE+1;
- if (fUseDistanceField) {
- bounds.fLeft -= pad;
- bounds.fRight += pad;
- bounds.fTop -= pad;
- bounds.fBottom += pad;
- }
glyph->init(packed, bounds);
fCache.insert(packed, glyph);
return glyph;
@@ -306,56 +299,27 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) {
int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat);
- GrPlot* plot;
+ size_t size = glyph->fBounds.area() * bytesPerPixel;
+ SkAutoSMalloc<1024> storage(size);
if (fUseDistanceField) {
- // we've already expanded the glyph dimensions to match the final size
- // but must shrink back down to get the packed glyph data
- int dfWidth = glyph->width();
- int dfHeight = glyph->height();
- int pad = DISTANCE_FIELD_RANGE+1;
- int width = dfWidth - 2*pad;
- int height = dfHeight - 2*pad;
- int stride = width*bytesPerPixel;
-
- size_t size = width * height * bytesPerPixel;
- SkAutoSMalloc<1024> storage(size);
- if (!scaler->getPackedGlyphImage(glyph->fPackedID, width, height, stride, storage.get())) {
+ if (!scaler->getPackedGlyphDFImage(glyph->fPackedID, glyph->width(),
+ glyph->height(),
+ storage.get())) {
return false;
}
-
- // alloc storage for distance field glyph
- size_t dfSize = dfWidth * dfHeight * bytesPerPixel;
- SkAutoSMalloc<1024> dfStorage(dfSize);
-
- if (1 == bytesPerPixel) {
- (void) SkGenerateDistanceFieldFromImage((unsigned char*)dfStorage.get(),
- (unsigned char*)storage.get(),
- width, height, DISTANCE_FIELD_RANGE);
- } else {
- // distance fields should only be used to represent alpha masks
- SkASSERT(false);
- return false;
- }
-
- // copy to atlas
- plot = fAtlasMgr->addToAtlas(&fAtlas, dfWidth, dfHeight, dfStorage.get(),
- &glyph->fAtlasLocation);
-
} else {
- size_t size = glyph->fBounds.area() * bytesPerPixel;
- SkAutoSMalloc<1024> storage(size);
if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(),
glyph->height(),
glyph->width() * bytesPerPixel,
storage.get())) {
return false;
}
-
- plot = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(),
- glyph->height(), storage.get(),
- &glyph->fAtlasLocation);
}
+ GrPlot* plot = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(),
+ glyph->height(), storage.get(),
+ &glyph->fAtlasLocation);
+
if (NULL == plot) {
return false;
}
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.cpp ('k') | src/gpu/SkGrFontScaler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698