Index: src/views/win/SkOSWindow_win.cpp |
diff --git a/src/views/win/SkOSWindow_win.cpp b/src/views/win/SkOSWindow_win.cpp |
index a0288d973c9d15b671dc24ed77885d0d3023d2e5..b0bb76ca19cc05071a108a6902cce64b5e4fee2e 100644 |
--- a/src/views/win/SkOSWindow_win.cpp |
+++ b/src/views/win/SkOSWindow_win.cpp |
@@ -60,7 +60,6 @@ SkOSWindow::SkOSWindow(const void* winInit) { |
} |
SkOSWindow::~SkOSWindow() { |
- this->setFullscreen(false); |
#if SK_SUPPORT_GPU |
if (fHGLRC) { |
wglDeleteContext((HGLRC)fHGLRC); |
@@ -82,8 +81,7 @@ SkOSWindow::~SkOSWindow() { |
} |
#endif // SK_ANGLE |
#endif // SK_SUPPORT_GPU |
- gHwndToOSWindowMap.remove(fHWND); |
- DestroyWindow((HWND)fHWND); |
+ this->closeWindow(); |
} |
static SkKey winToskKey(WPARAM vk) { |
@@ -613,106 +611,78 @@ void SkOSWindow::present() { |
} |
} |
-void SkOSWindow::setFullscreen(bool fullscreen) { |
- if (fullscreen == fFullscreen) { |
- return; |
+bool SkOSWindow::makeFullscreen() { |
+ if (fFullscreen) { |
+ return true; |
} |
if (fHGLRC) { |
this->detachGL(); |
} |
// This is hacked together from various sources on the web. It can certainly be improved and be |
// made more robust. |
- if (fullscreen) { |
- // Save current window/resolution information. |
- fSavedWindowState.fZoomed = SkToBool(IsZoomed((HWND)fHWND)); |
- if (fSavedWindowState.fZoomed) { |
- SendMessage((HWND)fHWND, WM_SYSCOMMAND, SC_RESTORE, 0); |
- } |
- fSavedWindowState.fStyle = GetWindowLong((HWND)fHWND, GWL_STYLE); |
- fSavedWindowState.fExStyle = GetWindowLong((HWND)fHWND, GWL_EXSTYLE); |
- GetWindowRect((HWND)fHWND, &fSavedWindowState.fRect); |
- DEVMODE dmScreenSettings; // Device Mode |
- memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared |
- dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure |
- EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dmScreenSettings); |
- fSavedWindowState.fScreenWidth = dmScreenSettings.dmPelsWidth; |
- fSavedWindowState.fScreenHeight = dmScreenSettings.dmPelsHeight; |
- fSavedWindowState.fScreenBits = dmScreenSettings.dmBitsPerPel; |
- fSavedWindowState.fHWND = fHWND; |
- } |
- |
- if (fullscreen) { |
- // Try different sizes to find an allowed setting? Use ChangeDisplaySettingsEx? |
- static const int kWidth = 1280; |
- static const int kHeight = 1024; |
- DEVMODE dmScreenSettings; |
- memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); |
- dmScreenSettings.dmSize=sizeof(dmScreenSettings); |
- dmScreenSettings.dmPelsWidth = kWidth; |
- dmScreenSettings.dmPelsHeight = kHeight; |
- dmScreenSettings.dmBitsPerPel = 32; |
- dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; |
- if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { |
- return; |
- } |
- RECT WindowRect; |
- WindowRect.left = 0; |
- WindowRect.right = kWidth; |
- WindowRect.top = 0; |
- WindowRect.bottom = kHeight; |
- ShowCursor(FALSE); |
- AdjustWindowRectEx(&WindowRect, WS_POPUP, FALSE, WS_EX_APPWINDOW); |
- HWND fsHWND = CreateWindowEx( |
- WS_EX_APPWINDOW, |
- fWinInit.fClass, |
- NULL, |
- WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP, |
- 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, |
- NULL, |
- NULL, |
- fWinInit.fInstance, |
- NULL |
- ); |
- if (!fsHWND) { |
- return; |
- } |
- // Hide the old window and set the entry in the global mapping for this SkOSWindow to the |
- // new HWND. |
- ShowWindow((HWND)fHWND, SW_HIDE); |
- gHwndToOSWindowMap.remove(fHWND); |
- fHWND = fsHWND; |
- gHwndToOSWindowMap.set(fHWND, this); |
- this->updateSize(); |
- } else { |
- DEVMODE dmScreenSettings; |
- memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); |
- dmScreenSettings.dmSize=sizeof(dmScreenSettings); |
- dmScreenSettings.dmPelsWidth = fSavedWindowState.fScreenWidth; |
- dmScreenSettings.dmPelsHeight = fSavedWindowState.fScreenHeight; |
- dmScreenSettings.dmBitsPerPel = fSavedWindowState.fScreenBits; |
- dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; |
- if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { |
- return; |
- } |
- gHwndToOSWindowMap.remove(fHWND); |
- DestroyWindow((HWND)fHWND); |
- fHWND = fSavedWindowState.fHWND; |
- gHwndToOSWindowMap.set(fHWND, this); |
- ShowWindow((HWND)fHWND, SW_SHOW); |
- SetWindowLong((HWND)fHWND, GWL_STYLE, fSavedWindowState.fStyle); |
- SetWindowLong((HWND)fHWND, GWL_EXSTYLE, fSavedWindowState.fExStyle); |
- |
- int width = fSavedWindowState.fRect.right - fSavedWindowState.fRect.left; |
- int height = fSavedWindowState.fRect.right - fSavedWindowState.fRect.left; |
- SetWindowPos((HWND)fHWND, NULL, fSavedWindowState.fRect.left, fSavedWindowState.fRect.top, |
- width, height, |
- SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); |
- if (fSavedWindowState.fZoomed) { |
- SendMessage((HWND)fHWND, WM_SYSCOMMAND, SC_MAXIMIZE, 0); |
- } |
- this->updateSize(); |
+ |
+ // Save current window/resolution information. We do this in case we ever implement switching |
+ // back to windowed mode. |
+ fSavedWindowState.fZoomed = SkToBool(IsZoomed((HWND)fHWND)); |
+ if (fSavedWindowState.fZoomed) { |
+ SendMessage((HWND)fHWND, WM_SYSCOMMAND, SC_RESTORE, 0); |
} |
- fFullscreen = fullscreen; |
+ fSavedWindowState.fStyle = GetWindowLong((HWND)fHWND, GWL_STYLE); |
+ fSavedWindowState.fExStyle = GetWindowLong((HWND)fHWND, GWL_EXSTYLE); |
+ GetWindowRect((HWND)fHWND, &fSavedWindowState.fRect); |
+ DEVMODE currScreenSettings; |
+ memset(&currScreenSettings,0,sizeof(currScreenSettings)); |
+ currScreenSettings.dmSize = sizeof(currScreenSettings); |
+ EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &currScreenSettings); |
+ fSavedWindowState.fScreenWidth = currScreenSettings.dmPelsWidth; |
+ fSavedWindowState.fScreenHeight = currScreenSettings.dmPelsHeight; |
+ fSavedWindowState.fScreenBits = currScreenSettings.dmBitsPerPel; |
+ fSavedWindowState.fHWND = fHWND; |
+ |
+ // Try different sizes to find an allowed setting? Use ChangeDisplaySettingsEx? |
+ static const int kWidth = 1280; |
+ static const int kHeight = 1024; |
+ DEVMODE newScreenSettings; |
+ memset(&newScreenSettings, 0, sizeof(newScreenSettings)); |
+ newScreenSettings.dmSize = sizeof(newScreenSettings); |
+ newScreenSettings.dmPelsWidth = kWidth; |
+ newScreenSettings.dmPelsHeight = kHeight; |
+ newScreenSettings.dmBitsPerPel = 32; |
+ newScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; |
+ if (ChangeDisplaySettings(&newScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { |
+ return false; |
+ } |
+ RECT WindowRect; |
+ WindowRect.left = 0; |
+ WindowRect.right = kWidth; |
+ WindowRect.top = 0; |
+ WindowRect.bottom = kHeight; |
+ ShowCursor(FALSE); |
+ AdjustWindowRectEx(&WindowRect, WS_POPUP, FALSE, WS_EX_APPWINDOW); |
+ HWND fsHWND = CreateWindowEx( |
+ WS_EX_APPWINDOW, |
+ fWinInit.fClass, |
+ NULL, |
+ WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP, |
+ 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, |
+ NULL, |
+ NULL, |
+ fWinInit.fInstance, |
+ NULL |
+ ); |
+ if (!fsHWND) { |
+ return false; |
+ } |
+ // Hide the old window and set the entry in the global mapping for this SkOSWindow to the |
+ // new HWND. |
+ ShowWindow((HWND)fHWND, SW_HIDE); |
+ gHwndToOSWindowMap.remove(fHWND); |
+ fHWND = fsHWND; |
+ gHwndToOSWindowMap.set(fHWND, this); |
+ this->updateSize(); |
+ |
+ fFullscreen = true; |
+ return true; |
} |
void SkOSWindow::setVsync(bool enable) { |
@@ -721,7 +691,10 @@ void SkOSWindow::setVsync(bool enable) { |
} |
void SkOSWindow::closeWindow() { |
- this->setFullscreen(false); |
DestroyWindow((HWND)fHWND); |
+ if (fFullscreen) { |
+ DestroyWindow((HWND)fSavedWindowState.fHWND); |
+ } |
+ gHwndToOSWindowMap.remove(fHWND); |
} |
#endif |