Fix SkModeColorFilter in 565

It has been incorrectly interpreting its SkColor as sRGB all the time.  Now, we plumb through the destintation color space and some scratch space, letting it decide how to interpret its SkColor later when it knows about the dst color space.  The scratch space is blitter scoped, which lets this be thread safe (this is much like SkShader::Context).

This only corrects the gamma transformation for now.  I've kept my previous TODO about gamut transformation.  Everything assumes sRGB gamut for now.

Shaders will get the same treatement in this pipeline.

BUG=skia:

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

Change-Id: I55b0c7d5db9ad8d7dcdd6295c9dac61d10aeaed4
Reviewed-on: https://skia-review.googlesource.com/4725
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/src/core/SkRasterPipelineBlitter.cpp b/src/core/SkRasterPipelineBlitter.cpp
index b8c0107..d382eba 100644
--- a/src/core/SkRasterPipelineBlitter.cpp
+++ b/src/core/SkRasterPipelineBlitter.cpp
@@ -9,8 +9,10 @@
 #include "SkBlendModePriv.h"
 #include "SkColor.h"
 #include "SkColorFilter.h"
+#include "SkFixedAlloc.h"
 #include "SkOpts.h"
 #include "SkPM4f.h"
+#include "SkPM4fPriv.h"
 #include "SkRasterPipeline.h"
 #include "SkShader.h"
 #include "SkXfermode.h"
@@ -24,6 +26,8 @@
         : fDst(dst)
         , fBlend(blend)
         , fPaintColor(paintColor)
+        , fScratchAlloc(fScratch, sizeof(fScratch))
+        , fScratchFallback(&fScratchAlloc)
     {}
 
     void blitH    (int x, int y, int w)                            override;
@@ -57,6 +61,11 @@
     const void* fMaskPtr          = nullptr;
     float       fConstantCoverage = 0.0f;
 
+    // Scratch space for shaders and color filters to use.
+    char            fScratch[64];
+    SkFixedAlloc    fScratchAlloc;
+    SkFallbackAlloc fScratchFallback;
+
     typedef SkBlitter INHERITED;
 };
 
@@ -75,29 +84,14 @@
     }
 }
 
-template <typename Effect>
-static bool append_effect_stages(const Effect* effect, SkRasterPipeline* pipeline) {
-    return !effect || effect->appendStages(pipeline);
-}
-
-static SkPM4f paint_color(const SkPixmap& dst, const SkPaint& paint) {
-    auto paintColor = paint.getColor();
-    SkColor4f color;
-    if (dst.info().colorSpace()) {
-        color = SkColor4f::FromColor(paintColor);
-        // TODO: transform from sRGB to dst gamut.
-    } else {
-        swizzle_rb(SkNx_cast<float>(Sk4b::Load(&paintColor)) * (1/255.0f)).store(&color);
-    }
-    return color.premul();
-}
-
 SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
                                            const SkPaint& paint,
                                            SkTBlitterAllocator* alloc) {
-    auto blitter = alloc->createT<SkRasterPipelineBlitter>(dst,
-                                                           paint.getBlendMode(),
-                                                           paint_color(dst, paint));
+    auto blitter = alloc->createT<SkRasterPipelineBlitter>(
+            dst,
+            paint.getBlendMode(),
+            SkPM4f_from_SkColor(paint.getColor(), dst.colorSpace()));
+
     auto earlyOut = [&] {
         blitter->~SkRasterPipelineBlitter();
         alloc->freeLast();
@@ -128,7 +122,8 @@
     }
 
     if (colorFilter) {
-        if (!colorFilter->appendStages(pipeline, is_opaque)) {
+        if (!colorFilter->appendStages(pipeline, dst.colorSpace(), &blitter->fScratchFallback,
+                                       is_opaque)) {
             return earlyOut();
         }
         is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);