ReactOS  0.4.14-dev-323-g6fe6a88
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 
15  LPDDSURFACEDESC pDDSD, LPVOID pContext, LPDDENUMMODESCALLBACK pCallback)
16 {
17  HRESULT ret = DD_OK;
18  INT iMode = 0;
19  DEVMODE DevMode;
20 
22 
23  ZeroMemory(&DevMode, sizeof(DEVMODE));
24 
25  _SEH2_TRY
26  {
27 
28  if (pDDSD != NULL)
29  {
30  if (pDDSD->dwSize != sizeof(DDSURFACEDESC))
31  {
33  }
34  }
35 
36  if (IsBadCodePtr((LPVOID)pCallback))
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 
113  LPDDSURFACEDESC2 pDDSD, LPVOID pContext, LPDDENUMMODESCALLBACK2 pCallback)
114 {
115  HRESULT ret = DD_OK;
116  INT iMode = 0;
117  DEVMODE DevMode;
118 
119  DX_WINDBG_trace();
120 
121  ZeroMemory(&DevMode, sizeof(DEVMODE));
122 
123  _SEH2_TRY
124  {
125 
126  if (pDDSD != NULL)
127  {
128  if (pDDSD->dwSize != sizeof(DDSURFACEDESC2))
129  {
131  }
132  }
133 
134  if (IsBadCodePtr((LPVOID)pCallback))
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 {
212  DX_WINDBG_trace();
213 
214  return Main_DirectDraw_SetDisplayMode2 (This, dwWidth, dwHeight, dwBPP, 0, 0 );
215 }
216 
220 {
221  HRESULT ret = DD_OK;
222  DX_WINDBG_trace();
223 
224  _SEH2_TRY
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  {
284  ret = DDERR_GENERIC;
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 {
308  DX_WINDBG_trace();
309 
310  _SEH2_TRY
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;
336  DX_WINDBG_trace();
337 
338  _SEH2_TRY
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;
369  DX_WINDBG_trace();
370 
371  _SEH2_TRY
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;
405  DX_WINDBG_trace();
406 
407  _SEH2_TRY
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 }
#define DX_WINDBG_trace()
Definition: rosdraw.h:262
DWORD dwFlags
Definition: ddraw.h:1153
#define TRUE
Definition: types.h:120
DWORD dwFlags
Definition: ddraw.h:1071
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:885
HRESULT(WINAPI * LPDDENUMMODESCALLBACK2)(LPDDSURFACEDESC2, LPVOID)
Definition: ddraw.h:1259
#define DDERR_UNSUPPORTED
Definition: ddraw.h:127
_In_ ULONG iMode
Definition: winddi.h:3520
#define DDEDM_REFRESHRATES
Definition: ddraw.h:529
WORD dmSize
Definition: wingdi.h:1563
HRESULT WINAPI Main_DirectDraw_RestoreDisplayMode(LPDDRAWI_DIRECTDRAW_INT This)
DWORD dmDisplayFrequency
Definition: wingdi.h:1597
#define DDENUMRET_CANCEL
Definition: ddraw.h:188
#define CDS_FULLSCREEN
Definition: winuser.h:183
#define DISP_CHANGE_BADMODE
Definition: winuser.h:195
#define DX_STUB_str(x)
Definition: rosdraw.h:254
#define ZeroMemory
Definition: winbase.h:1642
DEVMODEA DEVMODE
Definition: wingdi.h:4413
int32_t INT
Definition: typedefs.h:56
#define DX_WINDBG_trace_res(width, height, bpp, freq)
Definition: rosdraw.h:273
struct _DDPIXELFORMAT DDPIXELFORMAT
_SEH2_TRY
Definition: create.c:4250
#define DM_PELSWIDTH
Definition: wingdi.h:1268
void DDSURFACEDESC
Definition: amvideo.idl:24
BOOL NTAPI IsBadCodePtr(FARPROC lpfn)
Definition: except.c:874
DWORD dwWidth
Definition: ddraw.h:1155
#define DD_OK
Definition: ddraw.h:186
#define DdReenableDirectDrawObject
Definition: ddrawgdi.h:33
HRESULT WINAPI Main_DirectDraw_GetMonitorFrequency(LPDDRAWI_DIRECTDRAW_INT This, LPDWORD lpFreq)
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
HRESULT WINAPI Main_DirectDraw_EnumDisplayModes(LPDDRAWI_DIRECTDRAW_INT This, DWORD dwFlags, LPDDSURFACEDESC pDDSD, LPVOID pContext, LPDDENUMMODESCALLBACK pCallback)
struct IDirectDraw * LPDIRECTDRAW
Definition: ddraw.h:710
DDPIXELFORMAT ddpfPixelFormat
Definition: ddraw.h:1185
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI Main_DirectDraw_GetDisplayMode(LPDDRAWI_DIRECTDRAW_INT This, LPDDSURFACEDESC pDDSD)
HRESULT WINAPI Main_DirectDraw_SetDisplayMode(LPDDRAWI_DIRECTDRAW_INT This, DWORD dwWidth, DWORD dwHeight, DWORD dwBPP)
static const WCHAR dwHeight[]
Definition: provider.c:63
#define DDERR_GENERIC
Definition: ddraw.h:72
HRESULT(WINAPI * LPDDENUMMODESCALLBACK)(LPDDSURFACEDESC, LPVOID)
Definition: ddraw.h:1258
#define DDSD_HEIGHT
Definition: ddraw.h:209
DWORD dwRGBBitCount
Definition: ddraw.h:1075
#define DDPF_RGB
Definition: ddraw.h:507
DWORD dwRefreshRate
Definition: ddraw.h:1169
LONG HRESULT
Definition: typedefs.h:77
#define WINAPI
Definition: msvc.h:8
#define DISP_CHANGE_SUCCESSFUL
Definition: winuser.h:190
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT WINAPI StartDirectDraw(LPDIRECTDRAW iface, LPGUID pGUID, BOOL reenable)
Definition: startup.c:180
DWORD dmPelsHeight
Definition: wingdi.h:1592
DWORD dmFields
Definition: wingdi.h:1565
DWORD dwRefreshRate
Definition: ddraw.h:1135
int ret
DWORD dwSize
Definition: ddraw.h:1152
static BOOLEAN ModeChanged
Definition: svga.c:282
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define DM_DISPLAYFREQUENCY
Definition: wingdi.h:1271
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)
DWORD dwHeight
Definition: ddraw.h:1154
#define DDSD_WIDTH
Definition: ddraw.h:210
#define DDSD_PIXELFORMAT
Definition: ddraw.h:216
DWORD dmBitsPerPel
Definition: wingdi.h:1590
#define DDSD_REFRESHRATE
Definition: ddraw.h:222
#define DD_FALSE
Definition: ddraw.h:187
_SEH2_END
Definition: create.c:4424
#define DM_PELSHEIGHT
Definition: wingdi.h:1269
struct _DDSURFACEDESC2 DDSURFACEDESC2
HRESULT WINAPI Main_DirectDraw_GetDisplayMode4(LPDDRAWI_DIRECTDRAW_INT This, LPDDSURFACEDESC2 pDDSD)
uint32_t * LPDWORD
Definition: typedefs.h:57
#define DM_BITSPERPEL
Definition: wingdi.h:1267
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
DWORD dwSize
Definition: ddraw.h:1070
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
static const WCHAR dwWidth[]
Definition: provider.c:62
#define DDSD_PITCH
Definition: ddraw.h:211
DWORD dmPelsWidth
Definition: wingdi.h:1591