Create GrPathRenderingDrawContext

TBR=bsalomon@google.com
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1701013002

Review URL: https://codereview.chromium.org/1701013002
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index d971f58..f31e0b2 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -59,7 +59,7 @@
     : fDrawingManager(drawingMgr)
     , fRenderTarget(rt)
     , fDrawTarget(SkSafeRef(rt->getLastDrawTarget()))
-    , fTextContext(nullptr)
+    , fAtlasTextContext(nullptr)
     , fContext(context)
     , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
     , fAuditTrail(auditTrail)
@@ -116,12 +116,12 @@
     SkDEBUGCODE(this->validate();)
     GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawText");
 
-    if (!fTextContext) {
-        fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
+    if (!fAtlasTextContext) {
+        fAtlasTextContext = GrAtlasTextContext::Create();
     }
 
-    fTextContext->drawText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps,
-                           text, byteLength, x, y, clipBounds);
+    fAtlasTextContext->drawText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps,
+                                text, byteLength, x, y, clipBounds);
 }
 
 void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint,
@@ -135,12 +135,13 @@
     SkDEBUGCODE(this->validate();)
     GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPosText");
 
-    if (!fTextContext) {
-        fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
+    if (!fAtlasTextContext) {
+        fAtlasTextContext = GrAtlasTextContext::Create();
     }
 
-    fTextContext->drawPosText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps,
-                              text, byteLength, pos, scalarsPerPosition, offset, clipBounds);
+    fAtlasTextContext->drawPosText(fContext, this, clip, grPaint, skPaint, viewMatrix,
+                                   fSurfaceProps, text, byteLength, pos, scalarsPerPosition,
+                                   offset, clipBounds);
 
 }
 
@@ -153,12 +154,12 @@
     SkDEBUGCODE(this->validate();)
     GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawTextBlob");
 
-    if (!fTextContext) {
-        fTextContext = fDrawingManager->textContext(fSurfaceProps, fRenderTarget);
+    if (!fAtlasTextContext) {
+        fAtlasTextContext = GrAtlasTextContext::Create();
     }
 
-    fTextContext->drawTextBlob(fContext, this, clip, skPaint, viewMatrix, fSurfaceProps, blob, x,
-                               y, filter, clipBounds);
+    fAtlasTextContext->drawTextBlob(fContext, this, clip, skPaint, viewMatrix, fSurfaceProps, blob,
+                                    x, y, filter, clipBounds);
 }
 
 void GrDrawContext::discard() {
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index a063c39..ca50fe4 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -8,6 +8,7 @@
 #include "GrDrawContext.h"
 #include "GrDrawingManager.h"
 #include "GrDrawTarget.h"
+#include "GrPathRenderingDrawContext.h"
 #include "GrResourceProvider.h"
 #include "GrSoftwarePathRenderer.h"
 #include "SkTTopoSort.h"
@@ -28,12 +29,6 @@
 
     fDrawTargets.reset();
 
-    delete fNVPRTextContext;
-    fNVPRTextContext = nullptr;
-
-    delete fAtlasTextContext;
-    fAtlasTextContext = nullptr;
-
     delete fPathRendererChain;
     fPathRendererChain = nullptr;
     SkSafeSetNull(fSoftwarePathRenderer);
@@ -114,32 +109,6 @@
     fFlushing = false;
 }
 
-GrTextContext* GrDrawingManager::textContext(const SkSurfaceProps& props, GrRenderTarget* rt) {
-    if (this->abandoned()) {
-        return nullptr;
-    }
-
-    bool useDIF = props.isUseDeviceIndependentFonts();
-
-    if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() &&
-        rt->isStencilBufferMultisampled()) {
-        GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt);
-        if (sb) {
-            if (!fNVPRTextContext) {
-                fNVPRTextContext = GrStencilAndCoverTextContext::Create();
-            }
-
-            return fNVPRTextContext;
-        }
-    }
-
-    if (!fAtlasTextContext) {
-        fAtlasTextContext = GrAtlasTextContext::Create();
-    }
-
-    return fAtlasTextContext;
-}
-
 GrDrawTarget* GrDrawingManager::newDrawTarget(GrRenderTarget* rt) {
     SkASSERT(fContext);
 
@@ -196,6 +165,21 @@
         return nullptr;
     }
 
+
+    bool useDIF = false;
+    if (surfaceProps) {
+        useDIF = surfaceProps->isUseDeviceIndependentFonts();
+    }
+
+    if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() &&
+        rt->isStencilBufferMultisampled()) {
+        GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt);
+        if (sb) {
+            return new GrPathRenderingDrawContext(fContext, this, rt, surfaceProps,
+                                                  fContext->getAuditTrail(), fSingleOwner);
+        }
+    }
+
     return new GrDrawContext(fContext, this, rt, surfaceProps, fContext->getAuditTrail(),
                              fSingleOwner);
 }
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index a6d0104..d82a3a2 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -38,8 +38,6 @@
 
     GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps*);
 
-    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);
@@ -60,8 +58,6 @@
         , fOptionsForDrawTargets(optionsForDrawTargets)
         , fSingleOwner(singleOwner)
         , fAbandoned(false)
-        , fNVPRTextContext(nullptr)
-        , fAtlasTextContext(nullptr)
         , fPathRendererChain(nullptr)
         , fSoftwarePathRenderer(nullptr)
         , fFlushState(context->getGpu(), context->resourceProvider())
@@ -87,9 +83,6 @@
     bool                        fAbandoned;
     SkTDArray<GrDrawTarget*>    fDrawTargets;
 
-    GrTextContext*              fNVPRTextContext;
-    GrTextContext*              fAtlasTextContext;
-
     GrPathRendererChain*        fPathRendererChain;
     GrSoftwarePathRenderer*     fSoftwarePathRenderer;
 
diff --git a/src/gpu/GrPathRenderingDrawContext.cpp b/src/gpu/GrPathRenderingDrawContext.cpp
new file mode 100644
index 0000000..a29af84
--- /dev/null
+++ b/src/gpu/GrPathRenderingDrawContext.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrPathRenderingDrawContext.h"
+
+#include "GrDrawingManager.h"
+
+#include "text/GrStencilAndCoverTextContext.h"
+
+#define ASSERT_SINGLE_OWNER \
+    SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
+#define RETURN_IF_ABANDONED        if (this->drawingManager()->abandoned()) { return; }
+
+void GrPathRenderingDrawContext::drawText(const GrClip& clip,  const GrPaint& grPaint,
+                                          const SkPaint& skPaint,
+                                          const SkMatrix& viewMatrix, const char text[],
+                                          size_t byteLength, SkScalar x, SkScalar y,
+                                          const SkIRect& clipBounds) {
+    ASSERT_SINGLE_OWNER
+    RETURN_IF_ABANDONED
+    SkDEBUGCODE(this->validate();)
+    GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawText");
+
+    if (!fStencilAndCoverTextContext) {
+        fStencilAndCoverTextContext = GrStencilAndCoverTextContext::Create();
+    }
+
+    fStencilAndCoverTextContext->drawText(this->drawingManager()->getContext(), this, clip, grPaint,
+                                          skPaint, viewMatrix, this->surfaceProps(),
+                                          text, byteLength, x, y, clipBounds);
+}
+
+void GrPathRenderingDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint,
+                                             const SkPaint& skPaint,
+                                             const SkMatrix& viewMatrix, const char text[],
+                                             size_t byteLength,  const SkScalar pos[],
+                                             int scalarsPerPosition, const SkPoint& offset,
+                                             const SkIRect& clipBounds) {
+    ASSERT_SINGLE_OWNER
+    RETURN_IF_ABANDONED
+    SkDEBUGCODE(this->validate();)
+    GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawPosText");
+
+    if (!fStencilAndCoverTextContext) {
+        fStencilAndCoverTextContext = GrStencilAndCoverTextContext::Create();
+    }
+
+    fStencilAndCoverTextContext->drawPosText(this->drawingManager()->getContext(), this, clip,
+                                             grPaint, skPaint, viewMatrix, this->surfaceProps(),
+                                             text, byteLength, pos, scalarsPerPosition, offset,
+                                             clipBounds);
+}
+
+void GrPathRenderingDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
+                                              const SkMatrix& viewMatrix, const SkTextBlob* blob,
+                                              SkScalar x, SkScalar y,
+                                              SkDrawFilter* filter, const SkIRect& clipBounds) {
+    ASSERT_SINGLE_OWNER
+    RETURN_IF_ABANDONED
+    SkDEBUGCODE(this->validate();)
+    GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawTextBlob");
+
+    if (!fStencilAndCoverTextContext) {
+        fStencilAndCoverTextContext = GrStencilAndCoverTextContext::Create();
+    }
+
+    fStencilAndCoverTextContext->drawTextBlob(this->drawingManager()->getContext(), this, clip,
+                                              skPaint, viewMatrix, this->surfaceProps(), blob, x,
+                                              y, filter, clipBounds);
+}
diff --git a/src/gpu/GrPathRenderingDrawContext.h b/src/gpu/GrPathRenderingDrawContext.h
new file mode 100644
index 0000000..ab36955
--- /dev/null
+++ b/src/gpu/GrPathRenderingDrawContext.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrPathRenderingDrawContext_DEFINED
+#define GrPathRenderingDrawContext_DEFINED
+
+#include "GrDrawContext.h"
+
+class GrStencilAndCoverTextContext;
+
+class GrPathRenderingDrawContext : public GrDrawContext {
+public:
+    void drawText(const GrClip&,  const GrPaint&, const SkPaint&,
+                  const SkMatrix& viewMatrix, const char text[], size_t byteLength,
+                  SkScalar x, SkScalar y, const SkIRect& clipBounds) override;
+    void drawPosText(const GrClip&, const GrPaint&, const SkPaint&,
+                     const SkMatrix& viewMatrix, const char text[], size_t byteLength,
+                     const SkScalar pos[], int scalarsPerPosition,
+                     const SkPoint& offset, const SkIRect& clipBounds) override;
+    void drawTextBlob(const GrClip&, const SkPaint&,
+                      const SkMatrix& viewMatrix, const SkTextBlob*,
+                      SkScalar x, SkScalar y,
+                      SkDrawFilter*, const SkIRect& clipBounds) override;
+protected:
+    GrPathRenderingDrawContext(GrContext* ctx, GrDrawingManager* mgr, GrRenderTarget* rt,
+                               const SkSurfaceProps* surfaceProps, GrAuditTrail* at,
+                               GrSingleOwner* so)
+        : INHERITED(ctx, mgr, rt, surfaceProps, at, so)
+        , fStencilAndCoverTextContext(nullptr) {}
+
+private:
+    GrStencilAndCoverTextContext* fStencilAndCoverTextContext;
+
+    friend class GrDrawingManager; // for ctor
+
+    typedef GrDrawContext INHERITED;
+};
+
+#endif