ReactOS 0.4.16-dev-197-g92996da
ddraw_displaymode.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS DirectX
4 * FILE: dll/directx/ddraw/Ddraw/ddraw_displaymode.c
5 * PURPOSE: IDirectDraw7 Implementation
6 * PROGRAMMER: Maarten Bosma, Magnus Olsen (add seh support)
7 *
8 */
9
10
11#include "rosdraw.h"
12
16{
18 INT iMode = 0;
19 DEVMODE DevMode;
20
22
23 ZeroMemory(&DevMode, sizeof(DEVMODE));
24
26 {
27
28 if (pDDSD != NULL)
29 {
30 if (pDDSD->dwSize != sizeof(DDSURFACEDESC))
31 {
33 }
34 }
35
37 {
39 }
40 else if ( ret == DD_OK)
41 {
42
43 DevMode.dmSize = sizeof(DEVMODE);
44
45 while (EnumDisplaySettingsEx(NULL, iMode, &DevMode, 0) != FALSE)
46 {
47 DDSURFACEDESC SurfaceDesc;
48
49 ZeroMemory(&SurfaceDesc, sizeof(DDSURFACEDESC));
50
51 iMode++;
52
53 SurfaceDesc.dwSize = sizeof (DDSURFACEDESC);
55 SurfaceDesc.dwHeight = DevMode.dmPelsHeight;
56 SurfaceDesc.dwWidth = DevMode.dmPelsWidth;
57 SurfaceDesc.lPitch = DevMode.dmPelsWidth * DevMode.dmBitsPerPel / 8;
58 SurfaceDesc.dwRefreshRate = DevMode.dmDisplayFrequency;
59
60 SurfaceDesc.ddpfPixelFormat.dwSize = sizeof (DDPIXELFORMAT);
61 SurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_RGB;
62 // FIXME: get these
63 /*
64 SurfaceDesc.ddpfPixelFormat.dwRBitMask =
65 SurfaceDesc.ddpfPixelFormat.dwGBitMask =
66 SurfaceDesc.ddpfPixelFormat.dwBBitMask =
67 SurfaceDesc.ddpfPixelFormat.dwRGBAlphaBitMask =
68 */
69 SurfaceDesc.ddpfPixelFormat.dwRGBBitCount = DevMode.dmBitsPerPel;
70
71 // FIXME1: This->lpLcl->lpGbl->dwMonitorFrequency is not set !
72 if(dwFlags & DDEDM_REFRESHRATES && SurfaceDesc.dwRefreshRate != This->lpLcl->lpGbl->dwMonitorFrequency)
73 {
74 //continue; // FIXME2: what is SurfaceDesc.dwRefreshRate supposed to be set to ?
75 }
76
77 // FIXME: Take case when DDEDM_STANDARDVGAMODES flag is not set in account
78
79 if(pDDSD)
80 {
81 if (pDDSD->dwFlags & DDSD_HEIGHT && pDDSD->dwHeight != SurfaceDesc.dwHeight)
82 continue;
83
84 if (pDDSD->dwFlags & DDSD_WIDTH && pDDSD->dwWidth != SurfaceDesc.dwWidth)
85 continue;
86
87 if (pDDSD->dwFlags & DDSD_PITCH && pDDSD->lPitch != SurfaceDesc.lPitch)
88 continue;
89
90 if (pDDSD->dwFlags & DDSD_REFRESHRATE && pDDSD->dwRefreshRate != SurfaceDesc.dwRefreshRate)
91 continue;
92
93 if (pDDSD->dwFlags & DDSD_PIXELFORMAT && pDDSD->ddpfPixelFormat.dwRGBBitCount != SurfaceDesc.ddpfPixelFormat.dwRGBBitCount)
94 continue; // FIXME: test for the other members of ddpfPixelFormat as well
95 }
96
97 if((*pCallback)(&SurfaceDesc, pContext) == DDENUMRET_CANCEL)
98 break;
99 }
100 }
101
102 }
104 {
105 }
106 _SEH2_END;
107
108 return ret;
109}
110
114{
115 HRESULT ret = DD_OK;
116 INT iMode = 0;
117 DEVMODE DevMode;
118
120
121 ZeroMemory(&DevMode, sizeof(DEVMODE));
122
124 {
125
126 if (pDDSD != NULL)
127 {
128 if (pDDSD->dwSize != sizeof(DDSURFACEDESC2))
129 {
131 }
132 }
133
135 {
137 }
138 else if ( ret == DD_OK)
139 {
140
141 DevMode.dmSize = sizeof(DEVMODE);
142
143 while (EnumDisplaySettingsEx(NULL, iMode, &DevMode, 0) != FALSE)
144 {
145 DDSURFACEDESC2 SurfaceDesc;
146
147 ZeroMemory(&SurfaceDesc, sizeof(DDSURFACEDESC2));
148
149 iMode++;
150
151 SurfaceDesc.dwSize = sizeof (DDSURFACEDESC2);
153 SurfaceDesc.dwHeight = DevMode.dmPelsHeight;
154 SurfaceDesc.dwWidth = DevMode.dmPelsWidth;
155 SurfaceDesc.lPitch = DevMode.dmPelsWidth * DevMode.dmBitsPerPel / 8;
156 SurfaceDesc.dwRefreshRate = DevMode.dmDisplayFrequency;
157
158 SurfaceDesc.ddpfPixelFormat.dwSize = sizeof (DDPIXELFORMAT);
159 SurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_RGB;
160 // FIXME: get these
161 /*
162 SurfaceDesc.ddpfPixelFormat.dwRBitMask =
163 SurfaceDesc.ddpfPixelFormat.dwGBitMask =
164 SurfaceDesc.ddpfPixelFormat.dwBBitMask =
165 SurfaceDesc.ddpfPixelFormat.dwRGBAlphaBitMask =
166 */
167 SurfaceDesc.ddpfPixelFormat.dwRGBBitCount = DevMode.dmBitsPerPel;
168
169 // FIXME1: This->lpLcl->lpGbl->dwMonitorFrequency is not set !
170 if(dwFlags & DDEDM_REFRESHRATES && SurfaceDesc.dwRefreshRate != This->lpLcl->lpGbl->dwMonitorFrequency)
171 {
172 //continue; // FIXME2: what is SurfaceDesc.dwRefreshRate supposed to be set to ?
173 }
174
175 // FIXME: Take case when DDEDM_STANDARDVGAMODES flag is not set in account
176
177 if(pDDSD)
178 {
179 if (pDDSD->dwFlags & DDSD_HEIGHT && pDDSD->dwHeight != SurfaceDesc.dwHeight)
180 continue;
181
182 if (pDDSD->dwFlags & DDSD_WIDTH && pDDSD->dwWidth != SurfaceDesc.dwWidth)
183 continue;
184
185 if (pDDSD->dwFlags & DDSD_PITCH && pDDSD->lPitch != SurfaceDesc.lPitch)
186 continue;
187
188 if (pDDSD->dwFlags & DDSD_REFRESHRATE && pDDSD->dwRefreshRate != SurfaceDesc.dwRefreshRate)
189 continue;
190
192 continue; // FIXME: test for the other members of ddpfPixelFormat as well
193 }
194
195 if((*pCallback)(&SurfaceDesc, pContext) == DDENUMRET_CANCEL)
196 break;
197 }
198 }
199
200 }
202 {
203 }
204 _SEH2_END;
205
206 return ret;
207}
208
211{
213
214 return Main_DirectDraw_SetDisplayMode2 (This, dwWidth, dwHeight, dwBPP, 0, 0 );
215}
216
220{
221 HRESULT ret = DD_OK;
223
225 {
226 // FIXME: Check primary if surface is locked / busy etc.
227
228 // Check Parameters
229 if(dwFlags != 0)
230 {
232 }
233 else
234 {
235 if ((!dwHeight || This->lpLcl->lpGbl->vmiData.dwDisplayHeight == dwHeight) &&
236 (!dwWidth || This->lpLcl->lpGbl->vmiData.dwDisplayWidth == dwWidth) &&
237 (!dwBPP || This->lpLcl->lpGbl->vmiData.ddpfDisplay.dwRGBBitCount == dwBPP) &&
238 (!dwRefreshRate || This->lpLcl->lpGbl->dwMonitorFrequency == dwRefreshRate))
239 {
240 ret = DD_OK; // nothing to do here for us
241 }
242 else
243 {
244 LONG retval;
245 // Here we go
246 DEVMODE DevMode;
247 ZeroMemory(&DevMode, sizeof(DEVMODE));
248 DevMode.dmSize = sizeof(DEVMODE);
249
250 if (dwHeight)
251 DevMode.dmFields |= DM_PELSHEIGHT;
252 if (dwWidth)
253 DevMode.dmFields |= DM_PELSWIDTH;
254 if (dwBPP)
255 DevMode.dmFields |= DM_BITSPERPEL;
256 if (dwRefreshRate)
257 DevMode.dmFields |= DM_DISPLAYFREQUENCY;
258
259 DevMode.dmPelsHeight = dwHeight;
260 DevMode.dmPelsWidth = dwWidth;
261 DevMode.dmBitsPerPel = dwBPP;
263
265
266 retval = ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN);
267 /* FIXME: Are we supposed to set CDS_SET_PRIMARY as well ? */
268
269 if(retval == DISP_CHANGE_BADMODE)
270 {
271 /* Note : it seam ms ddraw ignore this and try using the bad mode any case.
272 * tested with Ati HD2400 that only support 16 and 32 Bpp in windows
273 */
274 DX_STUB_str("Warning ChangeDisplaySettings return DISP_CHANGE_BADMODE, but ddraw.dll ignore it\n");
275
276 //ret = DDERR_UNSUPPORTED;
278 This->lpLcl->lpGbl->hDD = This->lpLcl->hDD;
281 }
282 else if(retval != DISP_CHANGE_SUCCESSFUL)
283 {
285 }
286 else
287 {
288 // Update Interals
290 This->lpLcl->lpGbl->hDD = This->lpLcl->hDD;
293 }
294 }
295 }
296 }
298 {
299 }
300 _SEH2_END;
301
302 return ret;
303}
304
307{
309
311 {
313
314 ChangeDisplaySettings(NULL, 0);
315
316 // Update Interals
317
318
319 This->lpLcl->lpGbl->hDD = This->lpLcl->hDD;
322 }
324 {
325 }
326 _SEH2_END;
327
328
329 return DD_OK;
330}
331
334{
335 HRESULT retVal = DD_OK;
337
339 {
340 if(IsBadWritePtr(lpFreq,sizeof(LPDWORD)))
341 {
342 retVal = DDERR_INVALIDPARAMS;
343 }
344 else
345 {
346 if (This->lpLcl->lpGbl->dwMonitorFrequency)
347 {
348 *lpFreq = This->lpLcl->lpGbl->dwMonitorFrequency;
349 }
350 else
351 {
352 retVal = DDERR_UNSUPPORTED;
353 }
354 }
355 }
357 {
358 retVal = DD_FALSE;
359 }
360 _SEH2_END;
361
362 return retVal;
363}
364
367{
368 HRESULT retVal = DD_OK;
370
372 {
373 if(IsBadWritePtr(pDDSD,sizeof(LPDDSURFACEDESC)))
374 {
375 retVal = DDERR_INVALIDPARAMS;
376 }
377 else if (pDDSD->dwSize != sizeof(DDSURFACEDESC))
378 {
379 retVal = DDERR_INVALIDPARAMS;
380 }
381 else
382 {
383 // FIXME: More structure members might need to be filled
384
386 pDDSD->dwHeight = This->lpLcl->lpGbl->vmiData.dwDisplayHeight;
387 pDDSD->dwWidth = This->lpLcl->lpGbl->vmiData.dwDisplayWidth;
388 pDDSD->ddpfPixelFormat = This->lpLcl->lpGbl->vmiData.ddpfDisplay;
389 pDDSD->dwRefreshRate = This->lpLcl->lpGbl->dwMonitorFrequency;
390 pDDSD->lPitch = This->lpLcl->lpGbl->vmiData.lDisplayPitch;
391 }
392 }
394 {
395 }
396 _SEH2_END;
397
398 return retVal;
399}
400
403{
404 HRESULT retVal = DD_OK;
406
408 {
409 if(IsBadWritePtr(pDDSD,sizeof(LPDDSURFACEDESC2)))
410 {
411 retVal = DDERR_INVALIDPARAMS;
412 }
413 else if (pDDSD->dwSize != sizeof(DDSURFACEDESC2))
414 {
415 retVal = DDERR_INVALIDPARAMS;
416 }
417 else
418 {
419 // FIXME: More structure members might need to be filled
420
422 pDDSD->dwHeight = This->lpLcl->lpGbl->vmiData.dwDisplayHeight;
423 pDDSD->dwWidth = This->lpLcl->lpGbl->vmiData.dwDisplayWidth;
424 pDDSD->ddpfPixelFormat = This->lpLcl->lpGbl->vmiData.ddpfDisplay;
425 pDDSD->dwRefreshRate = This->lpLcl->lpGbl->dwMonitorFrequency;
426 pDDSD->lPitch = This->lpLcl->lpGbl->vmiData.lDisplayPitch;
427 }
428 }
430 {
431 }
432 _SEH2_END;
433
434 return retVal;
435}
void DDSURFACEDESC
Definition: amvideo.idl:25
HRESULT WINAPI Main_DirectDraw_GetDisplayMode4(LPDDRAWI_DIRECTDRAW_INT This, LPDDSURFACEDESC2 pDDSD)
HRESULT WINAPI Main_DirectDraw_RestoreDisplayMode(LPDDRAWI_DIRECTDRAW_INT This)
HRESULT WINAPI Main_DirectDraw_EnumDisplayModes4(LPDDRAWI_DIRECTDRAW_INT This, DWORD dwFlags, LPDDSURFACEDESC2 pDDSD, LPVOID pContext, LPDDENUMMODESCALLBACK2 pCallback)
HRESULT WINAPI Main_DirectDraw_SetDisplayMode2(LPDDRAWI_DIRECTDRAW_INT This, DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwRefreshRate, DWORD dwFlags)
HRESULT WINAPI Main_DirectDraw_EnumDisplayModes(LPDDRAWI_DIRECTDRAW_INT This, DWORD dwFlags, LPDDSURFACEDESC pDDSD, LPVOID pContext, LPDDENUMMODESCALLBACK pCallback)
HRESULT WINAPI Main_DirectDraw_GetDisplayMode(LPDDRAWI_DIRECTDRAW_INT This, LPDDSURFACEDESC pDDSD)
HRESULT WINAPI Main_DirectDraw_GetMonitorFrequency(LPDDRAWI_DIRECTDRAW_INT This, LPDWORD lpFreq)
HRESULT WINAPI Main_DirectDraw_SetDisplayMode(LPDDRAWI_DIRECTDRAW_INT This, DWORD dwWidth, DWORD dwHeight, DWORD dwBPP)
#define DdReenableDirectDrawObject
Definition: ddrawgdi.h:33
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR dwWidth[]
Definition: provider.c:62
static const WCHAR dwHeight[]
Definition: provider.c:63
static const WCHAR dwRefreshRate[]
Definition: provider.c:73
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:883
BOOL NTAPI IsBadCodePtr(FARPROC lpfn)
Definition: except.c:872
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxPnpStateCallbackInfo * pCallback
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
long LONG
Definition: pedump.c:60
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define DX_STUB_str(x)
Definition: rosdraw.h:254
#define DX_WINDBG_trace_res(width, height, bpp, freq)
Definition: rosdraw.h:273
#define DX_WINDBG_trace()
Definition: rosdraw.h:262
HRESULT WINAPI StartDirectDraw(LPDIRECTDRAW iface, LPGUID pGUID, BOOL reenable)
Definition: startup.c:180
#define DDSD_WIDTH
Definition: ddraw.h:210
#define DDSD_PIXELFORMAT
Definition: ddraw.h:216
HRESULT(WINAPI * LPDDENUMMODESCALLBACK2)(LPDDSURFACEDESC2, LPVOID)
Definition: ddraw.h:1259
#define DDSD_PITCH
Definition: ddraw.h:211
#define DDEDM_REFRESHRATES
Definition: ddraw.h:529
#define DDSD_REFRESHRATE
Definition: ddraw.h:222
struct _DDSURFACEDESC2 DDSURFACEDESC2
#define DDSD_HEIGHT
Definition: ddraw.h:209
struct _DDPIXELFORMAT DDPIXELFORMAT
struct IDirectDraw * LPDIRECTDRAW
Definition: ddraw.h:710
#define DDENUMRET_CANCEL
Definition: ddraw.h:188
HRESULT(WINAPI * LPDDENUMMODESCALLBACK)(LPDDSURFACEDESC, LPVOID)
Definition: ddraw.h:1258
#define DDPF_RGB
Definition: ddraw.h:507
#define DD_OK
Definition: ddraw.h:186
#define DDERR_UNSUPPORTED
Definition: ddraw.h:127
#define DDERR_GENERIC
Definition: ddraw.h:72
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
#define DD_FALSE
Definition: ddraw.h:187
DWORD dwSize
Definition: ddraw.h:1070
DWORD dwRGBBitCount
Definition: ddraw.h:1075
DWORD dwFlags
Definition: ddraw.h:1071
DWORD dwWidth
Definition: ddraw.h:1155
DWORD dwHeight
Definition: ddraw.h:1154
DWORD dwRefreshRate
Definition: ddraw.h:1169
DDPIXELFORMAT ddpfPixelFormat
Definition: ddraw.h:1185
DWORD dwFlags
Definition: ddraw.h:1153
DWORD dwSize
Definition: ddraw.h:1152
DWORD dmDisplayFrequency
Definition: wingdi.h:1602
DWORD dmFields
Definition: wingdi.h:1570
DWORD dmPelsWidth
Definition: wingdi.h:1596
DWORD dmPelsHeight
Definition: wingdi.h:1597
DWORD dmBitsPerPel
Definition: wingdi.h:1595
WORD dmSize
Definition: wingdi.h:1568
static BOOLEAN ModeChanged
Definition: svga.c:282
uint32_t * LPDWORD
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
int ret
#define ZeroMemory
Definition: winbase.h:1736
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
_In_ ULONG iMode
Definition: winddi.h:3520
#define WINAPI
Definition: msvc.h:6
#define DM_DISPLAYFREQUENCY
Definition: wingdi.h:1272
DEVMODEA DEVMODE
Definition: wingdi.h:4418
#define DM_PELSWIDTH
Definition: wingdi.h:1269
#define DM_BITSPERPEL
Definition: wingdi.h:1268
#define DM_PELSHEIGHT
Definition: wingdi.h:1270
#define DISP_CHANGE_BADMODE
Definition: winuser.h:195
#define DISP_CHANGE_SUCCESSFUL
Definition: winuser.h:190
#define CDS_FULLSCREEN
Definition: winuser.h:183