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
;
21 // this if it is not called by DirectDrawCreate
23 return DDERR_ALREADYINITIALIZED
;
26 This
->lpGUID
= lpGUID
;
29 This
->hdc
= GetWindowDC(GetDesktopWindow());
30 This
->Height
= GetDeviceCaps(This
->hdc
, VERTRES
);
31 This
->Width
= GetDeviceCaps(This
->hdc
, HORZRES
);
32 This
->Bpp
= GetDeviceCaps(This
->hdc
, BITSPIXEL
);
34 // call software first
35 if((ret
= Hal_DirectDraw_Initialize (iface
)) != DD_OK
)
38 // ... then overwrite with hal
39 if((ret
= Hel_DirectDraw_Initialize (iface
)) != DD_OK
)
46 HRESULT WINAPI
Main_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface
, HWND hwnd
, DWORD cooplevel
)
49 // - create a scaner that check which driver we should get the HDC from
50 // for now we always asume it is the active dirver that should be use.
53 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
55 // check the parameters
56 if (This
->cooperative_level
== cooplevel
&& This
->window
== hwnd
)
60 return DDERR_HWNDALREADYSET
;
62 if (This
->cooperative_level
)
63 return DDERR_EXCLUSIVEMODEALREADYSET
;
65 if ((cooplevel
&DDSCL_EXCLUSIVE
) && !(cooplevel
&DDSCL_FULLSCREEN
))
66 return DDERR_INVALIDPARAMS
;
68 if (cooplevel
&DDSCL_NORMAL
&& cooplevel
&DDSCL_FULLSCREEN
)
69 return DDERR_INVALIDPARAMS
;
73 This
->hdc
= GetDC(hwnd
);
74 This
->cooperative_level
= cooplevel
;
77 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_SETEXCLUSIVEMODE
)
79 return Hal_DirectDraw_SetCooperativeLevel (iface
);
82 return Hel_DirectDraw_SetCooperativeLevel(iface
);
86 HRESULT WINAPI
Main_DirectDraw_SetDisplayMode (LPDIRECTDRAW7 iface
, DWORD dwWidth
, DWORD dwHeight
,
87 DWORD dwBPP
, DWORD dwRefreshRate
, DWORD dwFlags
)
91 /* FIXME implement hal setMode */
92 if((ret
= Hal_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
,
93 dwBPP
, dwRefreshRate
, dwFlags
)) == DD_OK
)
98 ret
= Hel_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
, dwBPP
, dwRefreshRate
, dwFlags
);
103 ULONG WINAPI
Main_DirectDraw_AddRef (LPDIRECTDRAW7 iface
)
105 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
106 ULONG ref
= InterlockedIncrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
111 ULONG WINAPI
Main_DirectDraw_Release (LPDIRECTDRAW7 iface
)
113 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
114 ULONG ref
= InterlockedDecrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
118 // set resoltion back to the one in registry
119 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
120 ChangeDisplaySettings(NULL
, 0);
122 HeapFree(GetProcessHeap(), 0, This
);
128 HRESULT WINAPI
Main_DirectDraw_QueryInterface (
129 LPDIRECTDRAW7 iface
, REFIID id
, LPVOID
*obj
)
131 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
133 if (IsEqualGUID(&IID_IDirectDraw7
, id
))
135 *obj
= &This
->lpVtbl
;
137 else if (IsEqualGUID(&IID_IDirectDraw
, id
))
139 *obj
= &This
->lpVtbl_v1
;
141 else if (IsEqualGUID(&IID_IDirectDraw2
, id
))
143 *obj
= &This
->lpVtbl_v2
;
145 else if (IsEqualGUID(&IID_IDirectDraw4
, id
))
147 *obj
= &This
->lpVtbl_v4
;
152 return E_NOINTERFACE
;
155 Main_DirectDraw_AddRef(iface
);
159 HRESULT WINAPI
Main_DirectDraw_CreateSurface (LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
,
160 LPDIRECTDRAWSURFACE7
*ppSurf
, IUnknown
*pUnkOuter
)
163 return DDERR_INVALIDPARAMS
;
165 if(sizeof(DDSURFACEDESC2
)!=pDDSD
->dwSize
)
166 return DDERR_UNSUPPORTED
;
168 // the nasty com stuff
169 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
171 IDirectDrawSurfaceImpl
* That
;
173 That
= (IDirectDrawSurfaceImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawSurfaceImpl
));
176 return E_OUTOFMEMORY
;
178 ZeroMemory(That
, sizeof(IDirectDrawSurfaceImpl
));
180 That
->lpVtbl
= &DirectDrawSurface7_Vtable
;
181 That
->lpVtbl_v3
= &DDRAW_IDDS3_Thunk_VTable
;
183 This
->DirectDrawGlobal
.dsList
= (LPDDRAWI_DDRAWSURFACE_INT
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
184 sizeof(DDRAWI_DDRAWSURFACE_INT
));
186 That
->owner
= (IDirectDrawImpl
*)This
;
188 That
->owner
->DirectDrawGlobal
.dsList
->dwIntRefCnt
=1;
190 /* we alwasy set to use the DirectDrawSurface7_Vtable as internel */
191 That
->owner
->DirectDrawGlobal
.dsList
->lpVtbl
= (PVOID
) &DirectDrawSurface7_Vtable
;
194 *ppSurf
= (LPDIRECTDRAWSURFACE7
)That
;
196 // the real surface object creation
197 return That
->lpVtbl
->Initialize (*ppSurf
, (LPDIRECTDRAW
)iface
, pDDSD
);
200 HRESULT WINAPI
Main_DirectDraw_CreateClipper(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
201 LPDIRECTDRAWCLIPPER
*ppClipper
, IUnknown
*pUnkOuter
)
204 return DDERR_INVALIDPARAMS
;
206 IDirectDrawClipperImpl
* That
;
207 That
= (IDirectDrawClipperImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawClipperImpl
));
210 return E_OUTOFMEMORY
;
212 ZeroMemory(That
, sizeof(IDirectDrawClipperImpl
));
214 That
->lpVtbl
= &DirectDrawClipper_Vtable
;
216 *ppClipper
= (LPDIRECTDRAWCLIPPER
)That
;
218 return That
->lpVtbl
->Initialize (*ppClipper
, (LPDIRECTDRAW
)iface
, dwFlags
);
221 // This function is exported by the dll
222 HRESULT WINAPI
DirectDrawCreateClipper (DWORD dwFlags
,
223 LPDIRECTDRAWCLIPPER
* lplpDDClipper
, LPUNKNOWN pUnkOuter
)
225 return Main_DirectDraw_CreateClipper(NULL
, dwFlags
, lplpDDClipper
, pUnkOuter
);
228 HRESULT WINAPI
Main_DirectDraw_CreatePalette(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
229 LPPALETTEENTRY palent
, LPDIRECTDRAWPALETTE
* ppPalette
, LPUNKNOWN pUnkOuter
)
232 return DDERR_INVALIDPARAMS
;
234 IDirectDrawPaletteImpl
* That
;
235 That
= (IDirectDrawPaletteImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
238 return E_OUTOFMEMORY
;
240 ZeroMemory(That
, sizeof(IDirectDrawPaletteImpl
));
242 That
->lpVtbl
= &DirectDrawPalette_Vtable
;
244 *ppPalette
= (LPDIRECTDRAWPALETTE
)That
;
246 return That
->lpVtbl
->Initialize (*ppPalette
, (LPDIRECTDRAW
)iface
, dwFlags
, palent
);
251 HRESULT WINAPI
Main_DirectDraw_Compact(LPDIRECTDRAW7 iface
)
256 HRESULT WINAPI
Main_DirectDraw_DuplicateSurface(LPDIRECTDRAW7 iface
, LPDIRECTDRAWSURFACE7 src
,
257 LPDIRECTDRAWSURFACE7
* dst
)
262 HRESULT WINAPI
Main_DirectDraw_EnumDisplayModes(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
263 LPDDSURFACEDESC2 pDDSD
, LPVOID context
, LPDDENUMMODESCALLBACK2 callback
)
268 HRESULT WINAPI
Main_DirectDraw_EnumSurfaces(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
269 LPDDSURFACEDESC2 lpDDSD2
, LPVOID context
,
270 LPDDENUMSURFACESCALLBACK7 callback
)
275 HRESULT WINAPI
Main_DirectDraw_FlipToGDISurface(LPDIRECTDRAW7 iface
)
277 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
279 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_FLIPTOGDISURFACE
)
281 return Hal_DirectDraw_FlipToGDISurface( iface
);
284 return Hel_DirectDraw_FlipToGDISurface( iface
);
287 HRESULT WINAPI
Main_DirectDraw_GetCaps(LPDIRECTDRAW7 iface
, LPDDCAPS pDriverCaps
,
290 DWORD status
= DD_FALSE
;
291 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
293 if (pDriverCaps
!= NULL
)
295 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
299 if (pHELCaps
!= NULL
)
301 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddHELCaps
,sizeof(DDCORECAPS
));
305 /* Both caps mixed ?? */
306 /* DDCORECAPS ddBothCaps; */
311 HRESULT WINAPI
Main_DirectDraw_GetDisplayMode(LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
)
313 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
320 pDDSD
->dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_PITCH
| DDSD_PIXELFORMAT
| DDSD_REFRESHRATE
| DDSD_WIDTH
;
321 pDDSD
->dwHeight
= This
->DirectDrawGlobal
.vmiData
.dwDisplayHeight
;
322 pDDSD
->dwWidth
= This
->DirectDrawGlobal
.vmiData
.dwDisplayWidth
;
324 /* FIXME Do not use DUMMYUNIONNAME1 some how union lPitch does not see by the compiler
325 but rest of the union are visable. more header problem ???
327 pDDSD
->DUMMYUNIONNAME1
.lPitch
= This
->DirectDrawGlobal
.vmiData
.lDisplayPitch
;
330 /* have not check where I should get hold of this info yet
331 DWORD dwBackBufferCount;
334 pDDSD
->dwRefreshRate
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
336 /* have not check where I should get hold of this info yet
337 DWORD dwAlphaBitDepth;
342 DDCOLORKEY ddckCKDestOverlay;
343 DWORD dwEmptyFaceColor;
345 DDCOLORKEY ddckCKDestBlt;
346 DDCOLORKEY ddckCKSrcOverlay;
347 DDCOLORKEY ddckCKSrcBlt;
351 RtlCopyMemory(&pDDSD
->ddpfPixelFormat
,&This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
,sizeof(DDPIXELFORMAT
));
352 RtlCopyMemory(&pDDSD
->ddsCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
354 /* have not check where I should get hold of this info yet
355 DWORD dwTextureStage;
362 HRESULT WINAPI
Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface
, LPDWORD pNumCodes
, LPDWORD pCodes
)
367 HRESULT WINAPI
Main_DirectDraw_GetGDISurface(LPDIRECTDRAW7 iface
,
368 LPDIRECTDRAWSURFACE7
*lplpGDIDDSSurface
)
373 HRESULT WINAPI
Main_DirectDraw_GetMonitorFrequency(LPDIRECTDRAW7 iface
,LPDWORD freq
)
375 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
382 *freq
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
386 HRESULT WINAPI
Main_DirectDraw_GetScanLine(LPDIRECTDRAW7 iface
, LPDWORD lpdwScanLine
)
388 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
390 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_GETSCANLINE
)
392 return Hal_DirectDraw_GetScanLine( iface
, lpdwScanLine
);
395 return Hel_DirectDraw_GetScanLine( iface
, lpdwScanLine
);
398 HRESULT WINAPI
Main_DirectDraw_GetVerticalBlankStatus(LPDIRECTDRAW7 iface
, LPBOOL status
)
403 HRESULT WINAPI
Main_DirectDraw_RestoreDisplayMode(LPDIRECTDRAW7 iface
)
408 HRESULT WINAPI
Main_DirectDraw_WaitForVerticalBlank(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
411 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
413 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_WAITFORVERTICALBLANK
)
415 return Hal_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
);
418 return Hel_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
);
421 HRESULT WINAPI
Main_DirectDraw_GetAvailableVidMem(LPDIRECTDRAW7 iface
, LPDDSCAPS2 ddscaps
,
422 LPDWORD total
, LPDWORD free
)
424 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
426 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDDMiscellaneous
.dwFlags
& DDHAL_MISCCB32_GETAVAILDRIVERMEMORY
)
428 return Hal_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
);
431 return Hel_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
);
434 HRESULT WINAPI
Main_DirectDraw_GetSurfaceFromDC(LPDIRECTDRAW7 iface
, HDC hdc
,
435 LPDIRECTDRAWSURFACE7
*lpDDS
)
440 HRESULT WINAPI
Main_DirectDraw_RestoreAllSurfaces(LPDIRECTDRAW7 iface
)
445 HRESULT WINAPI
Main_DirectDraw_TestCooperativeLevel(LPDIRECTDRAW7 iface
)
450 HRESULT WINAPI
Main_DirectDraw_GetDeviceIdentifier(LPDIRECTDRAW7 iface
,
451 LPDDDEVICEIDENTIFIER2 pDDDI
, DWORD dwFlags
)
456 HRESULT WINAPI
Main_DirectDraw_StartModeTest(LPDIRECTDRAW7 iface
, LPSIZE pModes
,
457 DWORD dwNumModes
, DWORD dwFlags
)
462 HRESULT WINAPI
Main_DirectDraw_EvaluateMode(LPDIRECTDRAW7 iface
,DWORD a
,DWORD
* b
)
467 IDirectDraw7Vtbl DirectDraw7_Vtable
=
469 Main_DirectDraw_QueryInterface
,
470 Main_DirectDraw_AddRef
,
471 Main_DirectDraw_Release
,
472 Main_DirectDraw_Compact
,
473 Main_DirectDraw_CreateClipper
,
474 Main_DirectDraw_CreatePalette
,
475 Main_DirectDraw_CreateSurface
,
476 Main_DirectDraw_DuplicateSurface
,
477 Main_DirectDraw_EnumDisplayModes
,
478 Main_DirectDraw_EnumSurfaces
,
479 Main_DirectDraw_FlipToGDISurface
,
480 Main_DirectDraw_GetCaps
,
481 Main_DirectDraw_GetDisplayMode
,
482 Main_DirectDraw_GetFourCCCodes
,
483 Main_DirectDraw_GetGDISurface
,
484 Main_DirectDraw_GetMonitorFrequency
,
485 Main_DirectDraw_GetScanLine
,
486 Main_DirectDraw_GetVerticalBlankStatus
,
487 Main_DirectDraw_Initialize
,
488 Main_DirectDraw_RestoreDisplayMode
,
489 Main_DirectDraw_SetCooperativeLevel
,
490 Main_DirectDraw_SetDisplayMode
,
491 Main_DirectDraw_WaitForVerticalBlank
,
492 Main_DirectDraw_GetAvailableVidMem
,
493 Main_DirectDraw_GetSurfaceFromDC
,
494 Main_DirectDraw_RestoreAllSurfaces
,
495 Main_DirectDraw_TestCooperativeLevel
,
496 Main_DirectDraw_GetDeviceIdentifier
,
497 Main_DirectDraw_StartModeTest
,
498 Main_DirectDraw_EvaluateMode