Module: wine Branch: master Commit: 1fab14af9e2ecdc26c9cf7b72b28c74b1f98ad6f URL: http://source.winehq.org/git/wine.git/?a=commit;h=1fab14af9e2ecdc26c9cf7b72b...
Author: Henri Verbeet hverbeet@codeweavers.com Date: Mon Oct 15 22:26:21 2012 +0200
ddraw: Just implement ddraw7_RestoreDisplayMode() on top of wined3d_set_adapter_display_mode().
---
dlls/ddraw/ddraw.c | 155 +++++++++++++++++++------------------------- dlls/ddraw/ddraw_private.h | 4 +- 2 files changed, 68 insertions(+), 91 deletions(-)
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index 1ef06d0..9d2a78a 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -1003,79 +1003,6 @@ static HRESULT WINAPI ddraw1_SetCooperativeLevel(IDirectDraw *iface, HWND window }
/***************************************************************************** - * - * Helper function for SetDisplayMode and RestoreDisplayMode - * - * Implements DirectDraw's SetDisplayMode, but ignores the value of - * ForceRefreshRate, since it is already handled by - * ddraw7_SetDisplayMode. RestoreDisplayMode can use this function - * without worrying that ForceRefreshRate will override the refresh rate. For - * argument and return value documentation, see - * ddraw7_SetDisplayMode. - * - *****************************************************************************/ -static HRESULT ddraw_set_display_mode(struct ddraw *ddraw, DWORD Width, DWORD Height, - DWORD BPP, DWORD RefreshRate, DWORD Flags) -{ - struct wined3d_display_mode mode; - enum wined3d_format_id format; - HRESULT hr; - - TRACE("ddraw %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", ddraw, Width, - Height, BPP, RefreshRate, Flags); - - wined3d_mutex_lock(); - if( !Width || !Height ) - { - ERR("Width %u, Height %u, what to do?\n", Width, Height); - /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */ - wined3d_mutex_unlock(); - return DD_OK; - } - - switch(BPP) - { - case 8: format = WINED3DFMT_P8_UINT; break; - case 15: format = WINED3DFMT_B5G5R5X1_UNORM; break; - case 16: format = WINED3DFMT_B5G6R5_UNORM; break; - case 24: format = WINED3DFMT_B8G8R8_UNORM; break; - case 32: format = WINED3DFMT_B8G8R8X8_UNORM; break; - default: format = WINED3DFMT_UNKNOWN; break; - } - - /* Check the exclusive mode - if(!(ddraw->cooperative_level & DDSCL_EXCLUSIVE)) - return DDERR_NOEXCLUSIVEMODE; - * This is WRONG. Don't know if the SDK is completely - * wrong and if there are any conditions when DDERR_NOEXCLUSIVE - * is returned, but Half-Life 1.1.1.1 (Steam version) - * depends on this - */ - - mode.width = Width; - mode.height = Height; - mode.refresh_rate = RefreshRate; - mode.format_id = format; - mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN; - - /* TODO: The possible return values from msdn suggest that - * the screen mode can't be changed if a surface is locked - * or some drawing is in progress - */ - - /* TODO: Lose the primary surface */ - hr = wined3d_set_adapter_display_mode(ddraw->wined3d, WINED3DADAPTER_DEFAULT, &mode); - - wined3d_mutex_unlock(); - - switch(hr) - { - case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED; - default: return hr; - } -} - -/***************************************************************************** * IDirectDraw7::SetDisplayMode * * Sets the display screen resolution, color depth and refresh frequency @@ -1097,22 +1024,67 @@ static HRESULT ddraw_set_display_mode(struct ddraw *ddraw, DWORD Width, DWORD He * DD_OK on success * *****************************************************************************/ -static HRESULT WINAPI ddraw7_SetDisplayMode(IDirectDraw7 *iface, DWORD Width, DWORD Height, - DWORD BPP, DWORD RefreshRate, DWORD Flags) +static HRESULT WINAPI ddraw7_SetDisplayMode(IDirectDraw7 *iface, DWORD width, DWORD height, + DWORD bpp, DWORD refresh_rate, DWORD flags) { struct ddraw *ddraw = impl_from_IDirectDraw7(iface); + struct wined3d_display_mode mode; + enum wined3d_format_id format; + HRESULT hr;
TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", - iface, Width, Height, BPP, RefreshRate, Flags); + iface, width, height, bpp, refresh_rate, flags);
if (force_refresh_rate != 0) { TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n", - RefreshRate, force_refresh_rate); - RefreshRate = force_refresh_rate; + refresh_rate, force_refresh_rate); + refresh_rate = force_refresh_rate; }
- return ddraw_set_display_mode(ddraw, Width, Height, BPP, RefreshRate, Flags); + wined3d_mutex_lock(); + + if (!width || !height) + { + /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */ + wined3d_mutex_unlock(); + return DD_OK; + } + + switch (bpp) + { + case 8: format = WINED3DFMT_P8_UINT; break; + case 15: format = WINED3DFMT_B5G5R5X1_UNORM; break; + case 16: format = WINED3DFMT_B5G6R5_UNORM; break; + case 24: format = WINED3DFMT_B8G8R8_UNORM; break; + case 32: format = WINED3DFMT_B8G8R8X8_UNORM; break; + default: format = WINED3DFMT_UNKNOWN; break; + } + + /* Check the exclusive mode. + * if(!(ddraw->cooperative_level & DDSCL_EXCLUSIVE)) + * return DDERR_NOEXCLUSIVEMODE; + * This is WRONG. Don't know if the SDK is completely wrong and if there + * are any conditions when DDERR_NOEXCLUSIVE is returned, but Half-Life + * 1.1.1.1 (Steam version) depends on this. */ + mode.width = width; + mode.height = height; + mode.refresh_rate = refresh_rate; + mode.format_id = format; + mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN; + + /* TODO: The possible return values from msdn suggest that the screen mode + * can't be changed if a surface is locked or some drawing is in progress. */ + /* TODO: Lose the primary surface. */ + hr = wined3d_set_adapter_display_mode(ddraw->wined3d, WINED3DADAPTER_DEFAULT, &mode); + + wined3d_mutex_unlock(); + + switch (hr) + { + case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED; + default: return hr; + } }
static HRESULT WINAPI ddraw4_SetDisplayMode(IDirectDraw4 *iface, DWORD width, DWORD height, @@ -1170,10 +1142,17 @@ static HRESULT WINAPI ddraw1_SetDisplayMode(IDirectDraw *iface, DWORD width, DWO static HRESULT WINAPI ddraw7_RestoreDisplayMode(IDirectDraw7 *iface) { struct ddraw *ddraw = impl_from_IDirectDraw7(iface); + HRESULT hr;
TRACE("iface %p.\n", iface);
- return ddraw_set_display_mode(ddraw, ddraw->orig_width, ddraw->orig_height, ddraw->orig_bpp, 0, 0); + wined3d_mutex_lock(); + + hr = wined3d_set_adapter_display_mode(ddraw->wined3d, WINED3DADAPTER_DEFAULT, &ddraw->original_mode); + + wined3d_mutex_unlock(); + + return hr; }
static HRESULT WINAPI ddraw4_RestoreDisplayMode(IDirectDraw4 *iface) @@ -5359,7 +5338,6 @@ static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops = HRESULT ddraw_init(struct ddraw *ddraw, enum wined3d_device_type device_type) { HRESULT hr; - HDC hDC;
ddraw->IDirectDraw7_iface.lpVtbl = &ddraw7_vtbl; ddraw->IDirectDraw_iface.lpVtbl = &ddraw1_vtbl; @@ -5373,13 +5351,6 @@ HRESULT ddraw_init(struct ddraw *ddraw, enum wined3d_device_type device_type) ddraw->numIfaces = 1; ddraw->ref7 = 1;
- /* Get the current screen settings. */ - hDC = GetDC(0); - ddraw->orig_bpp = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES); - ReleaseDC(0, hDC); - ddraw->orig_width = GetSystemMetrics(SM_CXSCREEN); - ddraw->orig_height = GetSystemMetrics(SM_CYSCREEN); - ddraw->wined3d = wined3d_create(7, WINED3D_LEGACY_DEPTH_BIAS); if (!ddraw->wined3d) { @@ -5387,6 +5358,14 @@ HRESULT ddraw_init(struct ddraw *ddraw, enum wined3d_device_type device_type) return E_OUTOFMEMORY; }
+ if (FAILED(hr = wined3d_get_adapter_display_mode(ddraw->wined3d, + WINED3DADAPTER_DEFAULT, &ddraw->original_mode, NULL))) + { + ERR("Failed to get display mode, hr %#x.\n", hr); + wined3d_decref(ddraw->wined3d); + return hr; + } + hr = wined3d_device_create(ddraw->wined3d, WINED3DADAPTER_DEFAULT, device_type, NULL, 0, 8, &ddraw->device_parent, &ddraw->wined3d_device); if (FAILED(hr)) diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index 563377f..0d15727 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -78,9 +78,7 @@ struct ddraw
/* DirectDraw things, which are not handled by WineD3D */ DWORD cooperative_level; - - DWORD orig_width, orig_height; - DWORD orig_bpp; + struct wined3d_display_mode original_mode;
/* D3D things */ HWND d3d_window;