From f1d63aa80dc951417ad34dd00914c8150112e42a Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Wed, 22 Jan 2014 22:01:41 +0000 Subject: [PATCH] Revert of Add factory class for generating various flavors of GrTextContext. (https://codereview.chromium.org/144283002/) Reason for revert: Breaks Chrome. Need to fix template issue. Original issue's description: > Add factory class for generating various flavors of GrTextContext. > > This is the first pass of making Gr*TextContext more generic and easily > subclassed. The next stage will be making GrBitmapTextContext and > GrDistanceFieldTextContext more similar by moving the SkDraw loop into > each subclass. > > BUG=skia:2018 > > Committed: http://code.google.com/p/skia/source/detail?r=13142 R=bsalomon@google.com, reed@google.com TBR=bsalomon@google.com, reed@google.com NOTREECHECKS=true NOTRY=true BUG=skia:2018 Author: jvanverth@google.com Review URL: https://codereview.chromium.org/145023006 git-svn-id: http://skia.googlecode.com/svn/trunk@13143 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/gpu/GrBitmapTextContext.h | 8 ++-- include/gpu/GrDistanceFieldTextContext.h | 8 ++-- include/gpu/GrTextContext.h | 74 +------------------------------- include/gpu/SkGpuDevice.h | 4 +- src/gpu/GrBitmapTextContext.cpp | 10 +++-- src/gpu/GrDistanceFieldTextContext.cpp | 3 +- src/gpu/GrTextContext.cpp | 3 +- src/gpu/SkGpuDevice.cpp | 43 ++++++------------- 8 files changed, 32 insertions(+), 121 deletions(-) diff --git a/include/gpu/GrBitmapTextContext.h b/include/gpu/GrBitmapTextContext.h index e1b3d72..e0900ec 100755 --- a/include/gpu/GrBitmapTextContext.h +++ b/include/gpu/GrBitmapTextContext.h @@ -17,14 +17,13 @@ class GrTextStrike; */ class GrBitmapTextContext : public GrTextContext { public: + GrBitmapTextContext(GrContext*, const GrPaint&, SkColor); + virtual ~GrBitmapTextContext(); + virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, GrFontScaler*) SK_OVERRIDE; private: - GrBitmapTextContext(GrContext*, const GrPaint&, const SkPaint&); - virtual ~GrBitmapTextContext(); - friend class GrTTextContextManager; - GrContext::AutoMatrix fAutoMatrix; GrTextStrike* fStrike; @@ -37,6 +36,7 @@ private: kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4, }; + SkColor fSkPaintColor; SkPoint* fVertices; int32_t fMaxVertices; GrTexture* fCurrTexture; diff --git a/include/gpu/GrDistanceFieldTextContext.h b/include/gpu/GrDistanceFieldTextContext.h index 4fde6ce..3e00ff2 100755 --- a/include/gpu/GrDistanceFieldTextContext.h +++ b/include/gpu/GrDistanceFieldTextContext.h @@ -17,6 +17,9 @@ class GrTextStrike; */ class GrDistanceFieldTextContext : public GrTextContext { public: + GrDistanceFieldTextContext(GrContext*, const GrPaint&, const SkPaint&); + virtual ~GrDistanceFieldTextContext(); + virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, GrFontScaler*) SK_OVERRIDE; @@ -30,10 +33,6 @@ public: const SkPaint& getSkPaint() { return fSkPaint; } private: - GrDistanceFieldTextContext(GrContext*, const GrPaint&, const SkPaint&); - virtual ~GrDistanceFieldTextContext(); - friend class GrTTextContextManager; - GrTextStrike* fStrike; SkScalar fTextRatio; @@ -46,6 +45,7 @@ private: kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4, }; + SkPaint fSkPaint; SkPoint* fVertices; int32_t fMaxVertices; GrTexture* fCurrTexture; diff --git a/include/gpu/GrTextContext.h b/include/gpu/GrTextContext.h index 3c61cbc..b367cf2 100644 --- a/include/gpu/GrTextContext.h +++ b/include/gpu/GrTextContext.h @@ -12,8 +12,6 @@ #include "GrGlyph.h" #include "GrPaint.h" -#include "SkPostConfig.h" - class GrContext; class GrDrawTarget; class GrFontScaler; @@ -23,88 +21,20 @@ class GrFontScaler; */ class GrTextContext { public: - virtual ~GrTextContext() {} virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top, GrFontScaler*) = 0; protected: - GrTextContext(GrContext*, const GrPaint&, const SkPaint&); + GrTextContext(GrContext*, const GrPaint&); + virtual ~GrTextContext() {} GrPaint fPaint; - SkPaint fSkPaint; GrContext* fContext; GrDrawTarget* fDrawTarget; SkIRect fClipRect; -}; - -/* - * These classes wrap the creation of a single text context for a given GPU device. The - * assumption is that we'll only be using one text context at a time for that device. - */ -class GrTextContextManager { -public: - virtual ~GrTextContextManager() {} - virtual GrTextContext* create(GrContext* context, const GrPaint& grPaint, - const SkPaint& skPaint) = 0; -}; -template -class GrTTextContextManager : public GrTextContextManager { private: - class ManagedTextContext : public TextContextClass { - public: - ~ManagedTextContext() {} - - ManagedTextContext(GrContext* context, - const GrPaint& grPaint, - const SkPaint& skPaint, - GrTTextContextManager* manager) : - TextContextClass(context, grPaint, skPaint) { - fManager = manager; - } - - static void operator delete(void* ptr) { - if (ptr == NULL) { - return; - } - ManagedTextContext* context = reinterpret_cast(ptr); - context->fManager->recycle(context); - } - - GrTTextContextManager* fManager; - }; - -public: - GrTTextContextManager() { - fAllocation = sk_malloc_throw(sizeof(ManagedTextContext)); - fUsed = false; - } - - ~GrTTextContextManager() { - SkASSERT(!fUsed); - sk_free(fAllocation); - } - - GrTextContext* create(GrContext* context, const GrPaint& grPaint, - const SkPaint& skPaint) { - // add check for usePath here? - SkASSERT(!fUsed); - ManagedTextContext* obj = SkNEW_PLACEMENT_ARGS(fAllocation, ManagedTextContext, - (context, grPaint, skPaint, this)); - fUsed = true; - return obj; - } - -private: - void recycle(GrTextContext* textContext) { - SkASSERT((void*)textContext == fAllocation); - SkASSERT(fUsed); - fUsed = false; - } - - void* fAllocation; - bool fUsed; }; #endif diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h index 2888951..9b7129f 100644 --- a/include/gpu/SkGpuDevice.h +++ b/include/gpu/SkGpuDevice.h @@ -16,10 +16,10 @@ #include "SkBitmapDevice.h" #include "SkRegion.h" #include "GrContext.h" -#include "GrTextContext.h" struct SkDrawProcs; struct GrSkDrawProcs; +class GrTextContext; /** * Subclass of SkBitmapDevice, which directs all drawing to the GrGpu owned by the @@ -149,8 +149,6 @@ private: GrClipData fClipData; - GrTextContextManager* fTextContextManager; - // state for our render-target GrRenderTarget* fRenderTarget; bool fNeedClear; diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp index 6e33d90..a43c4a2 100755 --- a/src/gpu/GrBitmapTextContext.cpp +++ b/src/gpu/GrBitmapTextContext.cpp @@ -24,10 +24,12 @@ SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, "Dump the contents of the font cache before every purge."); GrBitmapTextContext::GrBitmapTextContext(GrContext* context, const GrPaint& paint, - const SkPaint& skPaint) : - GrTextContext(context, paint, skPaint) { + SkColor color) : + GrTextContext(context, paint) { fAutoMatrix.setIdentity(fContext, &fPaint); + fSkPaintColor = color; + fStrike = NULL; fCurrTexture = NULL; @@ -81,11 +83,11 @@ void GrBitmapTextContext::flushGlyphs() { // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by // the mask texture color. The end result is that we get // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstColor - int a = SkColorGetA(fSkPaint.getColor()); + int a = SkColorGetA(fSkPaintColor); // paintAlpha drawState->setColor(SkColorSetARGB(a, a, a, a)); // paintColor - drawState->setBlendConstant(skcolor_to_grcolor_nopremultiply(fSkPaint.getColor())); + drawState->setBlendConstant(skcolor_to_grcolor_nopremultiply(fSkPaintColor)); drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); } else { // set back to normal in case we took LCD path previously. diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp index 4c9631e..95e773e 100755 --- a/src/gpu/GrDistanceFieldTextContext.cpp +++ b/src/gpu/GrDistanceFieldTextContext.cpp @@ -28,7 +28,8 @@ SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, const GrPaint& grPaint, const SkPaint& skPaint) - : GrTextContext(context, grPaint, skPaint) { + : GrTextContext(context, grPaint), + fSkPaint(skPaint) { fStrike = NULL; fCurrTexture = NULL; diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp index 77e98d2..9e91628 100644 --- a/src/gpu/GrTextContext.cpp +++ b/src/gpu/GrTextContext.cpp @@ -8,8 +8,7 @@ #include "GrTextContext.h" -GrTextContext::GrTextContext(GrContext* context, const GrPaint& paint, - const SkPaint& skPaint) : fPaint(paint), fSkPaint(skPaint) { +GrTextContext::GrTextContext(GrContext* context, const GrPaint& paint) : fPaint(paint) { fContext = context; const GrClipData* clipData = context->getClip(); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 0e91182..5ba174c 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -200,12 +200,6 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context, fContext = context; fContext->ref(); -#if SK_DISTANCEFIELD_FONTS - fTextContextManager = SkNEW(GrTTextContextManager); -#else - fTextContextManager = SkNEW(GrTTextContextManager); -#endif - fRenderTarget = NULL; fNeedClear = false; @@ -241,12 +235,6 @@ SkGpuDevice::SkGpuDevice(GrContext* context, fContext = context; fContext->ref(); -#if SK_DISTANCEFIELD_FONTS - fTextContextManager = SkNEW(GrTTextContextManager); -#else - fTextContextManager = SkNEW(GrTTextContextManager); -#endif - fRenderTarget = NULL; fNeedClear = false; @@ -291,8 +279,6 @@ SkGpuDevice::~SkGpuDevice() { if (fDrawProcs) { delete fDrawProcs; } - - delete fTextContextManager; // The GrContext takes a ref on the target. We don't want to cause the render // target to be unnecessarily kept alive. @@ -1834,15 +1820,13 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text, SkDEBUGCODE(this->validate();) - SkAutoTDelete context(fTextContextManager->create(fContext, grPaint, paint)); - GrDistanceFieldTextContext* dfContext = - static_cast(context.get()); + GrDistanceFieldTextContext context(fContext, grPaint, paint); - SkAutoGlyphCache autoCache(dfContext->getSkPaint(), &this->fLeakyProperties, NULL); + SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyProperties, NULL); SkGlyphCache* cache = autoCache.getCache(); GrFontScaler* fontScaler = get_gr_font_scaler(cache); - dfContext->drawText((const char *)text, byteLength, x, y, cache, fontScaler); + context.drawText((const char *)text, byteLength, x, y, cache, fontScaler); #endif } else { SkDraw myDraw(draw); @@ -1852,8 +1836,8 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text, return; } - SkAutoTDelete context(fTextContextManager->create(fContext, grPaint, paint)); - myDraw.fProcs = this->initDrawForText(context.get()); + GrBitmapTextContext context(fContext, grPaint, paint.getColor()); + myDraw.fProcs = this->initDrawForText(&context); this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); } } @@ -1877,15 +1861,13 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, SkDEBUGCODE(this->validate();) - SkAutoTDelete context(fTextContextManager->create(fContext, grPaint, paint)); - GrDistanceFieldTextContext* dfContext = - static_cast(context.get()); - - SkAutoGlyphCache autoCache(dfContext->getSkPaint(), &this->fLeakyProperties, NULL); + GrDistanceFieldTextContext context(fContext, grPaint, paint); + + SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyProperties, NULL); SkGlyphCache* cache = autoCache.getCache(); GrFontScaler* fontScaler = get_gr_font_scaler(cache); - - dfContext->drawPosText((const char *)text, byteLength, pos, constY, scalarsPerPos, + + context.drawPosText((const char *)text, byteLength, pos, constY, scalarsPerPos, cache, fontScaler); #endif } else { @@ -1895,9 +1877,8 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { return; } - - SkAutoTDelete context(fTextContextManager->create(fContext, grPaint, paint)); - myDraw.fProcs = this->initDrawForText(context.get()); + GrBitmapTextContext context(fContext, grPaint, paint.getColor()); + myDraw.fProcs = this->initDrawForText(&context); this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, scalarsPerPos, paint); } -- 2.7.4