From 56cee3c00eef896da32684e2dd28909329e52acd Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 29 Jun 2014 21:03:24 +0200 Subject: [PATCH] Prevent rendering and multiple WM_SIZE events when switching between windowed and fullscreen May help #6295 but also it may not, I can't test it as I don't have that GPU. Also gets rid of some outdated code. --- Windows/OpenGLBase.cpp | 16 ----------- Windows/OpenGLBase.h | 2 -- Windows/WindowsHost.cpp | 4 +-- Windows/WndMainWindow.cpp | 58 +++++++++++++++++++++++++-------------- Windows/WndMainWindow.h | 4 +-- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Windows/OpenGLBase.cpp b/Windows/OpenGLBase.cpp index 1a31d85d07..a6b5bd66a0 100644 --- a/Windows/OpenGLBase.cpp +++ b/Windows/OpenGLBase.cpp @@ -21,20 +21,6 @@ static int xres, yres; // TODO: Make config? static bool enableGLDebug = false; -void GL_Resized() { - if (!hWnd) - return; - RECT rc; - GetWindowRect(hWnd, &rc); - xres = rc.right - rc.left; //account for border :P - yres = rc.bottom - rc.top; - - if (yres == 0) - yres = 1; - glstate.viewport.set(0, 0, xres, yres); - glstate.viewport.restore(); -} - void GL_SwapBuffers() { SwapBuffers(hDC); } @@ -253,8 +239,6 @@ bool GL_Init(HWND window, std::string *error_message) { glDebugMessageCallbackARB((GLDEBUGPROCARB)&DebugCallbackARB, 0); // print debug output to stderr glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); } - - GL_Resized(); // Set up our perspective GL screen return true; // Success } diff --git a/Windows/OpenGLBase.h b/Windows/OpenGLBase.h index 7b35d6f0d2..e900b4bed5 100644 --- a/Windows/OpenGLBase.h +++ b/Windows/OpenGLBase.h @@ -5,7 +5,5 @@ #include "Common/CommonWindows.h" bool GL_Init(HWND window, std::string *error_message); - void GL_Shutdown(); -void GL_Resized(); void GL_SwapBuffers(); diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index c606b644e6..d3b9191605 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -335,9 +335,9 @@ bool WindowsHost::CreateDesktopShortcut(std::string argumentPath, std::string ga void WindowsHost::GoFullscreen(bool viewFullscreen) { if (viewFullscreen) - MainWindow::_ViewFullScreen(MainWindow::GetHWND()); + MainWindow::SwitchToFullscreen(MainWindow::GetHWND()); else - MainWindow::_ViewNormal(MainWindow::GetHWND()); + MainWindow::SwitchToWindowed(MainWindow::GetHWND()); } void WindowsHost::ToggleDebugConsoleVisibility() { diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 6e52816b34..b4330b1b1d 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -132,6 +132,8 @@ namespace MainWindow { static std::vector availableShaders; static W32Util::AsyncBrowseDialog *browseDialog; static bool browsePauseAfter; + static bool g_inModeSwitch; // when true, don't react to WM_SIZE + #define MAX_LOADSTRING 100 const TCHAR *szTitle = TEXT("PPSSPP"); const TCHAR *szWindowClass = TEXT("PPSSPPWnd"); @@ -286,7 +288,11 @@ namespace MainWindow { } } - void _ViewNormal(HWND hWnd) { + void SwitchToWindowed(HWND hWnd) { + // Make sure no rendering is happening during the switch. + Core_NotifyWindowHidden(true); + g_inModeSwitch = true; // Make sure WM_SIZE doesn't call Core_NotifyWindowHidden(false)... + // Put caption and border styles back. DWORD dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE); DWORD dwNewStyle = dwOldStyle | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU; @@ -308,16 +314,23 @@ namespace MainWindow { CorrectCursor(); bool showOSM = (g_Config.iInternalResolution == RESOLUTION_AUTO); - ResizeDisplay(true); + ResizeDisplay(false); if (showOSM) { ShowScreenResolution(); } ShowOwnedPopups(hwndMain, TRUE); W32Util::MakeTopMost(hwndMain, g_Config.bTopMost); + + g_inModeSwitch = false; + Core_NotifyWindowHidden(false); } - void _ViewFullScreen(HWND hWnd) { - // Keep in mind normal window rectangle. + void SwitchToFullscreen(HWND hWnd) { + // Make sure no rendering is happening during the switch. + Core_NotifyWindowHidden(true); + g_inModeSwitch = true; // Make sure WM_SIZE doesn't call Core_NotifyWindowHidden(false)... + + // Remember the normal window rectangle. ::GetWindowRect(hWnd, &g_normalRC); // Remove caption and border styles. @@ -341,12 +354,15 @@ namespace MainWindow { CorrectCursor(); bool showOSM = (g_Config.iInternalResolution == RESOLUTION_AUTO); - ResizeDisplay(true); + ResizeDisplay(false); if (showOSM) { ShowScreenResolution(); } ShowOwnedPopups(hwndMain, FALSE); + + g_inModeSwitch = false; + Core_NotifyWindowHidden(false); } RECT DetermineWindowRectangle() { @@ -800,7 +816,7 @@ namespace MainWindow { SetFocus(hwndMain); if (g_Config.bFullScreen) - _ViewFullScreen(hwndMain); + SwitchToFullscreen(hwndMain); return TRUE; } @@ -914,18 +930,20 @@ namespace MainWindow { switch (message) { case WM_SIZE: - switch (wParam) { - case SIZE_MAXIMIZED: - case SIZE_RESTORED: - Core_NotifyWindowHidden(false); - SavePosition(); - ResizeDisplay(); - break; - case SIZE_MINIMIZED: - Core_NotifyWindowHidden(true); - break; - default: - break; + if (!g_inModeSwitch) { + switch (wParam) { + case SIZE_MAXIMIZED: + case SIZE_RESTORED: + Core_NotifyWindowHidden(false); + SavePosition(); + ResizeDisplay(); + break; + case SIZE_MINIMIZED: + Core_NotifyWindowHidden(true); + break; + default: + break; + } } break; @@ -1433,9 +1451,9 @@ namespace MainWindow { g_Config.bFullScreen = !g_Config.bFullScreen; if (g_Config.bFullScreen) - _ViewFullScreen(hWnd); + SwitchToFullscreen(hWnd); else - _ViewNormal(hWnd); + SwitchToWindowed(hWnd); break; diff --git a/Windows/WndMainWindow.h b/Windows/WndMainWindow.h index 942d3f3dde..b6648d63b2 100644 --- a/Windows/WndMainWindow.h +++ b/Windows/WndMainWindow.h @@ -62,8 +62,8 @@ namespace MainWindow HINSTANCE GetHInstance(); void BrowseAndBoot(std::string defaultPath, bool browseDirectory = false); void SaveStateActionFinished(bool result, void *userdata); - void _ViewFullScreen(HWND hWnd); - void _ViewNormal(HWND hWnd); + void SwitchToFullscreen(HWND hWnd); + void SwitchToWindowed(HWND hWnd); void ToggleDebugConsoleVisibility(); void TranslateMenus(); void setTexScalingMultiplier(int level);