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

Unified Diff: src/gpu/SkGpuDevice.cpp

Issue 144283002: Add factory class for generating various flavors of GrTextContext. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« include/gpu/GrTextContext.h ('K') | « src/gpu/GrTextContext.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/SkGpuDevice.cpp
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 5ba174cafcc53e9f483b7844c1f1d98b173629ac..a5d5be1903fabb15eec2b3ddd99a5ea0e5e104cf 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -200,6 +200,12 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context,
fContext = context;
fContext->ref();
+#if SK_DISTANCEFIELD_FONTS
+ fTextContextFactory = new GrTTextContextFactory<GrDistanceFieldTextContext>();
+#else
+ fTextContextFactory = new GrTTextContextFactory<GrBitmapTextContext>();
+#endif
+
fRenderTarget = NULL;
fNeedClear = false;
@@ -235,6 +241,12 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
fContext = context;
fContext->ref();
+#if SK_DISTANCEFIELD_FONTS
+ fTextContextFactory = new GrTTextContextFactory<GrDistanceFieldTextContext>();
+#else
+ fTextContextFactory = new GrTTextContextFactory<GrBitmapTextContext>();
+#endif
+
fRenderTarget = NULL;
fNeedClear = false;
@@ -279,6 +291,10 @@ SkGpuDevice::~SkGpuDevice() {
if (fDrawProcs) {
delete fDrawProcs;
}
+
+ if (fTextContextFactory) {
+ delete fTextContextFactory;
+ }
// The GrContext takes a ref on the target. We don't want to cause the render
// target to be unnecessarily kept alive.
@@ -1820,13 +1836,15 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
SkDEBUGCODE(this->validate();)
- GrDistanceFieldTextContext context(fContext, grPaint, paint);
+ GrDistanceFieldTextContext* context =
+ (GrDistanceFieldTextContext*) fTextContextFactory->Create(fContext, grPaint, paint);
- SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyProperties, NULL);
+ SkAutoGlyphCache autoCache(context->getSkPaint(), &this->fLeakyProperties, NULL);
SkGlyphCache* cache = autoCache.getCache();
GrFontScaler* fontScaler = get_gr_font_scaler(cache);
- context.drawText((const char *)text, byteLength, x, y, cache, fontScaler);
+ context->drawText((const char *)text, byteLength, x, y, cache, fontScaler);
+ fTextContextFactory->Destroy(context);
#endif
} else {
SkDraw myDraw(draw);
@@ -1836,9 +1854,10 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
return;
}
- GrBitmapTextContext context(fContext, grPaint, paint.getColor());
- myDraw.fProcs = this->initDrawForText(&context);
+ GrTextContext* context = fTextContextFactory->Create(fContext, grPaint, paint);
+ myDraw.fProcs = this->initDrawForText(context);
this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint);
+ fTextContextFactory->Destroy(context);
}
}
@@ -1861,14 +1880,16 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
SkDEBUGCODE(this->validate();)
- GrDistanceFieldTextContext context(fContext, grPaint, paint);
+ GrDistanceFieldTextContext* context =
+ (GrDistanceFieldTextContext*) fTextContextFactory->Create(fContext, grPaint, paint);
bsalomon 2014/01/21 20:46:17 Does phase 2 remove the need for this downcast?
jvanverth1 2014/01/21 21:10:56 Yes. The current shared interface is for working w
- SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyProperties, NULL);
+ SkAutoGlyphCache autoCache(context->getSkPaint(), &this->fLeakyProperties, NULL);
SkGlyphCache* cache = autoCache.getCache();
GrFontScaler* fontScaler = get_gr_font_scaler(cache);
- context.drawPosText((const char *)text, byteLength, pos, constY, scalarsPerPos,
+ context->drawPosText((const char *)text, byteLength, pos, constY, scalarsPerPos,
cache, fontScaler);
+ fTextContextFactory->Destroy(context);
#endif
} else {
SkDraw myDraw(draw);
@@ -1877,10 +1898,12 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
return;
}
- GrBitmapTextContext context(fContext, grPaint, paint.getColor());
- myDraw.fProcs = this->initDrawForText(&context);
+
+ GrTextContext* context = fTextContextFactory->Create(fContext, grPaint, paint);
+ myDraw.fProcs = this->initDrawForText(context);
this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY,
scalarsPerPos, paint);
+ fTextContextFactory->Destroy(context);
}
}
« include/gpu/GrTextContext.h ('K') | « src/gpu/GrTextContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698