Avoid double-dithering of legacy/gpu gradients

The GPU backend is the only remaining user of getGradientTableBitmap().

But with Ganesh, dithering is applied as a separate GrPaint effect
=> we must not pre-dither the gradient texture also.

Change-Id: Icc47c1e762c4913205b3715512894d3d2c3b7659
Reviewed-on: https://skia-review.googlesource.com/63261
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/src/shaders/gradients/SkGradientShader.cpp b/src/shaders/gradients/SkGradientShader.cpp
index 339f7ee..0e1a511 100644
--- a/src/shaders/gradients/SkGradientShader.cpp
+++ b/src/shaders/gradients/SkGradientShader.cpp
@@ -813,9 +813,6 @@
  */
 void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap,
                                                   GradientBitmapType bitmapType) const {
-    // our caller assumes no external alpha, so we ensure that our cache is built with 0xFF
-    sk_sp<GradientShaderCache> cache(this->refCache(0xFF, true));
-
     // build our key: [numColors + colors[] + {positions[]} + flags + colorType ]
     int count = 1 + fColorCount + 1 + 1;
     if (fColorCount > 2) {
@@ -851,6 +848,14 @@
 
     if (!gCache->find(storage.get(), size, bitmap)) {
         if (GradientBitmapType::kLegacy == bitmapType) {
+#ifdef SK_SUPPORT_LEGACY_GPU_GRADIENT_DITHER
+            static constexpr bool dither = true;
+#else
+            static constexpr bool dither = false;
+#endif
+            // our caller assumes no external alpha, so we ensure that our cache is built with 0xFF
+            sk_sp<GradientShaderCache> cache(this->refCache(0xFF, dither));
+
             // force our cache32pixelref to be built
             (void)cache->getCache32();
             bitmap->setInfo(SkImageInfo::MakeN32Premul(kCache32Count, 1));