aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/gpu/gl/mac
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gpu/gl/mac')
-rw-r--r--tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp b/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp
index a94f503d48..9f1c61e564 100644
--- a/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp
+++ b/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp
@@ -14,6 +14,12 @@
#include <dlfcn.h>
namespace {
+
+std::function<void()> context_restorer() {
+ auto context = CGLGetCurrentContext();
+ return [context] { CGLSetCurrentContext(context); };
+}
+
class MacGLTestContext : public sk_gpu_test::GLTestContext {
public:
MacGLTestContext(MacGLTestContext* shareContext);
@@ -23,6 +29,7 @@ private:
void destroyGLContext();
void onPlatformMakeCurrent() const override;
+ std::function<void()> onPlatformGetAutoContextRestore() const override;
void onPlatformSwapBuffers() const override;
GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
@@ -58,6 +65,7 @@ MacGLTestContext::MacGLTestContext(MacGLTestContext* shareContext)
return;
}
+ SkScopeExit restorer(context_restorer());
CGLSetCurrentContext(fContext);
sk_sp<const GrGLInterface> gl(GrGLCreateNativeInterface());
@@ -86,6 +94,10 @@ MacGLTestContext::~MacGLTestContext() {
void MacGLTestContext::destroyGLContext() {
if (fContext) {
+ if (CGLGetCurrentContext() == fContext) {
+ // This will ensure that the context is immediately deleted.
+ CGLSetCurrentContext(nullptr);
+ }
CGLReleaseContext(fContext);
fContext = nullptr;
}
@@ -98,6 +110,13 @@ void MacGLTestContext::onPlatformMakeCurrent() const {
CGLSetCurrentContext(fContext);
}
+std::function<void()> MacGLTestContext::onPlatformGetAutoContextRestore() const {
+ if (CGLGetCurrentContext() == fContext) {
+ return nullptr;
+ }
+ return context_restorer();
+}
+
void MacGLTestContext::onPlatformSwapBuffers() const {
CGLFlushDrawable(fContext);
}