Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: src/views/win/SkOSWindow_win.cpp

Issue 1181723006: Move closeWindow()/setFullscreen()/setVSynv() from SkWindow to SkOSWindow (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/views/unix/SkOSWindow_Unix.cpp ('k') | tools/VisualBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkTypes.h" 8 #include "SkTypes.h"
9 9
10 #if defined(SK_BUILD_FOR_WIN) 10 #if defined(SK_BUILD_FOR_WIN)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 fContext = EGL_NO_CONTEXT; 53 fContext = EGL_NO_CONTEXT;
54 fSurface = EGL_NO_SURFACE; 54 fSurface = EGL_NO_SURFACE;
55 #endif 55 #endif
56 fHGLRC = NULL; 56 fHGLRC = NULL;
57 #endif 57 #endif
58 fAttached = kNone_BackEndType; 58 fAttached = kNone_BackEndType;
59 fFullscreen = false; 59 fFullscreen = false;
60 } 60 }
61 61
62 SkOSWindow::~SkOSWindow() { 62 SkOSWindow::~SkOSWindow() {
63 this->setFullscreen(false);
64 #if SK_SUPPORT_GPU 63 #if SK_SUPPORT_GPU
65 if (fHGLRC) { 64 if (fHGLRC) {
66 wglDeleteContext((HGLRC)fHGLRC); 65 wglDeleteContext((HGLRC)fHGLRC);
67 } 66 }
68 #if SK_ANGLE 67 #if SK_ANGLE
69 if (EGL_NO_CONTEXT != fContext) { 68 if (EGL_NO_CONTEXT != fContext) {
70 eglDestroyContext(fDisplay, fContext); 69 eglDestroyContext(fDisplay, fContext);
71 fContext = EGL_NO_CONTEXT; 70 fContext = EGL_NO_CONTEXT;
72 } 71 }
73 72
74 if (EGL_NO_SURFACE != fSurface) { 73 if (EGL_NO_SURFACE != fSurface) {
75 eglDestroySurface(fDisplay, fSurface); 74 eglDestroySurface(fDisplay, fSurface);
76 fSurface = EGL_NO_SURFACE; 75 fSurface = EGL_NO_SURFACE;
77 } 76 }
78 77
79 if (EGL_NO_DISPLAY != fDisplay) { 78 if (EGL_NO_DISPLAY != fDisplay) {
80 eglTerminate(fDisplay); 79 eglTerminate(fDisplay);
81 fDisplay = EGL_NO_DISPLAY; 80 fDisplay = EGL_NO_DISPLAY;
82 } 81 }
83 #endif // SK_ANGLE 82 #endif // SK_ANGLE
84 #endif // SK_SUPPORT_GPU 83 #endif // SK_SUPPORT_GPU
85 gHwndToOSWindowMap.remove(fHWND); 84 this->closeWindow();
86 DestroyWindow((HWND)fHWND);
87 } 85 }
88 86
89 static SkKey winToskKey(WPARAM vk) { 87 static SkKey winToskKey(WPARAM vk) {
90 static const struct { 88 static const struct {
91 WPARAM fVK; 89 WPARAM fVK;
92 SkKey fKey; 90 SkKey fKey;
93 } gPair[] = { 91 } gPair[] = {
94 { VK_BACK, kBack_SkKey }, 92 { VK_BACK, kBack_SkKey },
95 { VK_CLEAR, kBack_SkKey }, 93 { VK_CLEAR, kBack_SkKey },
96 { VK_RETURN, kOK_SkKey }, 94 { VK_RETURN, kOK_SkKey },
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 presentANGLE(); 604 presentANGLE();
607 break; 605 break;
608 #endif // SK_ANGLE 606 #endif // SK_ANGLE
609 #endif // SK_SUPPORT_GPU 607 #endif // SK_SUPPORT_GPU
610 default: 608 default:
611 SkASSERT(false); 609 SkASSERT(false);
612 break; 610 break;
613 } 611 }
614 } 612 }
615 613
616 void SkOSWindow::setFullscreen(bool fullscreen) { 614 bool SkOSWindow::makeFullscreen() {
617 if (fullscreen == fFullscreen) { 615 if (fFullscreen) {
618 return; 616 return true;
619 } 617 }
620 if (fHGLRC) { 618 if (fHGLRC) {
621 this->detachGL(); 619 this->detachGL();
622 } 620 }
623 // This is hacked together from various sources on the web. It can certainly be improved and be 621 // This is hacked together from various sources on the web. It can certainly be improved and be
624 // made more robust. 622 // made more robust.
625 if (fullscreen) { 623
626 // Save current window/resolution information. 624 // Save current window/resolution information. We do this in case we ever im plement switching
627 fSavedWindowState.fZoomed = SkToBool(IsZoomed((HWND)fHWND)); 625 // back to windowed mode.
628 if (fSavedWindowState.fZoomed) { 626 fSavedWindowState.fZoomed = SkToBool(IsZoomed((HWND)fHWND));
629 SendMessage((HWND)fHWND, WM_SYSCOMMAND, SC_RESTORE, 0); 627 if (fSavedWindowState.fZoomed) {
630 } 628 SendMessage((HWND)fHWND, WM_SYSCOMMAND, SC_RESTORE, 0);
631 fSavedWindowState.fStyle = GetWindowLong((HWND)fHWND, GWL_STYLE);
632 fSavedWindowState.fExStyle = GetWindowLong((HWND)fHWND, GWL_EXSTYLE);
633 GetWindowRect((HWND)fHWND, &fSavedWindowState.fRect);
634 DEVMODE dmScreenSettings; // Device Mode
635 memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sur e Memory's Cleared
636 dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The D evmode Structure
637 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dmScreenSettings);
638 fSavedWindowState.fScreenWidth = dmScreenSettings.dmPelsWidth;
639 fSavedWindowState.fScreenHeight = dmScreenSettings.dmPelsHeight;
640 fSavedWindowState.fScreenBits = dmScreenSettings.dmBitsPerPel;
641 fSavedWindowState.fHWND = fHWND;
642 } 629 }
630 fSavedWindowState.fStyle = GetWindowLong((HWND)fHWND, GWL_STYLE);
631 fSavedWindowState.fExStyle = GetWindowLong((HWND)fHWND, GWL_EXSTYLE);
632 GetWindowRect((HWND)fHWND, &fSavedWindowState.fRect);
633 DEVMODE currScreenSettings;
634 memset(&currScreenSettings,0,sizeof(currScreenSettings));
635 currScreenSettings.dmSize = sizeof(currScreenSettings);
636 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &currScreenSettings);
637 fSavedWindowState.fScreenWidth = currScreenSettings.dmPelsWidth;
638 fSavedWindowState.fScreenHeight = currScreenSettings.dmPelsHeight;
639 fSavedWindowState.fScreenBits = currScreenSettings.dmBitsPerPel;
640 fSavedWindowState.fHWND = fHWND;
643 641
644 if (fullscreen) { 642 // Try different sizes to find an allowed setting? Use ChangeDisplaySettings Ex?
645 // Try different sizes to find an allowed setting? Use ChangeDisplaySett ingsEx? 643 static const int kWidth = 1280;
646 static const int kWidth = 1280; 644 static const int kHeight = 1024;
647 static const int kHeight = 1024; 645 DEVMODE newScreenSettings;
648 DEVMODE dmScreenSettings; 646 memset(&newScreenSettings, 0, sizeof(newScreenSettings));
649 memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); 647 newScreenSettings.dmSize = sizeof(newScreenSettings);
650 dmScreenSettings.dmSize=sizeof(dmScreenSettings); 648 newScreenSettings.dmPelsWidth = kWidth;
651 dmScreenSettings.dmPelsWidth = kWidth; 649 newScreenSettings.dmPelsHeight = kHeight;
652 dmScreenSettings.dmPelsHeight = kHeight; 650 newScreenSettings.dmBitsPerPel = 32;
653 dmScreenSettings.dmBitsPerPel = 32; 651 newScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
654 dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; 652 if (ChangeDisplaySettings(&newScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE _SUCCESSFUL) {
655 if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHA NGE_SUCCESSFUL) { 653 return false;
656 return; 654 }
657 } 655 RECT WindowRect;
658 RECT WindowRect; 656 WindowRect.left = 0;
659 WindowRect.left = 0; 657 WindowRect.right = kWidth;
660 WindowRect.right = kWidth; 658 WindowRect.top = 0;
661 WindowRect.top = 0; 659 WindowRect.bottom = kHeight;
662 WindowRect.bottom = kHeight; 660 ShowCursor(FALSE);
663 ShowCursor(FALSE); 661 AdjustWindowRectEx(&WindowRect, WS_POPUP, FALSE, WS_EX_APPWINDOW);
664 AdjustWindowRectEx(&WindowRect, WS_POPUP, FALSE, WS_EX_APPWINDOW); 662 HWND fsHWND = CreateWindowEx(
665 HWND fsHWND = CreateWindowEx( 663 WS_EX_APPWINDOW,
666 WS_EX_APPWINDOW, 664 fWinInit.fClass,
667 fWinInit.fClass, 665 NULL,
668 NULL, 666 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
669 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP, 667 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top ,
670 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect .top, 668 NULL,
671 NULL, 669 NULL,
672 NULL, 670 fWinInit.fInstance,
673 fWinInit.fInstance, 671 NULL
674 NULL 672 );
675 ); 673 if (!fsHWND) {
676 if (!fsHWND) { 674 return false;
677 return; 675 }
678 } 676 // Hide the old window and set the entry in the global mapping for this SkOS Window to the
679 // Hide the old window and set the entry in the global mapping for this SkOSWindow to the 677 // new HWND.
680 // new HWND. 678 ShowWindow((HWND)fHWND, SW_HIDE);
681 ShowWindow((HWND)fHWND, SW_HIDE); 679 gHwndToOSWindowMap.remove(fHWND);
682 gHwndToOSWindowMap.remove(fHWND); 680 fHWND = fsHWND;
683 fHWND = fsHWND; 681 gHwndToOSWindowMap.set(fHWND, this);
684 gHwndToOSWindowMap.set(fHWND, this); 682 this->updateSize();
685 this->updateSize();
686 } else {
687 DEVMODE dmScreenSettings;
688 memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
689 dmScreenSettings.dmSize=sizeof(dmScreenSettings);
690 dmScreenSettings.dmPelsWidth = fSavedWindowState.fScreenWidth;
691 dmScreenSettings.dmPelsHeight = fSavedWindowState.fScreenHeight;
692 dmScreenSettings.dmBitsPerPel = fSavedWindowState.fScreenBits;
693 dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
694 if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHA NGE_SUCCESSFUL) {
695 return;
696 }
697 gHwndToOSWindowMap.remove(fHWND);
698 DestroyWindow((HWND)fHWND);
699 fHWND = fSavedWindowState.fHWND;
700 gHwndToOSWindowMap.set(fHWND, this);
701 ShowWindow((HWND)fHWND, SW_SHOW);
702 SetWindowLong((HWND)fHWND, GWL_STYLE, fSavedWindowState.fStyle);
703 SetWindowLong((HWND)fHWND, GWL_EXSTYLE, fSavedWindowState.fExStyle);
704 683
705 int width = fSavedWindowState.fRect.right - fSavedWindowState.fRect.left ; 684 fFullscreen = true;
706 int height = fSavedWindowState.fRect.right - fSavedWindowState.fRect.lef t; 685 return true;
707 SetWindowPos((HWND)fHWND, NULL, fSavedWindowState.fRect.left, fSavedWind owState.fRect.top,
708 width, height,
709 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
710 if (fSavedWindowState.fZoomed) {
711 SendMessage((HWND)fHWND, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
712 }
713 this->updateSize();
714 }
715 fFullscreen = fullscreen;
716 } 686 }
717 687
718 void SkOSWindow::setVsync(bool enable) { 688 void SkOSWindow::setVsync(bool enable) {
719 SkWGLExtensions wgl; 689 SkWGLExtensions wgl;
720 wgl.swapInterval(enable ? 1 : 0); 690 wgl.swapInterval(enable ? 1 : 0);
721 } 691 }
722 692
723 void SkOSWindow::closeWindow() { 693 void SkOSWindow::closeWindow() {
724 this->setFullscreen(false);
725 DestroyWindow((HWND)fHWND); 694 DestroyWindow((HWND)fHWND);
695 if (fFullscreen) {
696 DestroyWindow((HWND)fSavedWindowState.fHWND);
697 }
698 gHwndToOSWindowMap.remove(fHWND);
726 } 699 }
727 #endif 700 #endif
OLDNEW
« no previous file with comments | « src/views/unix/SkOSWindow_Unix.cpp ('k') | tools/VisualBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698