Just pass the draw context to paint conversion

Concentrate on using draw context functionality to answer gamma and color
related queries in more places.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2182603003

Review-Url: https://codereview.chromium.org/2182603003
diff --git a/gm/constcolorprocessor.cpp b/gm/constcolorprocessor.cpp
index 3a5d73a..d9b5f6c 100644
--- a/gm/constcolorprocessor.cpp
+++ b/gm/constcolorprocessor.cpp
@@ -100,7 +100,7 @@
                         skPaint.setColor(kPaintColors[paintType]);
                     }
                     // SRGBTODO: No sRGB inputs allowed here?
-                    SkAssertResult(SkPaintToGrPaint(context, skPaint, viewMatrix, false, nullptr,
+                    SkAssertResult(SkPaintToGrPaint(context, drawContext, skPaint, viewMatrix,
                                                     &grPaint));
 
                     GrConstColorProcessor::InputMode mode = (GrConstColorProcessor::InputMode) m;
diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h
index b8ecca0..3cc57b5 100644
--- a/include/gpu/GrDrawContext.h
+++ b/include/gpu/GrDrawContext.h
@@ -269,6 +269,10 @@
     GrPixelConfig config() const { return fRenderTarget->config(); }
     int numColorSamples() const { return fRenderTarget->numColorSamples(); }
     bool isGammaCorrect() const { return fSurfaceProps.isGammaCorrect(); }
+    SkSourceGammaTreatment sourceGammaTreatment() const {
+        return this->isGammaCorrect() ? SkSourceGammaTreatment::kRespect
+                                      : SkSourceGammaTreatment::kIgnore;
+    }
     const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
     SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
 
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index 27d7dff..48aa28b 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -287,8 +287,7 @@
     SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;)
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(context, paint, viewMatrix, drawContext->isGammaCorrect(),
-                          drawContext->getColorSpace(), &grPaint)) {
+    if (!SkPaintToGrPaint(context, drawContext, paint, viewMatrix, &grPaint)) {
         return;
     }
 
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 5351f4b..5bc347c 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -309,9 +309,7 @@
     GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext);
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
-                          this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
         return;
     }
 
@@ -361,8 +359,7 @@
     if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
         GrStyle style(paint, SkPaint::kStroke_Style);
         GrPaint grPaint;
-        if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
-                              this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
+        if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
                               &grPaint)) {
             return;
         }
@@ -383,9 +380,7 @@
     }
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
-                          this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
         return;
     }
 
@@ -422,9 +417,7 @@
     }
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
-                          this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
         return;
     }
 
@@ -441,9 +434,7 @@
     CHECK_SHOULD_DRAW(draw);
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
-                          this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
         return;
     }
 
@@ -518,8 +509,7 @@
 
     if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()) {
         GrPaint grPaint;
-        if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
-                              this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
+        if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
                               &grPaint)) {
             return;
         }
@@ -564,9 +554,7 @@
     }
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
-                          this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
         return;
     }
 
@@ -622,9 +610,7 @@
     m.postConcat(*draw.fMatrix);
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(this->context(), newPaint, m,
-                          this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), newPaint, m, &grPaint)) {
         return;
     }
 
@@ -1036,9 +1022,8 @@
     SkASSERT(bitmap.width() <= fContext->caps()->maxTileSize() &&
              bitmap.height() <= fContext->caps()->maxTileSize());
 
-    SkSourceGammaTreatment gammaTreatment = this->surfaceProps().isGammaCorrect()
-        ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
-    sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext, bitmap, params, gammaTreatment);
+    sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext, bitmap, params,
+                                                         fDrawContext->sourceGammaTreatment());
     if (nullptr == texture) {
         return;
     }
@@ -1105,10 +1090,9 @@
     }
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaintWithTexture(this->context(), paint, viewMatrix, std::move(fp),
-                                     kAlpha_8_SkColorType == bitmap.colorType(),
-                                     this->surfaceProps().isGammaCorrect(),
-                                     fDrawContext->getColorSpace(), &grPaint)) {
+    if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, viewMatrix,
+                                     std::move(fp), kAlpha_8_SkColorType == bitmap.colorType(),
+                                     &grPaint)) {
         return;
     }
 
@@ -1198,9 +1182,8 @@
     } else {
         fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp));
     }
-    if (!SkPaintToGrPaintReplaceShader(this->context(), tmpUnfiltered, std::move(fp),
-                                       this->surfaceProps().isGammaCorrect(),
-                                       fDrawContext->getColorSpace(), &grPaint)) {
+    if (!SkPaintToGrPaintReplaceShader(this->context(), fDrawContext.get(), tmpUnfiltered,
+                                       std::move(fp), &grPaint)) {
         return;
     }
 
@@ -1471,18 +1454,15 @@
     }
 
     static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_FilterMode;
-    bool gammaCorrect = this->surfaceProps().isGammaCorrect();
-    SkSourceGammaTreatment gammaTreatment = gammaCorrect
-        ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
     sk_sp<GrFragmentProcessor> fp(
         producer->createFragmentProcessor(SkMatrix::I(),
                                           SkRect::MakeIWH(producer->width(), producer->height()),
                                           GrTextureProducer::kNo_FilterConstraint, true,
-                                          &kMode, fDrawContext->getColorSpace(), gammaTreatment));
+                                          &kMode, fDrawContext->getColorSpace(),
+                                          fDrawContext->sourceGammaTreatment()));
     GrPaint grPaint;
-    if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, std::move(fp),
-                                     producer->isAlphaOnly(), gammaCorrect,
-                                     fDrawContext->getColorSpace(), &grPaint)) {
+    if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
+                                     std::move(fp), producer->isAlphaOnly(), &grPaint)) {
         return;
     }
 
@@ -1544,9 +1524,7 @@
 
         GrPaint grPaint;
         // we ignore the shader if texs is null.
-        if (!SkPaintToGrPaintNoShader(this->context(), copy,
-                                      this->surfaceProps().isGammaCorrect(),
-                                      fDrawContext->getColorSpace(), &grPaint)) {
+        if (!SkPaintToGrPaintNoShader(this->context(), fDrawContext.get(), copy, &grPaint)) {
             return;
         }
 
@@ -1617,16 +1595,14 @@
             } else {
                 colorMode = SkXfermode::kModulate_Mode;
             }
-            if (!SkPaintToGrPaintWithXfermode(this->context(), paint, *draw.fMatrix, colorMode,
-                                              false, this->surfaceProps().isGammaCorrect(),
-                                              fDrawContext->getColorSpace(), &grPaint)) {
+            if (!SkPaintToGrPaintWithXfermode(this->context(), fDrawContext.get(), paint,
+                                              *draw.fMatrix, colorMode, false, &grPaint)) {
                 return;
             }
         } else {
             // We have a shader, but no colors to blend it against.
-            if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
-                                  this->surfaceProps().isGammaCorrect(),
-                                  fDrawContext->getColorSpace(), &grPaint)) {
+            if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
+                                  &grPaint)) {
                 return;
             }
         }
@@ -1634,16 +1610,13 @@
         if (colors) {
             // We have colors, but either have no shader or no texture coords (which implies that
             // we should ignore the shader).
-            if (!SkPaintToGrPaintWithPrimitiveColor(this->context(), paint,
-                                                    this->surfaceProps().isGammaCorrect(),
-                                                    fDrawContext->getColorSpace(), &grPaint)) {
+            if (!SkPaintToGrPaintWithPrimitiveColor(this->context(), fDrawContext.get(), paint,
+                                                    &grPaint)) {
                 return;
             }
         } else {
             // No colors and no shaders. Just draw with the paint color.
-            if (!SkPaintToGrPaintNoShader(this->context(), paint,
-                                          this->surfaceProps().isGammaCorrect(),
-                                          fDrawContext->getColorSpace(), &grPaint)) {
+            if (!SkPaintToGrPaintNoShader(this->context(), fDrawContext.get(), paint, &grPaint)) {
                 return;
             }
         }
@@ -1680,15 +1653,12 @@
 
     GrPaint grPaint;
     if (colors) {
-        if (!SkPaintToGrPaintWithXfermode(this->context(), p, *draw.fMatrix, mode, true,
-                                          this->surfaceProps().isGammaCorrect(),
-                                          fDrawContext->getColorSpace(), &grPaint)) {
+        if (!SkPaintToGrPaintWithXfermode(this->context(), fDrawContext.get(), p, *draw.fMatrix,
+                                          mode, true, &grPaint)) {
             return;
         }
     } else {
-        if (!SkPaintToGrPaint(this->context(), p, *draw.fMatrix,
-                              this->surfaceProps().isGammaCorrect(),
-                              fDrawContext->getColorSpace(), &grPaint)) {
+        if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), p, *draw.fMatrix, &grPaint)) {
             return;
         }
     }
@@ -1707,9 +1677,7 @@
     GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext);
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
-                          this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
         return;
     }
 
@@ -1727,9 +1695,7 @@
     CHECK_SHOULD_DRAW(draw);
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
-                          this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
         return;
     }
 
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index 6014e95..da0a4ac 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -201,19 +201,16 @@
         }
         textureMatrix = &tempMatrix;
     }
-    bool gammaCorrect = this->surfaceProps().isGammaCorrect();
-    SkSourceGammaTreatment gammaTreatment = gammaCorrect
-        ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
     sk_sp<GrFragmentProcessor> fp(producer->createFragmentProcessor(
         *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode,
-        fDrawContext->getColorSpace(), gammaTreatment));
+        fDrawContext->getColorSpace(), fDrawContext->sourceGammaTreatment()));
     if (!fp) {
         return;
     }
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaintWithTexture(fContext, paint, viewMatrix, fp, producer->isAlphaOnly(),
-                                     gammaCorrect, fDrawContext->getColorSpace(), &grPaint)) {
+    if (!SkPaintToGrPaintWithTexture(fContext, fDrawContext.get(), paint, viewMatrix, fp,
+                                     producer->isAlphaOnly(), &grPaint)) {
         return;
     }
 
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 51eb910..cf36b3a 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -11,6 +11,7 @@
 
 #include "GrCaps.h"
 #include "GrContext.h"
+#include "GrDrawContext.h"
 #include "GrGpuResourcePriv.h"
 #include "GrImageIDTextureAdjuster.h"
 #include "GrTextureParamsAdjuster.h"
@@ -515,22 +516,21 @@
 }
 
 static inline bool skpaint_to_grpaint_impl(GrContext* context,
+                                           GrDrawContext* dc,
                                            const SkPaint& skPaint,
                                            const SkMatrix& viewM,
                                            sk_sp<GrFragmentProcessor>* shaderProcessor,
                                            SkXfermode::Mode* primColorMode,
                                            bool primitiveIsSrc,
-                                           bool allowSRGBInputs,
-                                           SkColorSpace* dstColorSpace,
                                            GrPaint* grPaint) {
     grPaint->setAntiAlias(skPaint.isAntiAlias());
-    grPaint->setAllowSRGBInputs(allowSRGBInputs);
+    grPaint->setAllowSRGBInputs(dc->isGammaCorrect());
 
     // Raw translation of the SkPaint color to our 4f format:
     GrColor4f origColor = GrColor4f::FromGrColor(SkColorToUnpremulGrColor(skPaint.getColor()));
 
     // Linearize, if the color is meant to be in sRGB gamma:
-    if (allowSRGBInputs) {
+    if (dc->isGammaCorrect()) {
         origColor.fRGBA[0] = exact_srgb_to_linear(origColor.fRGBA[0]);
         origColor.fRGBA[1] = exact_srgb_to_linear(origColor.fRGBA[1]);
         origColor.fRGBA[2] = exact_srgb_to_linear(origColor.fRGBA[2]);
@@ -543,12 +543,10 @@
         if (shaderProcessor) {
             shaderFP = *shaderProcessor;
         } else if (const SkShader* shader = skPaint.getShader()) {
-            SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
-                ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
             shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, &viewM, nullptr,
                                                                       skPaint.getFilterQuality(),
-                                                                      dstColorSpace,
-                                                                      gammaTreatment));
+                                                                      dc->getColorSpace(),
+                                                                      dc->sourceGammaTreatment()));
             if (!shaderFP) {
                 return false;
             }
@@ -653,79 +651,72 @@
     }
 
 #ifndef SK_IGNORE_GPU_DITHER
-    if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !allowSRGBInputs) {
+    if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !dc->isGammaCorrect()) {
         grPaint->addColorFragmentProcessor(GrDitherEffect::Make());
     }
 #endif
     return true;
 }
 
-bool SkPaintToGrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix& viewM,
-                      bool allowSRGBInputs, SkColorSpace* dstColorSpace, GrPaint* grPaint) {
-    return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, false,
-                                   allowSRGBInputs, dstColorSpace, grPaint);
+bool SkPaintToGrPaint(GrContext* context, GrDrawContext* dc, const SkPaint& skPaint,
+                      const SkMatrix& viewM, GrPaint* grPaint) {
+    return skpaint_to_grpaint_impl(context, dc, skPaint, viewM, nullptr, nullptr, false, grPaint);
 }
 
 /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. */
 bool SkPaintToGrPaintReplaceShader(GrContext* context,
+                                   GrDrawContext* dc,
                                    const SkPaint& skPaint,
                                    sk_sp<GrFragmentProcessor> shaderFP,
-                                   bool allowSRGBInputs,
-                                   SkColorSpace* dstColorSpace,
                                    GrPaint* grPaint) {
     if (!shaderFP) {
         return false;
     }
-    return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), &shaderFP, nullptr, false,
-                                   allowSRGBInputs, dstColorSpace, grPaint);
+    return skpaint_to_grpaint_impl(context, dc, skPaint, SkMatrix::I(), &shaderFP, nullptr, false,
+                                   grPaint);
 }
 
 /** Ignores the SkShader (if any) on skPaint. */
 bool SkPaintToGrPaintNoShader(GrContext* context,
+                              GrDrawContext* dc,
                               const SkPaint& skPaint,
-                              bool allowSRGBInputs,
-                              SkColorSpace* dstColorSpace,
                               GrPaint* grPaint) {
     // Use a ptr to a nullptr to to indicate that the SkShader is ignored and not replaced.
     static sk_sp<GrFragmentProcessor> kNullShaderFP(nullptr);
     static sk_sp<GrFragmentProcessor>* kIgnoreShader = &kNullShaderFP;
-    return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), kIgnoreShader, nullptr, false,
-                                   allowSRGBInputs, dstColorSpace, grPaint);
+    return skpaint_to_grpaint_impl(context, dc, skPaint, SkMatrix::I(), kIgnoreShader, nullptr,
+                                   false, grPaint);
 }
 
 /** Blends the SkPaint's shader (or color if no shader) with a per-primitive color which must
 be setup as a vertex attribute using the specified SkXfermode::Mode. */
 bool SkPaintToGrPaintWithXfermode(GrContext* context,
+                                  GrDrawContext* dc,
                                   const SkPaint& skPaint,
                                   const SkMatrix& viewM,
                                   SkXfermode::Mode primColorMode,
                                   bool primitiveIsSrc,
-                                  bool allowSRGBInputs,
-                                  SkColorSpace* dstColorSpace,
                                   GrPaint* grPaint) {
-    return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, &primColorMode, primitiveIsSrc,
-                                   allowSRGBInputs, dstColorSpace, grPaint);
+    return skpaint_to_grpaint_impl(context, dc, skPaint, viewM, nullptr, &primColorMode,
+                                   primitiveIsSrc, grPaint);
 }
 
 bool SkPaintToGrPaintWithTexture(GrContext* context,
+                                 GrDrawContext* dc,
                                  const SkPaint& paint,
                                  const SkMatrix& viewM,
                                  sk_sp<GrFragmentProcessor> fp,
                                  bool textureIsAlphaOnly,
-                                 bool allowSRGBInputs,
-                                 SkColorSpace* dstColorSpace,
                                  GrPaint* grPaint) {
     sk_sp<GrFragmentProcessor> shaderFP;
     if (textureIsAlphaOnly) {
         if (const SkShader* shader = paint.getShader()) {
-            SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
-                ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
             shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context,
                                                                       &viewM,
                                                                       nullptr,
                                                                       paint.getFilterQuality(),
-                                                                      dstColorSpace,
-                                                                      gammaTreatment));
+                                                                      dc->getColorSpace(),
+                                                                      dc->sourceGammaTreatment()));
             if (!shaderFP) {
                 return false;
             }
@@ -738,8 +729,7 @@
         shaderFP = GrFragmentProcessor::MulOutputByInputAlpha(fp);
     }
 
-    return SkPaintToGrPaintReplaceShader(context, paint, std::move(shaderFP), allowSRGBInputs,
-                                         dstColorSpace, grPaint);
+    return SkPaintToGrPaintReplaceShader(context, dc, paint, std::move(shaderFP), grPaint);
 }
 
 
diff --git a/src/gpu/SkGrPriv.h b/src/gpu/SkGrPriv.h
index ad1e88a..26dc4aa 100644
--- a/src/gpu/SkGrPriv.h
+++ b/src/gpu/SkGrPriv.h
@@ -16,6 +16,7 @@
 
 class GrCaps;
 class GrContext;
+class GrDrawContext;
 class GrFragmentProcessor;
 class GrPaint;
 class GrTexture;
@@ -46,27 +47,24 @@
 /** Converts an SkPaint to a GrPaint for a given GrContext. The matrix is required in order
     to convert the SkShader (if any) on the SkPaint. The primitive itself has no color. */
 bool SkPaintToGrPaint(GrContext*,
+                      GrDrawContext*,
                       const SkPaint& skPaint,
                       const SkMatrix& viewM,
-                      bool allowSRGBInputs,
-                      SkColorSpace* dstColorSpace,
                       GrPaint* grPaint);
 
 /** Same as above but ignores the SkShader (if any) on skPaint. */
 bool SkPaintToGrPaintNoShader(GrContext* context,
+                              GrDrawContext* dc,
                               const SkPaint& skPaint,
-                              bool allowSRGBInputs,
-                              SkColorSpace* dstColorSpace,
                               GrPaint* grPaint);
 
 /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. The processor
     should expect an unpremul input color and produce a premultiplied output color. There is
     no primitive color. */
 bool SkPaintToGrPaintReplaceShader(GrContext*,
+                                   GrDrawContext*,
                                    const SkPaint& skPaint,
                                    sk_sp<GrFragmentProcessor> shaderFP,
-                                   bool allowSRGBInputs,
-                                   SkColorSpace* dstColorSpace,
                                    GrPaint* grPaint);
 
 /** Blends the SkPaint's shader (or color if no shader) with the color which specified via a
@@ -74,34 +72,31 @@
     primitive color is the dst or src color to the blend in order to work around differences between
     drawVertices and drawAtlas. */
 bool SkPaintToGrPaintWithXfermode(GrContext* context,
+                                  GrDrawContext* dc,
                                   const SkPaint& skPaint,
                                   const SkMatrix& viewM,
                                   SkXfermode::Mode primColorMode,
                                   bool primitiveIsSrc,
-                                  bool allowSRGBInputs,
-                                  SkColorSpace* dstColorSpace,
                                   GrPaint* grPaint);
 
 /** This is used when there is a primitive color, but the shader should be ignored. Currently,
     the expectation is that the primitive color will be premultiplied, though it really should be
     unpremultiplied so that interpolation is done in unpremul space. The paint's alpha will be
     applied to the primitive color after interpolation. */
-inline bool SkPaintToGrPaintWithPrimitiveColor(GrContext* context, const SkPaint& skPaint,
-                                               bool allowSRGBInputs, SkColorSpace* dstColorSpace,
-                                               GrPaint* grPaint) {
-    return SkPaintToGrPaintWithXfermode(context, skPaint, SkMatrix::I(), SkXfermode::kDst_Mode,
-                                        false, allowSRGBInputs, dstColorSpace, grPaint);
+inline bool SkPaintToGrPaintWithPrimitiveColor(GrContext* context, GrDrawContext* dc,
+                                               const SkPaint& skPaint, GrPaint* grPaint) {
+    return SkPaintToGrPaintWithXfermode(context, dc, skPaint, SkMatrix::I(), SkXfermode::kDst_Mode,
+                                        false, grPaint);
 }
 
 /** This is used when there may or may not be a shader, and the caller wants to plugin a texture
     lookup.  If there is a shader, then its output will only be used if the texture is alpha8. */
 bool SkPaintToGrPaintWithTexture(GrContext* context,
+                                 GrDrawContext* dc,
                                  const SkPaint& paint,
                                  const SkMatrix& viewM,
                                  sk_sp<GrFragmentProcessor> fp,
                                  bool textureIsAlphaOnly,
-                                 bool allowSRGBInputs,
-                                 SkColorSpace* dstColorSpace,
                                  GrPaint* grPaint);
 
 //////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index 9b66d2f..b46963c 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -124,8 +124,7 @@
     // Though for the time being runs in the textblob can override the paint, they only touch font
     // info.
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(context, skPaint, viewMatrix, props.isGammaCorrect(), dc->getColorSpace(),
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(context, dc, skPaint, viewMatrix, &grPaint)) {
         return;
     }
 
@@ -389,7 +388,10 @@
         gTextContext = GrAtlasTextContext::Create();
     }
 
-    // Setup dummy SkPaint / GrPaint
+    // Setup dummy SkPaint / GrPaint / GrDrawContext
+    sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kApprox, 1024, 1024,
+                                                             kSkia8888_GrPixelConfig, nullptr));
+
     GrColor color = GrRandomColor(random);
     SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
     SkPaint skPaint;
@@ -399,8 +401,7 @@
     skPaint.setSubpixelText(random->nextBool());
 
     GrPaint grPaint;
-    if (!SkPaintToGrPaint(context, skPaint, viewMatrix, gSurfaceProps.isGammaCorrect(), nullptr,
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(context, drawContext.get(), skPaint, viewMatrix, &grPaint)) {
         SkFAIL("couldn't convert paint\n");
     }
 
diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp
index 9c75da4..e9677df 100644
--- a/src/gpu/text/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp
@@ -165,8 +165,7 @@
         runPaint.setFlags(GrTextUtils::FilterTextFlags(props, runPaint));
 
         GrPaint grPaint;
-        if (!SkPaintToGrPaint(context, runPaint, viewMatrix, dc->isGammaCorrect(),
-                              dc->getColorSpace(), &grPaint)) {
+        if (!SkPaintToGrPaint(context, dc, runPaint, viewMatrix, &grPaint)) {
             return;
         }
 
@@ -221,8 +220,7 @@
     }
 
     GrPaint paint;
-    if (!SkPaintToGrPaint(context, skPaint, viewMatrix, dc->isGammaCorrect(), dc->getColorSpace(),
-                          &paint)) {
+    if (!SkPaintToGrPaint(context, dc, skPaint, viewMatrix, &paint)) {
         return;
     }
 
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index f7c1f0c..aa36885 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -139,9 +139,7 @@
     GrPaint grPaint;
     SkMatrix mat;
     mat.reset();
-    if (!SkPaintToGrPaint(this->context(), paint, mat,
-                          this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
-                          &grPaint)) {
+    if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, mat, &grPaint)) {
         return;
     }
     SkMatrix textureMat;