Add query to imagegenerator if it can efficiently generate a texture

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3780

Change-Id: If5fb6ee82e47f0d007b4ad7c46ac73574eccd8c5
Reviewed-on: https://skia-review.googlesource.com/3780
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h
index 3712a92..f815898 100644
--- a/include/core/SkImageGenerator.h
+++ b/include/core/SkImageGenerator.h
@@ -14,6 +14,7 @@
 #include "SkYUVSizeInfo.h"
 
 class GrContext;
+class GrContextThreadSafeProxy;
 class GrTexture;
 class GrTextureParams;
 class SkBitmap;
@@ -152,6 +153,15 @@
     bool getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]);
 
     /**
+     *  Returns true if the generate can efficiently return a texture (given the properties of the
+     *  proxy). By default, simple codecs will usually return false, since they must be decoded
+     *  on the CPU and then uploaded to become a texture.
+     */
+    bool canGenerateTexture(const GrContextThreadSafeProxy& proxy) {
+        return this->onCanGenerateTexture(proxy);
+    }
+
+    /**
      *  If the generator can natively/efficiently return its pixels as a GPU image (backed by a
      *  texture) this will return that image. If not, this will return NULL.
      *
@@ -269,6 +279,9 @@
         return false;
     }
 
+    virtual bool onCanGenerateTexture(const GrContextThreadSafeProxy&) {
+        return false;
+    }
     virtual GrTexture* onGenerateTexture(GrContext*, const SkIRect*) {
         return nullptr;
     }
diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp
index 6f4ffa1..68742ca 100644
--- a/src/core/SkPictureImageGenerator.cpp
+++ b/src/core/SkPictureImageGenerator.cpp
@@ -26,6 +26,9 @@
     bool onGenerateScaledPixels(const SkISize&, const SkIPoint&, const SkPixmap&) override;
 
 #if SK_SUPPORT_GPU
+    bool onCanGenerateTexture(const GrContextThreadSafeProxy&) override {
+        return true;
+    }
     GrTexture* onGenerateTexture(GrContext*, const SkIRect*) override;
 #endif