Chromium Code Reviews| Index: src/gpu/SkGpuDevice.cpp |
| diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp |
| index 5ba174cafcc53e9f483b7844c1f1d98b173629ac..7b5f4be51929883c9ac6f126b16b926b59741513 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>(); |
|
bsalomon
2014/01/22 19:13:36
SkNEW()
jvanverth1
2014/01/22 20:28:40
Done.
|
| +#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>(); |
|
bsalomon
2014/01/22 19:13:36
SkNEW()
jvanverth1
2014/01/22 20:28:40
Done.
|
| +#else |
| + fTextContextFactory = new GrTTextContextFactory<GrBitmapTextContext>(); |
| +#endif |
| + |
| fRenderTarget = NULL; |
| fNeedClear = false; |
| @@ -279,6 +291,10 @@ SkGpuDevice::~SkGpuDevice() { |
| if (fDrawProcs) { |
| delete fDrawProcs; |
| } |
| + |
| + if (fTextContextFactory) { |
| + delete fTextContextFactory; |
|
bsalomon
2014/01/22 19:13:36
delete doesn't need a null check.
jvanverth1
2014/01/22 20:28:40
Done.
|
| + } |
| // 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); |
| + SkAutoTDelete<GrTextContext> context(fTextContextFactory->Create(fContext, grPaint, paint)); |
| + GrDistanceFieldTextContext* dfContext = |
| + static_cast<GrDistanceFieldTextContext*>(context.get()); |
| - SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyProperties, NULL); |
| + SkAutoGlyphCache autoCache(dfContext->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); |
| + dfContext->drawText((const char *)text, byteLength, x, y, cache, fontScaler); |
| #endif |
| } else { |
| SkDraw myDraw(draw); |
| @@ -1836,8 +1854,8 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
| return; |
| } |
| - GrBitmapTextContext context(fContext, grPaint, paint.getColor()); |
| - myDraw.fProcs = this->initDrawForText(&context); |
| + SkAutoTDelete<GrTextContext> context(fTextContextFactory->Create(fContext, grPaint, paint)); |
| + myDraw.fProcs = this->initDrawForText(context.get()); |
| this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); |
| } |
| } |
| @@ -1861,13 +1879,15 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, |
| SkDEBUGCODE(this->validate();) |
| - GrDistanceFieldTextContext context(fContext, grPaint, paint); |
| - |
| - SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyProperties, NULL); |
| + SkAutoTDelete<GrTextContext> context(fTextContextFactory->Create(fContext, grPaint, paint)); |
| + GrDistanceFieldTextContext* dfContext = |
| + static_cast<GrDistanceFieldTextContext*>(context.get()); |
| + |
| + SkAutoGlyphCache autoCache(dfContext->getSkPaint(), &this->fLeakyProperties, NULL); |
| SkGlyphCache* cache = autoCache.getCache(); |
| GrFontScaler* fontScaler = get_gr_font_scaler(cache); |
| - |
| - context.drawPosText((const char *)text, byteLength, pos, constY, scalarsPerPos, |
| + |
| + dfContext->drawPosText((const char *)text, byteLength, pos, constY, scalarsPerPos, |
| cache, fontScaler); |
| #endif |
| } else { |
| @@ -1877,8 +1897,9 @@ 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); |
| + |
| + SkAutoTDelete<GrTextContext> context(fTextContextFactory->Create(fContext, grPaint, paint)); |
| + myDraw.fProcs = this->initDrawForText(context.get()); |
| this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, |
| scalarsPerPos, paint); |
| } |