Remove DrawingMgr shims from GrContext
authorrobertphillips <robertphillips@google.com>
Sat, 17 Oct 2015 14:43:27 +0000 (07:43 -0700)
committerCommit bot <commit-bot@chromium.org>
Sat, 17 Oct 2015 14:43:27 +0000 (07:43 -0700)
BUG=skia:4094

Review URL: https://codereview.chromium.org/1413673002

include/gpu/GrContext.h
include/gpu/GrDrawContext.h
src/effects/SkGpuBlurUtils.cpp
src/effects/SkMorphologyImageFilter.cpp
src/gpu/GrContext.cpp
src/gpu/GrDrawContext.cpp
src/gpu/GrDrawingManager.h [new file with mode: 0644]
src/gpu/GrTest.cpp
src/gpu/SkGpuDevice.cpp
src/gpu/effects/GrConfigConversionEffect.cpp

index 904a041..7136ce4 100644 (file)
@@ -23,6 +23,7 @@ struct GrBatchAtlasConfig;
 class GrBatchFontCache;
 class GrCaps;
 struct GrContextOptions;
+class GrDrawingManager;
 class GrDrawContext;
 class GrDrawTarget;
 class GrFragmentProcessor;
@@ -172,7 +173,7 @@ public:
 
     /**
      * Returns a helper object to orchestrate draws.
-     * Callers should take a ref if they rely on the GrDrawContext sticking around.
+     * Callers assume the creation ref of the drawContext
      * NULL will be returned if the context has been abandoned.
      *
      * @param  rt           the render target receiving the draws
@@ -180,19 +181,7 @@ public:
      *
      * @return a draw context
      */
-    GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps = NULL) {
-        return fDrawingMgr.drawContext(rt, surfaceProps);
-    }
-
-    GrTextContext* textContext(const SkSurfaceProps& surfaceProps, GrRenderTarget* rt) {
-        return fDrawingMgr.textContext(surfaceProps, rt);
-    }
-
-    // The caller automatically gets a ref on the returned drawTarget. It must 
-    // be balanced by an unref call.
-    GrDrawTarget* newDrawTarget(GrRenderTarget* rt) {
-        return fDrawingMgr.newDrawTarget(rt);
-    }
+    GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps = NULL);
 
     ///////////////////////////////////////////////////////////////////////////
     // Misc.
@@ -336,7 +325,7 @@ public:
     GrBatchFontCache* getBatchFontCache() { return fBatchFontCache; }
     GrLayerCache* getLayerCache() { return fLayerCache.get(); }
     GrTextBlobCache* getTextBlobCache() { return fTextBlobCache; }
-    bool abandoned() const { return fDrawingMgr.abandoned(); }
+    bool abandoned() const;
     GrResourceProvider* resourceProvider() { return fResourceProvider; }
     const GrResourceProvider* resourceProvider() const { return fResourceProvider; }
     GrResourceCache* getResourceCache() { return fResourceCache; }
@@ -418,64 +407,11 @@ private:
 
     const uint32_t                  fUniqueID;
 
+    SkAutoTDelete<GrDrawingManager> fDrawingManager;
+
     GrContext(); // init must be called after the constructor.
     bool init(GrBackend, GrBackendContext, const GrContextOptions& options);
 
-    // Currently the DrawingMgr creates a separate GrTextContext for each
-    // combination of text drawing options (pixel geometry x DFT use)
-    // and hands the appropriate one back given the DrawContext's request.
-    //
-    // It allocates a new GrDrawContext for each GrRenderTarget
-    // but all of them still land in the same GrDrawTarget!
-    //
-    // In the future this class will allocate a new GrDrawContext for
-    // each GrRenderTarget/GrDrawTarget and manage the DAG.
-    class DrawingMgr {
-    public:
-        DrawingMgr()
-            : fContext(nullptr)
-            , fAbandoned(false)
-            , fNVPRTextContext(nullptr) {
-            sk_bzero(fTextContexts, sizeof(fTextContexts));
-        }
-
-        ~DrawingMgr();
-
-        void init(GrContext* context);
-
-        void abandon();
-        bool abandoned() const { return fAbandoned; }
-
-        void reset();
-        void flush();
-
-        // Callers assume the creation ref of the drawContext!
-        // NULL will be returned if the context has been abandoned.
-        GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps);
-
-        GrTextContext* textContext(const SkSurfaceProps& props, GrRenderTarget* rt);
-        
-        GrDrawTarget* newDrawTarget(GrRenderTarget* rt);
-
-    private:
-        void cleanup();
-
-        friend class GrContext;  // for access to fDrawTarget for testing
-
-        static const int kNumPixelGeometries = 5; // The different pixel geometries
-        static const int kNumDFTOptions = 2;      // DFT or no DFT
-
-        GrContext*        fContext;
-
-        bool              fAbandoned;
-        SkTDArray<GrDrawTarget*> fDrawTargets;
-
-        GrTextContext*    fNVPRTextContext;
-        GrTextContext*    fTextContexts[kNumPixelGeometries][kNumDFTOptions];
-    };
-
-    DrawingMgr                      fDrawingMgr;
-
     void initMockContext();
     void initCommon();
 
index 86a0efe..5986da9 100644 (file)
@@ -15,6 +15,7 @@
 class GrClip;
 class GrContext;
 class GrDrawBatch;
+class GrDrawingManager;
 class GrDrawTarget;
 class GrPaint;
 class GrPathProcessor;
@@ -252,11 +253,11 @@ public:
 
 private:
     friend class GrAtlasTextContext; // for access to drawBatch
-    friend class GrContext; // for ctor
+    friend class GrDrawingManager; // for ctor
 
     SkDEBUGCODE(void validate() const;)
 
-    GrDrawContext(GrContext*, GrRenderTarget*, const SkSurfaceProps* surfaceProps);
+    GrDrawContext(GrDrawingManager*, GrRenderTarget*, const SkSurfaceProps* surfaceProps);
 
     void internalDrawPath(GrDrawTarget*,
                           GrPipelineBuilder*,
@@ -272,15 +273,15 @@ private:
 
     GrDrawTarget* getDrawTarget();
 
-    GrContext*          fContext;     // owning context -> no ref
-    GrRenderTarget*     fRenderTarget;
+    GrDrawingManager* fDrawingManager;
+    GrRenderTarget*   fRenderTarget;
 
     // In MDB-mode the drawTarget can be closed by some other drawContext that has picked
     // it up. For this reason, the drawTarget should only ever be accessed via 'getDrawTarget'.
-    GrDrawTarget*       fDrawTarget;
-    GrTextContext*      fTextContext; // lazily gotten from GrContext::DrawingMgr
+    GrDrawTarget*     fDrawTarget;
+    GrTextContext*    fTextContext; // lazily gotten from GrContext::DrawingManager
 
-    SkSurfaceProps      fSurfaceProps;
+    SkSurfaceProps    fSurfaceProps;
 };
 
 #endif
index ec37505..f0c10c2 100644 (file)
@@ -275,7 +275,7 @@ GrTexture* GaussianBlur(GrContext* context,
             SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
 
             SkAutoTUnref<GrDrawContext> dstDrawContext(
-                                            context->drawContext(dstTexture->asRenderTarget()));
+                                             context->drawContext(dstTexture->asRenderTarget()));
             if (!dstDrawContext) {
                 return nullptr;
             }
@@ -309,7 +309,7 @@ GrTexture* GaussianBlur(GrContext* context,
             SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
 
             SkAutoTUnref<GrDrawContext> dstDrawContext(
-                                             context->drawContext(dstTexture->asRenderTarget()));
+                                               context->drawContext(dstTexture->asRenderTarget()));
             if (!dstDrawContext) {
                 return nullptr;
             }
@@ -347,7 +347,7 @@ GrTexture* GaussianBlur(GrContext* context,
         scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
 
         SkAutoTUnref<GrDrawContext> dstDrawContext(
-                                            context->drawContext(dstTexture->asRenderTarget()));
+                                context->drawContext(dstTexture->asRenderTarget()));
         if (!dstDrawContext) {
             return nullptr;
         }
index 6f6a1e1..416bd23 100644 (file)
@@ -564,7 +564,8 @@ bool apply_morphology(const SkBitmap& input,
         if (nullptr == scratch) {
             return false;
         }
-        SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext(scratch->asRenderTarget()));
+        SkAutoTUnref<GrDrawContext> dstDrawContext(
+                                                context->drawContext(scratch->asRenderTarget()));
         if (!dstDrawContext) {
             return false;
         }
@@ -587,7 +588,8 @@ bool apply_morphology(const SkBitmap& input,
         if (nullptr == scratch) {
             return false;
         }
-        SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext(scratch->asRenderTarget()));
+        SkAutoTUnref<GrDrawContext> dstDrawContext(
+                                                context->drawContext(scratch->asRenderTarget()));
         if (!dstDrawContext) {
             return false;
         }
index a691da7..dfbe2fc 100644 (file)
@@ -14,6 +14,7 @@
 #include "GrCaps.h"
 #include "GrContextOptions.h"
 #include "GrDefaultGeoProcFactory.h"
+#include "GrDrawingManager.h"
 #include "GrDrawContext.h"
 #include "GrDrawTarget.h"
 #include "GrGpuResource.h"
 #include "effects/GrSingleTextureEffect.h"
 
 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
-#define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; }
-#define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; }
-#define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return nullptr; }
+#define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; }
+#define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return false; }
+#define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return nullptr; }
 
 
 ////////////////////////////////////////////////////////////////////////////////
 
-void GrContext::DrawingMgr::init(GrContext* context) {
-    fContext = context;
-}
-
-void GrContext::DrawingMgr::cleanup() {
+void GrDrawingManager::cleanup() {
     for (int i = 0; i < fDrawTargets.count(); ++i) {
         fDrawTargets[i]->unref();
     }
@@ -82,29 +79,29 @@ void GrContext::DrawingMgr::cleanup() {
     }
 }
 
-GrContext::DrawingMgr::~DrawingMgr() {
+GrDrawingManager::~GrDrawingManager() {
     this->cleanup();
 }
 
-void GrContext::DrawingMgr::abandon() {
+void GrDrawingManager::abandon() {
     fAbandoned = true;
     this->cleanup();
 }
 
-void GrContext::DrawingMgr::reset() {
+void GrDrawingManager::reset() {
     for (int i = 0; i < fDrawTargets.count(); ++i) {
         fDrawTargets[i]->reset();
     }
 }
 
-void GrContext::DrawingMgr::flush() {
+void GrDrawingManager::flush() {
     for (int i = 0; i < fDrawTargets.count(); ++i) {
         fDrawTargets[i]->flush();
     }
 }
 
-GrTextContext* GrContext::DrawingMgr::textContext(const SkSurfaceProps& props,
-                                                  GrRenderTarget* rt) {
+GrTextContext* GrDrawingManager::textContext(const SkSurfaceProps& props,
+                                             GrRenderTarget* rt) {
     if (this->abandoned()) {
         return nullptr;
     }
@@ -131,14 +128,14 @@ GrTextContext* GrContext::DrawingMgr::textContext(const SkSurfaceProps& props,
     return fTextContexts[props.pixelGeometry()][useDIF];
 }
 
-GrDrawTarget* GrContext::DrawingMgr::newDrawTarget(GrRenderTarget* rt) {
+GrDrawTarget* GrDrawingManager::newDrawTarget(GrRenderTarget* rt) {
     SkASSERT(fContext);
 
     // When MDB is disabled we always just return the single drawTarget
 #ifndef ENABLE_MDB
     if (fDrawTargets.count()) {
         SkASSERT(fDrawTargets.count() == 1);
-        // DrawingMgr gets the creation ref - this ref is for the caller
+        // DrawingManager gets the creation ref - this ref is for the caller
         return SkRef(fDrawTargets[0]);
     }
 #endif
@@ -147,17 +144,17 @@ GrDrawTarget* GrContext::DrawingMgr::newDrawTarget(GrRenderTarget* rt) {
 
     *fDrawTargets.append() = dt;
 
-    // DrawingMgr gets the creation ref - this ref is for the caller 
+    // DrawingManager gets the creation ref - this ref is for the caller 
     return SkRef(dt);
 }
 
-GrDrawContext* GrContext::DrawingMgr::drawContext(GrRenderTarget* rt, 
-                                                  const SkSurfaceProps* surfaceProps) {
+GrDrawContext* GrDrawingManager::drawContext(GrRenderTarget* rt, 
+                                             const SkSurfaceProps* surfaceProps) {
     if (this->abandoned()) {
         return nullptr;
     }
 
-    return new GrDrawContext(fContext, rt, surfaceProps);
+    return new GrDrawContext(this, rt, surfaceProps);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -222,7 +219,7 @@ void GrContext::initCommon() {
 
     fDidTestPMConversions = false;
 
-    fDrawingMgr.init(this);
+    fDrawingManager.reset(new GrDrawingManager(this));
 
     // GrBatchFontCache will eventually replace GrFontCache
     fBatchFontCache = new GrBatchFontCache(this);
@@ -238,7 +235,7 @@ GrContext::~GrContext() {
 
     this->flush();
 
-    fDrawingMgr.cleanup();
+    fDrawingManager->cleanup();
 
     for (int i = 0; i < fCleanUpData.count(); ++i) {
         (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
@@ -267,7 +264,7 @@ void GrContext::abandonContext() {
     SkSafeSetNull(fPathRendererChain);
     SkSafeSetNull(fSoftwarePathRenderer);
 
-    fDrawingMgr.abandon();
+    fDrawingManager->abandon();
 
     fBatchFontCache->freeAll();
     fLayerCache->freeAll();
@@ -327,9 +324,9 @@ void GrContext::flush(int flagsBitfield) {
     RETURN_IF_ABANDONED
 
     if (kDiscard_FlushBit & flagsBitfield) {
-        fDrawingMgr.reset();
+        fDrawingManager->reset();
     } else {
-        fDrawingMgr.flush();
+        fDrawingManager->flush();
     }
     fResourceCache->notifyFlushOccurred();
     fFlushToReduceCacheSize = false;
@@ -717,6 +714,15 @@ int GrContext::getRecommendedSampleCount(GrPixelConfig config,
         chosenSampleCount : 0;
 }
 
+
+GrDrawContext* GrContext::drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps) {
+    return fDrawingManager->drawContext(rt, surfaceProps);
+}
+
+bool GrContext::abandoned() const { 
+    return fDrawingManager->abandoned();
+}
+
 namespace {
 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) {
     GrConfigConversionEffect::PMConversion pmToUPM;
index 1aec92e..99a1ce5 100644 (file)
@@ -10,6 +10,7 @@
 #include "GrBatchTest.h"
 #include "GrColor.h"
 #include "GrDrawContext.h"
+#include "GrDrawingManager.h"
 #include "GrOvalRenderer.h"
 #include "GrPathRenderer.h"
 #include "GrRenderTarget.h"
 #include "batches/GrDrawVerticesBatch.h"
 #include "batches/GrRectBatchFactory.h"
 
-#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext)
-#define RETURN_IF_ABANDONED        if (fContext->abandoned()) { return; }
-#define RETURN_FALSE_IF_ABANDONED  if (fContext->abandoned()) { return false; }
-#define RETURN_NULL_IF_ABANDONED   if (fContext->abandoned()) { return nullptr; }
+#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingManager->getContext())
+#define RETURN_IF_ABANDONED        if (fDrawingManager->abandoned()) { return; }
+#define RETURN_FALSE_IF_ABANDONED  if (fDrawingManager->abandoned()) { return false; }
+#define RETURN_NULL_IF_ABANDONED   if (fDrawingManager->abandoned()) { return nullptr; }
 
 class AutoCheckFlush {
 public:
-    AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); }
-    ~AutoCheckFlush() { fContext->flushIfNecessary(); }
+    AutoCheckFlush(GrDrawingManager* drawingManager) : fDrawingManager(drawingManager) { 
+        SkASSERT(fDrawingManager);
+    }
+    ~AutoCheckFlush() { fDrawingManager->getContext()->flushIfNecessary(); }
 
 private:
-    GrContext* fContext;
+    GrDrawingManager* fDrawingManager;
 };
 
 // In MDB mode the reffing of the 'getLastDrawTarget' call's result allows in-progress
 // drawTargets to be picked up and added to by drawContexts lower in the call
 // stack. When this occurs with a closed drawTarget, a new one will be allocated
 // when the drawContext attempts to use it (via getDrawTarget).
-GrDrawContext::GrDrawContext(GrContext* context,
+GrDrawContext::GrDrawContext(GrDrawingManager* drawingMgr,
                              GrRenderTarget* rt,
                              const SkSurfaceProps* surfaceProps)
-    : fContext(context)
+    : fDrawingManager(drawingMgr)
     , fRenderTarget(rt)
     , fDrawTarget(SkSafeRef(rt->getLastDrawTarget()))
     , fTextContext(nullptr)
@@ -71,7 +74,7 @@ GrDrawTarget* GrDrawContext::getDrawTarget() {
     SkDEBUGCODE(this->validate();)
 
     if (!fDrawTarget || fDrawTarget->isClosed()) {
-        fDrawTarget = fContext->newDrawTarget(fRenderTarget);
+        fDrawTarget = fDrawingManager->newDrawTarget(fRenderTarget);
         fRenderTarget->setLastDrawTarget(fDrawTarget);
     }
 
@@ -95,7 +98,7 @@ void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint,
     SkDEBUGCODE(this->validate();)
 
     if (!fTextContext) {
-        fTextContext = fContext->textContext(fSurfaceProps, fRenderTarget);
+        fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
     }
 
     fTextContext->drawText(this, fRenderTarget, clip, grPaint, skPaint, viewMatrix,
@@ -112,7 +115,7 @@ void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint,
     SkDEBUGCODE(this->validate();)
 
     if (!fTextContext) {
-        fTextContext = fContext->textContext(fSurfaceProps, fRenderTarget);
+        fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
     }
 
     fTextContext->drawPosText(this, fRenderTarget, clip, grPaint, skPaint, viewMatrix, text, byteLength,
@@ -127,7 +130,7 @@ void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
     SkDEBUGCODE(this->validate();)
 
     if (!fTextContext) {
-        fTextContext = fContext->textContext(fSurfaceProps, fRenderTarget);
+        fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
     }
 
     fTextContext->drawTextBlob(this, fRenderTarget,
@@ -152,7 +155,7 @@ void GrDrawContext::discard() {
     RETURN_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
     this->getDrawTarget()->discard(fRenderTarget);
 }
 
@@ -162,7 +165,7 @@ void GrDrawContext::clear(const SkIRect* rect,
     RETURN_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
     this->getDrawTarget()->clear(rect, color, canIgnoreRect, fRenderTarget);
 }
 
@@ -206,7 +209,7 @@ void GrDrawContext::drawPaint(const GrClip& clip,
             return;
         }
 
-        AutoCheckFlush acf(fContext);
+        AutoCheckFlush acf(fDrawingManager);
 
         GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip);
         this->getDrawTarget()->drawNonAARect(pipelineBuilder,
@@ -238,7 +241,7 @@ void GrDrawContext::drawRect(const GrClip& clip,
         return;
     }
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
 
     GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
 
@@ -327,7 +330,7 @@ void GrDrawContext::drawNonAARectToRect(const GrClip& clip,
     RETURN_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
 
     GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
     this->getDrawTarget()->drawNonAARect(pipelineBuilder,
@@ -345,7 +348,7 @@ void GrDrawContext::drawNonAARectWithLocalMatrix(const GrClip& clip,
     RETURN_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
 
     GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
     this->getDrawTarget()->drawNonAARect(pipelineBuilder,
@@ -368,7 +371,7 @@ void GrDrawContext::drawVertices(const GrClip& clip,
     RETURN_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
 
     GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
 
@@ -409,7 +412,7 @@ void GrDrawContext::drawAtlas(const GrClip& clip,
     RETURN_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
     
     GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
     
@@ -443,7 +446,7 @@ void GrDrawContext::drawRRect(const GrClip& clip,
         return;
     }
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
 
     GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
     GrColor color = paint.getColor();
@@ -477,7 +480,7 @@ void GrDrawContext::drawDRRect(const GrClip& clip,
        return;
     }
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
 
     GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
     GrColor color = paint.getColor();
@@ -522,7 +525,7 @@ void GrDrawContext::drawOval(const GrClip& clip,
         return;
     }
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
 
     GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
     GrColor color = paint.getColor();
@@ -597,7 +600,7 @@ void GrDrawContext::drawBatch(const GrClip& clip,
     RETURN_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
 
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
 
     GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
     this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
@@ -625,7 +628,7 @@ void GrDrawContext::drawPath(const GrClip& clip,
     // cache. This presents a potential hazard for buffered drawing. However,
     // the writePixels that uploads to the scratch will perform a flush so we're
     // OK.
-    AutoCheckFlush acf(fContext);
+    AutoCheckFlush acf(fDrawingManager);
 
     GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
     if (!strokeInfo.isDashed()) {
@@ -689,8 +692,10 @@ void GrDrawContext::internalDrawPath(GrDrawTarget* target,
     const GrStrokeInfo* strokeInfoPtr = &strokeInfo;
 
     // Try a 1st time without stroking the path and without allowing the SW renderer
-    GrPathRenderer* pr = fContext->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr,
-                                                    *strokeInfoPtr, false, type);
+    GrPathRenderer* pr = fDrawingManager->getContext()->getPathRenderer(target, pipelineBuilder,
+                                                                        viewMatrix, *pathPtr,
+                                                                        *strokeInfoPtr, false,
+                                                                        type);
 
     GrStrokeInfo dashlessStrokeInfo(strokeInfo, false);
     if (nullptr == pr && strokeInfo.isDashed()) {
@@ -703,8 +708,9 @@ void GrDrawContext::internalDrawPath(GrDrawTarget* target,
             return;
         }
         strokeInfoPtr = &dashlessStrokeInfo;
-        pr = fContext->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr, *strokeInfoPtr,
-                                       false, type);
+        pr = fDrawingManager->getContext()->getPathRenderer(target, pipelineBuilder, viewMatrix,
+                                                            *pathPtr, *strokeInfoPtr,
+                                                            false, type);
     }
 
     if (nullptr == pr) {
@@ -727,8 +733,9 @@ void GrDrawContext::internalDrawPath(GrDrawTarget* target,
         }
 
         // This time, allow SW renderer
-        pr = fContext->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr, *strokeInfoPtr,
-                                       true, type);
+        pr = fDrawingManager->getContext()->getPathRenderer(target, pipelineBuilder, viewMatrix,
+                                                            *pathPtr, *strokeInfoPtr,
+                                                            true, type);
     }
 
     if (nullptr == pr) {
@@ -740,7 +747,7 @@ void GrDrawContext::internalDrawPath(GrDrawTarget* target,
 
     GrPathRenderer::DrawPathArgs args;
     args.fTarget = target;
-    args.fResourceProvider = fContext->resourceProvider();
+    args.fResourceProvider = fDrawingManager->getContext()->resourceProvider();
     args.fPipelineBuilder = pipelineBuilder;
     args.fColor = color;
     args.fViewMatrix = &viewMatrix;
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
new file mode 100644 (file)
index 0000000..d799493
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrDrawingManager_DEFINED
+#define GrDrawingManager_DEFINED
+
+#include "SkTDArray.h"
+
+class GrContext;
+class GrDrawContext;
+class GrTextContext;
+
+// Currently the DrawingManager creates a separate GrTextContext for each
+// combination of text drawing options (pixel geometry x DFT use)
+// and hands the appropriate one back given the DrawContext's request.
+//
+// It allocates a new GrDrawContext for each GrRenderTarget
+// but all of them still land in the same GrDrawTarget!
+//
+// In the future this class will allocate a new GrDrawContext for
+// each GrRenderTarget/GrDrawTarget and manage the DAG.
+class GrDrawingManager {
+public:
+    ~GrDrawingManager();
+
+    bool abandoned() const { return fAbandoned; }
+
+    GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps);
+
+    GrTextContext* textContext(const SkSurfaceProps& props, GrRenderTarget* rt);
+
+    // The caller automatically gets a ref on the returned drawTarget. It must 
+    // be balanced by an unref call.
+    GrDrawTarget* newDrawTarget(GrRenderTarget* rt);
+
+    GrContext* getContext() { return fContext; }
+
+private:
+    GrDrawingManager(GrContext* context)
+        : fContext(context)
+        , fAbandoned(false)
+        , fNVPRTextContext(nullptr) {
+        sk_bzero(fTextContexts, sizeof(fTextContexts));
+    }
+
+    void abandon();
+    void cleanup();
+    void reset();
+    void flush();
+
+    friend class GrContext;  // for access to: ctor, abandon, reset & flush
+
+    static const int kNumPixelGeometries = 5; // The different pixel geometries
+    static const int kNumDFTOptions = 2;      // DFT or no DFT
+
+    GrContext*        fContext;
+
+    bool              fAbandoned;
+    SkTDArray<GrDrawTarget*> fDrawTargets;
+
+    GrTextContext*    fNVPRTextContext;
+    GrTextContext*    fTextContexts[kNumPixelGeometries][kNumDFTOptions];
+};
+
+#endif
index 9096ef8..aafb0b9 100644 (file)
@@ -11,6 +11,7 @@
 #include "GrBatchAtlas.h"
 #include "GrBatchFontCache.h"
 #include "GrContextOptions.h"
+#include "GrDrawingManager.h"
 #include "GrGpuResourceCacheAccess.h"
 #include "GrResourceCache.h"
 #include "GrTextBlobCache.h"
@@ -54,7 +55,7 @@ void GrContext::getTestTarget(GrTestTarget* tar) {
     // then disconnects. This would help prevent test writers from mixing using the returned
     // GrDrawTarget and regular drawing. We could also assert or fail in GrContext drawing methods
     // until ~GrTestTarget().
-    SkAutoTUnref<GrDrawTarget> dt(fDrawingMgr.newDrawTarget(nullptr));
+    SkAutoTUnref<GrDrawTarget> dt(fDrawingManager->newDrawTarget(nullptr));
     tar->init(this, dt);
 }
 
@@ -292,5 +293,5 @@ void GrContext::initMockContext() {
     // We delete these because we want to test the cache starting with zero resources. Also, none of
     // these objects are required for any of tests that use this context. TODO: make stop allocating
     // resources in the buffer pools.
-    fDrawingMgr.abandon();
+    fDrawingManager->abandon();
 }
index f8b3724..abccd19 100644 (file)
@@ -198,7 +198,7 @@ SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height,
     fLegacyBitmap.setInfo(info);
     fLegacyBitmap.setPixelRef(pr)->unref();
 
-    fDrawContext.reset(fContext->drawContext(rt, &this->surfaceProps()));
+    fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps()));
 }
 
 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::Budgeted budgeted,
@@ -349,7 +349,7 @@ void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) {
                                                        : SkSurface::kNo_Budgeted;
 
     SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget(
-        fRenderTarget->getContext(), budgeted, this->imageInfo(), fRenderTarget->desc().fSampleCnt));
+        this->context(), budgeted, this->imageInfo(), fRenderTarget->desc().fSampleCnt));
 
     if (nullptr == newRT) {
         return;
@@ -375,8 +375,7 @@ void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) {
     SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget);
     fLegacyBitmap.setPixelRef(pr)->unref();
 
-    fDrawContext.reset(fRenderTarget->getContext()->drawContext(fRenderTarget,
-                                                                &this->surfaceProps()));
+    fDrawContext.reset(this->context()->drawContext(fRenderTarget, &this->surfaceProps()));
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index 8acf727..ec418d0 100644 (file)
@@ -224,7 +224,8 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
         paint1.addColorFragmentProcessor(pmToUPM1);
 
 
-        SkAutoTUnref<GrDrawContext> readDrawContext(context->drawContext(readTex->asRenderTarget()));
+        SkAutoTUnref<GrDrawContext> readDrawContext(
+                                    context->drawContext(readTex->asRenderTarget()));
         if (!readDrawContext) {
             failed = true;
             break;
@@ -240,7 +241,8 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
 
         paint2.addColorFragmentProcessor(upmToPM);
 
-        SkAutoTUnref<GrDrawContext> tempDrawContext(context->drawContext(tempTex->asRenderTarget()));
+        SkAutoTUnref<GrDrawContext> tempDrawContext(
+                                    context->drawContext(tempTex->asRenderTarget()));
         if (!tempDrawContext) {
             failed = true;
             break;