Remove SkSurface_Gpu::MakeWrappedRenderTarget

Change-Id: I3c069825e26cd5e56de215447ddcb883868d33fa
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/409997
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Adlai Holler <adlai@google.com>
diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp
index 58ec233..e22dad7 100644
--- a/src/core/SkDeferredDisplayListRecorder.cpp
+++ b/src/core/SkDeferredDisplayListRecorder.cpp
@@ -56,6 +56,7 @@
 #include "src/gpu/GrRecordingContextPriv.h"
 #include "src/gpu/GrSurfaceDrawContext.h"
 #include "src/gpu/GrTexture.h"
+#include "src/gpu/SkGpuDevice.h"
 #include "src/gpu/SkGr.h"
 #include "src/image/SkImage_Gpu.h"
 #include "src/image/SkImage_GpuYUVA.h"
@@ -157,8 +158,6 @@
         optionalTextureInfo = &kTextureInfo;
     }
 
-    GrSwizzle readSwizzle = caps->getReadSwizzle(fCharacterization.backendFormat(), grColorType);
-
     fTargetProxy = proxyProvider->createLazyRenderTargetProxy(
             [lazyProxyData = fLazyProxyData](GrResourceProvider* resourceProvider,
                                              const GrSurfaceProxy::LazySurfaceDesc&) {
@@ -186,16 +185,19 @@
     }
     fTargetProxy->priv().setIsDDLTarget();
 
-    GrSwizzle writeSwizzle = caps->getWriteSwizzle(fCharacterization.backendFormat(), grColorType);
+    auto sdc = GrSurfaceDrawContext::Make(fContext.get(),
+                                          grColorType,
+                                          fCharacterization.refColorSpace(),
+                                          fTargetProxy,
+                                          fCharacterization.origin(),
+                                          fCharacterization.surfaceProps());
 
-    GrSurfaceProxyView readView(fTargetProxy, fCharacterization.origin(), readSwizzle);
-    GrSurfaceProxyView writeView(fTargetProxy, fCharacterization.origin(), writeSwizzle);
+    auto device = SkGpuDevice::Make(std::move(sdc), SkGpuDevice::kUninit_InitContents);
+    if (!device) {
+        return false;
+    }
 
-    auto rtc = std::make_unique<GrSurfaceDrawContext>(fContext.get(), std::move(readView),
-                                                      std::move(writeView), grColorType,
-                                                      fCharacterization.refColorSpace(),
-                                                      fCharacterization.surfaceProps());
-    fSurface = SkSurface_Gpu::MakeWrappedRenderTarget(fContext.get(), std::move(rtc));
+    fSurface = sk_make_sp<SkSurface_Gpu>(std::move(device));
     return SkToBool(fSurface.get());
 }
 
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index df63f87..156807b 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -487,20 +487,6 @@
     return sk_make_sp<SkSurface_Gpu>(std::move(device));
 }
 
-sk_sp<SkSurface> SkSurface_Gpu::MakeWrappedRenderTarget(GrRecordingContext* context,
-                                                        std::unique_ptr<GrSurfaceDrawContext> sdc) {
-    if (!context) {
-        return nullptr;
-    }
-
-    auto device = SkGpuDevice::Make(std::move(sdc), SkGpuDevice::kUninit_InitContents);
-    if (!device) {
-        return nullptr;
-    }
-
-    return sk_make_sp<SkSurface_Gpu>(std::move(device));
-}
-
 sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrRecordingContext* context,
                                                    const GrBackendTexture& tex,
                                                    GrSurfaceOrigin origin, int sampleCnt,
diff --git a/src/image/SkSurface_Gpu.h b/src/image/SkSurface_Gpu.h
index a7f8ec8..b1ba869 100644
--- a/src/image/SkSurface_Gpu.h
+++ b/src/image/SkSurface_Gpu.h
@@ -21,10 +21,6 @@
     SkSurface_Gpu(sk_sp<SkGpuDevice>);
     ~SkSurface_Gpu() override;
 
-    // This is an internal-only factory
-    static sk_sp<SkSurface> MakeWrappedRenderTarget(GrRecordingContext*,
-                                                    std::unique_ptr<GrSurfaceDrawContext>);
-
     GrRecordingContext* onGetRecordingContext() override;
 
     GrBackendTexture onGetBackendTexture(BackendHandleAccess) override;
diff --git a/src/image/SkSurface_GpuMtl.mm b/src/image/SkSurface_GpuMtl.mm
index f95b1ec..48aa35b 100644
--- a/src/image/SkSurface_GpuMtl.mm
+++ b/src/image/SkSurface_GpuMtl.mm
@@ -19,6 +19,7 @@
 #if SK_SUPPORT_GPU
 
 #include "src/gpu/GrSurface.h"
+#include "src/gpu/SkGpuDevice.h"
 #include "src/gpu/mtl/GrMtlTextureRenderTarget.h"
 
 #ifdef SK_METAL
@@ -35,7 +36,6 @@
                                                  const SkSurfaceProps* surfaceProps,
                                                  GrMTLHandle* drawable) {
     GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
-    const GrCaps* caps = rContext->priv().caps();
 
     CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer;
     GrBackendFormat backendFormat = GrBackendFormat::MakeMtl(metalLayer.pixelFormat);
@@ -84,18 +84,19 @@
             false,
             GrSurfaceProxy::UseAllocator::kYes);
 
-    GrSwizzle readSwizzle = caps->getReadSwizzle(backendFormat, grColorType);
-    GrSwizzle writeSwizzle = caps->getWriteSwizzle(backendFormat, grColorType);
+    auto sdc = GrSurfaceDrawContext::Make(rContext,
+                                          grColorType,
+                                          std::move(colorSpace),
+                                          std::move(proxy),
+                                          origin,
+                                          SkSurfacePropsCopyOrDefault(surfaceProps));
 
-    GrSurfaceProxyView readView(proxy, origin, readSwizzle);
-    GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
+    auto device = SkGpuDevice::Make(std::move(sdc), SkGpuDevice::kUninit_InitContents);
+    if (!device) {
+        return nullptr;
+    }
 
-    auto rtc = std::make_unique<GrSurfaceDrawContext>(rContext, std::move(readView),
-                                                      std::move(writeView), grColorType, colorSpace,
-                                                      SkSurfacePropsCopyOrDefault(surfaceProps));
-
-    sk_sp<SkSurface> surface = SkSurface_Gpu::MakeWrappedRenderTarget(rContext, std::move(rtc));
-    return surface;
+    return sk_make_sp<SkSurface_Gpu>(std::move(device));
 }
 
 sk_sp<SkSurface> SkSurface::MakeFromMTKView(GrRecordingContext* rContext,
@@ -106,7 +107,6 @@
                                             sk_sp<SkColorSpace> colorSpace,
                                             const SkSurfaceProps* surfaceProps) {
     GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
-    const GrCaps* caps = rContext->priv().caps();
 
     MTKView* mtkView = (__bridge MTKView*)view;
     GrBackendFormat backendFormat = GrBackendFormat::MakeMtl(mtkView.colorPixelFormat);
@@ -154,18 +154,19 @@
             false,
             GrSurfaceProxy::UseAllocator::kYes);
 
-    GrSwizzle readSwizzle = caps->getReadSwizzle(backendFormat, grColorType);
-    GrSwizzle writeSwizzle = caps->getWriteSwizzle(backendFormat, grColorType);
+    auto sdc = GrSurfaceDrawContext::Make(rContext,
+                                          grColorType,
+                                          std::move(colorSpace),
+                                          std::move(proxy),
+                                          origin,
+                                          SkSurfacePropsCopyOrDefault(surfaceProps));
 
-    GrSurfaceProxyView readView(proxy, origin, readSwizzle);
-    GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
+    auto device = SkGpuDevice::Make(std::move(sdc), SkGpuDevice::kUninit_InitContents);
+    if (!device) {
+        return nullptr;
+    }
 
-    auto rtc = std::make_unique<GrSurfaceDrawContext>(rContext, std::move(readView),
-                                                      std::move(writeView), grColorType, colorSpace,
-                                                      SkSurfacePropsCopyOrDefault(surfaceProps));
-
-    sk_sp<SkSurface> surface = SkSurface_Gpu::MakeWrappedRenderTarget(rContext, std::move(rtc));
-    return surface;
+    return sk_make_sp<SkSurface_Gpu>(std::move(device));
 }
 
 #endif