Make GrTextContext be owned by the GrDrawContext

This CL makes the GrTextContext be owned (and hidden) by the GrDrawContext. This funnels all the drawText* calls through the GrDrawContext and hides the (dispreferred) GrPipelineBuilder drawText variant.

Some consequences of this are:

GrDrawContext now has to get the text drawing settings (i.e., SkDeviceProperties & useDFT). This means that we need a separate GrDrawContext for each combination of pixel geometry and DFT-use.

All the GrTextContext-derived classes now get a back pointer to the originating GrDrawContext so their method calls no longer take one.

Committed: https://skia.googlesource.com/skia/+/5b16e740fe6ab6d679083d06f07651602265081b

Review URL: https://codereview.chromium.org/1175553002
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index 23c349b..7f97275 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -7,12 +7,16 @@
  */
 
 #include "GrAARectRenderer.h"
+#include "GrAtlasTextContext.h"
 #include "GrBatch.h"
 #include "GrBatchTest.h"
 #include "GrDefaultGeoProcFactory.h"
 #include "GrDrawContext.h"
 #include "GrOvalRenderer.h"
 #include "GrPathRenderer.h"
+#include "GrRenderTarget.h"
+#include "GrRenderTargetPriv.h"
+#include "GrStencilAndCoverTextContext.h"
 
 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext)
 #define RETURN_IF_ABANDONED        if (!fDrawTarget) { return; }
@@ -28,13 +32,21 @@
     GrContext* fContext;
 };
 
-GrDrawContext::GrDrawContext(GrContext* context, GrDrawTarget* drawTarget)
+GrDrawContext::GrDrawContext(GrContext* context,
+                             GrDrawTarget* drawTarget,
+                             const SkDeviceProperties& devProps,
+                             bool useDFT)
     : fContext(context)
-    , fDrawTarget(SkRef(drawTarget)) {
+    , fDrawTarget(SkRef(drawTarget))
+    , fTextContext(NULL)
+    , fDevProps(SkNEW_ARGS(SkDeviceProperties, (devProps)))
+    , fUseDFT(useDFT) {
 }
 
 GrDrawContext::~GrDrawContext() {
     SkSafeUnref(fDrawTarget);
+    SkDELETE(fTextContext);
+    SkDELETE(fDevProps);
 }
 
 void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src,
@@ -46,8 +58,58 @@
     fDrawTarget->copySurface(dst, src, srcRect, dstPoint);
 }
 
-void GrDrawContext::drawText(GrPipelineBuilder* pipelineBuilder, GrBatch* batch) {
-    fDrawTarget->drawBatch(pipelineBuilder, batch);
+GrTextContext* GrDrawContext::createTextContext(GrRenderTarget* renderTarget,
+                                                const SkDeviceProperties& leakyProperties,
+                                                bool enableDistanceFieldFonts) {
+    if (fContext->caps()->shaderCaps()->pathRenderingSupport() &&
+        renderTarget->isStencilBufferMultisampled()) {
+        GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencilAttachment();
+        if (sb) {
+            return GrStencilAndCoverTextContext::Create(fContext, this, 
+                                                        leakyProperties,
+                                                        enableDistanceFieldFonts);
+        }
+    } 
+
+    return GrAtlasTextContext::Create(fContext, this, leakyProperties, enableDistanceFieldFonts);
+}
+
+void GrDrawContext::drawText(GrRenderTarget* rt, 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) {
+    if (!fTextContext) {
+        fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT);
+    }
+
+    fTextContext->drawText(rt, clip, grPaint, skPaint, viewMatrix,
+                           text, byteLength, x, y, clipBounds);
+
+}
+void GrDrawContext::drawPosText(GrRenderTarget* rt, 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) {
+    if (!fTextContext) {
+        fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT);
+    }
+
+    fTextContext->drawPosText(rt, clip, grPaint, skPaint, viewMatrix, text, byteLength,
+                               pos, scalarsPerPosition, offset, clipBounds);
+
+}
+void GrDrawContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const SkPaint& skPaint,
+                                 const SkMatrix& viewMatrix, const SkTextBlob* blob,
+                                 SkScalar x, SkScalar y,
+                                 SkDrawFilter* filter, const SkIRect& clipBounds) {
+    if (!fTextContext) {
+        fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT);
+    }
+
+    fTextContext->drawTextBlob(rt, clip, skPaint, viewMatrix, blob, x, y, filter, clipBounds);
 }
 
 void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder,
@@ -1147,6 +1209,10 @@
     return true;
 }
 
+void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch) {
+    fDrawTarget->drawBatch(pipelineBuilder, batch);
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #ifdef GR_TEST_UTILS