support a8

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>
diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp
index 3def5ec..4415521 100644
--- a/src/image/SkImageShader.cpp
+++ b/src/image/SkImageShader.cpp
@@ -273,7 +273,7 @@
 
 
 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 @@
         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 @@
     }
 
     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 @@
             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 @@
     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);