Revert "Revert "Use ManagedBackendTexture in place of TestUtils backend texture helpers.""

This reverts commit f625e4ce4504facbf0cfa210f8d9770b8431cdd9.

Change-Id: Id73c53ec7ab8d4a5951712dc150d86e6349addbf
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325658
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/tools/gpu/BackendSurfaceFactory.cpp b/tools/gpu/BackendSurfaceFactory.cpp
index 32a6500..2c24760 100644
--- a/tools/gpu/BackendSurfaceFactory.cpp
+++ b/tools/gpu/BackendSurfaceFactory.cpp
@@ -15,7 +15,38 @@
 
 namespace sk_gpu_test {
 
-sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* context,
+sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* dContext,
+                                           const SkImageInfo& ii,
+                                           GrSurfaceOrigin origin,
+                                           int sampleCnt,
+                                           GrMipmapped mipMapped,
+                                           GrProtected isProtected,
+                                           const SkSurfaceProps* props) {
+    if (ii.alphaType() == kUnpremul_SkAlphaType) {
+        return nullptr;
+    }
+    auto mbet = ManagedBackendTexture::MakeWithoutData(dContext,
+                                                       ii.width(),
+                                                       ii.height(),
+                                                       ii.colorType(),
+                                                       mipMapped,
+                                                       GrRenderable::kYes,
+                                                       isProtected);
+    if (!mbet) {
+        return nullptr;
+    }
+    return SkSurface::MakeFromBackendTexture(dContext,
+                                             mbet->texture(),
+                                             origin,
+                                             sampleCnt,
+                                             ii.colorType(),
+                                             ii.refColorSpace(),
+                                             props,
+                                             ManagedBackendTexture::ReleaseProc,
+                                             mbet->releaseContext());
+}
+
+sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* dContext,
                                            SkISize dimensions,
                                            GrSurfaceOrigin origin,
                                            int sampleCnt,
@@ -24,45 +55,29 @@
                                            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());
+    auto ii = SkImageInfo::Make(dimensions, colorType, kPremul_SkAlphaType, std::move(colorSpace));
+    return MakeBackendTextureSurface(
+            dContext, ii, origin, sampleCnt, mipMapped, isProtected, props);
 }
-
-sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* context,
-                                                SkISize dimensions,
+sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* dContext,
+                                                const SkImageInfo& ii,
                                                 GrSurfaceOrigin origin,
                                                 int sampleCnt,
-                                                SkColorType colorType,
-                                                sk_sp<SkColorSpace> colorSpace,
                                                 GrProtected isProtected,
                                                 const SkSurfaceProps* props) {
-    auto ct = SkColorTypeToGrColorType(colorType);
+    if (ii.alphaType() == kUnpremul_SkAlphaType) {
+        return nullptr;
+    }
+    auto ct = SkColorTypeToGrColorType(ii.colorType());
 
     struct ReleaseContext {
         GrDirectContext* fContext;
         GrBackendRenderTarget fRenderTarget;
     };
 
-    auto bert = context->priv().getGpu()->createTestingOnlyBackendRenderTarget(
-            dimensions, ct, sampleCnt, isProtected);
-    auto rc = new ReleaseContext{context, bert};
+    auto bert = dContext->priv().getGpu()->createTestingOnlyBackendRenderTarget(
+            ii.dimensions(), ct, sampleCnt, isProtected);
+    auto rc = new ReleaseContext{dContext, bert};
     SkASSERT(!bert.isValid() || bert.sampleCnt() >= sampleCnt);
 
     auto proc = [](void* c) {
@@ -74,7 +89,19 @@
     };
 
     return SkSurface::MakeFromBackendRenderTarget(
-            context, bert, origin, colorType, std::move(colorSpace), props, proc, rc);
+            dContext, bert, origin, ii.colorType(), ii.refColorSpace(), props, proc, rc);
+}
+
+sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* dContext,
+                                                SkISize dimensions,
+                                                GrSurfaceOrigin origin,
+                                                int sampleCnt,
+                                                SkColorType colorType,
+                                                sk_sp<SkColorSpace> colorSpace,
+                                                GrProtected isProtected,
+                                                const SkSurfaceProps* props) {
+    auto ii = SkImageInfo::Make(dimensions, colorType, kPremul_SkAlphaType, std::move(colorSpace));
+    return MakeBackendRenderTargetSurface(dContext, ii, origin, sampleCnt, isProtected, props);
 }
 
 }  // namespace sk_gpu_test