From 28b1252bab2915a028a3c9da3e8a64c89e3b8d9d Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Wed, 8 Mar 2017 17:10:24 -0500 Subject: Added MSAA selection to viewer GUI On Windows, we need to reconstruct the window to allow setting a new pixel format with a different sample count. Added some code that maintains window size/position across these changes. Previously, just cycling through backends would cause the window to move, as the "default" position would cycle across the screen. Now it's pinned. BUG=skia: Change-Id: Iecbe7a490577382043ffe5a88c910b4c0be2ed5c Reviewed-on: https://skia-review.googlesource.com/9085 Commit-Queue: Brian Osman Reviewed-by: Brian Salomon --- tools/viewer/Viewer.cpp | 14 ++++++++++++++ tools/viewer/sk_app/Window.h | 2 +- tools/viewer/sk_app/win/Window_win.cpp | 24 +++++++++++++++++++++++- tools/viewer/sk_app/win/Window_win.h | 7 +++++++ 4 files changed, 45 insertions(+), 2 deletions(-) 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 -- cgit v1.2.3