Get gpudft support working in dm, gm, nanobench and bench_pictures

Adds a new config to test distance field text.
Clean up some flags and #defines to read "distance field text",
not "distance field fonts" to be consistent with Chromium

NOTREECHECKS=true

Committed: https://skia.googlesource.com/skia/+/06ba179838ba4fe187cf290750aeeb4a02a2960b

Review URL: https://codereview.chromium.org/699453005
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index aade590..1f5ae60 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -283,8 +283,10 @@
     int samples;
 #if SK_SUPPORT_GPU
     GrContextFactory::GLContextType ctxType;
+    bool useDFText;
 #else
     int bogusInt;
+    bool bogusBool;
 #endif
 };
 
@@ -327,10 +329,11 @@
 
 // Append all configs that are enabled and supported.
 static void create_configs(SkTDArray<Config>* configs) {
-    #define CPU_CONFIG(name, backend, color, alpha)                                               \
-        if (is_cpu_config_allowed(#name)) {                                                       \
-            Config config = { #name, Benchmark::backend, color, alpha, 0, kBogusGLContextType };  \
-            configs->push(config);                                                                \
+    #define CPU_CONFIG(name, backend, color, alpha)                       \
+        if (is_cpu_config_allowed(#name)) {                               \
+            Config config = { #name, Benchmark::backend, color, alpha, 0, \
+                              kBogusGLContextType, false };               \
+            configs->push(config);                                        \
         }
 
     if (FLAGS_cpu) {
@@ -340,7 +343,7 @@
     }
 
 #if SK_SUPPORT_GPU
-    #define GPU_CONFIG(name, ctxType, samples)                                   \
+    #define GPU_CONFIG(name, ctxType, samples, useDFText)                        \
         if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) {  \
             Config config = {                                                    \
                 #name,                                                           \
@@ -348,20 +351,22 @@
                 kN32_SkColorType,                                                \
                 kPremul_SkAlphaType,                                             \
                 samples,                                                         \
-                GrContextFactory::ctxType };                                     \
+                GrContextFactory::ctxType,                                       \
+                useDFText };                                                     \
             configs->push(config);                                               \
         }
 
     if (FLAGS_gpu) {
-        GPU_CONFIG(gpu, kNative_GLContextType, 0)
-        GPU_CONFIG(msaa4, kNative_GLContextType, 4)
-        GPU_CONFIG(msaa16, kNative_GLContextType, 16)
-        GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4)
-        GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16)
-        GPU_CONFIG(debug, kDebug_GLContextType, 0)
-        GPU_CONFIG(nullgpu, kNull_GLContextType, 0)
+        GPU_CONFIG(gpu, kNative_GLContextType, 0, false)
+        GPU_CONFIG(msaa4, kNative_GLContextType, 4, false)
+        GPU_CONFIG(msaa16, kNative_GLContextType, 16, false)
+        GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4, false)
+        GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16, false)
+        GPU_CONFIG(gpudft, kNative_GLContextType, 0, true)
+        GPU_CONFIG(debug, kDebug_GLContextType, 0, false)
+        GPU_CONFIG(nullgpu, kNull_GLContextType, 0, false)
 #ifdef SK_ANGLE
-        GPU_CONFIG(angle, kANGLE_GLContextType, 0)
+        GPU_CONFIG(angle, kANGLE_GLContextType, 0, false)
 #endif
     }
 #endif
@@ -383,8 +388,10 @@
     }
 #if SK_SUPPORT_GPU
     else if (Benchmark::kGPU_Backend == config.backend) {
+        uint32_t flags = config.useDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
+        SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
         target->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(config.ctxType), info,
-                                                         config.samples));
+                                                         config.samples, &props));
         target->gl = gGrFactory->getGLContext(config.ctxType);
     }
 #endif
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 2a0c636..52c86d5 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -86,18 +86,19 @@
 
             START("565",        CpuGMTask, kRGB_565_SkColorType);
             START("8888",       CpuGMTask, kN32_SkColorType);
-            START("gpu",        GpuGMTask, native, gpuAPI, 0);
-            START("msaa4",      GpuGMTask, native, gpuAPI, 4);
-            START("msaa16",     GpuGMTask, native, gpuAPI, 16);
-            START("nvprmsaa4",  GpuGMTask, nvpr,   gpuAPI, 4);
-            START("nvprmsaa16", GpuGMTask, nvpr,   gpuAPI, 16);
-            START("gpunull",    GpuGMTask, null,   gpuAPI, 0);
-            START("gpudebug",   GpuGMTask, debug,  gpuAPI, 0);
+            START("gpu",        GpuGMTask, native, gpuAPI, 0,  false);
+            START("msaa4",      GpuGMTask, native, gpuAPI, 4,  false);
+            START("msaa16",     GpuGMTask, native, gpuAPI, 16, false);
+            START("nvprmsaa4",  GpuGMTask, nvpr,   gpuAPI, 4,  false);
+            START("nvprmsaa16", GpuGMTask, nvpr,   gpuAPI, 16, false);
+            START("gpudft",     GpuGMTask, native, gpuAPI, 0,  true);
+            START("gpunull",    GpuGMTask, null,   gpuAPI, 0,  false);
+            START("gpudebug",   GpuGMTask, debug,  gpuAPI, 0,  false);
 #if SK_ANGLE
-            START("angle",      GpuGMTask, angle,  gpuAPI, 0);
+            START("angle",      GpuGMTask, angle,  gpuAPI, 0,  false);
 #endif
 #if SK_MESA
-            START("mesa",       GpuGMTask, mesa,   gpuAPI, 0);
+            START("mesa",       GpuGMTask, mesa,   gpuAPI, 0,  false);
 #endif
             START("pdf",        PDFTask,   RASTERIZE_PDF_PROC);
         }
diff --git a/dm/DMGpuGMTask.cpp b/dm/DMGpuGMTask.cpp
index 2890483..9347ebd 100644
--- a/dm/DMGpuGMTask.cpp
+++ b/dm/DMGpuGMTask.cpp
@@ -13,13 +13,15 @@
                      skiagm::GMRegistry::Factory gmFactory,
                      GrContextFactory::GLContextType contextType,
                      GrGLStandard gpuAPI,
-                     int sampleCount)
+                     int sampleCount,
+                     bool useDFText)
     : GpuTask(reporter, taskRunner)
     , fGM(gmFactory(NULL))
     , fName(UnderJoin(fGM->getName(), config))
     , fContextType(contextType)
     , fGpuAPI(gpuAPI)
     , fSampleCount(sampleCount)
+    , fUseDFText(useDFText)
     {}
 
 static bool gAlreadyWarned[GrContextFactory::kGLContextTypeCnt][kGrGLStandardCnt];
@@ -30,7 +32,7 @@
                                          kN32_SkColorType,
                                          kPremul_SkAlphaType);
     SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, fGpuAPI, info,
-                                                  fSampleCount));
+                                                  fSampleCount, fUseDFText));
     if (!surface) {
         if (!gAlreadyWarned[fContextType][fGpuAPI]) {
             SkDebugf("FYI: couldn't create GPU context, type %d API %d.  Will skip.\n",
diff --git a/dm/DMGpuGMTask.h b/dm/DMGpuGMTask.h
index 23f3a45..553436d 100644
--- a/dm/DMGpuGMTask.h
+++ b/dm/DMGpuGMTask.h
@@ -22,7 +22,8 @@
               skiagm::GMRegistry::Factory,
               GrContextFactory::GLContextType,
               GrGLStandard gpuAPI,
-              int sampleCount);
+              int sampleCount,
+              bool useDFText);
 
     virtual void draw(GrContextFactory*) SK_OVERRIDE;
     virtual bool shouldSkip() const SK_OVERRIDE;
@@ -34,6 +35,7 @@
     const GrContextFactory::GLContextType fContextType;
     GrGLStandard fGpuAPI;
     const int fSampleCount;
+    const bool fUseDFText;
 };
 
 }  // namespace DM
diff --git a/dm/DMGpuSupport.h b/dm/DMGpuSupport.h
index 90b0ea5..33d8995 100644
--- a/dm/DMGpuSupport.h
+++ b/dm/DMGpuSupport.h
@@ -21,8 +21,11 @@
                                        GrContextFactory::GLContextType type,
                                        GrGLStandard gpuAPI,
                                        SkImageInfo info,
-                                       int samples) {
-    return SkSurface::NewRenderTarget(grFactory->get(type, gpuAPI), info, samples, NULL);
+                                       int samples,
+                                       bool useDFText) {
+    uint32_t flags = useDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
+    SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
+    return SkSurface::NewRenderTarget(grFactory->get(type, gpuAPI), info, samples, &props);
 }
 
 }  // namespace DM
@@ -62,7 +65,8 @@
                                        GrContextFactory::GLContextType,
                                        GrGLStandard,
                                        SkImageInfo,
-                                       int) {
+                                       int,
+                                       bool) {
     return NULL;
 }
 
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index cd3f03a..606b7f7 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -151,6 +151,9 @@
     /* Read reference GM images if a read path is provided. */
     kRead_ConfigFlag  = 0x2,
     kRW_ConfigFlag    = (kWrite_ConfigFlag | kRead_ConfigFlag),
+    /* Use distance fields for rendering text */
+    kDFText_ConfigFlag = 0x4,
+    kRWDFT_ConfigFlag = (kRW_ConfigFlag | kDFText_ConfigFlag),
 };
 
 struct ConfigData {
@@ -584,7 +587,10 @@
         }
 #if SK_SUPPORT_GPU
         else {  // GPU
-            surface.reset(SkSurface::NewRenderTargetDirect(gpuTarget->asRenderTarget()));
+            uint32_t flags = (gRec.fFlags & kDFText_ConfigFlag) ?
+                             SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
+            SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
+            surface.reset(SkSurface::NewRenderTargetDirect(gpuTarget->asRenderTarget(), &props));
             if (deferred) {
                 canvas.reset(SkDeferredCanvas::Create(surface));
             } else {
@@ -1291,6 +1297,7 @@
     { kN32_SkColorType, kGPU_Backend,    GrContextFactory::kNative_GLContextType,  4, kRW_ConfigFlag,    "msaa4",        false},
     { kN32_SkColorType, kGPU_Backend,    GrContextFactory::kNVPR_GLContextType,    4, kRW_ConfigFlag,    "nvprmsaa4",   true },
     { kN32_SkColorType, kGPU_Backend,    GrContextFactory::kNVPR_GLContextType,   16, kRW_ConfigFlag,    "nvprmsaa16",  false},
+    { kN32_SkColorType, kGPU_Backend,    GrContextFactory::kNative_GLContextType,  0, kRWDFT_ConfigFlag, "gpudft",       true },
     /* The gpudebug context does not generate meaningful images, so don't record
      * the images it generates!  We only run it to look for asserts. */
     { kN32_SkColorType, kGPU_Backend,    GrContextFactory::kDebug_GLContextType,   0, kNone_ConfigFlag,  "gpudebug",     kDebugOnly},
diff --git a/gyp/common_conditions.gypi b/gyp/common_conditions.gypi
index d9c0487..dd701dd 100644
--- a/gyp/common_conditions.gypi
+++ b/gyp/common_conditions.gypi
@@ -5,7 +5,7 @@
     'SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=<(skia_static_initializers)',
     'SK_SUPPORT_GPU=<(skia_gpu)',
     'SK_SUPPORT_OPENCL=<(skia_opencl)',
-    'SK_FORCE_DISTANCEFIELD_FONTS=<(skia_force_distancefield_fonts)',
+    'SK_FORCE_DISTANCE_FIELD_TEXT=<(skia_force_distance_field_text)',
   ],
   'conditions' : [
     ['skia_pic', {
diff --git a/gyp/common_variables.gypi b/gyp/common_variables.gypi
index ab25eef..09d84ec 100644
--- a/gyp/common_variables.gypi
+++ b/gyp/common_variables.gypi
@@ -152,7 +152,7 @@
       'skia_win_debuggers_path%': '',
       'skia_shared_lib%': 0,
       'skia_opencl%': 0,
-      'skia_force_distancefield_fonts%': 0,
+      'skia_force_distance_field_text%': 0,
 
       # These variables determine the default optimization level for different
       # compilers.
@@ -231,7 +231,7 @@
     'skia_profile_enabled%': '<(skia_profile_enabled)',
     'skia_shared_lib%': '<(skia_shared_lib)',
     'skia_opencl%': '<(skia_opencl)',
-    'skia_force_distancefield_fonts%': '<(skia_force_distancefield_fonts)',
+    'skia_force_distance_field_text%': '<(skia_force_distance_field_text)',
     'skia_static_initializers%': '<(skia_static_initializers)',
     'ios_sdk_version%': '6.0',
     'skia_win_debuggers_path%': '<(skia_win_debuggers_path)',
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index 1976cf1..58c8121 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -64,7 +64,7 @@
                                                        const SkDeviceProperties& properties,
                                                        bool enable)
                                                     : GrTextContext(context, properties) {
-#if SK_FORCE_DISTANCEFIELD_FONTS
+#if SK_FORCE_DISTANCE_FIELD_TEXT
     fEnableDFRendering = true;
 #else
     fEnableDFRendering = enable;
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index da81c69..96c0714 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -67,7 +67,7 @@
 
 #define DO_DEFERRED_CLEAR()             \
     do {                                \
-        if (fNeedClear) {               \
+        if (fFlags & kNeedClear_Flag) {  \
             this->clear(SK_ColorTRANSPARENT); \
         }                               \
     } while (false)                     \
@@ -137,7 +137,7 @@
 
     fContext = SkRef(surface->getContext());
 
-    fNeedClear = flags & kNeedClear_Flag;
+    fFlags = flags;
 
     fRenderTarget = SkRef(surface->asRenderTarget());
 
@@ -148,8 +148,8 @@
 
     this->setPixelGeometry(props.pixelGeometry());
 
-    bool useDFFonts = !!(flags & kDFFonts_Flag);
-    fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProperties(), useDFFonts);
+    bool useDFT = SkToBool(flags & kDFText_Flag);
+    fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProperties(), useDFT);
 }
 
 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo,
@@ -310,7 +310,7 @@
     GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clear", fContext);
     SkIRect rect = SkIRect::MakeWH(this->width(), this->height());
     fContext->clear(&rect, SkColor2GrColor(color), true, fRenderTarget);
-    fNeedClear = false;
+    fFlags &= ~kNeedClear_Flag;
 }
 
 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
@@ -1473,7 +1473,7 @@
     // clear of the source device must occur before CHECK_SHOULD_DRAW
     GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext);
     SkGpuDevice* dev = static_cast<SkGpuDevice*>(device);
-    if (dev->fNeedClear) {
+    if (dev->fFlags & kNeedClear_Flag) {
         // TODO: could check here whether we really need to draw at all
         dev->clear(0x0);
     }
@@ -1763,6 +1763,8 @@
     SkAutoTUnref<GrTexture> texture;
     // Skia's convention is to only clear a device if it is non-opaque.
     unsigned flags = info.isOpaque() ? 0 : kNeedClear_Flag;
+    // If we're using distance field text, enable in the new device
+    flags |= (fFlags & kDFText_Flag) ? kDFText_Flag : 0;
 
 #if CACHE_COMPATIBLE_DEVICE_TEXTURES
     // layers are never draw in repeat modes, so we can request an approx
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index 6a68eeb..6bba974 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -34,7 +34,7 @@
 public:
     enum Flags {
         kNeedClear_Flag = 1 << 0,  //!< Surface requires an initial clear
-        kDFFonts_Flag   = 1 << 1,  //!< Surface should render fonts using signed distance fields
+        kDFText_Flag   = 1 << 1,  //!< Surface should render text using signed distance fields
     };
 
     /**
@@ -136,8 +136,8 @@
     GrTextContext*  fTextContext;
 
     // state for our render-target
-    GrRenderTarget*     fRenderTarget;
-    bool                fNeedClear;
+    GrRenderTarget* fRenderTarget;
+    uint32_t        fFlags;
 
     // remove when our clients don't rely on accessBitmap()
     SkBitmap fLegacyBitmap;
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 3e1eb94..1555c9a 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -39,7 +39,7 @@
                              bool doClear)
         : INHERITED(renderTarget->width(), renderTarget->height(), props) {
     int deviceFlags = 0;
-    deviceFlags |= this->props().isUseDistanceFieldFonts() ? SkGpuDevice::kDFFonts_Flag : 0;
+    deviceFlags |= this->props().isUseDistanceFieldFonts() ? SkGpuDevice::kDFText_Flag : 0;
     fDevice = SkGpuDevice::Create(renderTarget, this->props(), deviceFlags);
 
     if (kRGB_565_GrPixelConfig != renderTarget->config() && doClear) {
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index e4a6998..1c31e68 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -161,8 +161,10 @@
                 return NULL;
             }
 
+            uint32_t flags = fUseDFText ? SkGpuDevice::kDFText_Flag : 0;
             SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(target,
-                                         SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)));
+                                         SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
+                                         flags));
             canvas = SkNEW_ARGS(SkCanvas, (device.get()));
             break;
         }
diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h
index e82eb7f..c8462d9 100644
--- a/tools/PictureRenderer.h
+++ b/tools/PictureRenderer.h
@@ -220,6 +220,10 @@
     void setSampleCount(int sampleCount) {
         fSampleCount = sampleCount;
     }
+
+    void setUseDFText(bool useDFText) {
+        fUseDFText = useDFText;
+    }
 #endif
 
     void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) {
@@ -274,6 +278,8 @@
             case kGPU_DeviceType:
                 if (fSampleCount) {
                     config.appendf("_msaa%d", fSampleCount);
+                } else if (fUseDFText) {
+                    config.append("_gpudft");
                 } else {
                     config.append("_gpu");
                 }
@@ -325,6 +331,8 @@
                     tmp = "msaa";
                     tmp.appendS32(fSampleCount);
                     result["config"] = tmp.c_str();
+                } else if (fUseDFText) {
+                    result["config"] = "gpudft";
                 } else {
                     result["config"] = "gpu";
                 }
@@ -428,6 +436,7 @@
         , fGrContextFactory(opts)
         , fGrContext(NULL)
         , fSampleCount(0)
+        , fUseDFText(false)
 #endif
         {
             fGridInfo.fMargin.setEmpty();
@@ -495,6 +504,7 @@
     GrContextFactory       fGrContextFactory;
     GrContext*             fGrContext;
     int                    fSampleCount;
+    bool                   fUseDFText;
 #endif
 
     virtual SkString getConfigNameInternal() = 0;
diff --git a/tools/PictureRenderingFlags.cpp b/tools/PictureRenderingFlags.cpp
index d78229a..ac72cad 100644
--- a/tools/PictureRenderingFlags.cpp
+++ b/tools/PictureRenderingFlags.cpp
@@ -28,7 +28,7 @@
 #if SK_SUPPORT_GPU
 static const char kGpuAPINameGL[] = "gl";
 static const char kGpuAPINameGLES[] = "gles";
-#define GPU_CONFIG_STRING "|gpu|msaa4|msaa16|nvprmsaa4|nvprmsaa16"
+#define GPU_CONFIG_STRING "|gpu|msaa4|msaa16|nvprmsaa4|nvprmsaa16|gpudft"
 #else
 #define GPU_CONFIG_STRING ""
 #endif
@@ -286,6 +286,7 @@
     }
 
     int sampleCount = 0;
+    bool useDFText = false;
 #endif
     if (FLAGS_config.count() > 0) {
         if (0 == strcmp(FLAGS_config[0], "8888")) {
@@ -311,6 +312,10 @@
             deviceType = sk_tools::PictureRenderer::kNVPR_DeviceType;
             sampleCount = 16;
         }
+        else if (0 == strcmp(FLAGS_config[0], "gpudft")) {
+            deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
+            useDFText = true;
+        }
 #if SK_ANGLE
         else if (0 == strcmp(FLAGS_config[0], "angle")) {
             deviceType = sk_tools::PictureRenderer::kAngle_DeviceType;
@@ -336,6 +341,7 @@
         }
 #if SK_SUPPORT_GPU
         renderer->setSampleCount(sampleCount);
+        renderer->setUseDFText(useDFText);
 #endif
     }
 
diff --git a/tools/flags/SkCommonFlags.cpp b/tools/flags/SkCommonFlags.cpp
index 4d329c5..c7fc17f 100644
--- a/tools/flags/SkCommonFlags.cpp
+++ b/tools/flags/SkCommonFlags.cpp
@@ -9,7 +9,7 @@
 
 DEFINE_string(config, "565 8888 pdf gpu nonrendering angle nvprmsaa4",
               "Options: 565 8888 pdf gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 "
-              "gpunull gpudebug angle mesa");
+              "gpudft gpunull gpudebug angle mesa");
 
 DEFINE_bool(cpu, true, "master switch for running CPU-bound work.");