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
;
52 // check the parameters
53 if (This
->cooperative_level
== cooplevel
&& This
->window
== hwnd
)
57 return DDERR_HWNDALREADYSET
;
59 if (This
->cooperative_level
)
60 return DDERR_EXCLUSIVEMODEALREADYSET
;
62 if ((cooplevel
&DDSCL_EXCLUSIVE
) && !(cooplevel
&DDSCL_FULLSCREEN
))
63 return DDERR_INVALIDPARAMS
;
65 if (cooplevel
&DDSCL_NORMAL
&& cooplevel
&DDSCL_FULLSCREEN
)
66 return DDERR_INVALIDPARAMS
;
70 This
->hdc
= GetDC(hwnd
);
71 This
->cooperative_level
= cooplevel
;
73 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_SETEXCLUSIVEMODE
)
75 return Hal_DirectDraw_SetCooperativeLevel (iface
);
78 return Hel_DirectDraw_SetCooperativeLevel(iface
);
82 HRESULT WINAPI
Main_DirectDraw_SetDisplayMode (LPDIRECTDRAW7 iface
, DWORD dwWidth
, DWORD dwHeight
,
83 DWORD dwBPP
, DWORD dwRefreshRate
, DWORD dwFlags
)
85 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
89 /* FIXME check the refresrate if it same if it not same do the mode switch */
90 if ((This
->DirectDrawGlobal
.vmiData
.dwDisplayHeight
== dwHeight
) &&
91 (This
->DirectDrawGlobal
.vmiData
.dwDisplayWidth
== dwWidth
) &&
92 (This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
.dwRGBBitCount
== dwBPP
))
98 /* Check use the Hal or Hel for SetMode */
99 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_SETMODE
)
101 ret
= Hal_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
, dwBPP
, dwRefreshRate
, dwFlags
);
105 ret
= Hel_DirectDraw_SetDisplayMode(iface
, dwWidth
, dwHeight
, dwBPP
, dwRefreshRate
, dwFlags
);
110 DdReenableDirectDrawObject(&This
->DirectDrawGlobal
, &dummy
);
111 /* FIXME fill the This->DirectDrawGlobal.vmiData right */
117 ULONG WINAPI
Main_DirectDraw_AddRef (LPDIRECTDRAW7 iface
)
119 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
120 ULONG ref
= InterlockedIncrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
125 ULONG WINAPI
Main_DirectDraw_Release (LPDIRECTDRAW7 iface
)
127 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
128 ULONG ref
= InterlockedDecrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
132 // set resoltion back to the one in registry
133 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
134 ChangeDisplaySettings(NULL
, 0);
136 HeapFree(GetProcessHeap(), 0, This
);
142 HRESULT WINAPI
Main_DirectDraw_QueryInterface (
143 LPDIRECTDRAW7 iface
, REFIID id
, LPVOID
*obj
)
145 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
147 if (IsEqualGUID(&IID_IDirectDraw7
, id
))
149 *obj
= &This
->lpVtbl
;
151 else if (IsEqualGUID(&IID_IDirectDraw
, id
))
153 *obj
= &This
->lpVtbl_v1
;
155 else if (IsEqualGUID(&IID_IDirectDraw2
, id
))
157 *obj
= &This
->lpVtbl_v2
;
159 else if (IsEqualGUID(&IID_IDirectDraw4
, id
))
161 *obj
= &This
->lpVtbl_v4
;
166 return E_NOINTERFACE
;
169 Main_DirectDraw_AddRef(iface
);
173 HRESULT WINAPI
Main_DirectDraw_CreateSurface (LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
,
174 LPDIRECTDRAWSURFACE7
*ppSurf
, IUnknown
*pUnkOuter
)
177 return DDERR_INVALIDPARAMS
;
179 if(sizeof(DDSURFACEDESC2
)!=pDDSD
->dwSize
&& sizeof(DDSURFACEDESC
)!=pDDSD
->dwSize
)
180 return DDERR_UNSUPPORTED
;
182 // the nasty com stuff
183 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
185 IDirectDrawSurfaceImpl
* That
;
187 That
= (IDirectDrawSurfaceImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawSurfaceImpl
));
190 return E_OUTOFMEMORY
;
192 ZeroMemory(That
, sizeof(IDirectDrawSurfaceImpl
));
194 That
->lpVtbl
= &DirectDrawSurface7_Vtable
;
195 That
->lpVtbl_v3
= &DDRAW_IDDS3_Thunk_VTable
;
197 This
->DirectDrawGlobal
.dsList
= (LPDDRAWI_DDRAWSURFACE_INT
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
198 sizeof(DDRAWI_DDRAWSURFACE_INT
));
199 That
->owner
= (IDirectDrawImpl
*)This
;
200 That
->owner
->DirectDrawGlobal
.dsList
->dwIntRefCnt
=1;
202 /* we alwasy set to use the DirectDrawSurface7_Vtable as internel */
203 That
->owner
->DirectDrawGlobal
.dsList
->lpVtbl
= (PVOID
) &DirectDrawSurface7_Vtable
;
205 *ppSurf
= (LPDIRECTDRAWSURFACE7
)That
;
207 // the real surface object creation
208 return That
->lpVtbl
->Initialize (*ppSurf
, (LPDIRECTDRAW
)iface
, pDDSD
);
211 HRESULT WINAPI
Main_DirectDraw_CreateClipper(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
212 LPDIRECTDRAWCLIPPER
*ppClipper
, IUnknown
*pUnkOuter
)
215 return DDERR_INVALIDPARAMS
;
217 IDirectDrawClipperImpl
* That
;
218 That
= (IDirectDrawClipperImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawClipperImpl
));
221 return E_OUTOFMEMORY
;
223 ZeroMemory(That
, sizeof(IDirectDrawClipperImpl
));
225 That
->lpVtbl
= &DirectDrawClipper_Vtable
;
227 *ppClipper
= (LPDIRECTDRAWCLIPPER
)That
;
229 return That
->lpVtbl
->Initialize (*ppClipper
, (LPDIRECTDRAW
)iface
, dwFlags
);
232 // This function is exported by the dll
233 HRESULT WINAPI
DirectDrawCreateClipper (DWORD dwFlags
,
234 LPDIRECTDRAWCLIPPER
* lplpDDClipper
, LPUNKNOWN pUnkOuter
)
236 return Main_DirectDraw_CreateClipper(NULL
, dwFlags
, lplpDDClipper
, pUnkOuter
);
239 HRESULT WINAPI
Main_DirectDraw_CreatePalette(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
240 LPPALETTEENTRY palent
, LPDIRECTDRAWPALETTE
* ppPalette
, LPUNKNOWN pUnkOuter
)
243 return DDERR_INVALIDPARAMS
;
245 IDirectDrawPaletteImpl
* That
;
246 That
= (IDirectDrawPaletteImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
249 return E_OUTOFMEMORY
;
251 ZeroMemory(That
, sizeof(IDirectDrawPaletteImpl
));
253 That
->lpVtbl
= &DirectDrawPalette_Vtable
;
255 *ppPalette
= (LPDIRECTDRAWPALETTE
)That
;
257 return That
->lpVtbl
->Initialize (*ppPalette
, (LPDIRECTDRAW
)iface
, dwFlags
, palent
);
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
;
308 pDDSD
->lPitch
= This
->DirectDrawGlobal
.vmiData
.lDisplayPitch
;
309 pDDSD
->dwRefreshRate
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
311 RtlCopyMemory(&pDDSD
->ddpfPixelFormat
,&This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
,sizeof(DDPIXELFORMAT
));
312 RtlCopyMemory(&pDDSD
->ddsCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
314 /* have not check where I should get hold of this info yet
315 DWORD dwBackBufferCount;
316 DWORD dwAlphaBitDepth;
321 DDCOLORKEY ddckCKDestOverlay;
322 DWORD dwEmptyFaceColor;
324 DDCOLORKEY ddckCKDestBlt;
325 DDCOLORKEY ddckCKSrcOverlay;
326 DDCOLORKEY ddckCKSrcBlt;
327 DWORD dwTextureStage;
333 HRESULT WINAPI
Main_DirectDraw_WaitForVerticalBlank(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
336 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
338 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_WAITFORVERTICALBLANK
)
340 return Hal_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
);
343 return Hel_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
);
346 HRESULT WINAPI
Main_DirectDraw_GetAvailableVidMem(LPDIRECTDRAW7 iface
, LPDDSCAPS2 ddscaps
,
347 LPDWORD total
, LPDWORD free
)
349 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
351 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDDMiscellaneous
.dwFlags
& DDHAL_MISCCB32_GETAVAILDRIVERMEMORY
)
353 return Hal_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
);
356 return Hel_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
);
359 HRESULT WINAPI
Main_DirectDraw_GetMonitorFrequency(LPDIRECTDRAW7 iface
,LPDWORD freq
)
361 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
368 *freq
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
372 HRESULT WINAPI
Main_DirectDraw_GetScanLine(LPDIRECTDRAW7 iface
, LPDWORD lpdwScanLine
)
374 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
376 if (This
->DirectDrawGlobal
.lpDDCBtmp
->HALDD
.dwFlags
& DDHAL_CB32_GETSCANLINE
)
378 return Hal_DirectDraw_GetScanLine( iface
, lpdwScanLine
);
381 return Hel_DirectDraw_GetScanLine( iface
, lpdwScanLine
);
384 /********************************** Stubs **********************************/
386 HRESULT WINAPI
Main_DirectDraw_Compact(LPDIRECTDRAW7 iface
)
391 HRESULT WINAPI
Main_DirectDraw_DuplicateSurface(LPDIRECTDRAW7 iface
, LPDIRECTDRAWSURFACE7 src
,
392 LPDIRECTDRAWSURFACE7
* dst
)
397 HRESULT WINAPI
Main_DirectDraw_EnumDisplayModes(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
398 LPDDSURFACEDESC2 pDDSD
, LPVOID context
, LPDDENUMMODESCALLBACK2 callback
)
403 HRESULT WINAPI
Main_DirectDraw_EnumSurfaces(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
404 LPDDSURFACEDESC2 lpDDSD2
, LPVOID context
,
405 LPDDENUMSURFACESCALLBACK7 callback
)
411 HRESULT WINAPI
Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface
, LPDWORD pNumCodes
, LPDWORD pCodes
)
416 HRESULT WINAPI
Main_DirectDraw_GetGDISurface(LPDIRECTDRAW7 iface
,
417 LPDIRECTDRAWSURFACE7
*lplpGDIDDSSurface
)
422 HRESULT WINAPI
Main_DirectDraw_GetVerticalBlankStatus(LPDIRECTDRAW7 iface
, LPBOOL status
)
427 HRESULT WINAPI
Main_DirectDraw_RestoreDisplayMode(LPDIRECTDRAW7 iface
)
432 HRESULT WINAPI
Main_DirectDraw_GetSurfaceFromDC(LPDIRECTDRAW7 iface
, HDC hdc
,
433 LPDIRECTDRAWSURFACE7
*lpDDS
)
438 HRESULT WINAPI
Main_DirectDraw_RestoreAllSurfaces(LPDIRECTDRAW7 iface
)
443 HRESULT WINAPI
Main_DirectDraw_TestCooperativeLevel(LPDIRECTDRAW7 iface
)
448 HRESULT WINAPI
Main_DirectDraw_GetDeviceIdentifier(LPDIRECTDRAW7 iface
,
449 LPDDDEVICEIDENTIFIER2 pDDDI
, DWORD dwFlags
)
454 HRESULT WINAPI
Main_DirectDraw_StartModeTest(LPDIRECTDRAW7 iface
, LPSIZE pModes
,
455 DWORD dwNumModes
, DWORD dwFlags
)
460 HRESULT WINAPI
Main_DirectDraw_EvaluateMode(LPDIRECTDRAW7 iface
,DWORD a
,DWORD
* b
)
465 IDirectDraw7Vtbl DirectDraw7_Vtable
=
467 Main_DirectDraw_QueryInterface
,
468 Main_DirectDraw_AddRef
,
469 Main_DirectDraw_Release
,
470 Main_DirectDraw_Compact
,
471 Main_DirectDraw_CreateClipper
,
472 Main_DirectDraw_CreatePalette
,
473 Main_DirectDraw_CreateSurface
,
474 Main_DirectDraw_DuplicateSurface
,
475 Main_DirectDraw_EnumDisplayModes
,
476 Main_DirectDraw_EnumSurfaces
,
477 Main_DirectDraw_FlipToGDISurface
,
478 Main_DirectDraw_GetCaps
,
479 Main_DirectDraw_GetDisplayMode
,
480 Main_DirectDraw_GetFourCCCodes
,
481 Main_DirectDraw_GetGDISurface
,
482 Main_DirectDraw_GetMonitorFrequency
,
483 Main_DirectDraw_GetScanLine
,
484 Main_DirectDraw_GetVerticalBlankStatus
,
485 Main_DirectDraw_Initialize
,
486 Main_DirectDraw_RestoreDisplayMode
,
487 Main_DirectDraw_SetCooperativeLevel
,
488 Main_DirectDraw_SetDisplayMode
,
489 Main_DirectDraw_WaitForVerticalBlank
,
490 Main_DirectDraw_GetAvailableVidMem
,
491 Main_DirectDraw_GetSurfaceFromDC
,
492 Main_DirectDraw_RestoreAllSurfaces
,
493 Main_DirectDraw_TestCooperativeLevel
,
494 Main_DirectDraw_GetDeviceIdentifier
,
495 Main_DirectDraw_StartModeTest
,
496 Main_DirectDraw_EvaluateMode