Add useDFT field to SkDeviceProperties

Review URL: https://codereview.chromium.org/1191943002
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 31cb4d0..a98cf0b 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -177,12 +177,11 @@
      * NULL will be returned if the context has been abandoned.
      *
      * @param  devProps the device properties (mainly defines text drawing)
-     * @param  uesDFT should Distance Field Text be used?
      *
      * @return a draw context
      */
-    GrDrawContext* drawContext(const SkDeviceProperties* devProps = NULL, bool useDFT = false) {
-        return fDrawingMgr.drawContext(devProps, useDFT);    
+    GrDrawContext* drawContext(const SkDeviceProperties* devProps = NULL) {
+        return fDrawingMgr.drawContext(devProps);    
     }
 
     ///////////////////////////////////////////////////////////////////////////
@@ -420,7 +419,7 @@
 
         // Callers should take a ref if they rely on the GrDrawContext sticking around.
         // NULL will be returned if the context has been abandoned.
-        GrDrawContext* drawContext(const SkDeviceProperties* devProps, bool useDFT);
+        GrDrawContext* drawContext(const SkDeviceProperties* devProps);
 
     private:
         void cleanup();
diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h
index 7e71126..1688694 100644
--- a/include/gpu/GrDrawContext.h
+++ b/include/gpu/GrDrawContext.h
@@ -244,14 +244,14 @@
     friend class GrAtlasTextContext; // for access to drawBatch
     friend class GrContext; // for ctor
 
-    GrDrawContext(GrContext*, GrDrawTarget*, const SkDeviceProperties&, bool useDFT);
+    GrDrawContext(GrContext*, GrDrawTarget*, const SkDeviceProperties&);
 
     // Sets the paint. Returns true on success; false on failure.
     bool prepareToDraw(GrPipelineBuilder*,
                        GrRenderTarget* rt,
                        const GrClip&,
                        const GrPaint* paint);
-    GrTextContext* createTextContext(GrRenderTarget*, const SkDeviceProperties&, bool useDFT);
+    GrTextContext* createTextContext(GrRenderTarget*, const SkDeviceProperties&);
 
     // A simpler version of the above which just returns true on success; false on failure.  
     // Clip is *NOT* set
@@ -274,7 +274,6 @@
     GrTextContext*      fTextContext; // lazily created
 
     SkDeviceProperties* fDevProps;    // ptr b.c. SkDeviceProperties isn't public
-    bool                fUseDFT;
 };
 
 #endif
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 343bbc8..8e8c102 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -117,7 +117,7 @@
 }
 
 SkBaseDevice* SkBitmapDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) {
-    SkDeviceProperties leaky(cinfo.fPixelGeometry);
+    const SkDeviceProperties leaky(cinfo.fPixelGeometry);
     return SkBitmapDevice::Create(cinfo.fInfo, &leaky);
 }
 
diff --git a/src/core/SkDeviceProperties.h b/src/core/SkDeviceProperties.h
index 85f87bc..53c0fa3 100644
--- a/src/core/SkDeviceProperties.h
+++ b/src/core/SkDeviceProperties.h
@@ -13,20 +13,24 @@
 struct SkDeviceProperties {
     SkDeviceProperties(const SkDeviceProperties& src) 
         : fGamma(src.fGamma)
+        , fUseDFT(src.fUseDFT)
         , fPixelGeometry(src.fPixelGeometry) {
     }
 
     SkDeviceProperties(float gamma = SK_GAMMA_EXPONENT)
         : fGamma(gamma)
+        , fUseDFT(false)
         , fPixelGeometry(SkSurfacePropsDefaultPixelGeometry())
     {}
 
-    SkDeviceProperties(SkPixelGeometry geo, float gamma = SK_GAMMA_EXPONENT)
+    SkDeviceProperties(SkPixelGeometry geo, bool useDFT = false, float gamma = SK_GAMMA_EXPONENT)
         : fGamma(gamma)
+        , fUseDFT(useDFT)
         , fPixelGeometry(geo)
     {}
 
     float gamma() const { return fGamma; }
+    bool useDFT() const { return fUseDFT; }
     SkPixelGeometry pixelGeometry() const { return fPixelGeometry; }
 
     void setPixelGeometry(SkPixelGeometry geo) {
@@ -35,6 +39,7 @@
 
 private:
     const float     fGamma;
+    const bool      fUseDFT;
     SkPixelGeometry fPixelGeometry;
 };
 
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index f2305ad..900d681 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -97,8 +97,7 @@
 
 GrAtlasTextContext::GrAtlasTextContext(GrContext* context,
                                        GrDrawContext* drawContext,
-                                       const SkDeviceProperties& properties,
-                                       bool useDFT)
+                                       const SkDeviceProperties& properties)
     : INHERITED(context, drawContext, properties)
     , fDistanceAdjustTable(SkNEW_ARGS(DistanceAdjustTable, (properties.gamma()))) {
     // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest
@@ -107,12 +106,6 @@
                       vertex_attribute_changed);
     fCurrStrike = NULL;
     fCache = context->getTextBlobCache();
-
-#if SK_FORCE_DISTANCE_FIELD_TEXT
-    fEnableDFRendering = true;
-#else
-    fEnableDFRendering = useDFT;
-#endif
 }
 
 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable(float gamma) {
@@ -199,9 +192,8 @@
 
 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context,
                                                GrDrawContext* drawContext,
-                                               const SkDeviceProperties& props,
-                                               bool useDFT) {
-    return SkNEW_ARGS(GrAtlasTextContext, (context, drawContext, props, useDFT));
+                                               const SkDeviceProperties& props) {
+    return SkNEW_ARGS(GrAtlasTextContext, (context, drawContext, props));
 }
 
 bool GrAtlasTextContext::canDraw(const GrRenderTarget*,
@@ -450,8 +442,12 @@
         return false;
     }
 
-    if (!fEnableDFRendering && !skPaint.isDistanceFieldTextTEMP() &&
-        scaledTextSize < kLargeDFFontSize) {
+    bool useDFT = fDeviceProperties.useDFT();
+#if SK_FORCE_DISTANCE_FIELD_TEXT
+    useDFT = true;
+#endif
+
+    if (!useDFT && !skPaint.isDistanceFieldTextTEMP() && scaledTextSize < kLargeDFFontSize) {
         return false;
     }
 
@@ -2228,13 +2224,12 @@
         gContextID = context->uniqueID();
         SkDELETE(gTextContext);
 
-        static const bool kUseDFT = false;
         // We don't yet test the fall back to paths in the GrTextContext base class.  This is mostly
         // because we don't really want to have a gpu device here.
         // We enable distance fields by twiddling a knob on the paint
-        GrDrawContext* drawContext = context->drawContext(&gDevProperties, kUseDFT);
+        GrDrawContext* drawContext = context->drawContext(&gDevProperties);
 
-        gTextContext = GrAtlasTextContext::Create(context, drawContext, gDevProperties, kUseDFT);
+        gTextContext = GrAtlasTextContext::Create(context, drawContext, gDevProperties);
     }
 
     // create dummy render target
diff --git a/src/gpu/GrAtlasTextContext.h b/src/gpu/GrAtlasTextContext.h
index 47bb7ae..68ec870 100644
--- a/src/gpu/GrAtlasTextContext.h
+++ b/src/gpu/GrAtlasTextContext.h
@@ -35,11 +35,10 @@
  */
 class GrAtlasTextContext : public GrTextContext {
 public:
-    static GrAtlasTextContext* Create(GrContext*, GrDrawContext*,
-                                      const SkDeviceProperties&, bool enableDistanceFields);
+    static GrAtlasTextContext* Create(GrContext*, GrDrawContext*, const SkDeviceProperties&);
 
 private:
-    GrAtlasTextContext(GrContext*, GrDrawContext*, const SkDeviceProperties&, bool useDFT);
+    GrAtlasTextContext(GrContext*, GrDrawContext*, const SkDeviceProperties&);
     ~GrAtlasTextContext() override {}
 
     bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
@@ -385,7 +384,6 @@
 
     GrBatchTextStrike* fCurrStrike;
     GrTextBlobCache* fCache;
-    bool fEnableDFRendering;
     SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable;
 
     friend class GrTextBlobCache;
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index d5f9f9c..03aeaa8 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -111,7 +111,7 @@
     }
 }
 
-GrDrawContext* GrContext::DrawingMgr::drawContext(const SkDeviceProperties* devProps, bool useDFT) { 
+GrDrawContext* GrContext::DrawingMgr::drawContext(const SkDeviceProperties* devProps) { 
     if (this->abandoned()) {
         return NULL;
     }
@@ -122,18 +122,12 @@
     }
 
     SkASSERT(devProps->pixelGeometry() < kNumPixelGeometries);
-    if (!fDrawContext[devProps->pixelGeometry()][useDFT]) {
-        fDrawContext[devProps->pixelGeometry()][useDFT] =
-                SkNEW_ARGS(GrDrawContext, (fContext, fDrawTarget, *devProps, useDFT));
+    if (!fDrawContext[devProps->pixelGeometry()][devProps->useDFT()]) {
+        fDrawContext[devProps->pixelGeometry()][devProps->useDFT()] =
+                SkNEW_ARGS(GrDrawContext, (fContext, fDrawTarget, *devProps));
     }
 
-    SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fDevProps->pixelGeometry() ==
-             devProps->pixelGeometry());
-    SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fDevProps->gamma() == 
-             devProps->gamma());
-    SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fUseDFT == useDFT);
-
-    return fDrawContext[devProps->pixelGeometry()][useDFT]; 
+    return fDrawContext[devProps->pixelGeometry()][devProps->useDFT()]; 
 }
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index 7f97275..6fd24ca 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -34,13 +34,11 @@
 
 GrDrawContext::GrDrawContext(GrContext* context,
                              GrDrawTarget* drawTarget,
-                             const SkDeviceProperties& devProps,
-                             bool useDFT)
+                             const SkDeviceProperties& devProps)
     : fContext(context)
     , fDrawTarget(SkRef(drawTarget))
     , fTextContext(NULL)
-    , fDevProps(SkNEW_ARGS(SkDeviceProperties, (devProps)))
-    , fUseDFT(useDFT) {
+    , fDevProps(SkNEW_ARGS(SkDeviceProperties, (devProps))) {
 }
 
 GrDrawContext::~GrDrawContext() {
@@ -59,19 +57,16 @@
 }
 
 GrTextContext* GrDrawContext::createTextContext(GrRenderTarget* renderTarget,
-                                                const SkDeviceProperties& leakyProperties,
-                                                bool enableDistanceFieldFonts) {
+                                                const SkDeviceProperties& leakyProperties) {
     if (fContext->caps()->shaderCaps()->pathRenderingSupport() &&
         renderTarget->isStencilBufferMultisampled()) {
         GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencilAttachment();
         if (sb) {
-            return GrStencilAndCoverTextContext::Create(fContext, this, 
-                                                        leakyProperties,
-                                                        enableDistanceFieldFonts);
+            return GrStencilAndCoverTextContext::Create(fContext, this, leakyProperties);
         }
     } 
 
-    return GrAtlasTextContext::Create(fContext, this, leakyProperties, enableDistanceFieldFonts);
+    return GrAtlasTextContext::Create(fContext, this, leakyProperties);
 }
 
 void GrDrawContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPaint& grPaint,
@@ -80,7 +75,7 @@
                              const char text[], size_t byteLength,
                              SkScalar x, SkScalar y, const SkIRect& clipBounds) {
     if (!fTextContext) {
-        fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT);
+        fTextContext = this->createTextContext(rt, *fDevProps);
     }
 
     fTextContext->drawText(rt, clip, grPaint, skPaint, viewMatrix,
@@ -94,7 +89,7 @@
                                 const SkScalar pos[], int scalarsPerPosition,
                                 const SkPoint& offset, const SkIRect& clipBounds) {
     if (!fTextContext) {
-        fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT);
+        fTextContext = this->createTextContext(rt, *fDevProps);
     }
 
     fTextContext->drawPosText(rt, clip, grPaint, skPaint, viewMatrix, text, byteLength,
@@ -106,7 +101,7 @@
                                  SkScalar x, SkScalar y,
                                  SkDrawFilter* filter, const SkIRect& clipBounds) {
     if (!fTextContext) {
-        fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT);
+        fTextContext = this->createTextContext(rt, *fDevProps);
     }
 
     fTextContext->drawTextBlob(rt, clip, skPaint, viewMatrix, blob, x, y, filter, clipBounds);
diff --git a/src/gpu/GrStencilAndCoverTextContext.cpp b/src/gpu/GrStencilAndCoverTextContext.cpp
index d1b6a84..d086b3e 100644
--- a/src/gpu/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/GrStencilAndCoverTextContext.cpp
@@ -32,11 +32,10 @@
 
 GrStencilAndCoverTextContext*
 GrStencilAndCoverTextContext::Create(GrContext* context, GrDrawContext* drawContext,
-                                     const SkDeviceProperties& props, bool fallbackUsesDFT) {
+                                     const SkDeviceProperties& props) {
     GrStencilAndCoverTextContext* textContext = SkNEW_ARGS(GrStencilAndCoverTextContext,
                                                            (context, drawContext, props));
-    textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, drawContext,
-                                                                   props, fallbackUsesDFT);
+    textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, drawContext, props);
 
     return textContext;
 }
diff --git a/src/gpu/GrStencilAndCoverTextContext.h b/src/gpu/GrStencilAndCoverTextContext.h
index 920f2d7..f5795d0 100644
--- a/src/gpu/GrStencilAndCoverTextContext.h
+++ b/src/gpu/GrStencilAndCoverTextContext.h
@@ -24,7 +24,7 @@
 class GrStencilAndCoverTextContext : public GrTextContext {
 public:
     static GrStencilAndCoverTextContext* Create(GrContext*, GrDrawContext*,
-                                                const SkDeviceProperties&, bool fallbackUsesDFT);
+                                                const SkDeviceProperties&);
 
     virtual ~GrStencilAndCoverTextContext();
 
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 07c8dc1..c506959 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -136,7 +136,7 @@
 
 static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* props) {
     if (props) {
-        return SkDeviceProperties(props->pixelGeometry());
+        return SkDeviceProperties(props->pixelGeometry(), props->isUseDistanceFieldFonts());
     } else {
         return SkDeviceProperties();
     }
@@ -167,8 +167,7 @@
     fLegacyBitmap.setInfo(info);
     fLegacyBitmap.setPixelRef(pr)->unref();
 
-    bool useDFT = fSurfaceProps.isUseDistanceFieldFonts();
-    fDrawContext.reset(SkRef(fContext->drawContext(&this->getLeakyProperties(), useDFT)));
+    fDrawContext.reset(SkRef(fContext->drawContext(&this->getLeakyProperties())));
 }
 
 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::Budgeted budgeted,
@@ -353,9 +352,7 @@
     SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (fRenderTarget->surfacePriv().info(), fRenderTarget));
     fLegacyBitmap.setPixelRef(pr)->unref();
 
-    bool useDFT = fSurfaceProps.isUseDistanceFieldFonts();
-    fDrawContext.reset(SkRef(fRenderTarget->getContext()->drawContext(&this->getLeakyProperties(),
-                                                                      useDFT)));
+    fDrawContext.reset(SkRef(fRenderTarget->getContext()->drawContext(&this->getLeakyProperties())));
 }
 
 ///////////////////////////////////////////////////////////////////////////////