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
)
45 HRESULT WINAPI
Main_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface
, HWND hwnd
, DWORD cooplevel
)
48 // - create a scaner that check which driver we should get the HDC from
49 // for now we always asume it is the active dirver that should be use.
52 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
54 // check the parameters
55 if (This
->cooperative_level
== cooplevel
&& This
->window
== hwnd
)
59 return DDERR_HWNDALREADYSET
;
61 if (This
->cooperative_level
)
62 return DDERR_EXCLUSIVEMODEALREADYSET
;
64 if ((cooplevel
&DDSCL_EXCLUSIVE
) && !(cooplevel
&DDSCL_FULLSCREEN
))
65 return DDERR_INVALIDPARAMS
;
67 if (cooplevel
&DDSCL_NORMAL
&& cooplevel
&DDSCL_FULLSCREEN
)
68 return DDERR_INVALIDPARAMS
;
72 This
->hdc
= GetDC(hwnd
);
73 This
->cooperative_level
= cooplevel
;
76 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_SETEXCLUSIVEMODE
)
78 return Hal_DirectDraw_SetCooperativeLevel (iface
);
81 return Hel_DirectDraw_SetCooperativeLevel(iface
);
85 HRESULT WINAPI
Main_DirectDraw_SetDisplayMode (LPDIRECTDRAW7 iface
, DWORD dwWidth
, DWORD dwHeight
,
86 DWORD dwBPP
, DWORD dwRefreshRate
, DWORD dwFlags
)
90 /* FIXME implement hal setMode */
91 if((ret
= Hal_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
,
92 dwBPP
, dwRefreshRate
, dwFlags
)) == DD_OK
)
97 ret
= Hel_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
, dwBPP
, dwRefreshRate
, dwFlags
);
102 ULONG WINAPI
Main_DirectDraw_AddRef (LPDIRECTDRAW7 iface
)
104 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
105 ULONG ref
= InterlockedIncrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
110 ULONG WINAPI
Main_DirectDraw_Release (LPDIRECTDRAW7 iface
)
112 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
113 ULONG ref
= InterlockedDecrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
117 // set resoltion back to the one in registry
118 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
119 ChangeDisplaySettings(NULL
, 0);
121 HeapFree(GetProcessHeap(), 0, This
);
127 HRESULT WINAPI
Main_DirectDraw_QueryInterface (
128 LPDIRECTDRAW7 iface
, REFIID id
, LPVOID
*obj
)
130 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
132 if (IsEqualGUID(&IID_IDirectDraw7
, id
))
134 *obj
= &This
->lpVtbl
;
136 else if (IsEqualGUID(&IID_IDirectDraw
, id
))
138 *obj
= &This
->lpVtbl_v1
;
140 else if (IsEqualGUID(&IID_IDirectDraw2
, id
))
142 *obj
= &This
->lpVtbl_v2
;
144 else if (IsEqualGUID(&IID_IDirectDraw4
, id
))
146 *obj
= &This
->lpVtbl_v4
;
151 return E_NOINTERFACE
;
154 Main_DirectDraw_AddRef(iface
);
158 HRESULT WINAPI
Main_DirectDraw_CreateSurface (LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
,
159 LPDIRECTDRAWSURFACE7
*ppSurf
, IUnknown
*pUnkOuter
)
162 return DDERR_INVALIDPARAMS
;
164 if(sizeof(DDSURFACEDESC2
)!=pDDSD
->dwSize
)
165 return DDERR_UNSUPPORTED
;
167 // the nasty com stuff
168 IDirectDrawSurfaceImpl
* That
;
170 That
= (IDirectDrawSurfaceImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawSurfaceImpl
));
173 return E_OUTOFMEMORY
;
175 ZeroMemory(That
, sizeof(IDirectDrawSurfaceImpl
));
177 That
->lpVtbl
= &DirectDrawSurface7_Vtable
;
178 That
->lpVtbl_v3
= &DDRAW_IDDS3_Thunk_VTable
;
180 That
->owner
->DirectDrawGlobal
.dsList
->dwIntRefCnt
=1;
182 /* we alwasy set to use the DirectDrawSurface7_Vtable as internel */
183 That
->owner
->DirectDrawGlobal
.dsList
->lpVtbl
= (PVOID
) &DirectDrawSurface7_Vtable
;
185 *ppSurf
= (LPDIRECTDRAWSURFACE7
)That
;
187 // the real surface object creation
188 return That
->lpVtbl
->Initialize (*ppSurf
, (LPDIRECTDRAW
)iface
, pDDSD
);
191 HRESULT WINAPI
Main_DirectDraw_CreateClipper(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
192 LPDIRECTDRAWCLIPPER
*ppClipper
, IUnknown
*pUnkOuter
)
195 return DDERR_INVALIDPARAMS
;
197 IDirectDrawClipperImpl
* That
;
198 That
= (IDirectDrawClipperImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawClipperImpl
));
201 return E_OUTOFMEMORY
;
203 ZeroMemory(That
, sizeof(IDirectDrawClipperImpl
));
205 That
->lpVtbl
= &DirectDrawClipper_Vtable
;
207 *ppClipper
= (LPDIRECTDRAWCLIPPER
)That
;
209 return That
->lpVtbl
->Initialize (*ppClipper
, (LPDIRECTDRAW
)iface
, dwFlags
);
212 // This function is exported by the dll
213 HRESULT WINAPI
DirectDrawCreateClipper (DWORD dwFlags
,
214 LPDIRECTDRAWCLIPPER
* lplpDDClipper
, LPUNKNOWN pUnkOuter
)
216 return Main_DirectDraw_CreateClipper(NULL
, dwFlags
, lplpDDClipper
, pUnkOuter
);
219 HRESULT WINAPI
Main_DirectDraw_CreatePalette(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
220 LPPALETTEENTRY palent
, LPDIRECTDRAWPALETTE
* ppPalette
, LPUNKNOWN pUnkOuter
)
223 return DDERR_INVALIDPARAMS
;
225 IDirectDrawPaletteImpl
* That
;
226 That
= (IDirectDrawPaletteImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
229 return E_OUTOFMEMORY
;
231 ZeroMemory(That
, sizeof(IDirectDrawPaletteImpl
));
233 That
->lpVtbl
= &DirectDrawPalette_Vtable
;
235 *ppPalette
= (LPDIRECTDRAWPALETTE
)That
;
237 return That
->lpVtbl
->Initialize (*ppPalette
, (LPDIRECTDRAW
)iface
, dwFlags
, palent
);
242 HRESULT WINAPI
Main_DirectDraw_Compact(LPDIRECTDRAW7 iface
)
247 HRESULT WINAPI
Main_DirectDraw_DuplicateSurface(LPDIRECTDRAW7 iface
, LPDIRECTDRAWSURFACE7 src
,
248 LPDIRECTDRAWSURFACE7
* dst
)
253 HRESULT WINAPI
Main_DirectDraw_EnumDisplayModes(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
254 LPDDSURFACEDESC2 pDDSD
, LPVOID context
, LPDDENUMMODESCALLBACK2 callback
)
259 HRESULT WINAPI
Main_DirectDraw_EnumSurfaces(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
260 LPDDSURFACEDESC2 lpDDSD2
, LPVOID context
,
261 LPDDENUMSURFACESCALLBACK7 callback
)
266 HRESULT WINAPI
Main_DirectDraw_FlipToGDISurface(LPDIRECTDRAW7 iface
)
268 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
270 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_FLIPTOGDISURFACE
)
272 return Hal_DirectDraw_FlipToGDISurface( iface
);
275 return Hel_DirectDraw_FlipToGDISurface( iface
);
278 HRESULT WINAPI
Main_DirectDraw_GetCaps(LPDIRECTDRAW7 iface
, LPDDCAPS pDriverCaps
,
281 DWORD status
= DD_FALSE
;
282 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
284 if (pDriverCaps
!= NULL
)
286 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
290 if (pHELCaps
!= NULL
)
292 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddHELCaps
,sizeof(DDCORECAPS
));
296 /* Both caps mixed ?? */
297 /* DDCORECAPS ddBothCaps; */
302 HRESULT WINAPI
Main_DirectDraw_GetDisplayMode(LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
)
304 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
311 pDDSD
->dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_PITCH
| DDSD_PIXELFORMAT
| DDSD_REFRESHRATE
| DDSD_WIDTH
;
312 pDDSD
->dwHeight
= This
->DirectDrawGlobal
.vmiData
.dwDisplayHeight
;
313 pDDSD
->dwWidth
= This
->DirectDrawGlobal
.vmiData
.dwDisplayWidth
;
315 /* FIXME Do not use DUMMYUNIONNAME1 some how union lPitch does not see by the compiler
316 but rest of the union are visable. more header problem ???
318 pDDSD
->DUMMYUNIONNAME1
.lPitch
= This
->DirectDrawGlobal
.vmiData
.lDisplayPitch
;
321 /* have not check where I should get hold of this info yet
322 DWORD dwBackBufferCount;
325 pDDSD
->dwRefreshRate
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
327 /* have not check where I should get hold of this info yet
328 DWORD dwAlphaBitDepth;
333 DDCOLORKEY ddckCKDestOverlay;
334 DWORD dwEmptyFaceColor;
336 DDCOLORKEY ddckCKDestBlt;
337 DDCOLORKEY ddckCKSrcOverlay;
338 DDCOLORKEY ddckCKSrcBlt;
342 RtlCopyMemory(&pDDSD
->ddpfPixelFormat
,&This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
,sizeof(DDPIXELFORMAT
));
343 RtlCopyMemory(&pDDSD
->ddsCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
345 /* have not check where I should get hold of this info yet
346 DWORD dwTextureStage;
353 HRESULT WINAPI
Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface
, LPDWORD pNumCodes
, LPDWORD pCodes
)
358 HRESULT WINAPI
Main_DirectDraw_GetGDISurface(LPDIRECTDRAW7 iface
,
359 LPDIRECTDRAWSURFACE7
*lplpGDIDDSSurface
)
364 HRESULT WINAPI
Main_DirectDraw_GetMonitorFrequency(LPDIRECTDRAW7 iface
,LPDWORD freq
)
366 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
373 *freq
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
377 HRESULT WINAPI
Main_DirectDraw_GetScanLine(LPDIRECTDRAW7 iface
, LPDWORD lpdwScanLine
)
379 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
381 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_GETSCANLINE
)
383 return Hal_DirectDraw_GetScanLine( iface
, lpdwScanLine
);
386 return Hel_DirectDraw_GetScanLine( iface
, lpdwScanLine
);
389 HRESULT WINAPI
Main_DirectDraw_GetVerticalBlankStatus(LPDIRECTDRAW7 iface
, LPBOOL status
)
394 HRESULT WINAPI
Main_DirectDraw_RestoreDisplayMode(LPDIRECTDRAW7 iface
)
399 HRESULT WINAPI
Main_DirectDraw_WaitForVerticalBlank(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
402 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
404 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_WAITFORVERTICALBLANK
)
406 return Hal_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
);
409 return Hel_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
);
412 HRESULT WINAPI
Main_DirectDraw_GetAvailableVidMem(LPDIRECTDRAW7 iface
, LPDDSCAPS2 ddscaps
,
413 LPDWORD total
, LPDWORD free
)
415 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
417 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDDMiscellaneous
.dwFlags
& DDHAL_MISCCB32_GETAVAILDRIVERMEMORY
)
419 return Hal_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
);
422 return Hel_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
);
425 HRESULT WINAPI
Main_DirectDraw_GetSurfaceFromDC(LPDIRECTDRAW7 iface
, HDC hdc
,
426 LPDIRECTDRAWSURFACE7
*lpDDS
)
431 HRESULT WINAPI
Main_DirectDraw_RestoreAllSurfaces(LPDIRECTDRAW7 iface
)
436 HRESULT WINAPI
Main_DirectDraw_TestCooperativeLevel(LPDIRECTDRAW7 iface
)
441 HRESULT WINAPI
Main_DirectDraw_GetDeviceIdentifier(LPDIRECTDRAW7 iface
,
442 LPDDDEVICEIDENTIFIER2 pDDDI
, DWORD dwFlags
)
447 HRESULT WINAPI
Main_DirectDraw_StartModeTest(LPDIRECTDRAW7 iface
, LPSIZE pModes
,
448 DWORD dwNumModes
, DWORD dwFlags
)
453 HRESULT WINAPI
Main_DirectDraw_EvaluateMode(LPDIRECTDRAW7 iface
,DWORD a
,DWORD
* b
)
458 IDirectDraw7Vtbl DirectDraw7_Vtable
=
460 Main_DirectDraw_QueryInterface
,
461 Main_DirectDraw_AddRef
,
462 Main_DirectDraw_Release
,
463 Main_DirectDraw_Compact
,
464 Main_DirectDraw_CreateClipper
,
465 Main_DirectDraw_CreatePalette
,
466 Main_DirectDraw_CreateSurface
,
467 Main_DirectDraw_DuplicateSurface
,
468 Main_DirectDraw_EnumDisplayModes
,
469 Main_DirectDraw_EnumSurfaces
,
470 Main_DirectDraw_FlipToGDISurface
,
471 Main_DirectDraw_GetCaps
,
472 Main_DirectDraw_GetDisplayMode
,
473 Main_DirectDraw_GetFourCCCodes
,
474 Main_DirectDraw_GetGDISurface
,
475 Main_DirectDraw_GetMonitorFrequency
,
476 Main_DirectDraw_GetScanLine
,
477 Main_DirectDraw_GetVerticalBlankStatus
,
478 Main_DirectDraw_Initialize
,
479 Main_DirectDraw_RestoreDisplayMode
,
480 Main_DirectDraw_SetCooperativeLevel
,
481 Main_DirectDraw_SetDisplayMode
,
482 Main_DirectDraw_WaitForVerticalBlank
,
483 Main_DirectDraw_GetAvailableVidMem
,
484 Main_DirectDraw_GetSurfaceFromDC
,
485 Main_DirectDraw_RestoreAllSurfaces
,
486 Main_DirectDraw_TestCooperativeLevel
,
487 Main_DirectDraw_GetDeviceIdentifier
,
488 Main_DirectDraw_StartModeTest
,
489 Main_DirectDraw_EvaluateMode