Make use of backend texture creation finished procs in YUV GMs
Although not necessary this, at least, demonstrates how we expect these callbacks to be used.
Change-Id: I67c81e5cf882fbf2511729ede29f6ae9af389d52
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297862
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/tools/gpu/YUVUtils.cpp b/tools/gpu/YUVUtils.cpp
index 5b94135..b8dcc85 100644
--- a/tools/gpu/YUVUtils.cpp
+++ b/tools/gpu/YUVUtils.cpp
@@ -86,13 +86,26 @@
}
///////////////////////////////////////////////////////////////////////////////////////////////////
-void YUVABackendReleaseContext::Unwind(GrContext* context, YUVABackendReleaseContext* beContext) {
+void YUVABackendReleaseContext::Unwind(GrContext* context, YUVABackendReleaseContext* beContext,
+ bool fullFlush) {
+
// Some backends (e.g., Vulkan) require that all work associated w/ texture
// creation be completed before deleting the textures.
- GrFlushInfo flushInfoSyncCpu;
- flushInfoSyncCpu.fFlags = kSyncCpu_GrFlushFlag;
- context->flush(flushInfoSyncCpu);
- context->submit(true);
+
+ if (fullFlush) {
+ // If the release context client performed some operations other than backend texture
+ // creation then we may require a full flush to ensure that all the work is completed.
+ GrFlushInfo flushInfoSyncCpu;
+ flushInfoSyncCpu.fFlags = kSyncCpu_GrFlushFlag;
+ context->flush(flushInfoSyncCpu);
+ context->submit(true);
+ } else {
+ context->submit();
+
+ while (!beContext->creationCompleted()) {
+ context->checkAsyncWorkCompletion();
+ }
+ }
delete beContext;
}
@@ -105,9 +118,29 @@
YUVABackendReleaseContext::~YUVABackendReleaseContext() {
for (int i = 0; i < 4; ++i) {
if (fBETextures[i].isValid()) {
+ SkASSERT(fCreationComplete[i]);
fContext->deleteBackendTexture(fBETextures[i]);
}
}
}
+template<int I> static void CreationComplete(void* releaseContext) {
+ auto beContext = reinterpret_cast<YUVABackendReleaseContext*>(releaseContext);
+ beContext->setCreationComplete(I);
+}
+
+GrGpuFinishedProc YUVABackendReleaseContext::CreationCompleteProc(int index) {
+ SkASSERT(index >= 0 && index < 4);
+
+ switch (index) {
+ case 0: return CreationComplete<0>;
+ case 1: return CreationComplete<1>;
+ case 2: return CreationComplete<2>;
+ case 3: return CreationComplete<3>;
+ }
+
+ SK_ABORT("Invalid YUVA Index.");
+ return nullptr;
+}
+
} // namespace sk_gpu_test