Add destination color space to shader ContextRec

BUG=skia:

Change-Id: Ib1920fffd5735ad54a5b785bbc2676ea240bdbfa
Reviewed-on: https://skia-review.googlesource.com/5611
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/bench/SkLinearBitmapPipelineBench.cpp b/bench/SkLinearBitmapPipelineBench.cpp
index 8582ce9..f34cb45 100644
--- a/bench/SkLinearBitmapPipelineBench.cpp
+++ b/bench/SkLinearBitmapPipelineBench.cpp
@@ -202,7 +202,8 @@
 
         uint32_t storage[kSkBlitterContextSize];
         const SkShader::ContextRec rec(fPaint, fM, nullptr,
-                                       SkShader::ContextRec::kPMColor_DstType);
+                                       SkShader::ContextRec::kPMColor_DstType,
+                                       nullptr);
         SkASSERT(fPaint.getShader()->contextSize(rec) <= sizeof(storage));
         SkShader::Context* ctx = fPaint.getShader()->createContext(rec, storage);
 
diff --git a/gm/SkLinearBitmapPipelineGM.cpp b/gm/SkLinearBitmapPipelineGM.cpp
index bde8ee8..43e4a24 100644
--- a/gm/SkLinearBitmapPipelineGM.cpp
+++ b/gm/SkLinearBitmapPipelineGM.cpp
@@ -71,7 +71,8 @@
     }
     paint.setShader(std::move(shader));
     const SkShader::ContextRec rec(paint, *mat, nullptr,
-                                   SkBlitter::PreferredShaderDest(pmsrc.info()));
+                                   SkBlitter::PreferredShaderDest(pmsrc.info()),
+                                   canvas->imageInfo().colorSpace());
     SkASSERT(paint.getShader()->contextSize(rec) <= sizeof(storage));
 
     SkShader::Context* ctx = paint.getShader()->createContext(rec, storage);
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index 9e05a38..cafeedd 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -116,16 +116,18 @@
         };
 
         ContextRec(const SkPaint& paint, const SkMatrix& matrix, const SkMatrix* localM,
-                   DstType dstType)
+                   DstType dstType, SkColorSpace* dstColorSpace)
             : fPaint(&paint)
             , fMatrix(&matrix)
             , fLocalMatrix(localM)
-            , fPreferredDstType(dstType) {}
+            , fPreferredDstType(dstType)
+            , fDstColorSpace(dstColorSpace) {}
 
         const SkPaint*  fPaint;            // the current paint associated with the draw
         const SkMatrix* fMatrix;           // the current matrix in the canvas
         const SkMatrix* fLocalMatrix;      // optional local matrix
         const DstType   fPreferredDstType; // the "natural" client dest type
+        SkColorSpace*   fDstColorSpace;    // the color space of the dest surface (if any)
     };
 
     class Context : public ::SkNoncopyable {
diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp
index a05c176..c97956c 100644
--- a/src/core/SkBlitter.cpp
+++ b/src/core/SkBlitter.cpp
@@ -891,7 +891,8 @@
     SkShader::Context* shaderContext = nullptr;
     if (shader) {
         const SkShader::ContextRec rec(*paint, matrix, nullptr,
-                                       PreferredShaderDest(device.info()));
+                                       PreferredShaderDest(device.info()),
+                                       device.colorSpace());
         size_t contextSize = shader->contextSize(rec);
         if (contextSize) {
             // Try to create the ShaderContext
@@ -978,7 +979,7 @@
     SkZeroShaderContext(const SkShader& shader, const SkShader::ContextRec& rec)
         // Override rec with the identity matrix, so it is guaranteed to be invertible.
         : INHERITED(shader, SkShader::ContextRec(*rec.fPaint, SkMatrix::I(), nullptr,
-                                                 rec.fPreferredDstType)) {}
+                                                 rec.fPreferredDstType, rec.fDstColorSpace)) {}
 
     void shadeSpan(int x, int y, SkPMColor colors[], int count) override {
         sk_bzero(colors, count * sizeof(SkPMColor));
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index a2d7a51..2f3dd3e 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1956,7 +1956,8 @@
                 SkMatrix tempM;
                 if (texture_to_matrix(state, vertices, textures, &tempM)) {
                     SkShader::ContextRec rec(p, *fMatrix, &tempM,
-                                             SkBlitter::PreferredShaderDest(fDst.info()));
+                                             SkBlitter::PreferredShaderDest(fDst.info()),
+                                             fDst.colorSpace());
                     if (!blitter->resetShaderContext(rec)) {
                         continue;
                     }
diff --git a/src/core/SkNormalMapSource.cpp b/src/core/SkNormalMapSource.cpp
index 04f6d5a..204effa 100644
--- a/src/core/SkNormalMapSource.cpp
+++ b/src/core/SkNormalMapSource.cpp
@@ -157,7 +157,7 @@
     SkPaint* overridePaint = new (paintStorage) SkPaint(*(rec.fPaint));
     overridePaint->setAlpha(0xFF);
     SkShader::ContextRec overrideRec(*overridePaint, *(rec.fMatrix), rec.fLocalMatrix,
-                                     rec.fPreferredDstType);
+                                     rec.fPreferredDstType, rec.fDstColorSpace);
 
     void* mapContextStorage = (char*) paintStorage + sizeof(SkPaint);
     SkShader::Context* context = fMapShader->createContext(overrideRec, mapContextStorage);