aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/gpu/TestContext.h
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-11-17 09:25:23 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-17 16:22:56 +0000
commit55ad77481290384038d7638ac4136ebf32a4ee2b (patch)
treec5c99f170efa149a933d0839c7ae96645e25c243 /tools/gpu/TestContext.h
parent3e4d1fde7fab46875cb70e23003b40aac262f0bc (diff)
Revert "Revert "Add method to sk_gpu_test::TestContext to automatically restore the previous context.""
This reverts commit 1e09e461d2ffcf8b07242cfe93dd7d12c4d75866. Change-Id: I95d5544a7baaa078536790493ce4119816a77e94 Reviewed-on: https://skia-review.googlesource.com/72903 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tools/gpu/TestContext.h')
-rw-r--r--tools/gpu/TestContext.h23
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: