support a8
authorMike Klein <mtklein@chromium.org>
Tue, 29 Nov 2016 20:33:39 +0000 (15:33 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Tue, 29 Nov 2016 21:36:32 +0000 (21:36 +0000)
Most of this is plumbing through the full paint to shaders instead of just the filter quality.

CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD

Change-Id: I6afde07566afa3a4391c24dca7017a9a4f5ec700
Reviewed-on: https://skia-review.googlesource.com/5317
Commit-Queue: Mike Klein <mtklein@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
include/core/SkShader.h
src/core/SkColorShader.cpp
src/core/SkColorShader.h
src/core/SkPM4fPriv.h
src/core/SkRasterPipeline.h
src/core/SkRasterPipelineBlitter.cpp
src/core/SkShader.cpp
src/image/SkImageShader.cpp
src/image/SkImageShader.h
src/image/SkImageShaderContext.h
src/opts/SkRasterPipeline_opts.h

index 0dcd11157d9d8d7ef8a488533c0360a844e02cc1..9e05a388996aba13f3aee39a039df0c2695b7436 100644 (file)
@@ -477,7 +477,7 @@ public:
     SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
 
     bool appendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
-                      const SkMatrix& ctm, SkFilterQuality) const;
+                      const SkMatrix& ctm, const SkPaint&) const;
 
 protected:
     void flatten(SkWriteBuffer&) const override;
@@ -511,7 +511,7 @@ protected:
     }
 
     virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
-                                const SkMatrix&, SkFilterQuality) const {
+                                const SkMatrix&, const SkPaint&) const {
         return false;
     }
 
index a0906211883b7817a5a1845c0858b1494a5848ba..da87cdfe2c7be61651c726fccbad0a246a39f357 100644 (file)
@@ -313,7 +313,7 @@ bool SkColorShader::onAppendStages(SkRasterPipeline* p,
                                    SkColorSpace* dst,
                                    SkFallbackAlloc* scratch,
                                    const SkMatrix& ctm,
-                                   SkFilterQuality) const {
+                                   const SkPaint&) const {
     auto color = scratch->make<SkPM4f>(SkPM4f_from_SkColor(fColor, dst));
     p->append(SkRasterPipeline::constant_color, color);
     return append_gamut_transform(p, scratch,
@@ -324,7 +324,7 @@ bool SkColor4Shader::onAppendStages(SkRasterPipeline* p,
                                     SkColorSpace* dst,
                                     SkFallbackAlloc* scratch,
                                     const SkMatrix& ctm,
-                                    SkFilterQuality) const {
+                                    const SkPaint&) const {
     auto color = scratch->make<SkPM4f>(fColor4.premul());
     p->append(SkRasterPipeline::constant_color, color);
     return append_gamut_transform(p, scratch, fColorSpace.get(), dst);
index 3101fa3a9f1388f51268942d8b397e694b6dbf84..19c106ddfd974e5699115c1843d0aa7716c68662 100644 (file)
@@ -66,7 +66,7 @@ protected:
         return true;
     }
     bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
-                        const SkMatrix& ctm, SkFilterQuality) const override;
+                        const SkMatrix& ctm, const SkPaint&) const override;
 
 private:
     SkColor fColor;
@@ -122,7 +122,7 @@ protected:
         return true;
     }
     bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
-                        const SkMatrix& ctm, SkFilterQuality) const override;
+                        const SkMatrix& ctm, const SkPaint&) const override;
 
 private:
     sk_sp<SkColorSpace> fColorSpace;
index aedb0ad20f57ab0aeaae2ae88dfb02fdfa76df11..13c1fd9ab78a8cd1d94a95ef2b73a0fe78e9ac4d 100644 (file)
@@ -111,7 +111,7 @@ static inline bool append_gamut_transform(SkRasterPipeline* p, SkFallbackAlloc*
     return append_gamut_transform(p, scratch->make<matrix_3x4>()->arr, src, dst);
 }
 
-static inline SkPM4f SkPM4f_from_SkColor(SkColor color, SkColorSpace* dst) {
+static inline SkColor4f SkColor4f_from_SkColor(SkColor color, SkColorSpace* dst) {
     SkColor4f color4f;
     if (dst) {
         // sRGB gamma, sRGB gamut.
@@ -131,7 +131,11 @@ static inline SkPM4f SkPM4f_from_SkColor(SkColor color, SkColorSpace* dst) {
         // Linear gamma, dst gamut.
         swizzle_rb(SkNx_cast<float>(Sk4b::Load(&color)) * (1/255.0f)).store(&color4f);
     }
-    return color4f.premul();
+    return color4f;
+}
+
+static inline SkPM4f SkPM4f_from_SkColor(SkColor color, SkColorSpace* dst) {
+    return SkColor4f_from_SkColor(color, dst).premul();
 }
 
 #endif
index 96a93584c5fd17e2a352fbd0da445bf6c6a8f97e..0495ebc3e7c8c76b929063a8d60e2496ada3fb4d 100644 (file)
@@ -59,6 +59,7 @@
     M(move_src_dst) M(move_dst_src) M(swap_rb) M(swap_rb_d)      \
     M(clamp_0) M(clamp_a) M(clamp_1)                             \
     M(unpremul) M(premul)                                        \
+    M(set_rgb)                                                   \
     M(from_srgb) M(from_srgb_d) M(to_srgb)                       \
     M(constant_color) M(store_f32)                               \
     M(load_565)  M(load_565_d)  M(store_565)                     \
index 8f1a7ac75186d93d00ba0a00a8f8396454e20ae1..d1796f5766bbd077d5b1f4e60ce9ab031cebbe8d 100644 (file)
@@ -116,7 +116,7 @@ SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
 
     if (shader) {
         if (!shader->appendStages(pipeline, dst.colorSpace(), &blitter->fScratchFallback,
-                                  ctm, paint.getFilterQuality())) {
+                                  ctm, paint)) {
             return earlyOut();
         }
         if (!is_opaque) {
index ca0eac4c8d987189482d9aa1b8dde9e014bdaa73..87b2cc3f30d30a060f7e7a98f6241d17f89550ac 100644 (file)
@@ -261,8 +261,8 @@ bool SkShader::appendStages(SkRasterPipeline* pipeline,
                             SkColorSpace* dst,
                             SkFallbackAlloc* scratch,
                             const SkMatrix& ctm,
-                            SkFilterQuality quality) const {
-    return this->onAppendStages(pipeline, dst, scratch, ctm, quality);
+                            const SkPaint& paint) const {
+    return this->onAppendStages(pipeline, dst, scratch, ctm, paint);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
index 3def5ec345232fa8486b3b9df4712c3f550d72af..441552116460c69c4f20a76b463a7b36ed778f4a 100644 (file)
@@ -273,7 +273,7 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
 
 
 bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFallbackAlloc* scratch,
-                                   const SkMatrix& ctm, SkFilterQuality quality) const {
+                                   const SkMatrix& ctm, const SkPaint& paint) const {
     SkPixmap pm;
     if (!fImage->peekPixels(&pm)) {
         return false;
@@ -286,12 +286,7 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFal
         return false;
     }
 
-    // TODO: all formats
-    switch (info.colorType()) {
-        case kAlpha_8_SkColorType:
-            return false;
-        default: break;
-    }
+    auto quality = paint.getFilterQuality();
 
     // When the matrix is just an integer translate, bilerp == nearest neighbor.
     if (matrix.getType() <= SkMatrix::kTranslate_Mask &&
@@ -318,11 +313,12 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFal
     }
 
     auto ctx = scratch->make<SkImageShaderContext>();
-    ctx->pixels = pm.addr();
-    ctx->ctable = pm.ctable();
-    ctx->stride = pm.rowBytesAsPixels();
-    ctx->width  = pm.width();
-    ctx->height = pm.height();
+    ctx->pixels  = pm.addr();
+    ctx->ctable  = pm.ctable();
+    ctx->color4f = SkColor4f_from_SkColor(paint.getColor(), dst);
+    ctx->stride  = pm.rowBytesAsPixels();
+    ctx->width   = pm.width();
+    ctx->height  = pm.height();
     if (matrix.asAffine(ctx->matrix)) {
         p->append(SkRasterPipeline::matrix_2x3, ctx->matrix);
     } else {
@@ -342,6 +338,7 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFal
             case kRepeat_TileMode: p->append(SkRasterPipeline::repeat_y, &ctx->height); break;
         }
         switch (info.colorType()) {
+            case kAlpha_8_SkColorType:   p->append(SkRasterPipeline::gather_a8,   ctx); break;
             case kIndex_8_SkColorType:   p->append(SkRasterPipeline::gather_i8,   ctx); break;
             case kGray_8_SkColorType:    p->append(SkRasterPipeline::gather_g8,   ctx); break;
             case kRGB_565_SkColorType:   p->append(SkRasterPipeline::gather_565,  ctx); break;
@@ -386,7 +383,10 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFal
     if (effective_color_type(info.colorType()) == kBGRA_8888_SkColorType) {
         p->append(SkRasterPipeline::swap_rb);
     }
-    if (info.alphaType() == kUnpremul_SkAlphaType) {
+    if (info.colorType() == kAlpha_8_SkColorType) {
+        p->append(SkRasterPipeline::set_rgb, &ctx->color4f);
+    }
+    if (info.colorType() == kAlpha_8_SkColorType || info.alphaType() == kUnpremul_SkAlphaType) {
         p->append(SkRasterPipeline::premul);
     }
     return append_gamut_transform(p, scratch, info.colorSpace(), dst);
index e3bab5c924a2be1e17499d4c167e42881a5e7fdb..074ecca3a7bebbcd59a5dc80550f08ca34ae8130 100644 (file)
@@ -38,7 +38,7 @@ protected:
     SkImage* onIsAImage(SkMatrix*, TileMode*) const override;
 
     bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
-                        const SkMatrix& ctm, SkFilterQuality) const override;
+                        const SkMatrix& ctm, const SkPaint&) const override;
 
     sk_sp<SkImage>  fImage;
     const TileMode  fTileModeX;
index cb562369a91708c6c60652a62504a00b7bef1e15..1b28bf61f40f8869c28356c057fbfa5cfde7a952 100644 (file)
@@ -8,6 +8,7 @@
 #ifndef SkImageShaderContext_DEFINED
 #define SkImageShaderContext_DEFINED
 
+#include "SkColor.h"
 class SkColorTable;
 
 // Definition used by SkImageShader.cpp and SkRasterPipeline_opts.h.
@@ -16,6 +17,7 @@ class SkColorTable;
 struct SkImageShaderContext {
     const void*   pixels;
     SkColorTable* ctable;
+    SkColor4f     color4f;
     int           stride;
     int           width;
     int           height;
index 88a872cb1fcecb8e9e0e9996e7f284868d265e15..a40fe6c72ef8b8269d7af8755363320266097d9c 100644 (file)
@@ -288,6 +288,13 @@ STAGE(premul) {
     b *= a;
 }
 
+STAGE(set_rgb) {
+    auto rgb = (const float*)ctx;
+    r = rgb[0];
+    g = rgb[1];
+    b = rgb[2];
+}
+
 STAGE(move_src_dst) {
     dr = r;
     dg = g;
@@ -777,7 +784,13 @@ SI SkNi offset_and_ptr(T** ptr, const void* ctx, const SkNf& x, const SkNf& y) {
     return offset;
 }
 
-STAGE(gather_a8) {}  // TODO
+STAGE(gather_a8) {
+    const uint8_t* p;
+    SkNi offset = offset_and_ptr(&p, ctx, r, g);
+
+    r = g = b = 0.0f;
+    a = SkNx_cast<float>(gather(tail, p, offset)) * (1/255.0f);
+}
 STAGE(gather_i8) {
     auto sc = (const SkImageShaderContext*)ctx;
     const uint8_t* p;