ddraw: Do not restore the display mode from inside SetCooperativeLevel (resend 3)
Johan Gill
johan.gill at gmail.com
Fri Apr 16 16:04:41 CDT 2010
I got the formatting wrong in one place, so I resend this patch again.
-------------- next part --------------
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index 0a6781c..a8dbafa 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -264,8 +264,8 @@ IDirectDrawImpl_AddRef(IDirectDraw7 *iface)
void
IDirectDrawImpl_Destroy(IDirectDrawImpl *This)
{
- /* Clear the cooplevel to restore window and display mode */
IDirectDraw7_SetCooperativeLevel((IDirectDraw7 *)This, NULL, DDSCL_NORMAL);
+ IDirectDraw7_RestoreDisplayMode((IDirectDraw7 *)This);
/* Destroy the device window if we created one */
if(This->devicewindow != 0)
@@ -441,9 +441,6 @@ IDirectDrawImpl_SetCooperativeLevel(IDirectDraw7 *iface,
/* Switching from fullscreen? */
if(This->cooperative_level & DDSCL_FULLSCREEN)
{
- /* Restore the display mode */
- IDirectDraw7_RestoreDisplayMode(iface);
-
This->cooperative_level &= ~DDSCL_FULLSCREEN;
This->cooperative_level &= ~DDSCL_EXCLUSIVE;
This->cooperative_level &= ~DDSCL_ALLOWMODEX;
diff --git a/dlls/ddraw/tests/ddrawmodes.c b/dlls/ddraw/tests/ddrawmodes.c
index 59f668b..07514f4 100644
--- a/dlls/ddraw/tests/ddrawmodes.c
+++ b/dlls/ddraw/tests/ddrawmodes.c
@@ -37,6 +37,8 @@ static HWND hwnd;
static int modes_cnt;
static int modes_size;
static LPDDSURFACEDESC modes;
+static RECT rect_before_create;
+static RECT rect_after_delete;
static HRESULT (WINAPI *pDirectDrawEnumerateA)(LPDDENUMCALLBACKA,LPVOID);
static HRESULT (WINAPI *pDirectDrawEnumerateW)(LPDDENUMCALLBACKW,LPVOID);
@@ -83,6 +85,8 @@ static BOOL createdirectdraw(void)
{
HRESULT rc;
+ SetRect(&rect_before_create, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
+
rc = DirectDrawCreate(NULL, &lpDD, NULL);
ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
if (!lpDD) {
@@ -95,11 +99,16 @@ static BOOL createdirectdraw(void)
static void releasedirectdraw(void)
{
- if( lpDD != NULL )
- {
- IDirectDraw_Release(lpDD);
- lpDD = NULL;
- }
+ if( lpDD != NULL )
+ {
+ IDirectDraw_Release(lpDD);
+ lpDD = NULL;
+ SetRect(&rect_after_delete, 0, 0,
+ GetSystemMetrics(SM_CXSCREEN),
+ GetSystemMetrics(SM_CYSCREEN));
+ ok(EqualRect(&rect_before_create, &rect_after_delete) != 0,
+ "Original display mode was not restored\n");
+ }
}
static BOOL WINAPI crash_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
@@ -414,11 +423,36 @@ static void setdisplaymode(int i)
scrn.right, scrn.bottom, virt.left, virt.top, virt.right, virt.bottom);
if (!EqualRect(&scrn, &orig_rect))
{
+ HRESULT rect_result;
+
/* Check that the client rect was resized */
rc = GetClientRect(hwnd, &test);
ok(rc!=0, "GetClientRect returned %x\n", rc);
rc = EqualRect(&scrn, &test);
todo_wine ok(rc!=0, "Fullscreen window has wrong size\n");
+
+ /* Check that switching to normal cooperative level
+ does not restore the display mode */
+ rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_NORMAL);
+ ok(rc==DD_OK, "SetCooperativeLevel returned %x\n", rc);
+ SetRect(&test, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
+ rect_result = EqualRect(&scrn, &test);
+ ok(rect_result!=0, "Setting cooperative level to DDSCL_NORMAL changed the display mode\n");
+
+ /* Go back to fullscreen */
+ rc = IDirectDraw_SetCooperativeLevel(lpDD,
+ hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n",rc);
+
+ /* If the display mode was changed, set the correct mode
+ to avoid irrelevant failures */
+ if (rect_result == 0)
+ {
+ rc = IDirectDraw_SetDisplayMode(lpDD,
+ modes[i].dwWidth, modes[i].dwHeight,
+ U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
+ ok(DD_OK==rc, "SetDisplayMode returned: %x\n",rc);
+ }
}
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
/* ddraw sets clip rect here to the screen size, even for
More information about the wine-patches
mailing list