Replace factory generation of TextContexts with persistent objects.
BUG=skia:2018
R=bsalomon@google.com
Author: jvanverth@google.com
Review URL: https://codereview.chromium.org/150743002
git-svn-id: http://skia.googlecode.com/svn/trunk@13249 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index c858403..dfae1c4 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -201,9 +201,11 @@
fContext->ref();
#if SK_DISTANCEFIELD_FONTS
- fTextContextManager = SkNEW(GrTTextContextManager<GrDistanceFieldTextContext>);
+ fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyProperties));
+ fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties));
#else
- fTextContextManager = SkNEW(GrTTextContextManager<GrBitmapTextContext>);
+ fMainTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties));
+ fFallbackTextContext = NULL;
#endif
fRenderTarget = NULL;
@@ -242,9 +244,11 @@
fContext->ref();
#if SK_DISTANCEFIELD_FONTS
- fTextContextManager = SkNEW(GrTTextContextManager<GrDistanceFieldTextContext>);
+ fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyProperties));
+ fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties));
#else
- fTextContextManager = SkNEW(GrTTextContextManager<GrBitmapTextContext>);
+ fMainTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties));
+ fFallbackTextContext = NULL;
#endif
fRenderTarget = NULL;
@@ -292,7 +296,8 @@
delete fDrawProcs;
}
- delete fTextContextManager;
+ delete fMainTextContext;
+ delete fFallbackTextContext;
// The GrContext takes a ref on the target. We don't want to cause the render
// target to be unnecessarily kept alive.
@@ -1778,7 +1783,7 @@
const SkPaint& paint) {
CHECK_SHOULD_DRAW(draw, false);
- if (fTextContextManager->canDraw(paint, fContext->getMatrix())) {
+ if (fMainTextContext->canDraw(paint)) {
GrPaint grPaint;
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
return;
@@ -1786,11 +1791,8 @@
SkDEBUGCODE(this->validate();)
- SkAutoTDelete<GrTextContext> ctx(fTextContextManager->create(this->context(),
- grPaint, paint,
- this->getDeviceProperties()));
- ctx->drawText((const char *)text, byteLength, x, y);
- } else if (GrBitmapTextContext::CanDraw(paint, fContext->getMatrix())) {
+ fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLength, x, y);
+ } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
GrPaint grPaint;
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
return;
@@ -1798,9 +1800,7 @@
SkDEBUGCODE(this->validate();)
- GrBitmapTextContext textContext(this->context(), grPaint, paint,
- this->getDeviceProperties());
- textContext.drawText((const char *)text, byteLength, x, y);
+ fFallbackTextContext->drawText(grPaint, paint, (const char *)text, byteLength, x, y);
} else {
// this guy will just call our drawPath()
draw.drawText_asPaths((const char*)text, byteLength, x, y, paint);
@@ -1813,7 +1813,7 @@
const SkPaint& paint) {
CHECK_SHOULD_DRAW(draw, false);
- if (fTextContextManager->canDraw(paint, fContext->getMatrix())) {
+ if (fMainTextContext->canDraw(paint)) {
GrPaint grPaint;
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
return;
@@ -1821,11 +1821,9 @@
SkDEBUGCODE(this->validate();)
- SkAutoTDelete<GrTextContext> ctx(fTextContextManager->create(this->context(),
- grPaint, paint,
- this->getDeviceProperties()));
- ctx->drawPosText((const char *)text, byteLength, pos, constY, scalarsPerPos);
- } else if (GrBitmapTextContext::CanDraw(paint, fContext->getMatrix())) {
+ fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
+ constY, scalarsPerPos);
+ } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
GrPaint grPaint;
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
return;
@@ -1833,9 +1831,8 @@
SkDEBUGCODE(this->validate();)
- GrBitmapTextContext textContext(this->context(), grPaint, paint,
- this->getDeviceProperties());
- textContext.drawPosText((const char *)text, byteLength, pos, constY, scalarsPerPos);
+ fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
+ constY, scalarsPerPos);
} else {
draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY,
scalarsPerPos, paint);