diff options
author | 2017-11-16 10:17:20 -0500 | |
---|---|---|
committer | 2017-11-16 16:30:53 +0000 | |
commit | 5627d65146cb92624b682389e017d488872228c7 (patch) | |
tree | 9b90fe789341a23d05dc0e896eeafc1a20b70a26 /tools/gpu/GrContextFactory.cpp | |
parent | 47f6029d3dc5ee9e484931a13a14dcbe9d3f23d3 (diff) |
Add method to sk_gpu_test::TestContext to automatically restore the previous context.
The motivation for this is to allow a GM to create a GL context, do some some work in it, and then return to the context that was set when it was invoked.
Change-Id: Ie8496072a10f8f3ff36a08889e593a6ca961b61a
Reviewed-on: https://skia-review.googlesource.com/70720
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'tools/gpu/GrContextFactory.cpp')
-rw-r--r-- | tools/gpu/GrContextFactory.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp index 21766db2b8..00c4b65edc 100644 --- a/tools/gpu/GrContextFactory.cpp +++ b/tools/gpu/GrContextFactory.cpp @@ -52,8 +52,9 @@ GrContextFactory::~GrContextFactory() { void GrContextFactory::destroyContexts() { for (Context& context : fContexts) { + SkScopeExit restore(nullptr); if (context.fTestContext) { - context.fTestContext->makeCurrent(); + restore = context.fTestContext->makeCurrentAndAutoRestore(); } if (!context.fGrContext->unique()) { context.fGrContext->releaseResourcesAndAbandonContext(); @@ -69,7 +70,7 @@ void GrContextFactory::abandonContexts() { for (Context& context : fContexts) { if (!context.fAbandoned) { if (context.fTestContext) { - context.fTestContext->makeCurrent(); + auto restore = context.fTestContext->makeCurrentAndAutoRestore(); context.fTestContext->testAbandon(); delete(context.fTestContext); context.fTestContext = nullptr; @@ -82,9 +83,10 @@ void GrContextFactory::abandonContexts() { void GrContextFactory::releaseResourcesAndAbandonContexts() { for (Context& context : fContexts) { + SkScopeExit restore(nullptr); if (!context.fAbandoned) { if (context.fTestContext) { - context.fTestContext->makeCurrent(); + restore = context.fTestContext->makeCurrentAndAutoRestore(); } context.fGrContext->releaseResourcesAndAbandonContext(); context.fAbandoned = true; @@ -237,7 +239,7 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv default: return ContextInfo(); } - testCtx->makeCurrent(); + SkASSERT(testCtx && testCtx->backend() == backend); GrContextOptions grOptions = fGlobalOptions; if (ContextOverrides::kDisableNVPR & overrides) { @@ -252,7 +254,11 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv if (ContextOverrides::kAvoidStencilBuffers & overrides) { grOptions.fAvoidStencilBuffers = true; } - sk_sp<GrContext> grCtx = testCtx->makeGrContext(grOptions); + sk_sp<GrContext> grCtx; + { + auto restore = testCtx->makeCurrentAndAutoRestore(); + grCtx = testCtx->makeGrContext(grOptions); + } if (!grCtx.get()) { return ContextInfo(); } @@ -282,6 +288,7 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv context.fShareContext = shareContext; context.fShareIndex = shareIndex; context.fOptions = grOptions; + context.fTestContext->makeCurrent(); return ContextInfo(context.fType, context.fTestContext, context.fGrContext, context.fOptions); } |