diff options
author | Brian Salomon <bsalomon@google.com> | 2017-11-16 10:17:20 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-16 16:30:53 +0000 |
commit | 5627d65146cb92624b682389e017d488872228c7 (patch) | |
tree | 9b90fe789341a23d05dc0e896eeafc1a20b70a26 /tools/gpu/TestContext.h | |
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/TestContext.h')
-rw-r--r-- | tools/gpu/TestContext.h | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tools/gpu/TestContext.h b/tools/gpu/TestContext.h index 84794f3c34..5b512db7ba 100644 --- a/tools/gpu/TestContext.h +++ b/tools/gpu/TestContext.h @@ -9,10 +9,11 @@ #ifndef TestContext_DEFINED #define TestContext_DEFINED +#include "../private/SkTemplates.h" #include "FenceSync.h" #include "GrTypes.h" #include "SkRefCnt.h" -#include "../private/SkTemplates.h" +#include "SkScopeExit.h" class GrContext; struct GrContextOptions; @@ -45,6 +46,18 @@ public: void makeCurrent() const; + /** + * Like makeCurrent() but this returns an object that will restore the previous current + * context in its destructor. Useful to undo the effect making this current before returning to + * a caller that doesn't expect the current context to be changed underneath it. + * + * The returned object restores the current context of the same type (e.g. egl, glx, ...) in its + * destructor. It is undefined behavior if that context is destroyed before the destructor + * executes. If the concept of a current context doesn't make sense for this context type then + * the returned object's destructor is a no-op. + */ + SkScopeExit SK_WARN_UNUSED_RESULT makeCurrentAndAutoRestore() const; + virtual GrBackend backend() = 0; virtual GrBackendContext backendContext() = 0; @@ -94,6 +107,14 @@ protected: virtual void teardown(); virtual void onPlatformMakeCurrent() const = 0; + /** + * Subclasses should implement such that the returned function will cause the current context + * of this type to be made current again when it is called. It should additionally be the + * case that if "this" is already current when this is called, then "this" is destroyed (thereby + * setting the null context as current), and then the std::function is called the null context + * should remain current. + */ + virtual std::function<void()> onPlatformGetAutoContextRestore() const = 0; virtual void onPlatformSwapBuffers() const = 0; private: |