aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/gpu/gl/angle/GLTestContext_angle.cpp
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/gl/angle/GLTestContext_angle.cpp
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/gl/angle/GLTestContext_angle.cpp')
-rw-r--r--tools/gpu/gl/angle/GLTestContext_angle.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/gpu/gl/angle/GLTestContext_angle.cpp b/tools/gpu/gl/angle/GLTestContext_angle.cpp
index 52cc5128da..3b55c40bac 100644
--- a/tools/gpu/gl/angle/GLTestContext_angle.cpp
+++ b/tools/gpu/gl/angle/GLTestContext_angle.cpp
@@ -34,6 +34,16 @@ struct Libs {
void* fEGLLib;
};
+std::function<void()> context_restorer() {
+ auto display = eglGetCurrentDisplay();
+ auto dsurface = eglGetCurrentSurface(EGL_DRAW);
+ auto rsurface = eglGetCurrentSurface(EGL_READ);
+ auto context = eglGetCurrentContext();
+ return [display, dsurface, rsurface, context] {
+ eglMakeCurrent(display, dsurface, rsurface, context);
+ };
+}
+
static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) {
const Libs* libs = reinterpret_cast<const Libs*>(ctx);
GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(libs->fGLLib, name);
@@ -87,6 +97,7 @@ private:
void destroyGLContext();
void onPlatformMakeCurrent() const override;
+ std::function<void()> onPlatformGetAutoContextRestore() const override;
void onPlatformSwapBuffers() const override;
GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override;
@@ -214,6 +225,7 @@ ANGLEGLContext::ANGLEGLContext(ANGLEBackend type, ANGLEContextVersion version,
fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs);
+ SkScopeExit restorer(context_restorer());
if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
SkDebugf("Could not set the context.");
this->destroyGLContext();
@@ -320,7 +332,10 @@ std::unique_ptr<sk_gpu_test::GLTestContext> ANGLEGLContext::makeNew() const {
void ANGLEGLContext::destroyGLContext() {
if (EGL_NO_DISPLAY != fDisplay) {
- eglMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ if (eglGetCurrentContext() == fContext) {
+ // This will ensure that the context is immediately deleted.
+ eglMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ }
if (EGL_NO_CONTEXT != fContext) {
eglDestroyContext(fDisplay, fContext);
@@ -355,6 +370,13 @@ void ANGLEGLContext::onPlatformMakeCurrent() const {
}
}
+std::function<void()> ANGLEGLContext::onPlatformGetAutoContextRestore() const {
+ if (eglGetCurrentContext() == fContext) {
+ return nullptr;
+ }
+ return context_restorer();
+}
+
void ANGLEGLContext::onPlatformSwapBuffers() const {
if (!eglSwapBuffers(fDisplay, fSurface)) {
SkDebugf("Could not complete eglSwapBuffers.\n");