Add GrColorSpaceInfo and use in place of GrRenderTargetContext in paint conversion.

This moves us closer to making GrAtlasTextContext and related classes usable without a GrRenderTargetContext.

Change-Id: Ife52d69a3f925e23da88043acb4d8dc9f672a025
Reviewed-on: https://skia-review.googlesource.com/63304
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp
index 339ae6d..be83dc1 100644
--- a/src/gpu/text/GrAtlasTextBlob.cpp
+++ b/src/gpu/text/GrAtlasTextBlob.cpp
@@ -274,8 +274,8 @@
         bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
         op = GrAtlasTextOp::MakeDistanceField(
                 std::move(grPaint), glyphCount, cache, distanceAdjustTable,
-                renderTargetContext->isGammaCorrect(), paint.luminanceColor(), info.hasUseLCDText(),
-                useBGR, info.isAntiAliased());
+                renderTargetContext->colorSpaceInfo().isGammaCorrect(), paint.luminanceColor(),
+                info.hasUseLCDText(), useBGR, info.isAntiAliased());
     } else {
         op = GrAtlasTextOp::MakeBitmap(std::move(grPaint), format, glyphCount, cache);
     }
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index 8f310d0..4f8748b 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -50,10 +50,10 @@
     return canonicalColor;
 }
 
-uint32_t GrAtlasTextContext::ComputeScalerContextFlags(GrRenderTargetContext* rtc) {
+uint32_t GrAtlasTextContext::ComputeScalerContextFlags(const GrColorSpaceInfo& colorSpaceInfo) {
     // If we're doing gamma-correct rendering, then we can disable the gamma hacks.
     // Otherwise, leave them on. In either case, we still want the contrast boost:
-    if (rtc->isGammaCorrect()) {
+    if (colorSpaceInfo.isGammaCorrect()) {
         return SkPaint::kBoostContrast_ScalerContextFlag;
     } else {
         return SkPaint::kFakeGammaAndBoostContrast_ScalerContextFlags;
@@ -93,7 +93,7 @@
     bool canCache = !(skPaint.getPathEffect() ||
                       (mf && !mf->asABlur(&blurRec)) ||
                       drawFilter);
-    uint32_t scalerContextFlags = ComputeScalerContextFlags(rtc);
+    uint32_t scalerContextFlags = ComputeScalerContextFlags(rtc->colorSpaceInfo());
 
     GrTextBlobCache* cache = context->getTextBlobCache();
     if (canCache) {
@@ -118,7 +118,7 @@
         cacheBlob = cache->find(key);
     }
 
-    GrTextUtils::Paint paint(&skPaint, rtc->getColorSpace(), rtc->getColorXformFromSRGB());
+    GrTextUtils::Paint paint(&skPaint, rtc->colorSpaceInfo());
     if (cacheBlob) {
         if (cacheBlob->mustRegenerate(paint, blurRec, viewMatrix, x, y)) {
             // We have to remake the blob because changes may invalidate our masks.
@@ -295,14 +295,13 @@
     if (context->abandoned()) {
         return;
     }
-    GrTextUtils::Paint paint(&skPaint, rtc->getColorSpace(), rtc->getColorXformFromSRGB());
+    GrTextUtils::Paint paint(&skPaint, rtc->colorSpaceInfo());
     if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shaderCaps())) {
         sk_sp<GrAtlasTextBlob> blob(
-            MakeDrawTextBlob(context->getTextBlobCache(), context->getAtlasGlyphCache(),
-                             *context->caps()->shaderCaps(),
-                             paint, ComputeScalerContextFlags(rtc),
-                             viewMatrix, props,
-                             text, byteLength, x, y));
+                MakeDrawTextBlob(context->getTextBlobCache(), context->getAtlasGlyphCache(),
+                                 *context->caps()->shaderCaps(), paint,
+                                 ComputeScalerContextFlags(rtc->colorSpaceInfo()), viewMatrix,
+                                 props, text, byteLength, x, y));
         if (blob) {
             blob->flushThrowaway(context, rtc, props, fDistanceAdjustTable.get(), paint, clip,
                                  viewMatrix, regionClipBounds, x, y);
@@ -321,18 +320,15 @@
                                      const char text[], size_t byteLength, const SkScalar pos[],
                                      int scalarsPerPosition, const SkPoint& offset,
                                      const SkIRect& regionClipBounds) {
-    GrTextUtils::Paint paint(&skPaint, rtc->getColorSpace(), rtc->getColorXformFromSRGB());
+    GrTextUtils::Paint paint(&skPaint, rtc->colorSpaceInfo());
     if (context->abandoned()) {
         return;
     } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shaderCaps())) {
         sk_sp<GrAtlasTextBlob> blob(
-            MakeDrawPosTextBlob(context->getTextBlobCache(), context->getAtlasGlyphCache(),
-                                *context->caps()->shaderCaps(),
-                                paint, ComputeScalerContextFlags(rtc),
-                                viewMatrix, props,
-                                text, byteLength,
-                                pos, scalarsPerPosition,
-                                offset));
+                MakeDrawPosTextBlob(context->getTextBlobCache(), context->getAtlasGlyphCache(),
+                                    *context->caps()->shaderCaps(), paint,
+                                    ComputeScalerContextFlags(rtc->colorSpaceInfo()), viewMatrix,
+                                    props, text, byteLength, pos, scalarsPerPosition, offset));
         if (blob) {
             blob->flushThrowaway(context, rtc, props, fDistanceAdjustTable.get(), paint, clip,
                                  viewMatrix, regionClipBounds, offset.fX, offset.fY);
@@ -374,7 +370,7 @@
     skPaint.setLCDRenderText(random->nextBool());
     skPaint.setAntiAlias(skPaint.isLCDRenderText() ? true : random->nextBool());
     skPaint.setSubpixelText(random->nextBool());
-    GrTextUtils::Paint utilsPaint(&skPaint, rtc->getColorSpace(), rtc->getColorXformFromSRGB());
+    GrTextUtils::Paint utilsPaint(&skPaint, rtc->colorSpaceInfo());
 
     const char* text = "The quick brown fox jumps over the lazy dog.";
     int textLen = (int)strlen(text);
diff --git a/src/gpu/text/GrAtlasTextContext.h b/src/gpu/text/GrAtlasTextContext.h
index 458a365..f9540de 100644
--- a/src/gpu/text/GrAtlasTextContext.h
+++ b/src/gpu/text/GrAtlasTextContext.h
@@ -51,7 +51,7 @@
     // sets up the descriptor on the blob and returns a detached cache.  Client must attach
     inline static SkColor ComputeCanonicalColor(const SkPaint&, bool lcd);
     // Determines if we need to use fake gamma (and contrast boost):
-    inline static uint32_t ComputeScalerContextFlags(GrRenderTargetContext*);
+    inline static uint32_t ComputeScalerContextFlags(const GrColorSpaceInfo&);
     static void RegenerateTextBlob(GrAtlasTextBlob* bmp,
                                    GrAtlasGlyphCache*,
                                    const GrShaderCaps&,
diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp
index 854945e..502f4ad 100644
--- a/src/gpu/text/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp
@@ -133,7 +133,7 @@
                                                         SkScalar x, SkScalar y,
                                                         SkDrawFilter* drawFilter,
                                                         const SkIRect& clipBounds) {
-    GrTextUtils::Paint paint(&skPaint, rtc->getColorSpace(), rtc->getColorXformFromSRGB());
+    GrTextUtils::Paint paint(&skPaint, rtc->colorSpaceInfo());
     GrTextUtils::RunPaint runPaint(&paint, drawFilter, props);
     SkTextBlobRunIterator it(blob);
     for (;!it.done(); it.next()) {
@@ -580,7 +580,8 @@
         }
 
         GrPaint grPaint;
-        if (!SkPaintToGrPaint(ctx, renderTargetContext, originalSkPaint, viewMatrix, &grPaint)) {
+        if (!SkPaintToGrPaint(ctx, renderTargetContext->colorSpaceInfo(), originalSkPaint,
+                              viewMatrix, &grPaint)) {
             return;
         }
 
diff --git a/src/gpu/text/GrTextUtils.cpp b/src/gpu/text/GrTextUtils.cpp
index 7ad4b4a..f920ec4 100644
--- a/src/gpu/text/GrTextUtils.cpp
+++ b/src/gpu/text/GrTextUtils.cpp
@@ -44,9 +44,11 @@
     // TODO: this is the last use of GrSurfaceContextPriv
     GrContext* context = rtc->surfPriv().getContext();
     if (kARGB_GrMaskFormat == maskFormat) {
-        return SkPaintToGrPaintWithPrimitiveColor(context, rtc, this->skPaint(), grPaint);
+        return SkPaintToGrPaintWithPrimitiveColor(context, rtc->colorSpaceInfo(), this->skPaint(),
+                                                  grPaint);
     } else {
-        return SkPaintToGrPaint(context, rtc, this->skPaint(), viewMatrix, grPaint);
+        return SkPaintToGrPaint(context, rtc->colorSpaceInfo(), this->skPaint(), viewMatrix,
+                                grPaint);
     }
 }
 
diff --git a/src/gpu/text/GrTextUtils.h b/src/gpu/text/GrTextUtils.h
index bbf3ca4..0a6b2cc 100644
--- a/src/gpu/text/GrTextUtils.h
+++ b/src/gpu/text/GrTextUtils.h
@@ -9,6 +9,7 @@
 #define GrTextUtils_DEFINED
 
 #include "GrColor.h"
+#include "GrColorSpaceInfo.h"
 #include "SkColorFilter.h"
 #include "SkGr.h"
 #include "SkPaint.h"
@@ -47,12 +48,10 @@
      */
     class Paint {
     public:
-        explicit Paint(const SkPaint* paint,
-                       SkColorSpace* dstColorSpace,
-                       GrColorSpaceXform* colorXformFromSRGB)
+        explicit Paint(const SkPaint* paint, const GrColorSpaceInfo& dstColorSpaceInfo)
                 : fPaint(paint)
-                , fDstColorSpace(dstColorSpace)
-                , fColorXformFromSRGB(colorXformFromSRGB) {
+                , fDstColorSpace(dstColorSpaceInfo.colorSpace())
+                , fColorXformFromSRGB(dstColorSpaceInfo.colorSpaceXformFromSRGB()) {
             this->initFilteredColor();
         }