diff options
Diffstat (limited to 'tools/viewer/sk_app')
-rw-r--r-- | tools/viewer/sk_app/Window.h | 2 | ||||
-rw-r--r-- | tools/viewer/sk_app/win/Window_win.cpp | 24 | ||||
-rw-r--r-- | tools/viewer/sk_app/win/Window_win.h | 7 |
3 files changed, 31 insertions, 2 deletions
diff --git a/tools/viewer/sk_app/Window.h b/tools/viewer/sk_app/Window.h index 85cf3ac8a4..c5d8c346af 100644 --- a/tools/viewer/sk_app/Window.h +++ b/tools/viewer/sk_app/Window.h @@ -193,7 +193,7 @@ public: int height(); virtual const DisplayParams& getRequestedDisplayParams() { return fRequestedDisplayParams; } - void setRequestedDisplayParams(const DisplayParams&); + virtual void setRequestedDisplayParams(const DisplayParams&); // Actual parameters in effect, obtained from the native window. int sampleCount() const; diff --git a/tools/viewer/sk_app/win/Window_win.cpp b/tools/viewer/sk_app/win/Window_win.cpp index 9614d71c21..1bec410ad2 100644 --- a/tools/viewer/sk_app/win/Window_win.cpp +++ b/tools/viewer/sk_app/win/Window_win.cpp @@ -12,6 +12,7 @@ #include <windowsx.h> #include "SkUtils.h" +#include "../WindowContext.h" #include "WindowContextFactory_win.h" #ifdef SK_VULKAN #include "../VulkanWindowContext.h" @@ -36,7 +37,7 @@ Window* Window::CreateNativeWindow(void* platformData) { return window; } -Window_win::~Window_win() { +void Window_win::closeWindow() { RECT r; if (GetWindowRect(fHWnd, &r)) { gWindowX = r.left; @@ -47,6 +48,10 @@ Window_win::~Window_win() { DestroyWindow(fHWnd); } +Window_win::~Window_win() { + this->closeWindow(); +} + LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); @@ -308,6 +313,8 @@ void Window_win::show() { bool Window_win::attach(BackendType attachType) { + fBackend = attachType; + switch (attachType) { case kNativeGL_BackendType: fWindowContext = window_context_factory::NewGLForWin(fHWnd, fRequestedDisplayParams); @@ -332,4 +339,19 @@ void Window_win::onInval() { InvalidateRect(fHWnd, nullptr, false); } +void Window_win::setRequestedDisplayParams(const DisplayParams& params) { + // GL on Windows doesn't let us change MSAA after the window is created + if (params.fMSAASampleCount != this->getRequestedDisplayParams().fMSAASampleCount) { + // Need to change these early, so attach() creates the window context correctly + fRequestedDisplayParams = params; + + delete fWindowContext; + this->closeWindow(); + this->init(fHInstance); + this->attach(fBackend); + } + + INHERITED::setRequestedDisplayParams(params); +} + } // namespace sk_app diff --git a/tools/viewer/sk_app/win/Window_win.h b/tools/viewer/sk_app/win/Window_win.h index 6d2279393a..0c6e1f2915 100644 --- a/tools/viewer/sk_app/win/Window_win.h +++ b/tools/viewer/sk_app/win/Window_win.h @@ -27,9 +27,16 @@ public: void onInval() override; + void setRequestedDisplayParams(const DisplayParams&) override; + private: + void closeWindow(); + HINSTANCE fHInstance; HWND fHWnd; + BackendType fBackend; + + typedef Window INHERITED; }; } // namespace sk_app |