aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2018-02-15 13:33:26 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-15 19:14:32 +0000
commit4013db8e081644b14aba5ab7f3ae08daaddb4405 (patch)
tree4f4f343434bf8e8be1d8f27fa544a3e44a17a0fc
parent3708f024b1118a73f0e6b3080234311c6647663b (diff)
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 <jvanverth@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
-rw-r--r--tools/sk_app/mac/GLWindowContext_mac.cpp20
-rw-r--r--tools/sk_app/mac/RasterWindowContext_mac.cpp14
-rw-r--r--tools/sk_app/mac/WindowContextFactory_mac.h3
-rw-r--r--tools/sk_app/mac/Window_mac.cpp13
-rw-r--r--tools/sk_app/mac/Window_mac.h12
5 files changed, 29 insertions, 33 deletions
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<const GrGLInterface> 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<const GrGLInterface> 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<const GrGLInterface> 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<const GrGLInterface> 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<const GrGLInterface> RasterWindowContext_mac::onInitializeContext() {
}
void RasterWindowContext_mac::onDestroyContext() {
- if (!fWindow || !fGLContext) {
- return;
- }
fBackbufferSurface.reset(nullptr);
- SDL_GL_DeleteContext(fGLContext);
- fGLContext = nullptr;
}
sk_sp<SkSurface> 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<Window_mac, Uint32> gWindowMap;
- SDL_Window* fWindow;
- Uint32 fWindowID;
+ SDL_Window* fWindow;
+ Uint32 fWindowID;
+ SDL_GLContext fGLContext;
int fMSAASampleCount;