Plumb abandonment throughout GrContext hierarchy
When the GrImageContext & GrRecordingContext are actually GrDirectContexts it is useful for them to report the abandonment state of the GrDirectContext.
When the GrImageContext & GrRecordingContext are actually GrImageCreationContext or GrDDLContexts then they will just never be abandoned.
This CL also strips the GrProxyProvider and GrDrawingManager of their tracking on abandonment and centralizes it in the GrImageContext.
ImageContext
can't abandon
can only check abandonment privately
RecordingContext
can't abandon
can only check abandonment privately
DirectContext (aka GrContext)
can abandon publicly
can check abandonment publicly
Note that abandoning the DirectContext won't alter the abandonment status of any of
the other contexts in its group (e.g., DDL contexts that may be being used to record).
Change-Id: Ib790f74d90ab18da58a127fed2aad20e2477bd21
Reviewed-on: https://skia-review.googlesource.com/c/190669
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index fc8c7f5..1acb131 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -39,9 +39,9 @@
#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
#define ASSERT_SINGLE_OWNER \
SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
-#define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; }
-#define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; }
-#define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; }
+#define RETURN_IF_ABANDONED if (this->abandoned()) { return; }
+#define RETURN_FALSE_IF_ABANDONED if (this->abandoned()) { return false; }
+#define RETURN_NULL_IF_ABANDONED if (this->abandoned()) { return nullptr; }
////////////////////////////////////////////////////////////////////////////////
@@ -146,14 +146,17 @@
//////////////////////////////////////////////////////////////////////////////
void GrContext::abandonContext() {
- ASSERT_SINGLE_OWNER
+ if (this->abandoned()) {
+ return;
+ }
- this->proxyProvider()->abandon();
+ INHERITED::abandonContext();
+
fResourceProvider->abandon();
- // Need to abandon the drawing manager first so all the render targets
+ // Need to cleanup the drawing manager first so all the render targets
// will be released/forgotten before they too are abandoned.
- fDrawingManager->abandon();
+ fDrawingManager->cleanup();
// abandon first to so destructors
// don't try to free the resources in the API.
@@ -163,26 +166,21 @@
fGlyphCache->freeAll();
fTextBlobCache->freeAll();
-}
-bool GrContext::abandoned() const {
- ASSERT_SINGLE_OWNER
- // If called from ~GrContext(), the drawing manager may already be gone.
- return !fDrawingManager || fDrawingManager->wasAbandoned();
}
void GrContext::releaseResourcesAndAbandonContext() {
- ASSERT_SINGLE_OWNER
-
if (this->abandoned()) {
return;
}
- this->proxyProvider()->abandon();
+
+ INHERITED::abandonContext();
+
fResourceProvider->abandon();
- // Need to abandon the drawing manager first so all the render targets
+ // Need to cleanup the drawing manager first so all the render targets
// will be released/forgotten before they too are abandoned.
- fDrawingManager->abandon();
+ fDrawingManager->cleanup();
// Release all resources in the backend 3D API.
fResourceCache->releaseAll();
@@ -298,7 +296,9 @@
GrSemaphoresSubmitted GrContext::flushAndSignalSemaphores(int numSemaphores,
GrBackendSemaphore signalSemaphores[]) {
ASSERT_SINGLE_OWNER
- if (fDrawingManager->wasAbandoned()) { return GrSemaphoresSubmitted::kNo; }
+ if (this->abandoned()) {
+ return GrSemaphoresSubmitted::kNo;
+ }
return fDrawingManager->flush(nullptr, numSemaphores, signalSemaphores);
}