diff --git a/tools/sk_app/ios/GLWindowContext_ios.cpp b/tools/sk_app/ios/GLWindowContext_ios.cpp index 2a57b33e30..aac7e20fd9 100644 --- a/tools/sk_app/ios/GLWindowContext_ios.cpp +++ b/tools/sk_app/ios/GLWindowContext_ios.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_ios::GLWindowContext_ios(const IOSWindowInfo& 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_ios::~GLWindowContext_ios() { sk_sp GLWindowContext_ios::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_ios::onInitializeContext() { return GrGLMakeNativeInterface(); } -void GLWindowContext_ios::onDestroyContext() { - if (!fWindow || !fGLContext) { - return; - } - SDL_GL_DeleteContext(fGLContext); - fGLContext = nullptr; -} - - void GLWindowContext_ios::onSwapBuffers() { if (fWindow && fGLContext) { SDL_GL_SwapWindow(fWindow); diff --git a/tools/sk_app/ios/RasterWindowContext_ios.cpp b/tools/sk_app/ios/RasterWindowContext_ios.cpp index 53d7c1a372..18a6c36014 100644 --- a/tools/sk_app/ios/RasterWindowContext_ios.cpp +++ b/tools/sk_app/ios/RasterWindowContext_ios.cpp @@ -64,12 +64,7 @@ RasterWindowContext_ios::~RasterWindowContext_ios() { sk_sp RasterWindowContext_ios::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_ios::onInitializeContext() { } void RasterWindowContext_ios::onDestroyContext() { - if (!fWindow || !fGLContext) { - return; - } fBackbufferSurface.reset(nullptr); - SDL_GL_DeleteContext(fGLContext); - fGLContext = nullptr; } sk_sp RasterWindowContext_ios::getBackbufferSurface() { return fBackbufferSurface; } diff --git a/tools/sk_app/ios/WindowContextFactory_ios.h b/tools/sk_app/ios/WindowContextFactory_ios.h index 09999c4c83..93c6fbf450 100644 --- a/tools/sk_app/ios/WindowContextFactory_ios.h +++ b/tools/sk_app/ios/WindowContextFactory_ios.h @@ -19,7 +19,8 @@ struct DisplayParams; namespace window_context_factory { struct IOSWindowInfo { - SDL_Window* fWindow; + SDL_Window* fWindow; + SDL_GLContext fGLContext; }; inline WindowContext* NewVulkanForIOS(const IOSWindowInfo&, const DisplayParams&) { diff --git a/tools/sk_app/ios/Window_ios.cpp b/tools/sk_app/ios/Window_ios.cpp index ac0ad0caa0..9b2339d19e 100644 --- a/tools/sk_app/ios/Window_ios.cpp +++ b/tools/sk_app/ios/Window_ios.cpp @@ -71,10 +71,22 @@ bool Window_ios::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_ios::closeWindow() { + if (fGLContext) { + SDL_GL_DeleteContext(fGLContext); + fGLContext = nullptr; + } + if (fWindow) { gWindowMap.remove(fWindowID); SDL_DestroyWindow(fWindow); @@ -251,6 +263,7 @@ bool Window_ios::attach(BackendType attachType) { window_context_factory::IOSWindowInfo info; info.fWindow = fWindow; + info.fGLContext = fGLContext; switch (attachType) { case kRaster_BackendType: fWindowContext = NewRasterForIOS(info, fRequestedDisplayParams); diff --git a/tools/sk_app/ios/Window_ios.h b/tools/sk_app/ios/Window_ios.h index a0fed90697..260b133ff9 100644 --- a/tools/sk_app/ios/Window_ios.h +++ b/tools/sk_app/ios/Window_ios.h @@ -18,7 +18,12 @@ namespace sk_app { class Window_ios : public Window { public: - Window_ios() : INHERITED(), fWindow(nullptr), fWindowID(0), fMSAASampleCount(1) {} + Window_ios() + : INHERITED() + , fWindow(nullptr) + , fWindowID(0) + , fGLContext(nullptr) + , fMSAASampleCount(1) {} ~Window_ios() 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;