DXGL r581 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r580‎ | r581 | r582 >
Date:15:27, 4 January 2015
Author:admin
Status:new
Tags:
Comment:
Restore display mode when Alt+Tabbing out of a fullscreen application.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /ddraw/hooks.c (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -1420,6 +1420,17 @@
14211421 TRACE_EXIT(23,DD_OK);
14221422 return DD_OK;
14231423 }
 1424+extern "C" void glDirectDraw7_UnrestoreDisplayMode(glDirectDraw7 *This)
 1425+{
 1426+ if (!This) return;
 1427+ TRACE_ENTER(1, 14, This);
 1428+ if (This->currmode.dmSize != 0)
 1429+ {
 1430+ ChangeDisplaySettingsEx(NULL, &This->currmode, NULL, CDS_FULLSCREEN, NULL);
 1431+ }
 1432+ TRACE_EXIT(0, 0);
 1433+}
 1434+
14241435 HRESULT WINAPI glDirectDraw7::SetCooperativeLevel(HWND hWnd, DWORD dwFlags)
14251436 {
14261437 TRACE_ENTER(3,14,this,13,hWnd,9,dwFlags);
@@ -1592,6 +1603,7 @@
15931604 {
15941605 WaitForVerticalBlank(0, NULL);
15951606 WaitForVerticalBlank(0, NULL);
 1607+ RestoreDisplayMode();
15961608 TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
15971609 }
15981610 if ((dwBPP != 4) && (dwBPP != 8) && (dwBPP != 15) && (dwBPP != 16) && (dwBPP != 24) && (dwBPP != 32))
@@ -1610,6 +1622,7 @@
16111623 }
16121624 currmode.dmSize = sizeof(DEVMODE);
16131625 EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&currmode);
 1626+ this->currmode.dmSize = 0;
16141627 switch(dxglcfg.scaler)
16151628 {
16161629 case 0: // No scaling, switch mode
@@ -1630,6 +1643,7 @@
16311644 switch(error)
16321645 {
16331646 case DISP_CHANGE_SUCCESSFUL:
 1647+ if (fullscreen) this->currmode = newmode;
16341648 internalx = primaryx = screenx = newmode.dmPelsWidth;
16351649 internaly = primaryy = screeny = newmode.dmPelsHeight;
16361650 internalbpp = screenbpp = newmode.dmBitsPerPel;
@@ -1755,6 +1769,7 @@
17561770 error = ChangeDisplaySettingsEx(NULL,&newmode2,NULL,flags,NULL);
17571771 }
17581772 else newmode2 = newmode;
 1773+ if (error == DISP_CHANGE_SUCCESSFUL) this->currmode = newmode2;
17591774 switch(dxglcfg.scaler)
17601775 {
17611776 case 4:
Index: ddraw/glDirectDraw.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -115,6 +115,7 @@
116116 D3DDevice stored_devices[3];
117117 D3DDEVICEDESC7 d3ddesc;
118118 D3DDEVICEDESC d3ddesc3;
 119+ DEVMODE currmode;
119120 private:
120121 HRESULT error;
121122 ULONG refcount7, refcount4, refcount2, refcount1;
@@ -140,6 +141,8 @@
141142 DWORD cooplevel;
142143 };
143144
 145+extern "C" void glDirectDraw7_UnrestoreDisplayMode(glDirectDraw7 *This);
 146+
144147 class glDirectDraw1 : public IDirectDraw
145148 {
146149 public:
Index: ddraw/hooks.c
@@ -19,6 +19,7 @@
2020 #include "hooks.h"
2121 #include <tlhelp32.h>
2222 #include "../minhook-1.3/include/MinHook.h"
 23+void glDirectDraw7_UnrestoreDisplayMode(LPDIRECTDRAW7 lpDD7); // temporary until glDirectDraw is converted to C
2324
2425 const TCHAR *wndprop = _T("DXGLWndProc");
2526 const TCHAR *wndpropdd7 = _T("DXGLWndDD7");
@@ -268,6 +269,12 @@
269270 if (lpDD7) IDirectDraw7_SetDisplayMode(lpDD7, -1, -1, -1, -1, 0);
270271 }
271272 break;
 273+ case WM_SYSCOMMAND:
 274+ if (wParam == SC_RESTORE)
 275+ {
 276+ if (lpDD7) glDirectDraw7_UnrestoreDisplayMode(lpDD7);
 277+ }
 278+ break;
272279 }
273280 return CallWindowProc(parentproc, hWnd, uMsg, wParam, lParam);
274281 }