Separate out natively-texture image/bmp draws from cached-as-texture image/bmp draws

This makes texture-backed images and bitmaps down a new code path. It adds a pinch point via the texture adjuster that will be used to handle copied necessary for different texture targets. It also fixes bugs in the existing code exhibited by recent updates to the bleed GM. The plan is to move the the sw/generator-backed imgs/bmps on to this code path with future changes.

Review URL: https://codereview.chromium.org/1424313010
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 469ef5b..540edb6 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -12,6 +12,7 @@
 #include "GrContext.h"
 #include "GrTextureParamsAdjuster.h"
 #include "GrGpuResourcePriv.h"
+#include "GrImageIDTextureAdjuster.h"
 #include "GrXferProcessor.h"
 #include "GrYUVProvider.h"
 
@@ -271,7 +272,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-static void install_bmp_key_invalidator(const GrUniqueKey& key, SkPixelRef* pixelRef) {
+void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pixelRef) {
     class Invalidator : public SkPixelRef::GenIDChangeListener {
     public:
         explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {}
@@ -313,7 +314,7 @@
         tex = GrUploadBitmapToTexture(ctx, fBitmap);
         if (tex && fOriginalKey.isValid()) {
             tex->resourcePriv().setUniqueKey(fOriginalKey);
-            install_bmp_key_invalidator(fOriginalKey, fBitmap.pixelRef());
+            GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef());
         }
         return tex;
     }
@@ -325,7 +326,7 @@
     }
 
     void didCacheCopy(const GrUniqueKey& copyKey) override {
-        install_bmp_key_invalidator(copyKey, fBitmap.pixelRef());
+        GrInstallBitmapUniqueKeyInvalidator(copyKey, fBitmap.pixelRef());
     }
 
 private:
@@ -335,40 +336,10 @@
     typedef GrTextureMaker INHERITED;
 };
 
-class TextureBitmap_GrTextureAdjuster : public GrTextureAdjuster {
-public:
-    explicit TextureBitmap_GrTextureAdjuster(const SkBitmap* bmp)
-        : INHERITED(bmp->getTexture(), SkIRect::MakeWH(bmp->width(), bmp->height()))
-        , fBmp(bmp) {}
-
-private:
-    void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override {
-        if (fBmp->isVolatile()) {
-            return;
-        }
-        // The content area must represent the whole bitmap. Texture-backed bitmaps don't support
-        // extractSubset(). Therefore, either the bitmap and the texture are the same size or the
-        // content's dimensions are the bitmap's dimensions which is pinned to the upper left
-        // of the texture.
-        GrUniqueKey baseKey;
-        GrMakeKeyFromImageID(&baseKey, fBmp->getGenerationID(),
-                             SkIRect::MakeWH(fBmp->width(), fBmp->height()));
-        MakeCopyKeyFromOrigKey(baseKey, params, copyKey);
-    }
-
-    void didCacheCopy(const GrUniqueKey& copyKey) override {
-        install_bmp_key_invalidator(copyKey, fBmp->pixelRef());
-    }
-
-    const SkBitmap* fBmp;
-
-    typedef GrTextureAdjuster INHERITED;
-};
-
 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap,
                                     const GrTextureParams& params) {
     if (bitmap.getTexture()) {
-        return TextureBitmap_GrTextureAdjuster(&bitmap).refTextureSafeForParams(params, nullptr);
+        return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params, nullptr);
     }
     return RasterBitmap_GrTextureMaker(bitmap).refTextureForParams(ctx, params);
 }