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

Unified Diff: src/gpu/GrDistanceFieldTextContext.cpp

Issue 150743002: Replace factory generation of TextContexts with persistent objects. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: And an if statement Created 6 years, 11 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.h ('k') | src/gpu/GrTextContext.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrDistanceFieldTextContext.cpp
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index 52b714ce25ccb6326515b828bf195dcac6bac3f0..ac93433207224464c48f403a03c5c531c4bb6f8c 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -27,17 +27,9 @@ static const int kBaseDFFontSize = 32;
SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
"Dump the contents of the font cache before every purge.");
-bool GrDistanceFieldTextContext::CanDraw(const SkPaint& paint, const SkMatrix& ctm) {
- return !paint.getRasterizer() && !paint.getMaskFilter() &&
- paint.getStyle() == SkPaint::kFill_Style &&
- !SkDraw::ShouldDrawTextAsPaths(paint, ctm);
-}
-
GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
- const GrPaint& grPaint,
- const SkPaint& skPaint,
const SkDeviceProperties& properties)
- : GrTextContext(context, grPaint, skPaint, properties) {
+ : GrTextContext(context, properties) {
fStrike = NULL;
fCurrTexture = NULL;
@@ -45,19 +37,18 @@ GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
fVertices = NULL;
fMaxVertices = 0;
-
- fTextRatio = fSkPaint.getTextSize()/kBaseDFFontSize;
-
- fSkPaint.setTextSize(SkIntToScalar(kBaseDFFontSize));
- fSkPaint.setLCDRenderText(false);
- fSkPaint.setAutohinted(false);
- fSkPaint.setSubpixelText(false);
}
GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
this->flushGlyphs();
}
+bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
+ return !paint.getRasterizer() && !paint.getMaskFilter() &&
+ paint.getStyle() == SkPaint::kFill_Style &&
+ !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix());
+}
+
static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
unsigned r = SkColorGetR(c);
unsigned g = SkColorGetG(c);
@@ -291,7 +282,33 @@ HAS_ATLAS:
fCurrVertex += 4;
}
-void GrDistanceFieldTextContext::drawText(const char text[], size_t byteLength,
+inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint& skPaint) {
+ GrTextContext::init(paint, skPaint);
+
+ fStrike = NULL;
+
+ fCurrTexture = NULL;
+ fCurrVertex = 0;
+
+ fVertices = NULL;
+ fMaxVertices = 0;
+
+ fTextRatio = fSkPaint.getTextSize()/kBaseDFFontSize;
+
+ fSkPaint.setTextSize(SkIntToScalar(kBaseDFFontSize));
+ fSkPaint.setLCDRenderText(false);
+ fSkPaint.setAutohinted(false);
+ fSkPaint.setSubpixelText(false);
+}
+
+inline void GrDistanceFieldTextContext::finish() {
+ flushGlyphs();
+
+ GrTextContext::finish();
+}
+
+void GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
+ const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
SkASSERT(byteLength == 0 || text != NULL);
@@ -301,6 +318,8 @@ void GrDistanceFieldTextContext::drawText(const char text[], size_t byteLength,
return;
}
+ this->init(paint, skPaint);
+
SkScalar sizeRatio = fTextRatio;
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
@@ -357,9 +376,12 @@ void GrDistanceFieldTextContext::drawText(const char text[], size_t byteLength,
fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale);
fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale);
}
+
+ this->finish();
}
-void GrDistanceFieldTextContext::drawPosText(const char text[], size_t byteLength,
+void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
+ const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY,
int scalarsPerPosition) {
@@ -367,11 +389,12 @@ void GrDistanceFieldTextContext::drawPosText(const char text[], size_t byteLengt
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
// nothing to draw
- if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/
- || fSkPaint.getRasterizer()) {
+ if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) {
return;
}
+ this->init(paint, skPaint);
+
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL);
@@ -420,4 +443,6 @@ void GrDistanceFieldTextContext::drawPosText(const char text[], size_t byteLengt
pos += scalarsPerPosition;
}
}
+
+ this->finish();
}
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.h ('k') | src/gpu/GrTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698