From ec54539d3941dd65fef0e8ac04b3de82749b6824 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Fri, 4 May 2018 11:44:40 -0400 Subject: Make RenderDoc work automatically with GLX viewer Change-Id: I19769924882c2790cfc862373d6f26508b410eee Reviewed-on: https://skia-review.googlesource.com/125871 Reviewed-by: Brian Osman Commit-Queue: Brian Salomon --- tools/sk_app/unix/GLWindowContext_unix.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'tools/sk_app') diff --git a/tools/sk_app/unix/GLWindowContext_unix.cpp b/tools/sk_app/unix/GLWindowContext_unix.cpp index 3a3a4b16d4..d21951cda7 100644 --- a/tools/sk_app/unix/GLWindowContext_unix.cpp +++ b/tools/sk_app/unix/GLWindowContext_unix.cpp @@ -58,6 +58,8 @@ using CreateContextAttribsFn = GLXContext(Display*, GLXFBConfig, GLXContext, Boo sk_sp GLWindowContext_xlib::onInitializeContext() { SkASSERT(fDisplay); SkASSERT(!fGLContext); + sk_sp interface; + bool current = false; // We attempt to use glXCreateContextAttribsARB as RenderDoc requires that the context be // created with this rather than glXCreateContext. CreateContextAttribsFn* createContextAttribs = (CreateContextAttribsFn*)glXGetProcAddressARB( @@ -76,6 +78,20 @@ sk_sp GLWindowContext_xlib::onInitializeContext() { 0 }; fGLContext = createContextAttribs(fDisplay, *fFBConfig, nullptr, True, attribs); + if (fGLContext && profile == GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB && + glXMakeCurrent(fDisplay, fWindow, fGLContext)) { + current = true; + // Look to see if RenderDoc is attached. If so, re-create the context with a + // core profile. + interface = GrGLMakeNativeInterface(); + if (interface && interface->fExtensions.has("GL_EXT_debug_tool")) { + interface.reset(); + glXMakeCurrent(fDisplay, None, nullptr); + glXDestroyContext(fDisplay, fGLContext); + current = false; + fGLContext = nullptr; + } + } if (fGLContext) { break; } @@ -89,7 +105,7 @@ sk_sp GLWindowContext_xlib::onInitializeContext() { return nullptr; } - if (!glXMakeCurrent(fDisplay, fWindow, fGLContext)) { + if (!current && !glXMakeCurrent(fDisplay, fWindow, fGLContext)) { return nullptr; } glClearStencil(0); @@ -108,7 +124,7 @@ sk_sp GLWindowContext_xlib::onInitializeContext() { &border_width, &depth); glViewport(0, 0, fWidth, fHeight); - return GrGLMakeNativeInterface(); + return interface ? interface : GrGLMakeNativeInterface(); } GLWindowContext_xlib::~GLWindowContext_xlib() { -- cgit v1.2.3