- Remove redunant braces.
[wine] / dlls / ddraw / ddraw_user.c
1 /*      DirectDraw driver for User-based primary surfaces
2  *
3  * Copyright 2000-2001 TransGaming Technologies Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include "config.h"
21
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <string.h>
25
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "ddraw.h"
34 #include "ddraw_private.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
38
39 static const IDirectDraw7Vtbl User_DirectDraw_VTable;
40
41 static const DDDEVICEIDENTIFIER2 user_device =
42 {
43     "display",
44     "User (and GDI)",
45     { { 0x00010001, 0x00010001 } },
46     0, 0, 0, 0,
47     /* fe38440c-8969-4283-bc73-749e7bc3c2eb */
48     {0xfe38440c,0x8969,0x428e, {0x73,0xbc,0x74,0x9e,0x7b,0xc3,0xc2,0xeb}},
49     0
50 };
51
52 static const DDPIXELFORMAT pixelformats[] =
53 {
54     /* 8bpp paletted */
55     { sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_PALETTEINDEXED8, 0, { 8 } },
56     /* 15bpp 5/5/5 */
57     { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, { 16 }, { 0x7C00 }, { 0x3E0 },
58       { 0x1F } },
59     /* 16bpp 5/6/5 */
60     { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, { 16 }, { 0xF800 }, { 0x7E0 },
61       { 0x1F } },
62     /* 24bpp 8/8/8 */
63     { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, { 24 }, { 0xFF0000 },
64       { 0x00FF00 }, { 0x0000FF } },
65     /* 32bpp 8/8/8 */
66     { sizeof(DDPIXELFORMAT), DDPF_RGB, 0, { 32 }, { 0xFF0000 },
67       { 0x00FF00 }, { 0x0000FF } }
68 };
69
70 HRESULT User_DirectDraw_Create(const GUID* pGUID, LPDIRECTDRAW7* pIface,
71                                      IUnknown* pUnkOuter, BOOL ex);
72 HRESULT User_DirectDraw_Initialize(IDirectDrawImpl*, const GUID*);
73
74 static const ddraw_driver user_driver =
75 {
76     &user_device,
77     10,
78     User_DirectDraw_Create,
79     User_DirectDraw_Initialize
80 };
81
82 BOOL DDRAW_User_Init(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
83 {
84     if (fdwReason == DLL_PROCESS_ATTACH)
85         DDRAW_register_driver(&user_driver);
86
87     return TRUE;
88 }
89
90 static const DDPIXELFORMAT* pixelformat_for_depth(DWORD depth)
91 {
92     switch (depth)
93     {
94     case  8: return pixelformats + 0;
95     case 15: return pixelformats + 1;
96     case 16: return pixelformats + 2;
97     case 24: return pixelformats + 3;
98     case 32: return pixelformats + 4;
99     default: return NULL;
100     }
101 }
102
103 /* Not called from the vtable. */
104 HRESULT User_DirectDraw_Construct(IDirectDrawImpl *This, BOOL ex)
105 {
106     HRESULT hr;
107     DWORD depth;
108     HDC hDC;
109
110     TRACE("(%p,%d)\n",This,ex);
111
112     hr = Main_DirectDraw_Construct(This, ex);
113     if (FAILED(hr)) return hr;
114
115     This->final_release = User_DirectDraw_final_release;
116
117     This->create_primary    = User_DirectDraw_create_primary;
118     This->create_backbuffer = User_DirectDraw_create_backbuffer;
119
120     hDC = CreateDCA("DISPLAY", NULL, NULL, NULL);
121     depth = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES);
122     DeleteDC(hDC);
123
124     This->width       = GetSystemMetrics(SM_CXSCREEN);
125     This->height      = GetSystemMetrics(SM_CYSCREEN);
126     This->pitch       = DDRAW_width_bpp_to_pitch(This->width, depth);
127     This->pixelformat = *pixelformat_for_depth(depth);
128
129     This->orig_width       = This->width;
130     This->orig_height      = This->height;
131     This->orig_pitch       = This->pitch;
132     This->orig_pixelformat = This->pixelformat;
133
134     ICOM_INIT_INTERFACE(This, IDirectDraw7, User_DirectDraw_VTable);
135
136     /* capabilities */
137 #define BLIT_CAPS (DDCAPS_BLT | DDCAPS_BLTCOLORFILL | DDCAPS_BLTDEPTHFILL \
138           | DDCAPS_BLTSTRETCH | DDCAPS_CANBLTSYSMEM | DDCAPS_CANCLIP      \
139           | DDCAPS_CANCLIPSTRETCHED | DDCAPS_COLORKEY                     \
140           | DDCAPS_COLORKEYHWASSIST | DDCAPS_OVERLAY | DDCAPS_OVERLAYSTRETCH)
141 #define CKEY_CAPS (DDCKEYCAPS_DESTBLT | DDCKEYCAPS_SRCBLT)
142 #define FX_CAPS (DDFXCAPS_BLTALPHA | DDFXCAPS_BLTMIRRORLEFTRIGHT        \
143                 | DDFXCAPS_BLTMIRRORUPDOWN | DDFXCAPS_BLTROTATION90     \
144                 | DDFXCAPS_BLTSHRINKX | DDFXCAPS_BLTSHRINKXN            \
145                 | DDFXCAPS_BLTSHRINKY | DDFXCAPS_BLTSHRINKXN            \
146                 | DDFXCAPS_BLTSTRETCHX | DDFXCAPS_BLTSTRETCHXN          \
147                 | DDFXCAPS_BLTSTRETCHY | DDFXCAPS_BLTSTRETCHYN)
148     This->caps.dwCaps |= DDCAPS_GDI | DDCAPS_PALETTE | BLIT_CAPS;
149     if( opengl_initialized )
150     {
151         /* Hack for D3D code */
152         This->caps.dwCaps |= DDCAPS_3D;
153     }
154     This->caps.dwCaps2 |= DDCAPS2_CERTIFIED | DDCAPS2_NOPAGELOCKREQUIRED |
155                           DDCAPS2_PRIMARYGAMMA | DDCAPS2_WIDESURFACES;
156     This->caps.dwCKeyCaps |= CKEY_CAPS;
157     This->caps.dwFXCaps |= FX_CAPS;
158     This->caps.dwPalCaps |= DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE;
159     This->caps.dwVidMemTotal = 16*1024*1024;
160     This->caps.dwVidMemFree = 16*1024*1024;
161     This->caps.dwSVBCaps |= BLIT_CAPS;
162     This->caps.dwSVBCKeyCaps |= CKEY_CAPS;
163     This->caps.dwSVBFXCaps |= FX_CAPS;
164     This->caps.dwVSBCaps |= BLIT_CAPS;
165     This->caps.dwVSBCKeyCaps |= CKEY_CAPS;
166     This->caps.dwVSBFXCaps |= FX_CAPS;
167     This->caps.dwSSBCaps |= BLIT_CAPS;
168     This->caps.dwSSBCKeyCaps |= CKEY_CAPS;
169     This->caps.dwSSBFXCaps |= FX_CAPS;
170     This->caps.ddsCaps.dwCaps |= DDSCAPS_ALPHA | DDSCAPS_BACKBUFFER |
171                                  DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER |
172                                  DDSCAPS_OFFSCREENPLAIN | DDSCAPS_PALETTE |
173                                  DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY |
174                                  DDSCAPS_VIDEOMEMORY | DDSCAPS_VISIBLE;
175     if( opengl_initialized )
176     {
177         /* Hacks for D3D code */
178         This->caps.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE | DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_ZBUFFER;
179     }
180     
181     This->caps.ddsOldCaps.dwCaps = This->caps.ddsCaps.dwCaps;
182 #undef BLIT_CAPS
183 #undef CKEY_CAPS
184 #undef FX_CAPS
185
186     return S_OK;
187 }
188
189 /* This function is called from DirectDrawCreate(Ex) on the most-derived
190  * class to start construction.
191  * Not called from the vtable. */
192 HRESULT User_DirectDraw_Create(const GUID* pGUID, LPDIRECTDRAW7* pIface,
193                                IUnknown* pUnkOuter, BOOL ex)
194 {
195     HRESULT hr;
196     IDirectDrawImpl* This;
197
198     assert(pUnkOuter == NULL);
199
200     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
201                      sizeof(IDirectDrawImpl) + sizeof(User_DirectDrawImpl));
202     if (This == NULL) return E_OUTOFMEMORY;
203
204     /* Note that this relation does *not* hold true if the DD object was
205      * CoCreateInstanced then Initialized. */
206     This->private = (User_DirectDrawImpl *)(This+1);
207
208     /* Initialize the DDCAPS structure */
209     This->caps.dwSize = sizeof(This->caps);
210
211     hr = User_DirectDraw_Construct(This, ex);
212     if (FAILED(hr))
213         HeapFree(GetProcessHeap(), 0, This);
214     else
215         *pIface = ICOM_INTERFACE(This, IDirectDraw7);
216
217     return hr;
218 }
219
220 /* This function is called from Uninit_DirectDraw_Initialize on the
221  * most-derived-class to start initialization.
222  * Not called from the vtable. */
223 HRESULT User_DirectDraw_Initialize(IDirectDrawImpl *This, const GUID* guid)
224 {
225     HRESULT hr;
226     This->private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
227                               sizeof(User_DirectDrawImpl));
228     if (This->private == NULL) return E_OUTOFMEMORY;
229
230     /* Initialize the DDCAPS structure */
231     This->caps.dwSize = sizeof(This->caps);
232
233     hr = User_DirectDraw_Construct(This, TRUE); /* XXX ex? */
234     if (FAILED(hr))
235     {
236         HeapFree(GetProcessHeap(), 0, This->private);
237         return hr;
238     }
239
240     return DD_OK;
241 }
242
243 /* Called from an internal function pointer. */
244 void User_DirectDraw_final_release(IDirectDrawImpl *This)
245 {
246     Main_DirectDraw_final_release(This);
247 }
248
249 /* Compact: generic */
250 /* CreateClipper: generic */
251 /* CreatePalette: generic (with callback) */
252 /* CreateSurface: generic (with callbacks) */
253
254 HRESULT
255 User_DirectDraw_create_primary(IDirectDrawImpl* This,
256                                const DDSURFACEDESC2* pDDSD,
257                                LPDIRECTDRAWSURFACE7* ppSurf,
258                                IUnknown* pUnkOuter)
259 {
260     return User_DirectDrawSurface_Create(This, pDDSD, ppSurf, pUnkOuter);
261 }
262
263 HRESULT
264 User_DirectDraw_create_backbuffer(IDirectDrawImpl* This,
265                                   const DDSURFACEDESC2* pDDSD,
266                                   LPDIRECTDRAWSURFACE7* ppSurf,
267                                   IUnknown* pUnkOuter,
268                                   IDirectDrawSurfaceImpl* primary)
269 {
270     return User_DirectDrawSurface_Create(This, pDDSD, ppSurf, pUnkOuter);
271 }
272
273 /* DuplicateSurface: generic */
274
275 /* Originally derived from Xlib_IDirectDraw2Impl_EnumDisplayModes.
276  *
277  * The depths are whatever DIBsections support on the client side.
278  * Should they be limited by screen depth?
279  */
280 HRESULT WINAPI
281 User_DirectDraw_EnumDisplayModes(LPDIRECTDRAW7 iface, DWORD dwFlags,
282                                  LPDDSURFACEDESC2 pDDSD, LPVOID context,
283                                  LPDDENUMMODESCALLBACK2 callback)
284 {
285     DDSURFACEDESC2 callback_sd;
286     DEVMODEW DevModeW;
287     const DDPIXELFORMAT* pixelformat;
288
289     int i;
290
291     TRACE("(%p)->(0x%08lx,%p,%p,%p)\n",iface,dwFlags,pDDSD,context,callback);
292
293     ZeroMemory(&callback_sd, sizeof(callback_sd));
294     callback_sd.dwSize = sizeof(callback_sd);
295
296     callback_sd.dwFlags = DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_CAPS
297         | DDSD_PITCH;
298
299     if (dwFlags & DDEDM_REFRESHRATES)
300         callback_sd.dwFlags |= DDSD_REFRESHRATE;
301
302     callback_sd.u2.dwRefreshRate = 60.0;
303
304     i = 0;
305     while (EnumDisplaySettingsExW(NULL, i, &DevModeW, 0))
306     {
307         callback_sd.dwHeight = DevModeW.dmPelsHeight;
308         callback_sd.dwWidth = DevModeW.dmPelsWidth;
309         if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
310         {
311             callback_sd.u2.dwRefreshRate = DevModeW.dmDisplayFrequency;
312         }
313
314         TRACE("- mode: %ldx%ld\n", callback_sd.dwWidth, callback_sd.dwHeight);
315         
316         pixelformat = pixelformat_for_depth(DevModeW.dmBitsPerPel);
317         callback_sd.u1.lPitch
318             = DDRAW_width_bpp_to_pitch(DevModeW.dmPelsWidth,
319                                        pixelformat->u1.dwRGBBitCount);
320
321         callback_sd.u4.ddpfPixelFormat = *pixelformat;
322
323         callback_sd.ddsCaps.dwCaps = 0;
324         if (pixelformat->dwFlags & DDPF_PALETTEINDEXED8) /* ick */
325             callback_sd.ddsCaps.dwCaps |= DDSCAPS_PALETTE;
326
327         TRACE(" - %2ld bpp, R=%08lx G=%08lx B=%08lx\n",
328             callback_sd.u4.ddpfPixelFormat.u1.dwRGBBitCount,
329             callback_sd.u4.ddpfPixelFormat.u2.dwRBitMask,
330             callback_sd.u4.ddpfPixelFormat.u3.dwGBitMask,
331             callback_sd.u4.ddpfPixelFormat.u4.dwBBitMask);
332         if (callback(&callback_sd, context) == DDENUMRET_CANCEL)
333             return DD_OK;
334         i++;
335     }
336
337     return DD_OK;
338 }
339
340 /* EnumSurfaces: generic */
341 /* FlipToGDISurface: ??? */
342
343 #if 0
344 HRESULT WINAPI
345 User_DirectDraw_GetCaps(LPDIRECTDRAW7 iface, LPDDCAPS pDriverCaps,
346                         LPDDCAPS pHELCaps)
347 {
348 /* Based on my guesses for what is appropriate with some clues from the
349  * NVidia driver. Not everything is actually implemented yet.
350  * NV has but we don't: Overlays, Video Ports, DDCAPS_READSCANLINE,
351  * DDCAPS2_CERTIFIED (heh), DDSCAPS2_NONLOCALVIDMEM, DDSCAPS2_COPYFOURCC.
352  * It actually has no FX alpha caps.
353  * Oddly, it doesn't list DDPCAPS_PRIMARYSURFACE.
354  * And the HEL caps make little sense.
355  */
356 #define BLIT_CAPS (DDCAPS_BLT | DDCAPS_BLTCOLORFILL | DDCAPS_BLTDEPTHFILL \
357           | DDCAPS_BLTSTRETCH | DDCAPS_CANBLTSYSMEM | DDCAPS_CANCLIP      \
358           | DDCAPS_CANCLIPSTRETCHED | DDCAPS_COLORKEY                     \
359           | DDCAPS_COLORKEYHWASSIST | DDCAPS_OVERLAY | DDCAPS_OVERLAYSTRETCH)
360
361 #define CKEY_CAPS (DDCKEYCAPS_DESTBLT | DDCKEYCAPS_SRCBLT)
362
363 #define FX_CAPS (DDFXCAPS_BLTALPHA | DDFXCAPS_BLTMIRRORLEFTRIGHT        \
364                 | DDFXCAPS_BLTMIRRORUPDOWN | DDFXCAPS_BLTROTATION90     \
365                 | DDFXCAPS_BLTSHRINKX | DDFXCAPS_BLTSHRINKXN            \
366                 | DDFXCAPS_BLTSHRINKY | DDFXCAPS_BLTSHRINKXN            \
367                 | DDFXCAPS_BLTSTRETCHX | DDFXCAPS_BLTSTRETCHXN          \
368                 | DDFXCAPS_BLTSTRETCHY | DDFXCAPS_BLTSTRETCHYN)
369
370 #if 0
371 #define ROPS { SRCCOPY, SRCPAINT, SRCAND, SRCINVERT, SRCERASE, NOTSRCCOPY, \
372         NOTSRCERASE, MERGEPAINT, BLACKNESS, WHITENESS, }
373 #else
374 #define ROPS { 0, }
375 #endif
376
377     static const DDCAPS caps =
378     { sizeof(DDCAPS),
379       DDCAPS_3D | DDCAPS_GDI | DDCAPS_PALETTE | BLIT_CAPS,
380       DDCAPS2_CANMANAGETEXTURE | DDCAPS2_CANRENDERWINDOWED | DDCAPS2_CERTIFIED
381       | DDCAPS2_NOPAGELOCKREQUIRED | DDCAPS2_PRIMARYGAMMA
382       | DDCAPS2_WIDESURFACES,
383       CKEY_CAPS,
384       FX_CAPS,
385       0, /* dwFXAlphaCaps */
386       DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE,
387       0, /* dwSVCaps */
388       0, /* ? dwAlphaBitConstBitDepths */
389       0, /* ? dwAlphaBitPixelPitDepths */
390       0, /* ? dwAlphaBltSurfaceBitDepths */
391       0, /* ? dwAlphaOverlayConstBitDepths */
392       0, /* ? dwAlphaOverlayPixelBitDepths */
393       0, /* ? dwAlphaOverlaySurfaceBitDepths */
394       DDBD_16, /* ? dwZBufferBitDepths */
395       16*1024*1024, /* dwVidMemTotal */
396       16*1024*1024, /* dwVidMemFree */
397       0, /* dwMaxVisibleOverlays */
398       0, /* dwCurrVisibleOverlays */
399       0, /* dwNumFourCCCodes */
400       0, /* dwAlignBoundarySrc */
401       0, /* dwAlignSizeSrc */
402       0, /* dwAlignBoundaryDest */
403       0, /* dwAlignSizeDest */
404       0, /* dwAlignStrideAlign */
405       ROPS, /* XXX dwRops[DD_ROP_SPACE] */
406       { 0, }, /* XXX ddsOldCaps */
407       1000, /* dwMinOverlayStretch */
408       1000, /* dwMaxOverlayStretch */
409       1000, /* dwMinLiveVideoStretch */
410       1000, /* dwMaxLiveVideoStretch */
411       1000, /* dwMinHwCodecStretch */
412       1000, /* dwMaxHwCodecStretch */
413       0, 0, 0, /* dwReserved1, 2, 3 */
414       BLIT_CAPS, /* dwSVBCaps */
415       CKEY_CAPS, /* dwSVBCKeyCaps */
416       FX_CAPS, /* dwSVBFXCaps */
417       ROPS, /* dwSVBRops */
418       BLIT_CAPS, /* dwVSBCaps */
419       CKEY_CAPS, /* dwVSBCKeyCaps */
420       FX_CAPS, /* dwVSBFXCaps */
421       ROPS, /* dwVSBRops */
422       BLIT_CAPS, /* dwSSBCaps */
423       CKEY_CAPS, /* dwSSBCKeyCaps */
424       FX_CAPS, /* dwSSBFXCaps */
425       ROPS, /* dwSSBRops */
426       0, /* dwMaxVideoPorts */
427       0, /* dwCurrVideoPorts */
428       0, /* ? dwSVBCaps2 */
429       BLIT_CAPS, /* ? dwNLVBCaps */
430       0, /* ? dwNLVBCaps2 */
431       CKEY_CAPS, /* dwNLVBCKeyCaps */
432       FX_CAPS, /* dwNLVBFXCaps */
433       ROPS, /* dwNLVBRops */
434       { /* ddsCaps */
435           DDSCAPS_3DDEVICE | DDSCAPS_ALPHA | DDSCAPS_BACKBUFFER | DDSCAPS_FLIP
436           | DDSCAPS_FRONTBUFFER | DDSCAPS_MIPMAP | DDSCAPS_OFFSCREENPLAIN
437           | DDSCAPS_PALETTE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY
438           | DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_VISIBLE
439           | DDSCAPS_ZBUFFER,
440           DDSCAPS2_CUBEMAP,
441           0,
442           0
443       }
444     };
445
446 #undef BLIT_CAPS
447 #undef CKEY_CAPS
448 #undef FX_CAPS
449 #undef ROPS
450
451     IDirectDrawImpl *This = (IDirectDrawImpl *)iface;
452
453     TRACE("(%p)->(%p,%p)\n",This,pDriverCaps,pHELCaps);
454
455     if (pDriverCaps != NULL)
456         DD_STRUCT_COPY_BYSIZE(pDriverCaps,&caps);
457
458     if (pHELCaps != NULL)
459         DD_STRUCT_COPY_BYSIZE(pHELCaps,&caps);
460
461     return DD_OK;
462 }
463 #endif
464
465 HRESULT WINAPI
466 User_DirectDraw_GetDeviceIdentifier(LPDIRECTDRAW7 iface,
467                                     LPDDDEVICEIDENTIFIER2 pDDDI,
468                                     DWORD dwFlags)
469 {
470     TRACE("(%p)->(%p,%08lx)\n",iface,pDDDI,dwFlags);
471     *pDDDI = user_device;
472     return DD_OK;
473 }
474
475 /* GetDisplayMode: generic */
476 /* GetFourCCCodes: generic */
477 /* GetGDISurface: ??? */
478 /* GetMonitorFrequency: generic */
479 /* GetScanLine: generic */
480 /* GetSurfaceFromDC: generic */
481 /* GetVerticalBlankStatus: generic */
482 /* Initialize: generic */
483 /* RestoreAllSurfaces: generic */
484 /* RestoreDisplayMode: generic */
485 /* SetCooperativeLevel: ??? */
486
487 HRESULT WINAPI
488 User_DirectDraw_SetDisplayMode(LPDIRECTDRAW7 iface, DWORD dwWidth,
489                                DWORD dwHeight, DWORD dwBPP,
490                                DWORD dwRefreshRate, DWORD dwFlags)
491 {
492     IDirectDrawImpl *This = (IDirectDrawImpl *)iface;
493
494     const DDPIXELFORMAT* pixelformat;
495     DEVMODEW devmode;
496     LONG pitch;
497
498     TRACE("(%p)->(%ldx%ldx%ld,%ld Hz,%08lx)\n",This,dwWidth,dwHeight,dwBPP,dwRefreshRate,dwFlags);
499     devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
500     devmode.dmBitsPerPel = dwBPP;
501     devmode.dmPelsWidth  = dwWidth;
502     devmode.dmPelsHeight = dwHeight;
503     /* '0' means default frequency */
504     if (dwRefreshRate != 0) 
505     {
506         devmode.dmFields |= DM_DISPLAYFREQUENCY;
507         devmode.dmDisplayFrequency = dwRefreshRate;
508     }
509     if (ChangeDisplaySettingsExW(NULL, &devmode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL)
510         return DDERR_INVALIDMODE;
511
512     pixelformat = pixelformat_for_depth(dwBPP);
513     if (pixelformat == NULL)
514     {
515         assert(0);
516         return DDERR_GENERIC;
517     }
518
519     pitch = DDRAW_width_bpp_to_pitch(dwWidth, dwBPP);
520     return Main_DirectDraw_SetDisplayMode(iface, dwWidth, dwHeight, pitch,
521                                           dwRefreshRate, dwFlags, pixelformat);
522 }
523
524 /* StartModeTest: ??? */
525 /* TestCooperativeLevel: generic? */
526 /* WaitForVerticalBlank: ??? */
527
528 static const IDirectDraw7Vtbl User_DirectDraw_VTable =
529 {
530     Main_DirectDraw_QueryInterface,
531     Main_DirectDraw_AddRef,
532     Main_DirectDraw_Release,
533     Main_DirectDraw_Compact,
534     Main_DirectDraw_CreateClipper,
535     Main_DirectDraw_CreatePalette,
536     Main_DirectDraw_CreateSurface,
537     Main_DirectDraw_DuplicateSurface,
538     User_DirectDraw_EnumDisplayModes,
539     Main_DirectDraw_EnumSurfaces,
540     Main_DirectDraw_FlipToGDISurface,
541     Main_DirectDraw_GetCaps,
542     Main_DirectDraw_GetDisplayMode,
543     Main_DirectDraw_GetFourCCCodes,
544     Main_DirectDraw_GetGDISurface,
545     Main_DirectDraw_GetMonitorFrequency,
546     Main_DirectDraw_GetScanLine,
547     Main_DirectDraw_GetVerticalBlankStatus,
548     Main_DirectDraw_Initialize,
549     Main_DirectDraw_RestoreDisplayMode,
550     Main_DirectDraw_SetCooperativeLevel,
551     User_DirectDraw_SetDisplayMode,
552     Main_DirectDraw_WaitForVerticalBlank,
553     Main_DirectDraw_GetAvailableVidMem,
554     Main_DirectDraw_GetSurfaceFromDC,
555     Main_DirectDraw_RestoreAllSurfaces,
556     Main_DirectDraw_TestCooperativeLevel,
557     User_DirectDraw_GetDeviceIdentifier,
558     Main_DirectDraw_StartModeTest,
559     Main_DirectDraw_EvaluateMode
560 };