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 <brianosman@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
538f1a36e3
commit
28b1252bab
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user