Stop supporting HW dither

Review URL: https://codereview.chromium.org/1359833004
diff --git a/gm/constcolorprocessor.cpp b/gm/constcolorprocessor.cpp
index 23400e3..40eb1a0 100644
--- a/gm/constcolorprocessor.cpp
+++ b/gm/constcolorprocessor.cpp
@@ -104,8 +104,7 @@
                     } else {
                         skPaint.setColor(kPaintColors[paintType]);
                     }
-                    SkAssertResult(SkPaint2GrPaint(context, rt, skPaint, viewMatrix, false,
-                                                   &grPaint));
+                    SkAssertResult(SkPaint2GrPaint(context, skPaint, viewMatrix, false, &grPaint));
 
                     GrConstColorProcessor::InputMode mode = (GrConstColorProcessor::InputMode) m;
                     GrColor color = kColors[procColor];
diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h
index 51a4921..d52c6ba 100644
--- a/include/gpu/GrPaint.h
+++ b/include/gpu/GrPaint.h
@@ -57,12 +57,6 @@
     void setAntiAlias(bool aa) { fAntiAlias = aa; }
     bool isAntiAlias() const { return fAntiAlias; }
 
-    /**
-     * Should dithering be applied. Defaults to false.
-     */
-    void setDither(bool dither) { fDither = dither; }
-    bool isDither() const { return fDither; }
-
     const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
         fXPFactory.reset(SkRef(xpFactory));
         return xpFactory;
@@ -122,7 +116,6 @@
 
     GrPaint& operator=(const GrPaint& paint) {
         fAntiAlias = paint.fAntiAlias;
-        fDither = paint.fDither;
 
         fColor = paint.fColor;
         this->resetFragmentProcessors();
@@ -169,7 +162,6 @@
     SkSTArray<2, const GrFragmentProcessor*, true>  fCoverageFragmentProcessors;
 
     bool                                            fAntiAlias;
-    bool                                            fDither;
 
     GrColor                                         fColor;
     GrProcessorDataManager                          fProcDataManager;
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index 2d1b95d..145d409 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -115,14 +115,14 @@
 // an optimization where the color filter can be applied to the SkPaint's
 // color once while converting to GrPaint and then ignored. TODO: Remove this
 // bool and use the invariant info to automatically apply the color filter.
-bool SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget*, const SkPaint& skPaint,
-                             GrColor paintColor, bool constantColor, GrPaint* grPaint);
+bool SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor paintColor,
+                             bool constantColor, GrPaint* grPaint);
 
 // This function is similar to skPaint2GrPaintNoShader but also converts
 // skPaint's shader to a GrFragmentProcessor if possible.
 // constantColor has the same meaning as in skPaint2GrPaintNoShader.
-bool SkPaint2GrPaint(GrContext* context, GrRenderTarget*, const SkPaint& skPaint,
-                     const SkMatrix& viewM, bool constantColor, GrPaint* grPaint);
+bool SkPaint2GrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix& viewM,
+                     bool constantColor, GrPaint* grPaint);
 
 
 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque);
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index 822c480..81cc647 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -389,7 +389,7 @@
     // Though for the time being runs in the textblob can override the paint, they only touch font
     // info.
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(fContext, rt, skPaint, viewMatrix, true, &grPaint)) {
+    if (!SkPaint2GrPaint(fContext, skPaint, viewMatrix, true, &grPaint)) {
         return;
     }
 
@@ -2265,7 +2265,7 @@
     skPaint.setSubpixelText(random->nextBool());
 
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(context, rt, skPaint, viewMatrix, true, &grPaint)) {
+    if (!SkPaint2GrPaint(context, skPaint, viewMatrix, true, &grPaint)) {
         SkFAIL("couldn't convert paint\n");
     }
 
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index d37f9bf..b601a20 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -197,7 +197,7 @@
     SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;)
 
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(context, renderTarget, paint, viewMatrix, true, &grPaint)) {
+    if (!SkPaint2GrPaint(context, paint, viewMatrix, true, &grPaint)) {
         return;
     }
 
diff --git a/src/gpu/GrPaint.cpp b/src/gpu/GrPaint.cpp
index 3b38368..4a9f417 100644
--- a/src/gpu/GrPaint.cpp
+++ b/src/gpu/GrPaint.cpp
@@ -15,7 +15,6 @@
 
 GrPaint::GrPaint()
     : fAntiAlias(false)
-    , fDither(false)
     , fColor(GrColor_WHITE) {}
 
 void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
diff --git a/src/gpu/GrPipeline.cpp b/src/gpu/GrPipeline.cpp
index 1d7b71f..80e3cbd 100644
--- a/src/gpu/GrPipeline.cpp
+++ b/src/gpu/GrPipeline.cpp
@@ -66,9 +66,6 @@
     if (builder.isHWAntialias()) {
         pipeline->fFlags |= kHWAA_Flag;
     }
-    if (builder.isDither()) {
-        pipeline->fFlags |= kDither_Flag;
-    }
     if (builder.snapVerticesToPixelCenters()) {
         pipeline->fFlags |= kSnapVertices_Flag;
     }
diff --git a/src/gpu/GrPipeline.h b/src/gpu/GrPipeline.h
index b7e8b1f..df44ba6 100644
--- a/src/gpu/GrPipeline.h
+++ b/src/gpu/GrPipeline.h
@@ -120,7 +120,6 @@
 
     const GrScissorState& getScissorState() const { return fScissorState; }
 
-    bool isDitherState() const { return SkToBool(fFlags & kDither_Flag); }
     bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); }
     bool snapVerticesToPixelCenters() const { return SkToBool(fFlags & kSnapVertices_Flag); }
 
@@ -162,9 +161,8 @@
                             const GrCaps&);
 
     enum Flags {
-        kDither_Flag            = 0x1,
-        kHWAA_Flag              = 0x2,
-        kSnapVertices_Flag      = 0x4,
+        kHWAA_Flag              = 0x1,
+        kSnapVertices_Flag      = 0x2,
     };
 
     typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget;
diff --git a/src/gpu/GrPipelineBuilder.cpp b/src/gpu/GrPipelineBuilder.cpp
index dbef6e8..ab18550 100644
--- a/src/gpu/GrPipelineBuilder.cpp
+++ b/src/gpu/GrPipelineBuilder.cpp
@@ -42,7 +42,6 @@
 
     fClip = clip;
 
-    this->setState(GrPipelineBuilder::kDither_Flag, paint.isDither());
     this->setState(GrPipelineBuilder::kHWAntialias_Flag,
                    rt->isUnifiedMultisampled() && paint.isAntiAlias());
 }
diff --git a/src/gpu/GrPipelineBuilder.h b/src/gpu/GrPipelineBuilder.h
index e37b54a..e2a7bc7 100644
--- a/src/gpu/GrPipelineBuilder.h
+++ b/src/gpu/GrPipelineBuilder.h
@@ -296,25 +296,20 @@
      */
     enum Flags {
         /**
-         * Perform dithering. TODO: Re-evaluate whether we need this bit
-         */
-        kDither_Flag        = 0x01,
-        /**
          * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
          * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
          * the 3D API.
          */
-        kHWAntialias_Flag   = 0x02,
+        kHWAntialias_Flag   = 0x01,
 
         /**
          * Modifies the vertex shader so that vertices will be positioned at pixel centers.
          */
-        kSnapVerticesToPixelCenters_Flag = 0x04,
+        kSnapVerticesToPixelCenters_Flag = 0x02,
 
         kLast_Flag = kSnapVerticesToPixelCenters_Flag,
     };
 
-    bool isDither() const { return SkToBool(fFlags & kDither_Flag); }
     bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); }
     bool snapVerticesToPixelCenters() const {
         return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); }
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 6ab730c..32c056f 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -130,7 +130,7 @@
         runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint));
 
         GrPaint grPaint;
-        if (!SkPaint2GrPaint(fContext, rt, runPaint, viewMatrix, true, &grPaint)) {
+        if (!SkPaint2GrPaint(fContext, runPaint, viewMatrix, true, &grPaint)) {
             return;
         }
 
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index d897f3c..0920605 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -383,7 +383,7 @@
     GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext);
 
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) {
+    if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) {
         return;
     }
 
@@ -432,8 +432,7 @@
     if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
         GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style);
         GrPaint grPaint;
-        if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true,
-                             &grPaint)) {
+        if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) {
             return;
         }
         SkPath path;
@@ -453,7 +452,7 @@
     }
 
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) {
+    if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) {
         return;
     }
 
@@ -516,7 +515,7 @@
     }
 
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) {
+    if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) {
         return;
     }
 
@@ -532,7 +531,7 @@
     CHECK_SHOULD_DRAW(draw);
 
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) {
+    if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) {
         return;
     }
 
@@ -603,8 +602,7 @@
         CHECK_SHOULD_DRAW(draw);
 
         GrPaint grPaint;
-        if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true,
-                             &grPaint)) {
+        if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) {
             return;
         }
 
@@ -656,7 +654,7 @@
     }
 
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) {
+    if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) {
         return;
     }
 
@@ -1011,8 +1009,8 @@
 
     // The bitmap read has to be first
     grPaint.addColorFragmentProcessor(fp);
-    if (!SkPaint2GrPaintNoShader(context, renderTarget, paint, SkColor2GrColor(paint.getColor()),
-                                 false, &grPaint)) {
+    if (!SkPaint2GrPaintNoShader(context, paint, SkColor2GrColor(paint.getColor()), false,
+                                 &grPaint)) {
         return;
     }
 
@@ -1358,8 +1356,7 @@
     bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType());
     GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()) :
                                        SkColor2GrColor(paint.getColor());
-    if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, paintColor, false,
-                                 &grPaint)) {
+    if (!SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grPaint)) {
         return;
     }
 
@@ -1432,7 +1429,7 @@
     GrPaint grPaint;
     grPaint.addColorTextureProcessor(texture, SkMatrix::I());
 
-    if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint,
+    if (!SkPaint2GrPaintNoShader(this->context(), paint,
                                  SkColor2GrColorJustAlpha(paint.getColor()), false, &grPaint)) {
         return;
     }
@@ -1547,7 +1544,7 @@
     GrPaint grPaint;
     grPaint.addColorTextureProcessor(devTex, SkMatrix::I());
 
-    if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint,
+    if (!SkPaint2GrPaintNoShader(this->context(), paint,
                                  SkColor2GrColorJustAlpha(paint.getColor()), false, &grPaint)) {
         return;
     }
@@ -1684,7 +1681,7 @@
         copy.setStrokeWidth(0);
 
         // we ignore the shader if texs is null.
-        if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, copy,
+        if (!SkPaint2GrPaintNoShader(this->context(), copy,
                                      SkColor2GrColor(copy.getColor()), nullptr == colors, &grPaint)) {
             return;
         }
@@ -1726,13 +1723,13 @@
         primType = gVertexMode2PrimitiveType[vmode];
 
         if (nullptr == texs || nullptr == paint.getShader()) {
-            if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint,
+            if (!SkPaint2GrPaintNoShader(this->context(), paint,
                                          SkColor2GrColor(paint.getColor()),
                                          nullptr == colors, &grPaint)) {
                 return;
             }
         } else {
-            if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix,
+            if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix,
                                  nullptr == colors, &grPaint)) {
                 return;
             }
@@ -1792,7 +1789,7 @@
     p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode))->unref();
 
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(this->context(), fRenderTarget, p, *draw.fMatrix, !colors, &grPaint)) {
+    if (!SkPaint2GrPaint(this->context(), p, *draw.fMatrix, !colors, &grPaint)) {
         return;
     }
     
@@ -1820,7 +1817,7 @@
     GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext);
 
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) {
+    if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) {
         return;
     }
 
@@ -1837,7 +1834,7 @@
     CHECK_SHOULD_DRAW(draw);
 
     GrPaint grPaint;
-    if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) {
+    if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) {
         return;
     }
 
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 9ab2f63..09c83b9 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -708,10 +708,9 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-bool SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget* rt, const SkPaint& skPaint,
-                             GrColor paintColor, bool constantColor, GrPaint* grPaint) {
+bool SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor paintColor,
+                             bool constantColor, GrPaint* grPaint) {
 
-    grPaint->setDither(skPaint.isDither());
     grPaint->setAntiAlias(skPaint.isAntiAlias());
 
     SkXfermode* mode = skPaint.getXfermode();
@@ -748,34 +747,18 @@
     }
 
 #ifndef SK_IGNORE_GPU_DITHER
-    // If the dither flag is set, then we need to see if the underlying context
-    // supports it. If not, then install a dither effect.
     if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0) {
-        // What are we rendering into?
-        SkASSERT(rt);
-
-        // Suspect the dithering flag has no effect on these configs, otherwise
-        // fall back on setting the appropriate state.
-        if (GrPixelConfigIs8888(rt->config()) ||
-            GrPixelConfigIs8888(rt->config())) {
-            // The dither flag is set and the target is likely
-            // not going to be dithered by the GPU.
-            SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create());
-            if (fp.get()) {
-                grPaint->addColorFragmentProcessor(fp);
-                grPaint->setDither(false);
-            }
-        }
+        grPaint->addColorFragmentProcessor(GrDitherEffect::Create())->unref();
     }
 #endif
     return true;
 }
 
-bool SkPaint2GrPaint(GrContext* context, GrRenderTarget* rt, const SkPaint& skPaint,
-                     const SkMatrix& viewM, bool constantColor, GrPaint* grPaint) {
+bool SkPaint2GrPaint(GrContext* context,const SkPaint& skPaint, const SkMatrix& viewM,
+                     bool constantColor, GrPaint* grPaint) {
     SkShader* shader = skPaint.getShader();
     if (nullptr == shader) {
-        return SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skPaint.getColor()),
+        return SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getColor()),
                                        constantColor, grPaint);
     }
 
@@ -791,7 +774,7 @@
 
     // The grcolor is automatically set when calling asFragmentProcessor.
     // If the shader can be seen as an effect it returns true and adds its effect to the grpaint.
-    return SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantColor, grPaint);
+    return SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint);
 }
 
 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque) {
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index c07f704..cb12fef 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -286,7 +286,6 @@
         GL_CALL(DepthMask(GR_GL_FALSE));
 
         fHWDrawFace = GrPipelineBuilder::kInvalid_DrawFace;
-        fHWDitherEnabled = kUnknown_TriState;
 
         if (kGL_GrGLStandard == this->glStandard()) {
             // Desktop-only state that we never change
@@ -323,6 +322,7 @@
         fHWWriteToColor = kUnknown_TriState;
         // we only ever use lines in hairline mode
         GL_CALL(LineWidth(1));
+        GL_CALL(Disable(GR_GL_DITHER));
     }
 
     if (resetBits & kMSAAEnable_GrGLBackendState) {
@@ -1445,7 +1445,6 @@
     const GrPipeline& pipeline = *args.fPipeline;
     args.fPipeline->getXferProcessor()->getBlendInfo(&blendInfo);
 
-    this->flushDither(pipeline.isDitherState());
     this->flushColorWrite(blendInfo.fWriteColor);
     this->flushDrawFace(pipeline.getDrawFace());
 
@@ -2344,20 +2343,6 @@
     texture->setCachedTexParams(newTexParams, this->getResetTimestamp());
 }
 
-void GrGLGpu::flushDither(bool dither) {
-    if (dither) {
-        if (kYes_TriState != fHWDitherEnabled) {
-            GL_CALL(Enable(GR_GL_DITHER));
-            fHWDitherEnabled = kYes_TriState;
-        }
-    } else {
-        if (kNo_TriState != fHWDitherEnabled) {
-            GL_CALL(Disable(GR_GL_DITHER));
-            fHWDitherEnabled = kNo_TriState;
-        }
-    }
-}
-
 void GrGLGpu::flushColorWrite(bool writeColor) {
     if (!writeColor) {
         if (kNo_TriState != fHWWriteToColor) {
@@ -2930,7 +2915,6 @@
     blendInfo.reset();
     this->flushBlend(blendInfo);
     this->flushColorWrite(true);
-    this->flushDither(false);
     this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace);
     this->flushHWAAState(dstRT, false);
     this->disableScissor();
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 833f1ff..2387b44 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -234,7 +234,6 @@
 #endif
     };
 
-    void flushDither(bool dither);
     void flushColorWrite(bool writeColor);
     void flushDrawFace(GrPipelineBuilder::DrawFace face);
 
@@ -489,7 +488,6 @@
 
     GrPipelineBuilder::DrawFace fHWDrawFace;
     TriState                    fHWWriteToColor;
-    TriState                    fHWDitherEnabled;
     uint32_t                    fHWBoundRenderTargetUniqueID;
     TriState                    fHWSRGBFramebuffer;
     SkTArray<uint32_t, true>    fHWBoundTextureUniqueIDs;