diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index 1e3c231de4..0cc6486c2b 100644 --- a/tools/viewer/Viewer.cpp +++ b/tools/viewer/Viewer.cpp @@ -1013,6 +1013,20 @@ void Viewer::drawImGui(SkCanvas* canvas) { paramsChanged = true; } + if (ctx) { + int sampleCount = fWindow->sampleCount(); + ImGui::Text("MSAA: "); ImGui::SameLine(); + ImGui::RadioButton("0", &sampleCount, 0); ImGui::SameLine(); + ImGui::RadioButton("4", &sampleCount, 4); ImGui::SameLine(); + ImGui::RadioButton("8", &sampleCount, 8); ImGui::SameLine(); + ImGui::RadioButton("16", &sampleCount, 16); + + if (sampleCount != params.fMSAASampleCount) { + params.fMSAASampleCount = sampleCount; + paramsChanged = true; + } + } + if (ImGui::TreeNode("Path Renderers")) { GpuPathRenderers prevPr = params.fGrContextOptions.fGpuPathRenderers; auto prButton = [&](GpuPathRenderers x) { 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 #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