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 if (This
->InitializeDraw
== TRUE
)
20 return DDERR_ALREADYINITIALIZED
;
22 This
->InitializeDraw
= TRUE
;
28 This
->hdc
= GetWindowDC(GetDesktopWindow());
29 This
->Height
= GetDeviceCaps(This
->hdc
, VERTRES
);
30 This
->Width
= GetDeviceCaps(This
->hdc
, HORZRES
);
31 This
->Bpp
= GetDeviceCaps(This
->hdc
, BITSPIXEL
);
33 // call software first
34 if((ret
= Hal_DirectDraw_Initialize (iface
)) != DD_OK
)
37 // ... then overwrite with hal
38 if((ret
= Hel_DirectDraw_Initialize (iface
)) != DD_OK
)
44 HRESULT WINAPI
Main_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface
, HWND hwnd
, DWORD cooplevel
)
47 // - create a scaner that check which driver we should get the HDC from
48 // for now we always asume it is the active dirver that should be use.
51 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
;
74 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_SETEXCLUSIVEMODE
)
76 return Hal_DirectDraw_SetCooperativeLevel (iface
);
79 return Hel_DirectDraw_SetCooperativeLevel(iface
);
83 HRESULT WINAPI
Main_DirectDraw_SetDisplayMode (LPDIRECTDRAW7 iface
, DWORD dwWidth
, DWORD dwHeight
,
84 DWORD dwBPP
, DWORD dwRefreshRate
, DWORD dwFlags
)
86 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
90 /* FIXME check the refresrate if it same if it not same do the mode switch */
91 if ((This
->DirectDrawGlobal
.vmiData
.dwDisplayHeight
== dwHeight
) &&
92 (This
->DirectDrawGlobal
.vmiData
.dwDisplayWidth
== dwWidth
) &&
93 (This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
.dwRGBBitCount
== dwBPP
))
99 /* Check use the Hal or Hel for SetMode */
100 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_SETMODE
)
102 ret
= Hal_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
, dwBPP
, dwRefreshRate
, dwFlags
);
106 ret
= Hel_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
, dwBPP
, dwRefreshRate
, dwFlags
);
111 DdReenableDirectDrawObject(&This
->DirectDrawGlobal
, &dummy
);
112 /* FIXME fill the This->DirectDrawGlobal.vmiData right */
118 ULONG WINAPI
Main_DirectDraw_AddRef (LPDIRECTDRAW7 iface
)
120 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
121 ULONG ref
= InterlockedIncrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
126 ULONG WINAPI
Main_DirectDraw_Release (LPDIRECTDRAW7 iface
)
128 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
129 ULONG ref
= InterlockedDecrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
133 // set resoltion back to the one in registry
134 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
135 ChangeDisplaySettings(NULL
, 0);
137 HeapFree(GetProcessHeap(), 0, This
);
143 HRESULT WINAPI
Main_DirectDraw_QueryInterface (
144 LPDIRECTDRAW7 iface
, REFIID id
, LPVOID
*obj
)
146 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
148 if (IsEqualGUID(&IID_IDirectDraw7
, id
))
150 *obj
= &This
->lpVtbl
;
152 else if (IsEqualGUID(&IID_IDirectDraw
, id
))
154 *obj
= &This
->lpVtbl_v1
;
156 else if (IsEqualGUID(&IID_IDirectDraw2
, id
))
158 *obj
= &This
->lpVtbl_v2
;
160 else if (IsEqualGUID(&IID_IDirectDraw4
, id
))
162 *obj
= &This
->lpVtbl_v4
;
167 return E_NOINTERFACE
;
170 Main_DirectDraw_AddRef(iface
);
174 HRESULT WINAPI
Main_DirectDraw_CreateSurface (LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
,
175 LPDIRECTDRAWSURFACE7
*ppSurf
, IUnknown
*pUnkOuter
)
178 return DDERR_INVALIDPARAMS
;
180 if(sizeof(DDSURFACEDESC2
)!=pDDSD
->dwSize
&& sizeof(DDSURFACEDESC
)!=pDDSD
->dwSize
)
181 return DDERR_UNSUPPORTED
;
183 // the nasty com stuff
184 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
186 IDirectDrawSurfaceImpl
* That
;
188 That
= (IDirectDrawSurfaceImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawSurfaceImpl
));
191 return E_OUTOFMEMORY
;
193 ZeroMemory(That
, sizeof(IDirectDrawSurfaceImpl
));
195 That
->lpVtbl
= &DirectDrawSurface7_Vtable
;
196 That
->lpVtbl_v3
= &DDRAW_IDDS3_Thunk_VTable
;
198 This
->DirectDrawGlobal
.dsList
= (LPDDRAWI_DDRAWSURFACE_INT
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
199 sizeof(DDRAWI_DDRAWSURFACE_INT
));
200 That
->owner
= (IDirectDrawImpl
*)This
;
201 That
->owner
->DirectDrawGlobal
.dsList
->dwIntRefCnt
=1;
203 /* we alwasy set to use the DirectDrawSurface7_Vtable as internel */
204 That
->owner
->DirectDrawGlobal
.dsList
->lpVtbl
= (PVOID
) &DirectDrawSurface7_Vtable
;
206 *ppSurf
= (LPDIRECTDRAWSURFACE7
)That
;
208 // the real surface object creation
209 return That
->lpVtbl
->Initialize (*ppSurf
, (LPDIRECTDRAW
)iface
, pDDSD
);
212 HRESULT WINAPI
Main_DirectDraw_CreateClipper(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
213 LPDIRECTDRAWCLIPPER
*ppClipper
, IUnknown
*pUnkOuter
)
216 return DDERR_INVALIDPARAMS
;
218 IDirectDrawClipperImpl
* That
;
219 That
= (IDirectDrawClipperImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawClipperImpl
));
222 return E_OUTOFMEMORY
;
224 ZeroMemory(That
, sizeof(IDirectDrawClipperImpl
));
226 That
->lpVtbl
= &DirectDrawClipper_Vtable
;
228 *ppClipper
= (LPDIRECTDRAWCLIPPER
)That
;
230 return That
->lpVtbl
->Initialize (*ppClipper
, (LPDIRECTDRAW
)iface
, dwFlags
);
233 // This function is exported by the dll
234 HRESULT WINAPI
DirectDrawCreateClipper (DWORD dwFlags
,
235 LPDIRECTDRAWCLIPPER
* lplpDDClipper
, LPUNKNOWN pUnkOuter
)
237 return Main_DirectDraw_CreateClipper(NULL
, dwFlags
, lplpDDClipper
, pUnkOuter
);
240 HRESULT WINAPI
Main_DirectDraw_CreatePalette(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
241 LPPALETTEENTRY palent
, LPDIRECTDRAWPALETTE
* ppPalette
, LPUNKNOWN pUnkOuter
)
244 return DDERR_INVALIDPARAMS
;
246 IDirectDrawPaletteImpl
* That
;
247 That
= (IDirectDrawPaletteImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
250 return E_OUTOFMEMORY
;
252 ZeroMemory(That
, sizeof(IDirectDrawPaletteImpl
));
254 That
->lpVtbl
= &DirectDrawPalette_Vtable
;
256 *ppPalette
= (LPDIRECTDRAWPALETTE
)That
;
258 return That
->lpVtbl
->Initialize (*ppPalette
, (LPDIRECTDRAW
)iface
, dwFlags
, palent
);
261 HRESULT WINAPI
Main_DirectDraw_FlipToGDISurface(LPDIRECTDRAW7 iface
)
263 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
265 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_FLIPTOGDISURFACE
)
267 return Hal_DirectDraw_FlipToGDISurface( iface
);
270 return Hel_DirectDraw_FlipToGDISurface( iface
);
273 HRESULT WINAPI
Main_DirectDraw_GetCaps(LPDIRECTDRAW7 iface
, LPDDCAPS pDriverCaps
,
276 DWORD status
= DD_FALSE
;
277 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
279 if (pDriverCaps
!= NULL
)
281 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
285 if (pHELCaps
!= NULL
)
287 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddHELCaps
,sizeof(DDCORECAPS
));
291 /* Both caps mixed ?? */
292 /* DDCORECAPS ddBothCaps; */
297 HRESULT WINAPI
Main_DirectDraw_GetDisplayMode(LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
)
299 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
306 pDDSD
->dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_PITCH
| DDSD_PIXELFORMAT
| DDSD_REFRESHRATE
| DDSD_WIDTH
;
307 pDDSD
->dwHeight
= This
->DirectDrawGlobal
.vmiData
.dwDisplayHeight
;
308 pDDSD
->dwWidth
= This
->DirectDrawGlobal
.vmiData
.dwDisplayWidth
;
309 pDDSD
->lPitch
= This
->DirectDrawGlobal
.vmiData
.lDisplayPitch
;
310 pDDSD
->dwRefreshRate
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
312 RtlCopyMemory(&pDDSD
->ddpfPixelFormat
,&This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
,sizeof(DDPIXELFORMAT
));
313 RtlCopyMemory(&pDDSD
->ddsCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
315 /* have not check where I should get hold of this info yet
316 DWORD dwBackBufferCount;
317 DWORD dwAlphaBitDepth;
322 DDCOLORKEY ddckCKDestOverlay;
323 DWORD dwEmptyFaceColor;
325 DDCOLORKEY ddckCKDestBlt;
326 DDCOLORKEY ddckCKSrcOverlay;
327 DDCOLORKEY ddckCKSrcBlt;
328 DWORD dwTextureStage;
334 HRESULT WINAPI
Main_DirectDraw_WaitForVerticalBlank(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
337 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
339 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_WAITFORVERTICALBLANK
)
341 return Hal_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
);
344 return Hel_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
);
347 HRESULT WINAPI
Main_DirectDraw_GetAvailableVidMem(LPDIRECTDRAW7 iface
, LPDDSCAPS2 ddscaps
,
348 LPDWORD total
, LPDWORD free
)
350 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
352 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDDMiscellaneous
.dwFlags
& DDHAL_MISCCB32_GETAVAILDRIVERMEMORY
)
354 return Hal_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
);
357 return Hel_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
);
360 HRESULT WINAPI
Main_DirectDraw_GetMonitorFrequency(LPDIRECTDRAW7 iface
,LPDWORD freq
)
362 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
369 *freq
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
373 HRESULT WINAPI
Main_DirectDraw_GetScanLine(LPDIRECTDRAW7 iface
, LPDWORD lpdwScanLine
)
375 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
377 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_GETSCANLINE
)
379 return Hal_DirectDraw_GetScanLine( iface
, lpdwScanLine
);
382 return Hel_DirectDraw_GetScanLine( iface
, lpdwScanLine
);
385 /********************************** Stubs **********************************/
387 HRESULT WINAPI
Main_DirectDraw_Compact(LPDIRECTDRAW7 iface
)
392 HRESULT WINAPI
Main_DirectDraw_DuplicateSurface(LPDIRECTDRAW7 iface
, LPDIRECTDRAWSURFACE7 src
,
393 LPDIRECTDRAWSURFACE7
* dst
)
398 HRESULT WINAPI
Main_DirectDraw_EnumDisplayModes(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
399 LPDDSURFACEDESC2 pDDSD
, LPVOID context
, LPDDENUMMODESCALLBACK2 callback
)
404 HRESULT WINAPI
Main_DirectDraw_EnumSurfaces(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
405 LPDDSURFACEDESC2 lpDDSD2
, LPVOID context
,
406 LPDDENUMSURFACESCALLBACK7 callback
)
412 HRESULT WINAPI
Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface
, LPDWORD pNumCodes
, LPDWORD pCodes
)
417 HRESULT WINAPI
Main_DirectDraw_GetGDISurface(LPDIRECTDRAW7 iface
,
418 LPDIRECTDRAWSURFACE7
*lplpGDIDDSSurface
)
423 HRESULT WINAPI
Main_DirectDraw_GetVerticalBlankStatus(LPDIRECTDRAW7 iface
, LPBOOL status
)
428 HRESULT WINAPI
Main_DirectDraw_RestoreDisplayMode(LPDIRECTDRAW7 iface
)
433 HRESULT WINAPI
Main_DirectDraw_GetSurfaceFromDC(LPDIRECTDRAW7 iface
, HDC hdc
,
434 LPDIRECTDRAWSURFACE7
*lpDDS
)
439 HRESULT WINAPI
Main_DirectDraw_RestoreAllSurfaces(LPDIRECTDRAW7 iface
)
444 HRESULT WINAPI
Main_DirectDraw_TestCooperativeLevel(LPDIRECTDRAW7 iface
)
449 HRESULT WINAPI
Main_DirectDraw_GetDeviceIdentifier(LPDIRECTDRAW7 iface
,
450 LPDDDEVICEIDENTIFIER2 pDDDI
, DWORD dwFlags
)
455 HRESULT WINAPI
Main_DirectDraw_StartModeTest(LPDIRECTDRAW7 iface
, LPSIZE pModes
,
456 DWORD dwNumModes
, DWORD dwFlags
)
461 HRESULT WINAPI
Main_DirectDraw_EvaluateMode(LPDIRECTDRAW7 iface
,DWORD a
,DWORD
* b
)
466 IDirectDraw7Vtbl DirectDraw7_Vtable
=
468 Main_DirectDraw_QueryInterface
,
469 Main_DirectDraw_AddRef
,
470 Main_DirectDraw_Release
,
471 Main_DirectDraw_Compact
,
472 Main_DirectDraw_CreateClipper
,
473 Main_DirectDraw_CreatePalette
,
474 Main_DirectDraw_CreateSurface
,
475 Main_DirectDraw_DuplicateSurface
,
476 Main_DirectDraw_EnumDisplayModes
,
477 Main_DirectDraw_EnumSurfaces
,
478 Main_DirectDraw_FlipToGDISurface
,
479 Main_DirectDraw_GetCaps
,
480 Main_DirectDraw_GetDisplayMode
,
481 Main_DirectDraw_GetFourCCCodes
,
482 Main_DirectDraw_GetGDISurface
,
483 Main_DirectDraw_GetMonitorFrequency
,
484 Main_DirectDraw_GetScanLine
,
485 Main_DirectDraw_GetVerticalBlankStatus
,
486 Main_DirectDraw_Initialize
,
487 Main_DirectDraw_RestoreDisplayMode
,
488 Main_DirectDraw_SetCooperativeLevel
,
489 Main_DirectDraw_SetDisplayMode
,
490 Main_DirectDraw_WaitForVerticalBlank
,
491 Main_DirectDraw_GetAvailableVidMem
,
492 Main_DirectDraw_GetSurfaceFromDC
,
493 Main_DirectDraw_RestoreAllSurfaces
,
494 Main_DirectDraw_TestCooperativeLevel
,
495 Main_DirectDraw_GetDeviceIdentifier
,
496 Main_DirectDraw_StartModeTest
,
497 Main_DirectDraw_EvaluateMode