Make "alpha only" be a property of GrTextureProducer

Review URL: https://codereview.chromium.org/1507973005
diff --git a/src/gpu/GrImageIDTextureAdjuster.cpp b/src/gpu/GrImageIDTextureAdjuster.cpp
index a9189f6..2edff60 100644
--- a/src/gpu/GrImageIDTextureAdjuster.cpp
+++ b/src/gpu/GrImageIDTextureAdjuster.cpp
@@ -15,8 +15,12 @@
 #include "SkImageCacherator.h"
 #include "SkPixelRef.h"
 
+static bool bmp_is_alpha_only(const SkBitmap& bm) { return kAlpha_8_SkColorType == bm.colorType(); }
+
 GrBitmapTextureAdjuster::GrBitmapTextureAdjuster(const SkBitmap* bmp)
-    : INHERITED(bmp->getTexture(), SkIRect::MakeWH(bmp->width(), bmp->height()))
+    : INHERITED(bmp->getTexture(),
+                SkIRect::MakeWH(bmp->width(), bmp->height()),
+                bmp_is_alpha_only(*bmp))
     , fBmp(bmp) {}
 
 void GrBitmapTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) {
@@ -39,8 +43,15 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
+// SkImage's don't have a way of communicating whether they're alpha-only. So we fallback to
+// inspecting the texture.
+static bool tex_image_is_alpha_only(const SkImage_Base& img) {
+    return GrPixelConfigIsAlphaOnly(img.peekTexture()->config());
+}
+
 GrImageTextureAdjuster::GrImageTextureAdjuster(const SkImage_Base* img)
-    : INHERITED(img->peekTexture(), SkIRect::MakeWH(img->width(), img->height()))
+    : INHERITED(img->peekTexture(), SkIRect::MakeWH(img->width(), img->height()),
+                tex_image_is_alpha_only(*img))
     , fImageBase(img) {}
 
 void GrImageTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) {
@@ -59,7 +70,7 @@
 //////////////////////////////////////////////////////////////////////////////
 
 GrBitmapTextureMaker::GrBitmapTextureMaker(GrContext* context, const SkBitmap& bitmap)
-    : INHERITED(context, bitmap.width(), bitmap.height())
+    : INHERITED(context, bitmap.width(), bitmap.height(), bmp_is_alpha_only(bitmap))
     , fBitmap(bitmap) {
     SkASSERT(!bitmap.getTexture());
     if (!bitmap.isVolatile()) {
@@ -99,10 +110,13 @@
 }
 
 //////////////////////////////////////////////////////////////////////////////
-
+static bool cacher_is_alpha_only(const SkImageCacherator& cacher) {
+    return kAlpha_8_SkColorType == cacher.info().colorType();
+}
 GrImageTextureMaker::GrImageTextureMaker(GrContext* context, SkImageCacherator* cacher,
                                          const SkImage* client, SkImage::CachingHint chint)
-    : INHERITED(context, cacher->info().width(), cacher->info().height())
+    : INHERITED(context, cacher->info().width(), cacher->info().height(),
+                cacher_is_alpha_only(*cacher))
     , fCacher(cacher)
     , fClient(client)
     , fCachingHint(chint) {