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 ret
= Hel_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
, dwBPP
, dwRefreshRate
, dwFlags
);
100 ULONG WINAPI
Main_DirectDraw_AddRef (LPDIRECTDRAW7 iface
)
102 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
103 ULONG ref
= InterlockedIncrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
108 ULONG WINAPI
Main_DirectDraw_Release (LPDIRECTDRAW7 iface
)
110 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
111 ULONG ref
= InterlockedDecrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
115 // set resoltion back to the one in registry
116 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
117 ChangeDisplaySettings(NULL
, 0);
119 HeapFree(GetProcessHeap(), 0, This
);
125 HRESULT WINAPI
Main_DirectDraw_QueryInterface (
126 LPDIRECTDRAW7 iface
, REFIID id
, LPVOID
*obj
)
128 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
130 if (IsEqualGUID(&IID_IDirectDraw7
, id
))
132 *obj
= &This
->lpVtbl
;
134 else if (IsEqualGUID(&IID_IDirectDraw
, id
))
136 *obj
= &This
->lpVtbl_v1
;
138 else if (IsEqualGUID(&IID_IDirectDraw2
, id
))
140 *obj
= &This
->lpVtbl_v2
;
142 else if (IsEqualGUID(&IID_IDirectDraw4
, id
))
144 *obj
= &This
->lpVtbl_v4
;
149 return E_NOINTERFACE
;
152 Main_DirectDraw_AddRef(iface
);
156 HRESULT WINAPI
Main_DirectDraw_CreateSurface (LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
,
157 LPDIRECTDRAWSURFACE7
*ppSurf
, IUnknown
*pUnkOuter
)
160 return DDERR_INVALIDPARAMS
;
162 if(sizeof(DDSURFACEDESC2
)!=pDDSD
->dwSize
)
163 return DDERR_UNSUPPORTED
;
165 // the nasty com stuff
166 IDirectDrawSurfaceImpl
* That
;
168 That
= (IDirectDrawSurfaceImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawSurfaceImpl
));
171 return E_OUTOFMEMORY
;
173 ZeroMemory(That
, sizeof(IDirectDrawSurfaceImpl
));
175 That
->lpVtbl
= &DirectDrawSurface7_Vtable
;
176 That
->lpVtbl_v3
= &DDRAW_IDDS3_Thunk_VTable
;
179 *ppSurf
= (LPDIRECTDRAWSURFACE7
)That
;
181 // the real surface object creation
182 return That
->lpVtbl
->Initialize (*ppSurf
, (LPDIRECTDRAW
)iface
, pDDSD
);
185 HRESULT WINAPI
Main_DirectDraw_CreateClipper(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
186 LPDIRECTDRAWCLIPPER
*ppClipper
, IUnknown
*pUnkOuter
)
189 return DDERR_INVALIDPARAMS
;
191 IDirectDrawClipperImpl
* That
;
192 That
= (IDirectDrawClipperImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawClipperImpl
));
195 return E_OUTOFMEMORY
;
197 ZeroMemory(That
, sizeof(IDirectDrawClipperImpl
));
199 That
->lpVtbl
= &DirectDrawClipper_Vtable
;
201 *ppClipper
= (LPDIRECTDRAWCLIPPER
)That
;
203 return That
->lpVtbl
->Initialize (*ppClipper
, (LPDIRECTDRAW
)iface
, dwFlags
);
206 // This function is exported by the dll
207 HRESULT WINAPI
DirectDrawCreateClipper (DWORD dwFlags
,
208 LPDIRECTDRAWCLIPPER
* lplpDDClipper
, LPUNKNOWN pUnkOuter
)
210 return Main_DirectDraw_CreateClipper(NULL
, dwFlags
, lplpDDClipper
, pUnkOuter
);
213 HRESULT WINAPI
Main_DirectDraw_CreatePalette(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
214 LPPALETTEENTRY palent
, LPDIRECTDRAWPALETTE
* ppPalette
, LPUNKNOWN pUnkOuter
)
217 return DDERR_INVALIDPARAMS
;
219 IDirectDrawPaletteImpl
* That
;
220 That
= (IDirectDrawPaletteImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
223 return E_OUTOFMEMORY
;
225 ZeroMemory(That
, sizeof(IDirectDrawPaletteImpl
));
227 That
->lpVtbl
= &DirectDrawPalette_Vtable
;
229 *ppPalette
= (LPDIRECTDRAWPALETTE
)That
;
231 return That
->lpVtbl
->Initialize (*ppPalette
, (LPDIRECTDRAW
)iface
, dwFlags
, palent
);
236 HRESULT WINAPI
Main_DirectDraw_Compact(LPDIRECTDRAW7 iface
)
241 HRESULT WINAPI
Main_DirectDraw_DuplicateSurface(LPDIRECTDRAW7 iface
, LPDIRECTDRAWSURFACE7 src
,
242 LPDIRECTDRAWSURFACE7
* dst
)
247 HRESULT WINAPI
Main_DirectDraw_EnumDisplayModes(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
248 LPDDSURFACEDESC2 pDDSD
, LPVOID context
, LPDDENUMMODESCALLBACK2 callback
)
253 HRESULT WINAPI
Main_DirectDraw_EnumSurfaces(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
254 LPDDSURFACEDESC2 lpDDSD2
, LPVOID context
,
255 LPDDENUMSURFACESCALLBACK7 callback
)
260 HRESULT WINAPI
Main_DirectDraw_FlipToGDISurface(LPDIRECTDRAW7 iface
)
262 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
264 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_FLIPTOGDISURFACE
)
266 return Hal_DirectDraw_FlipToGDISurface( iface
);
269 return Hel_DirectDraw_FlipToGDISurface( iface
);
272 HRESULT WINAPI
Main_DirectDraw_GetCaps(LPDIRECTDRAW7 iface
, LPDDCAPS pDriverCaps
,
275 DWORD status
= DD_FALSE
;
276 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
278 if (pDriverCaps
!= NULL
)
280 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
284 if (pHELCaps
!= NULL
)
286 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddHELCaps
,sizeof(DDCORECAPS
));
290 /* Both caps mixed ?? */
291 /* DDCORECAPS ddBothCaps; */
296 HRESULT WINAPI
Main_DirectDraw_GetDisplayMode(LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
)
298 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
305 pDDSD
->dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_PITCH
| DDSD_PIXELFORMAT
| DDSD_REFRESHRATE
| DDSD_WIDTH
;
306 pDDSD
->dwHeight
= This
->DirectDrawGlobal
.vmiData
.dwDisplayHeight
;
307 pDDSD
->dwWidth
= This
->DirectDrawGlobal
.vmiData
.dwDisplayWidth
;
309 /* FIXME Do not use DUMMYUNIONNAME1 some how union lPitch does not see by the compiler
310 but rest of the union are visable. more header problem ???
312 pDDSD
->DUMMYUNIONNAME1
.lPitch
= This
->DirectDrawGlobal
.vmiData
.lDisplayPitch
;
315 /* have not check where I should get hold of this info yet
316 DWORD dwBackBufferCount;
319 pDDSD
->dwRefreshRate
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
321 /* have not check where I should get hold of this info yet
322 DWORD dwAlphaBitDepth;
327 DDCOLORKEY ddckCKDestOverlay;
328 DWORD dwEmptyFaceColor;
330 DDCOLORKEY ddckCKDestBlt;
331 DDCOLORKEY ddckCKSrcOverlay;
332 DDCOLORKEY ddckCKSrcBlt;
336 RtlCopyMemory(&pDDSD
->ddpfPixelFormat
,&This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
,sizeof(DDPIXELFORMAT
));
337 RtlCopyMemory(&pDDSD
->ddsCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
339 /* have not check where I should get hold of this info yet
340 DWORD dwTextureStage;
347 HRESULT WINAPI
Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface
, LPDWORD pNumCodes
, LPDWORD pCodes
)
352 HRESULT WINAPI
Main_DirectDraw_GetGDISurface(LPDIRECTDRAW7 iface
,
353 LPDIRECTDRAWSURFACE7
*lplpGDIDDSSurface
)
358 HRESULT WINAPI
Main_DirectDraw_GetMonitorFrequency(LPDIRECTDRAW7 iface
,LPDWORD freq
)
360 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
367 *freq
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
371 HRESULT WINAPI
Main_DirectDraw_GetScanLine(LPDIRECTDRAW7 iface
, LPDWORD lpdwScanLine
)
373 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
375 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_GETSCANLINE
)
377 return Hal_DirectDraw_GetScanLine( iface
, lpdwScanLine
);
380 return Hel_DirectDraw_GetScanLine( iface
, lpdwScanLine
);
383 HRESULT WINAPI
Main_DirectDraw_GetVerticalBlankStatus(LPDIRECTDRAW7 iface
, LPBOOL status
)
388 HRESULT WINAPI
Main_DirectDraw_RestoreDisplayMode(LPDIRECTDRAW7 iface
)
393 HRESULT WINAPI
Main_DirectDraw_WaitForVerticalBlank(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
396 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
398 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_WAITFORVERTICALBLANK
)
400 return Hal_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
);
403 return Hel_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
);
406 HRESULT WINAPI
Main_DirectDraw_GetAvailableVidMem(LPDIRECTDRAW7 iface
, LPDDSCAPS2 ddscaps
,
407 LPDWORD total
, LPDWORD free
)
409 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
411 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDDMiscellaneous
.dwFlags
& DDHAL_MISCCB32_GETAVAILDRIVERMEMORY
)
413 return Hal_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
);
416 return Hel_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
);
419 HRESULT WINAPI
Main_DirectDraw_GetSurfaceFromDC(LPDIRECTDRAW7 iface
, HDC hdc
,
420 LPDIRECTDRAWSURFACE7
*lpDDS
)
425 HRESULT WINAPI
Main_DirectDraw_RestoreAllSurfaces(LPDIRECTDRAW7 iface
)
430 HRESULT WINAPI
Main_DirectDraw_TestCooperativeLevel(LPDIRECTDRAW7 iface
)
435 HRESULT WINAPI
Main_DirectDraw_GetDeviceIdentifier(LPDIRECTDRAW7 iface
,
436 LPDDDEVICEIDENTIFIER2 pDDDI
, DWORD dwFlags
)
441 HRESULT WINAPI
Main_DirectDraw_StartModeTest(LPDIRECTDRAW7 iface
, LPSIZE pModes
,
442 DWORD dwNumModes
, DWORD dwFlags
)
447 HRESULT WINAPI
Main_DirectDraw_EvaluateMode(LPDIRECTDRAW7 iface
,DWORD a
,DWORD
* b
)
452 IDirectDraw7Vtbl DirectDraw7_Vtable
=
454 Main_DirectDraw_QueryInterface
,
455 Main_DirectDraw_AddRef
,
456 Main_DirectDraw_Release
,
457 Main_DirectDraw_Compact
,
458 Main_DirectDraw_CreateClipper
,
459 Main_DirectDraw_CreatePalette
,
460 Main_DirectDraw_CreateSurface
,
461 Main_DirectDraw_DuplicateSurface
,
462 Main_DirectDraw_EnumDisplayModes
,
463 Main_DirectDraw_EnumSurfaces
,
464 Main_DirectDraw_FlipToGDISurface
,
465 Main_DirectDraw_GetCaps
,
466 Main_DirectDraw_GetDisplayMode
,
467 Main_DirectDraw_GetFourCCCodes
,
468 Main_DirectDraw_GetGDISurface
,
469 Main_DirectDraw_GetMonitorFrequency
,
470 Main_DirectDraw_GetScanLine
,
471 Main_DirectDraw_GetVerticalBlankStatus
,
472 Main_DirectDraw_Initialize
,
473 Main_DirectDraw_RestoreDisplayMode
,
474 Main_DirectDraw_SetCooperativeLevel
,
475 Main_DirectDraw_SetDisplayMode
,
476 Main_DirectDraw_WaitForVerticalBlank
,
477 Main_DirectDraw_GetAvailableVidMem
,
478 Main_DirectDraw_GetSurfaceFromDC
,
479 Main_DirectDraw_RestoreAllSurfaces
,
480 Main_DirectDraw_TestCooperativeLevel
,
481 Main_DirectDraw_GetDeviceIdentifier
,
482 Main_DirectDraw_StartModeTest
,
483 Main_DirectDraw_EvaluateMode