Start removal of tool usage of SkSurface::MakeFromBackendTextureAsRenderTarget.
Adds a new helper that creates a GrBackendRenderTarget using
GrGpu and then wraps it in a SkSurface. Uses the SkSurface
release proc to delete the BERT using GrGpu.
Upgrades GrGpu::createTestingOnlyBackendRenderTarget to create MSAA
buffers.
Updates many tests/tool to call sites to use the helper instead of
SkSurface::MakeFromBackendTextureAsRenderTarget.
Adds syncToCpu bool to SkSurface:: and GrContext::flushAndSubmit.
Bug: skia:9832
Change-Id: I73a8f0ce09dc6523729af0814464c6b6657fda06
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293683
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/tools/gpu/BackendSurfaceFactory.cpp b/tools/gpu/BackendSurfaceFactory.cpp
new file mode 100644
index 0000000..f04eba2
--- /dev/null
+++ b/tools/gpu/BackendSurfaceFactory.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "tools/gpu/BackendSurfaceFactory.h"
+
+#include "include/core/SkSurface.h"
+#include "include/gpu/GrContext.h"
+#include "src/gpu/GrContextPriv.h"
+#include "src/gpu/GrGpu.h"
+
+sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* context,
+ SkISize dimensions,
+ int sampleCnt,
+ GrSurfaceOrigin origin,
+ SkColorType colorType,
+ sk_sp<SkColorSpace> colorSpace,
+ const SkSurfaceProps* props) {
+ auto ct = SkColorTypeToGrColorType(colorType);
+
+ struct ReleaseContext {
+ GrContext* fContext;
+ GrBackendRenderTarget fRenderTarget;
+ };
+
+ auto bert = context->priv().getGpu()->createTestingOnlyBackendRenderTarget(
+ dimensions, ct, sampleCnt);
+ auto rc = new ReleaseContext{context, bert};
+ SkASSERT(!bert.isValid() || bert.sampleCnt() >= sampleCnt);
+
+ auto proc = [](void* c) {
+ const auto* rc = static_cast<ReleaseContext*>(c);
+ if (auto gpu = rc->fContext->priv().getGpu(); gpu && rc->fRenderTarget.isValid()) {
+ gpu->deleteTestingOnlyBackendRenderTarget(rc->fRenderTarget);
+ }
+ delete rc;
+ };
+
+ return SkSurface::MakeFromBackendRenderTarget(
+ context, bert, origin, colorType, std::move(colorSpace), props, proc, rc);
+}