3 * COPYRIGHT: See COPYING in the top level directory
5 * FILE: lib/ddraw/main/ddraw.c
6 * PURPOSE: IDirectDraw7 Implementation
7 * PROGRAMMER: Magnus Olsen, Maarten Bosma
14 HRESULT WINAPI
Main_DirectDraw_Initialize (LPDIRECTDRAW7 iface
, LPGUID lpGUID
)
16 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
19 // this if it is not called by DirectDrawCreate
21 return DDERR_ALREADYINITIALIZED
;
24 This
->lpGUID
= lpGUID
;
27 This
->hdc
= GetWindowDC(GetDesktopWindow());
28 This
->Height
= GetDeviceCaps(This
->hdc
, VERTRES
);
29 This
->Width
= GetDeviceCaps(This
->hdc
, HORZRES
);
30 This
->Bpp
= GetDeviceCaps(This
->hdc
, BITSPIXEL
);
32 // call software first
33 if((ret
= Hal_DirectDraw_Initialize (iface
)) != DD_OK
)
36 // ... then overwrite with hal
37 if((ret
= Hel_DirectDraw_Initialize (iface
)) != DD_OK
)
43 HRESULT WINAPI
Main_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface
, HWND hwnd
, DWORD cooplevel
)
46 // - create a scaner that check which driver we should get the HDC from
47 // for now we always asume it is the active dirver that should be use.
50 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
53 // check the parameters
54 if (This
->cooperative_level
== cooplevel
&& This
->window
== hwnd
)
58 return DDERR_HWNDALREADYSET
;
60 if (This
->cooperative_level
)
61 return DDERR_EXCLUSIVEMODEALREADYSET
;
63 if ((cooplevel
&DDSCL_EXCLUSIVE
) && !(cooplevel
&DDSCL_FULLSCREEN
))
64 return DDERR_INVALIDPARAMS
;
66 if (cooplevel
&DDSCL_NORMAL
&& cooplevel
&DDSCL_FULLSCREEN
)
67 return DDERR_INVALIDPARAMS
;
71 This
->hdc
= GetDC(hwnd
);
72 This
->cooperative_level
= cooplevel
;
76 if((ret
= Hal_DirectDraw_SetCooperativeLevel (iface
)) != DD_OK
)
79 if((ret
= Hel_DirectDraw_SetCooperativeLevel (iface
)) != DD_OK
)
85 HRESULT WINAPI
Main_DirectDraw_SetDisplayMode (LPDIRECTDRAW7 iface
, DWORD dwWidth
, DWORD dwHeight
,
86 DWORD dwBPP
, DWORD dwRefreshRate
, DWORD dwFlags
)
89 if((ret
= Hal_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
,
90 dwBPP
, dwRefreshRate
, dwFlags
)) == DD_OK
)
95 if((ret
= Hel_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
,
96 dwBPP
, dwRefreshRate
, dwFlags
)) == DD_OK
)
101 return DDERR_NOTINITIALIZED
;
103 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
105 // this only for exclusive mode
106 if(!(This
->cooperative_level
& DDSCL_EXCLUSIVE
))
107 return DDERR_NOEXCLUSIVEMODE
;
109 // change the resolution using normal WinAPI function
111 mode
.dmSize
= sizeof(mode
);
112 mode
.dmPelsWidth
= dwWidth
;
113 mode
.dmPelsHeight
= dwHeight
;
114 mode
.dmBitsPerPel
= dwBPP
;
115 mode
.dmDisplayFrequency
= dwRefreshRate
;
119 mode
.dmFields
|= DM_PELSWIDTH
;
121 mode
.dmFields
|= DM_PELSHEIGHT
;
123 mode
.dmFields
|= DM_BITSPERPEL
;
125 mode
.dmFields
|= DM_DISPLAYFREQUENCY
;
127 if (ChangeDisplaySettings(&mode
, CDS_FULLSCREEN
) != DISP_CHANGE_SUCCESSFUL
)
128 return DDERR_UNSUPPORTEDMODE
;
130 // TODO: reactivate ddraw object, maximize window, set it in foreground
131 // and set excluive mode (if implemented by the driver)
134 This
->Height
= dwWidth
;
136 This
->Width
= dwHeight
;
143 ULONG WINAPI
Main_DirectDraw_AddRef (LPDIRECTDRAW7 iface
)
145 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
146 ULONG ref
= InterlockedIncrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
151 ULONG WINAPI
Main_DirectDraw_Release (LPDIRECTDRAW7 iface
)
153 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
154 ULONG ref
= InterlockedDecrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
158 // set resoltion back to the one in registry
159 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
160 ChangeDisplaySettings(NULL
, 0);
162 HeapFree(GetProcessHeap(), 0, This
);
168 HRESULT WINAPI
Main_DirectDraw_QueryInterface (
169 LPDIRECTDRAW7 iface
, REFIID id
, LPVOID
*obj
)
171 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
173 if (IsEqualGUID(&IID_IDirectDraw7
, id
))
175 *obj
= &This
->lpVtbl
;
177 else if (IsEqualGUID(&IID_IDirectDraw
, id
))
179 *obj
= &This
->lpVtbl_v1
;
181 else if (IsEqualGUID(&IID_IDirectDraw2
, id
))
183 *obj
= &This
->lpVtbl_v2
;
185 else if (IsEqualGUID(&IID_IDirectDraw4
, id
))
187 *obj
= &This
->lpVtbl_v4
;
192 return E_NOINTERFACE
;
195 Main_DirectDraw_AddRef(iface
);
199 HRESULT WINAPI
Main_DirectDraw_CreateSurface (LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
,
200 LPDIRECTDRAWSURFACE7
*ppSurf
, IUnknown
*pUnkOuter
)
203 return DDERR_INVALIDPARAMS
;
205 if(sizeof(DDSURFACEDESC2
)!=pDDSD
->dwSize
)
206 return DDERR_UNSUPPORTED
;
208 // the nasty com stuff
209 IDirectDrawSurfaceImpl
* That
;
211 That
= (IDirectDrawSurfaceImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawSurfaceImpl
));
214 return E_OUTOFMEMORY
;
216 ZeroMemory(That
, sizeof(IDirectDrawSurfaceImpl
));
218 That
->lpVtbl
= &DirectDrawSurface7_Vtable
;
219 That
->lpVtbl_v3
= &DDRAW_IDDS3_Thunk_VTable
;
222 *ppSurf
= (LPDIRECTDRAWSURFACE7
)That
;
224 // the real surface object creation
225 return That
->lpVtbl
->Initialize (*ppSurf
, (LPDIRECTDRAW
)iface
, pDDSD
);
228 HRESULT WINAPI
Main_DirectDraw_CreateClipper(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
229 LPDIRECTDRAWCLIPPER
*ppClipper
, IUnknown
*pUnkOuter
)
232 return DDERR_INVALIDPARAMS
;
234 IDirectDrawClipperImpl
* That
;
235 That
= (IDirectDrawClipperImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawClipperImpl
));
238 return E_OUTOFMEMORY
;
240 ZeroMemory(That
, sizeof(IDirectDrawClipperImpl
));
242 That
->lpVtbl
= &DirectDrawClipper_Vtable
;
244 *ppClipper
= (LPDIRECTDRAWCLIPPER
)That
;
246 return That
->lpVtbl
->Initialize (*ppClipper
, (LPDIRECTDRAW
)iface
, dwFlags
);
249 // This function is exported by the dll
250 HRESULT WINAPI
DirectDrawCreateClipper (DWORD dwFlags
,
251 LPDIRECTDRAWCLIPPER
* lplpDDClipper
, LPUNKNOWN pUnkOuter
)
253 return Main_DirectDraw_CreateClipper(NULL
, dwFlags
, lplpDDClipper
, pUnkOuter
);
256 HRESULT WINAPI
Main_DirectDraw_CreatePalette(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
257 LPPALETTEENTRY palent
, LPDIRECTDRAWPALETTE
* ppPalette
, LPUNKNOWN pUnkOuter
)
260 return DDERR_INVALIDPARAMS
;
262 IDirectDrawPaletteImpl
* That
;
263 That
= (IDirectDrawPaletteImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
266 return E_OUTOFMEMORY
;
268 ZeroMemory(That
, sizeof(IDirectDrawPaletteImpl
));
270 That
->lpVtbl
= &DirectDrawPalette_Vtable
;
272 *ppPalette
= (LPDIRECTDRAWPALETTE
)That
;
274 return That
->lpVtbl
->Initialize (*ppPalette
, (LPDIRECTDRAW
)iface
, dwFlags
, palent
);
279 HRESULT WINAPI
Main_DirectDraw_Compact(LPDIRECTDRAW7 iface
)
284 HRESULT WINAPI
Main_DirectDraw_DuplicateSurface(LPDIRECTDRAW7 iface
, LPDIRECTDRAWSURFACE7 src
,
285 LPDIRECTDRAWSURFACE7
* dst
)
290 HRESULT WINAPI
Main_DirectDraw_EnumDisplayModes(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
291 LPDDSURFACEDESC2 pDDSD
, LPVOID context
, LPDDENUMMODESCALLBACK2 callback
)
296 HRESULT WINAPI
Main_DirectDraw_EnumSurfaces(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
297 LPDDSURFACEDESC2 lpDDSD2
, LPVOID context
,
298 LPDDENUMSURFACESCALLBACK7 callback
)
303 HRESULT WINAPI
Main_DirectDraw_FlipToGDISurface(LPDIRECTDRAW7 iface
)
307 if((ret
= Hal_DirectDraw_FlipToGDISurface( iface
)) == DD_OK
)
310 if((ret
= Hel_DirectDraw_FlipToGDISurface( iface
)) == DD_OK
)
313 return DDERR_NOTINITIALIZED
;
316 HRESULT WINAPI
Main_DirectDraw_GetCaps(LPDIRECTDRAW7 iface
, LPDDCAPS pDriverCaps
,
319 DWORD status
= DD_FALSE
;
320 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
322 if (pDriverCaps
!= NULL
)
324 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
328 if (pHELCaps
!= NULL
)
330 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddHELCaps
,sizeof(DDCORECAPS
));
334 /* Both caps mixed ?? */
335 /* DDCORECAPS ddBothCaps; */
340 HRESULT WINAPI
Main_DirectDraw_GetDisplayMode(LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
)
342 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
349 pDDSD
->dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_PITCH
| DDSD_PIXELFORMAT
| DDSD_REFRESHRATE
| DDSD_WIDTH
;
350 pDDSD
->dwHeight
= This
->DirectDrawGlobal
.vmiData
.dwDisplayHeight
;
351 pDDSD
->dwWidth
= This
->DirectDrawGlobal
.vmiData
.dwDisplayWidth
;
353 /* FIXME Do not use DUMMYUNIONNAME1 some how union lPitch does not see by the compiler
354 but rest of the union are visable. more header problem ???
356 pDDSD
->DUMMYUNIONNAME1
.lPitch
= This
->DirectDrawGlobal
.vmiData
.lDisplayPitch
;
359 /* have not check where I should get hold of this info yet
360 DWORD dwBackBufferCount;
363 pDDSD
->dwRefreshRate
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
365 /* have not check where I should get hold of this info yet
366 DWORD dwAlphaBitDepth;
371 DDCOLORKEY ddckCKDestOverlay;
372 DWORD dwEmptyFaceColor;
374 DDCOLORKEY ddckCKDestBlt;
375 DDCOLORKEY ddckCKSrcOverlay;
376 DDCOLORKEY ddckCKSrcBlt;
380 RtlCopyMemory(&pDDSD
->ddpfPixelFormat
,&This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
,sizeof(DDPIXELFORMAT
));
381 RtlCopyMemory(&pDDSD
->ddsCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
383 /* have not check where I should get hold of this info yet
384 DWORD dwTextureStage;
391 HRESULT WINAPI
Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface
, LPDWORD pNumCodes
, LPDWORD pCodes
)
396 HRESULT WINAPI
Main_DirectDraw_GetGDISurface(LPDIRECTDRAW7 iface
,
397 LPDIRECTDRAWSURFACE7
*lplpGDIDDSSurface
)
402 HRESULT WINAPI
Main_DirectDraw_GetMonitorFrequency(LPDIRECTDRAW7 iface
,LPDWORD freq
)
404 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
411 *freq
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
415 HRESULT WINAPI
Main_DirectDraw_GetScanLine(LPDIRECTDRAW7 iface
, LPDWORD lpdwScanLine
)
419 if((ret
= Hal_DirectDraw_GetScanLine( iface
, lpdwScanLine
)) == DD_OK
)
422 if((ret
= Hel_DirectDraw_GetScanLine( iface
, lpdwScanLine
)) == DD_OK
)
425 return DDERR_NOTINITIALIZED
;
428 HRESULT WINAPI
Main_DirectDraw_GetVerticalBlankStatus(LPDIRECTDRAW7 iface
, LPBOOL status
)
433 HRESULT WINAPI
Main_DirectDraw_RestoreDisplayMode(LPDIRECTDRAW7 iface
)
438 HRESULT WINAPI
Main_DirectDraw_WaitForVerticalBlank(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
443 if((ret
= Hal_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
)) == DD_OK
)
446 if((ret
= Hel_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
)) == DD_OK
)
449 return DDERR_NOTINITIALIZED
;
452 HRESULT WINAPI
Main_DirectDraw_GetAvailableVidMem(LPDIRECTDRAW7 iface
, LPDDSCAPS2 ddscaps
,
453 LPDWORD total
, LPDWORD free
)
457 if((ret
= Hal_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
)) == DD_OK
)
460 if((ret
= Hel_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
)) == DD_OK
)
464 return DDERR_NOTINITIALIZED
;
468 HRESULT WINAPI
Main_DirectDraw_GetSurfaceFromDC(LPDIRECTDRAW7 iface
, HDC hdc
,
469 LPDIRECTDRAWSURFACE7
*lpDDS
)
474 HRESULT WINAPI
Main_DirectDraw_RestoreAllSurfaces(LPDIRECTDRAW7 iface
)
479 HRESULT WINAPI
Main_DirectDraw_TestCooperativeLevel(LPDIRECTDRAW7 iface
)
484 HRESULT WINAPI
Main_DirectDraw_GetDeviceIdentifier(LPDIRECTDRAW7 iface
,
485 LPDDDEVICEIDENTIFIER2 pDDDI
, DWORD dwFlags
)
490 HRESULT WINAPI
Main_DirectDraw_StartModeTest(LPDIRECTDRAW7 iface
, LPSIZE pModes
,
491 DWORD dwNumModes
, DWORD dwFlags
)
496 HRESULT WINAPI
Main_DirectDraw_EvaluateMode(LPDIRECTDRAW7 iface
,DWORD a
,DWORD
* b
)
501 IDirectDraw7Vtbl DirectDraw7_Vtable
=
503 Main_DirectDraw_QueryInterface
,
504 Main_DirectDraw_AddRef
,
505 Main_DirectDraw_Release
,
506 Main_DirectDraw_Compact
,
507 Main_DirectDraw_CreateClipper
,
508 Main_DirectDraw_CreatePalette
,
509 Main_DirectDraw_CreateSurface
,
510 Main_DirectDraw_DuplicateSurface
,
511 Main_DirectDraw_EnumDisplayModes
,
512 Main_DirectDraw_EnumSurfaces
,
513 Main_DirectDraw_FlipToGDISurface
,
514 Main_DirectDraw_GetCaps
,
515 Main_DirectDraw_GetDisplayMode
,
516 Main_DirectDraw_GetFourCCCodes
,
517 Main_DirectDraw_GetGDISurface
,
518 Main_DirectDraw_GetMonitorFrequency
,
519 Main_DirectDraw_GetScanLine
,
520 Main_DirectDraw_GetVerticalBlankStatus
,
521 Main_DirectDraw_Initialize
,
522 Main_DirectDraw_RestoreDisplayMode
,
523 Main_DirectDraw_SetCooperativeLevel
,
524 Main_DirectDraw_SetDisplayMode
,
525 Main_DirectDraw_WaitForVerticalBlank
,
526 Main_DirectDraw_GetAvailableVidMem
,
527 Main_DirectDraw_GetSurfaceFromDC
,
528 Main_DirectDraw_RestoreAllSurfaces
,
529 Main_DirectDraw_TestCooperativeLevel
,
530 Main_DirectDraw_GetDeviceIdentifier
,
531 Main_DirectDraw_StartModeTest
,
532 Main_DirectDraw_EvaluateMode