From 4013db8e081644b14aba5ab7f3ae08daaddb4405 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Thu, 15 Feb 2018 13:33:26 -0500 Subject: Fix flicker when changing backend on Mac viewer Tie the SDL GL context to the Window, not the context. Deleting the context causes the window to render a frame of black - this keeps the context alive along with the window, so that never happens. Change-Id: Id4df18a6f2fe09f617ec2ff1809d000f18f547ba Reviewed-on: https://skia-review.googlesource.com/107941 Reviewed-by: Jim Van Verth Commit-Queue: Brian Osman --- tools/sk_app/mac/GLWindowContext_mac.cpp | 20 +++----------------- tools/sk_app/mac/RasterWindowContext_mac.cpp | 14 ++------------ tools/sk_app/mac/WindowContextFactory_mac.h | 3 ++- tools/sk_app/mac/Window_mac.cpp | 13 +++++++++++++ tools/sk_app/mac/Window_mac.h | 12 +++++++++--- 5 files changed, 29 insertions(+), 33 deletions(-) (limited to 'tools/sk_app') diff --git a/tools/sk_app/mac/GLWindowContext_mac.cpp b/tools/sk_app/mac/GLWindowContext_mac.cpp index 67fb853fee..f7e56ccb62 100644 --- a/tools/sk_app/mac/GLWindowContext_mac.cpp +++ b/tools/sk_app/mac/GLWindowContext_mac.cpp @@ -27,7 +27,7 @@ public: void onSwapBuffers() override; sk_sp onInitializeContext() override; - void onDestroyContext() override; + void onDestroyContext() override {} private: SDL_Window* fWindow; @@ -39,7 +39,7 @@ private: GLWindowContext_mac::GLWindowContext_mac(const MacWindowInfo& info, const DisplayParams& params) : INHERITED(params) , fWindow(info.fWindow) - , fGLContext(nullptr) { + , fGLContext(info.fGLContext) { // any config code here (particularly for msaa)? @@ -52,12 +52,7 @@ GLWindowContext_mac::~GLWindowContext_mac() { sk_sp GLWindowContext_mac::onInitializeContext() { SkASSERT(fWindow); - - fGLContext = SDL_GL_CreateContext(fWindow); - if (!fGLContext) { - SkDebugf("%s\n", SDL_GetError()); - return nullptr; - } + SkASSERT(fGLContext); if (0 == SDL_GL_MakeCurrent(fWindow, fGLContext)) { glClearStencil(0); @@ -77,15 +72,6 @@ sk_sp GLWindowContext_mac::onInitializeContext() { return GrGLMakeNativeInterface(); } -void GLWindowContext_mac::onDestroyContext() { - if (!fWindow || !fGLContext) { - return; - } - SDL_GL_DeleteContext(fGLContext); - fGLContext = nullptr; -} - - void GLWindowContext_mac::onSwapBuffers() { if (fWindow && fGLContext) { SDL_GL_SwapWindow(fWindow); diff --git a/tools/sk_app/mac/RasterWindowContext_mac.cpp b/tools/sk_app/mac/RasterWindowContext_mac.cpp index fbe9837911..b66ba407fa 100644 --- a/tools/sk_app/mac/RasterWindowContext_mac.cpp +++ b/tools/sk_app/mac/RasterWindowContext_mac.cpp @@ -51,7 +51,7 @@ RasterWindowContext_mac::RasterWindowContext_mac(const MacWindowInfo& info, const DisplayParams& params) : INHERITED(params) , fWindow(info.fWindow) - , fGLContext(nullptr) { + , fGLContext(info.fGLContext) { // any config code here (particularly for msaa)? @@ -64,12 +64,7 @@ RasterWindowContext_mac::~RasterWindowContext_mac() { sk_sp RasterWindowContext_mac::onInitializeContext() { SkASSERT(fWindow); - - fGLContext = SDL_GL_CreateContext(fWindow); - if (!fGLContext) { - SkDebugf("%s\n", SDL_GetError()); - return nullptr; - } + SkASSERT(fGLContext); if (0 == SDL_GL_MakeCurrent(fWindow, fGLContext)) { glClearStencil(0); @@ -95,12 +90,7 @@ sk_sp RasterWindowContext_mac::onInitializeContext() { } void RasterWindowContext_mac::onDestroyContext() { - if (!fWindow || !fGLContext) { - return; - } fBackbufferSurface.reset(nullptr); - SDL_GL_DeleteContext(fGLContext); - fGLContext = nullptr; } sk_sp RasterWindowContext_mac::getBackbufferSurface() { return fBackbufferSurface; } diff --git a/tools/sk_app/mac/WindowContextFactory_mac.h b/tools/sk_app/mac/WindowContextFactory_mac.h index 3adc68bbc2..c195c24daa 100644 --- a/tools/sk_app/mac/WindowContextFactory_mac.h +++ b/tools/sk_app/mac/WindowContextFactory_mac.h @@ -19,7 +19,8 @@ struct DisplayParams; namespace window_context_factory { struct MacWindowInfo { - SDL_Window* fWindow; + SDL_Window* fWindow; + SDL_GLContext fGLContext; }; inline WindowContext* NewVulkanForMac(const MacWindowInfo&, const DisplayParams&) { diff --git a/tools/sk_app/mac/Window_mac.cpp b/tools/sk_app/mac/Window_mac.cpp index f2620518a2..309c8bbf36 100644 --- a/tools/sk_app/mac/Window_mac.cpp +++ b/tools/sk_app/mac/Window_mac.cpp @@ -71,10 +71,22 @@ bool Window_mac::initWindow() { fWindowID = SDL_GetWindowID(fWindow); gWindowMap.add(this); + fGLContext = SDL_GL_CreateContext(fWindow); + if (!fGLContext) { + SkDebugf("%s\n", SDL_GetError()); + this->closeWindow(); + return false; + } + return true; } void Window_mac::closeWindow() { + if (fGLContext) { + SDL_GL_DeleteContext(fGLContext); + fGLContext = nullptr; + } + if (fWindow) { gWindowMap.remove(fWindowID); SDL_DestroyWindow(fWindow); @@ -251,6 +263,7 @@ bool Window_mac::attach(BackendType attachType) { window_context_factory::MacWindowInfo info; info.fWindow = fWindow; + info.fGLContext = fGLContext; switch (attachType) { case kRaster_BackendType: fWindowContext = NewRasterForMac(info, fRequestedDisplayParams); diff --git a/tools/sk_app/mac/Window_mac.h b/tools/sk_app/mac/Window_mac.h index 35cba095fa..8b34b7c902 100644 --- a/tools/sk_app/mac/Window_mac.h +++ b/tools/sk_app/mac/Window_mac.h @@ -18,7 +18,12 @@ namespace sk_app { class Window_mac : public Window { public: - Window_mac() : INHERITED(), fWindow(nullptr), fWindowID(0), fMSAASampleCount(1) {} + Window_mac() + : INHERITED() + , fWindow(nullptr) + , fWindowID(0) + , fGLContext(nullptr) + , fMSAASampleCount(1) {} ~Window_mac() override { this->closeWindow(); } bool initWindow(); @@ -47,8 +52,9 @@ private: static SkTDynamicHash gWindowMap; - SDL_Window* fWindow; - Uint32 fWindowID; + SDL_Window* fWindow; + Uint32 fWindowID; + SDL_GLContext fGLContext; int fMSAASampleCount; -- cgit v1.2.3