Add SkBudgeted parameter to SkImage::makeTextureImage().

Also strengthens/adds some guarantees about this function:
* Always returns the same image if the original is texture-backed and
compatible with GrMipMapped (WRT HW MIP support)
* If a new texture backed image is returned it is always an uncached
texture that is not shared with another image or owned by an image
generator.

Adds a GrImageTexGenPolicy that allows control through image/bitmap
GrTextureProducers of whether a new texture must be made and whether
that texture should be budgeted or not.

Increases unit test coverage of this API.

Bug: skia:8669

Change-Id: Ifc0681856114a08fc8cfc57ca83d22efb1c1f166
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/274938
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrAHardwareBufferImageGenerator.cpp b/src/gpu/GrAHardwareBufferImageGenerator.cpp
index 174fb35..4062e8f 100644
--- a/src/gpu/GrAHardwareBufferImageGenerator.cpp
+++ b/src/gpu/GrAHardwareBufferImageGenerator.cpp
@@ -31,6 +31,7 @@
 #include "src/gpu/GrResourceProviderPriv.h"
 #include "src/gpu/GrTexture.h"
 #include "src/gpu/GrTextureProxy.h"
+#include "src/gpu/SkGr.h"
 #include "src/gpu/gl/GrGLDefines.h"
 
 #include <EGL/egl.h>
@@ -186,28 +187,33 @@
     return GrSurfaceProxyView(std::move(texProxy), fSurfaceOrigin, readSwizzle);
 }
 
-GrSurfaceProxyView GrAHardwareBufferImageGenerator::onGenerateTexture(GrRecordingContext* context,
-                                                                      const SkImageInfo& info,
-                                                                      const SkIPoint& origin,
-                                                                      GrMipMapped mipMapped) {
+GrSurfaceProxyView GrAHardwareBufferImageGenerator::onGenerateTexture(
+        GrRecordingContext* context,
+        const SkImageInfo& info,
+        const SkIPoint& origin,
+        GrMipMapped mipMapped,
+        GrImageTexGenPolicy texGenPolicy) {
     GrSurfaceProxyView texProxyView = this->makeView(context);
     if (!texProxyView.proxy()) {
         return {};
     }
     SkASSERT(texProxyView.asTextureProxy());
 
-    if (origin.isZero() && info.dimensions() == this->getInfo().dimensions() &&
-        mipMapped == GrMipMapped::kNo) {
+    if (texGenPolicy == GrImageTexGenPolicy::kDraw && origin.isZero() &&
+        info.dimensions() == this->getInfo().dimensions() && mipMapped == GrMipMapped::kNo) {
         // If the caller wants the full non-MIP mapped texture we're done.
         return texProxyView;
     }
     // Otherwise, make a copy for the requested subset and/or MIP maps.
     SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, info.width(), info.height());
 
+    SkBudgeted budgeted = texGenPolicy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted
+                                  ? SkBudgeted::kNo
+                                  : SkBudgeted::kYes;
+
     GrColorType grColorType = SkColorTypeToGrColorType(this->getInfo().colorType());
     return GrSurfaceProxy::Copy(context, texProxyView.proxy(), texProxyView.origin(), grColorType,
-                                mipMapped, subset, SkBackingFit::kExact,
-                                SkBudgeted::kYes);
+                                mipMapped, subset, SkBackingFit::kExact, budgeted);
 }
 
 bool GrAHardwareBufferImageGenerator::onIsValid(GrContext* context) const {