add helper static to SkColorSpaceXform
authorMike Reed <reed@google.com>
Mon, 22 May 2017 17:41:36 +0000 (13:41 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 22 May 2017 18:08:13 +0000 (18:08 +0000)
Bug: skia:
Change-Id: I62525b392dfbae3d7075cf7f14e30780bad41279
Reviewed-on: https://skia-review.googlesource.com/17485
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Mike Reed <reed@google.com>

include/core/SkColorSpaceXform.h
src/core/SkColorSpaceXform.cpp
src/core/SkDraw_vertices.cpp

index ccd36bc..1e761a9 100644 (file)
@@ -60,6 +60,15 @@ public:
 
     virtual ~SkColorSpaceXform() {}
 
+    enum AlphaOp {
+        kPreserve_AlphaOp,      // just transfer src-alpha to dst-alpha
+        kPremul_AlphaOp,        // like kPreserve, but multiplies RGB by it
+        kSrcIsOpaque_AlphaOp,   // src alphas are all 1, this is a perf hint
+    };
+    static bool Apply(SkColorSpace* dstCS, ColorFormat dstFormat, void* dst,
+                      SkColorSpace* srcCS, ColorFormat srcFormat, const void* src,
+                      int count, AlphaOp);
+
 protected:
     SkColorSpaceXform() {}
 };
index 56eadfc..195de48 100644 (file)
@@ -1137,6 +1137,18 @@ bool SkColorSpaceXform::apply(ColorFormat dstColorFormat, void* dst, ColorFormat
                                                      alphaType);
 }
 
+bool SkColorSpaceXform::Apply(SkColorSpace* dstCS, ColorFormat dstFormat, void* dst,
+                              SkColorSpace* srcCS, ColorFormat srcFormat, const void* src,
+                              int count, AlphaOp op) {
+    SkAlphaType at;
+    switch (op) {
+        case kPreserve_AlphaOp:    at = kUnpremul_SkAlphaType; break;
+        case kPremul_AlphaOp:      at = kPremul_SkAlphaType;   break;
+        case kSrcIsOpaque_AlphaOp: at = kOpaque_SkAlphaType;   break;
+    }
+    return New(srcCS, dstCS)->apply(dstFormat, dst, srcFormat, src, count, at);
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 template <ColorSpaceMatch kCSM>
index ceeb3c2..ff33d5d 100644 (file)
@@ -402,15 +402,11 @@ static SkPM4f* convert_colors(const SkColor src[], int count, SkColorSpace* devi
             dst[i] = SkPM4f_from_SkColor(src[i], nullptr);
         }
     } else {
-        // For now, we want premul to happen on the colors before interplation. If we later want
-        // to apply it after the interp, pass kUnpremul here.
-        SkAlphaType alphaVerb = kPremul_SkAlphaType;
         auto srcCS = SkColorSpace::MakeSRGB();
         auto dstCS = as_CSB(deviceCS)->makeLinearGamma();
-        SkColorSpaceXform::New(srcCS.get(),
-                               dstCS.get())->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
-                                                   SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
-                                                   count, alphaVerb);
+        SkColorSpaceXform::Apply(dstCS.get(), SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
+                                 srcCS.get(), SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
+                                 count, SkColorSpaceXform::kPremul_AlphaOp);
     }
     return dst;
 }