Expose ManagedBackendTexture from BackendTextureImageFactory.

Add helper to create self-managed BackendTexture-backed SkSurface for
tests using MBET.

GrGpu::createTestingOnlyBackendRenderTarget supports protected.

Make SkSurfaceCharacterization tests use self-managed SkSurface
factories and a use case of MakeFromBackendTextureAsRenderTarget is
removed.

Use self-managed BackendTexture-backed SkSurface factory in DM sinks and
in fm.

Bug: skia:9832

Change-Id: I0c1dc49697f8b3c942864e18b9112a3552f431ba
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323559
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/tools/gpu/BackendSurfaceFactory.cpp b/tools/gpu/BackendSurfaceFactory.cpp
index beae084..32a6500 100644
--- a/tools/gpu/BackendSurfaceFactory.cpp
+++ b/tools/gpu/BackendSurfaceFactory.cpp
@@ -11,13 +11,47 @@
 #include "include/gpu/GrDirectContext.h"
 #include "src/gpu/GrContextPriv.h"
 #include "src/gpu/GrGpu.h"
+#include "tools/gpu/ManagedBackendTexture.h"
+
+namespace sk_gpu_test {
+
+sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* context,
+                                           SkISize dimensions,
+                                           GrSurfaceOrigin origin,
+                                           int sampleCnt,
+                                           SkColorType colorType,
+                                           sk_sp<SkColorSpace> colorSpace,
+                                           GrMipmapped mipMapped,
+                                           GrProtected isProtected,
+                                           const SkSurfaceProps* props) {
+    auto mbet = ManagedBackendTexture::MakeWithoutData(context,
+                                                       dimensions.fWidth,
+                                                       dimensions.fHeight,
+                                                       colorType,
+                                                       mipMapped,
+                                                       GrRenderable::kYes,
+                                                       isProtected);
+    if (!mbet) {
+        return nullptr;
+    }
+    return SkSurface::MakeFromBackendTexture(context,
+                                             mbet->texture(),
+                                             origin,
+                                             sampleCnt,
+                                             colorType,
+                                             std::move(colorSpace),
+                                             props,
+                                             ManagedBackendTexture::ReleaseProc,
+                                             mbet->releaseContext());
+}
 
 sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* context,
                                                 SkISize dimensions,
-                                                int sampleCnt,
                                                 GrSurfaceOrigin origin,
+                                                int sampleCnt,
                                                 SkColorType colorType,
                                                 sk_sp<SkColorSpace> colorSpace,
+                                                GrProtected isProtected,
                                                 const SkSurfaceProps* props) {
     auto ct = SkColorTypeToGrColorType(colorType);
 
@@ -27,7 +61,7 @@
     };
 
     auto bert = context->priv().getGpu()->createTestingOnlyBackendRenderTarget(
-            dimensions, ct, sampleCnt);
+            dimensions, ct, sampleCnt, isProtected);
     auto rc = new ReleaseContext{context, bert};
     SkASSERT(!bert.isValid() || bert.sampleCnt() >= sampleCnt);
 
@@ -42,3 +76,5 @@
     return SkSurface::MakeFromBackendRenderTarget(
             context, bert, origin, colorType, std::move(colorSpace), props, proc, rc);
 }
+
+}  // namespace sk_gpu_test