Migrate last public API to GrDirectContext
Cut & paste with some reorganization of includes & forward-decls.
Next up is GrContextPriv.
Change-Id: I72d2d95c62692e3b37608517b796c0041ffedea3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/326157
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp
index aafe5a6..a0502d6 100644
--- a/src/gpu/GrDirectContext.cpp
+++ b/src/gpu/GrDirectContext.cpp
@@ -39,6 +39,7 @@
#ifdef SK_DAWN
#include "src/gpu/dawn/GrDawnGpu.h"
#endif
+#include <memory>
#if GR_TEST_UTILS
# include "include/utils/SkRandom.h"
@@ -817,6 +818,94 @@
return fGpu->updateCompressedBackendTexture(backendTexture, std::move(finishedCallback), &data);
}
+//////////////////////////////////////////////////////////////////////////////
+
+bool GrDirectContext::setBackendTextureState(const GrBackendTexture& backendTexture,
+ const GrBackendSurfaceMutableState& state,
+ GrBackendSurfaceMutableState* previousState,
+ GrGpuFinishedProc finishedProc,
+ GrGpuFinishedContext finishedContext) {
+ sk_sp<GrRefCntedCallback> callback;
+ if (finishedProc) {
+ callback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
+ }
+
+ if (this->abandoned()) {
+ return false;
+ }
+
+ return fGpu->setBackendTextureState(backendTexture, state, previousState, std::move(callback));
+}
+
+
+bool GrDirectContext::setBackendRenderTargetState(const GrBackendRenderTarget& backendRenderTarget,
+ const GrBackendSurfaceMutableState& state,
+ GrBackendSurfaceMutableState* previousState,
+ GrGpuFinishedProc finishedProc,
+ GrGpuFinishedContext finishedContext) {
+ sk_sp<GrRefCntedCallback> callback;
+ if (finishedProc) {
+ callback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
+ }
+
+ if (this->abandoned()) {
+ return false;
+ }
+
+ return fGpu->setBackendRenderTargetState(backendRenderTarget, state, previousState,
+ std::move(callback));
+}
+
+void GrDirectContext::deleteBackendTexture(GrBackendTexture backendTex) {
+ TRACE_EVENT0("skia.gpu", TRACE_FUNC);
+ // For the Vulkan backend we still must destroy the backend texture when the context is
+ // abandoned.
+ if ((this->abandoned() && this->backend() != GrBackendApi::kVulkan) || !backendTex.isValid()) {
+ return;
+ }
+
+ fGpu->deleteBackendTexture(backendTex);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+bool GrDirectContext::precompileShader(const SkData& key, const SkData& data) {
+ return fGpu->precompileShader(key, data);
+}
+
+#ifdef SK_ENABLE_DUMP_GPU
+#include "include/core/SkString.h"
+#include "src/utils/SkJSONWriter.h"
+SkString GrDirectContext::dump() const {
+ SkDynamicMemoryWStream stream;
+ SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty);
+ writer.beginObject();
+
+ writer.appendString("backend", GrBackendApiToStr(this->backend()));
+
+ writer.appendName("caps");
+ this->caps()->dumpJSON(&writer);
+
+ writer.appendName("gpu");
+ this->fGpu->dumpJSON(&writer);
+
+ writer.appendName("context");
+ this->dumpJSON(&writer);
+
+ // Flush JSON to the memory stream
+ writer.endObject();
+ writer.flush();
+
+ // Null terminate the JSON data in the memory stream
+ stream.write8(0);
+
+ // Allocate a string big enough to hold all the data, then copy out of the stream
+ SkString result(stream.bytesWritten());
+ stream.copyToAndReset(result.writable_str());
+ return result;
+}
+#endif
+
#ifdef SK_GL
/*************************************************************************************************/