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/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp
index 172d34a..f6bc4f2 100644
--- a/src/gpu/GrBitmapTextureMaker.cpp
+++ b/src/gpu/GrBitmapTextureMaker.cpp
@@ -26,10 +26,27 @@
     return {ct, bitmap.alphaType(), bitmap.refColorSpace(), bitmap.dimensions()};
 }
 
-GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context, const SkBitmap& bitmap,
-                                           Cached cached, SkBackingFit fit)
-        : INHERITED(context, get_image_info(context, bitmap)), fBitmap(bitmap), fFit(fit) {
-    if (!bitmap.isVolatile() && cached == Cached::kYes) {
+GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context,
+                                           const SkBitmap& bitmap,
+                                           SkBackingFit fit)
+        : GrBitmapTextureMaker(context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted, fit) {}
+
+GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context,
+                                           const SkBitmap& bitmap,
+                                           GrImageTexGenPolicy cachePolicy)
+        : GrBitmapTextureMaker(context, bitmap, cachePolicy, SkBackingFit::kExact) {}
+
+GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context,
+                                           const SkBitmap& bitmap,
+                                           GrImageTexGenPolicy cachePolicy,
+                                           SkBackingFit fit)
+        : INHERITED(context, get_image_info(context, bitmap))
+        , fBitmap(bitmap)
+        , fFit(fit)
+        , fBudgeted(cachePolicy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted
+                            ? SkBudgeted::kNo
+                            : SkBudgeted::kYes) {
+    if (!bitmap.isVolatile() && cachePolicy == GrImageTexGenPolicy::kDraw) {
         SkIPoint origin = bitmap.pixelRefOrigin();
         SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(),
                                            bitmap.height());
@@ -69,9 +86,9 @@
                 return {};
             }
             copy8888.setImmutable();
-            proxy = proxyProvider->createProxyFromBitmap(copy8888, mipMapped, fFit);
+            proxy = proxyProvider->createProxyFromBitmap(copy8888, mipMapped, fFit, fBudgeted);
         } else {
-            proxy = proxyProvider->createProxyFromBitmap(fBitmap, mipMapped, fFit);
+            proxy = proxyProvider->createProxyFromBitmap(fBitmap, mipMapped, fFit, fBudgeted);
         }
         if (proxy) {
             swizzle = this->context()->priv().caps()->getReadSwizzle(proxy->backendFormat(),