Fix flicker when changing backend on iOS viewer

This is the same fix from: https://skia-review.googlesource.com/c/skia/+/107941

Change-Id: I1367b1fc466cecbc2733b4e337376ce9f48cb6d8
Reviewed-on: https://skia-review.googlesource.com/107980
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2018-02-15 15:25:11 -05:00 committed by Skia Commit-Bot
parent 76a076bbdf
commit 6848b716f7
5 changed files with 28 additions and 32 deletions

View File

@ -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_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<const GrGLInterface> 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<const GrGLInterface> 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);

View File

@ -64,12 +64,7 @@ RasterWindowContext_ios::~RasterWindowContext_ios() {
sk_sp<const GrGLInterface> 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<const GrGLInterface> RasterWindowContext_ios::onInitializeContext() {
}
void RasterWindowContext_ios::onDestroyContext() {
if (!fWindow || !fGLContext) {
return;
}
fBackbufferSurface.reset(nullptr);
SDL_GL_DeleteContext(fGLContext);
fGLContext = nullptr;
}
sk_sp<SkSurface> RasterWindowContext_ios::getBackbufferSurface() { return fBackbufferSurface; }

View File

@ -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&) {

View File

@ -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);

View File

@ -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<Window_ios, Uint32> gWindowMap;
SDL_Window* fWindow;
Uint32 fWindowID;
SDL_Window* fWindow;
Uint32 fWindowID;
SDL_GLContext fGLContext;
int fMSAASampleCount;