Replace replaceSurfaceDrawContext with replaceBackingProxy
Change-Id: Iba2641f71bdc541d1a55a22c022031949c326c27
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/414444
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/SkBaseGpuDevice.cpp b/src/gpu/SkBaseGpuDevice.cpp
new file mode 100644
index 0000000..35e3fdf
--- /dev/null
+++ b/src/gpu/SkBaseGpuDevice.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "src/gpu/SkBaseGpuDevice.h"
+
+#include "include/gpu/GrRecordingContext.h"
+#include "src/gpu/GrProxyProvider.h"
+#include "src/gpu/GrRecordingContextPriv.h"
+
+#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(fContext->priv().singleOwner())
+
+bool SkBaseGpuDevice::replaceBackingProxy(SkSurface::ContentChangeMode mode) {
+ ASSERT_SINGLE_OWNER
+
+ const SkImageInfo& ii = this->imageInfo();
+ GrRenderTargetProxy* oldRTP = this->targetProxy();
+ GrSurfaceProxyView oldView = this->readSurfaceView();
+
+ auto grColorType = SkColorTypeToGrColorType(ii.colorType());
+ auto format = fContext->priv().caps()->getDefaultBackendFormat(grColorType, GrRenderable::kYes);
+ if (!format.isValid()) {
+ return false;
+ }
+
+ GrProxyProvider* proxyProvider = fContext->priv().proxyProvider();
+ // This entry point is used by SkSurface_Gpu::onCopyOnWrite so it must create a
+ // kExact-backed render target proxy
+ sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format,
+ ii.dimensions(),
+ GrRenderable::kYes,
+ oldRTP->numSamples(),
+ oldView.mipmapped(),
+ SkBackingFit::kExact,
+ oldRTP->isBudgeted(),
+ GrProtected::kNo);
+ if (!proxy) {
+ return false;
+ }
+
+ return this->replaceBackingProxy(mode, sk_ref_sp(proxy->asRenderTargetProxy()),
+ grColorType, ii.refColorSpace(), oldView.origin(),
+ this->surfaceProps());
+}