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>
This commit is contained in:
parent
3708f024b1
commit
4013db8e08
@ -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);
|
||||
|
@ -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; }
|
||||
|
@ -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&) {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user