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
)
264 if((ret
= Hal_DirectDraw_FlipToGDISurface( iface
)) == DD_OK
)
267 if((ret
= Hel_DirectDraw_FlipToGDISurface( iface
)) == DD_OK
)
270 return DDERR_NOTINITIALIZED
;
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
;
310 /* FIXME Do not use DUMMYUNIONNAME1 some how union lPitch does not see by the compiler
311 but rest of the union are visable. more header problem ???
313 pDDSD
->DUMMYUNIONNAME1
.lPitch
= This
->DirectDrawGlobal
.vmiData
.lDisplayPitch
;
316 /* have not check where I should get hold of this info yet
317 DWORD dwBackBufferCount;
320 pDDSD
->dwRefreshRate
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
322 /* have not check where I should get hold of this info yet
323 DWORD dwAlphaBitDepth;
328 DDCOLORKEY ddckCKDestOverlay;
329 DWORD dwEmptyFaceColor;
331 DDCOLORKEY ddckCKDestBlt;
332 DDCOLORKEY ddckCKSrcOverlay;
333 DDCOLORKEY ddckCKSrcBlt;
337 RtlCopyMemory(&pDDSD
->ddpfPixelFormat
,&This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
,sizeof(DDPIXELFORMAT
));
338 RtlCopyMemory(&pDDSD
->ddsCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
340 /* have not check where I should get hold of this info yet
341 DWORD dwTextureStage;
348 HRESULT WINAPI
Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface
, LPDWORD pNumCodes
, LPDWORD pCodes
)
353 HRESULT WINAPI
Main_DirectDraw_GetGDISurface(LPDIRECTDRAW7 iface
,
354 LPDIRECTDRAWSURFACE7
*lplpGDIDDSSurface
)
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
)
376 if((ret
= Hal_DirectDraw_GetScanLine( iface
, lpdwScanLine
)) == DD_OK
)
379 if((ret
= Hel_DirectDraw_GetScanLine( iface
, lpdwScanLine
)) == DD_OK
)
382 return DDERR_NOTINITIALIZED
;
385 HRESULT WINAPI
Main_DirectDraw_GetVerticalBlankStatus(LPDIRECTDRAW7 iface
, LPBOOL status
)
390 HRESULT WINAPI
Main_DirectDraw_RestoreDisplayMode(LPDIRECTDRAW7 iface
)
395 HRESULT WINAPI
Main_DirectDraw_WaitForVerticalBlank(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
400 if((ret
= Hal_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
)) == DD_OK
)
403 if((ret
= Hel_DirectDraw_WaitForVerticalBlank( iface
, dwFlags
, h
)) == DD_OK
)
406 return DDERR_NOTINITIALIZED
;
409 HRESULT WINAPI
Main_DirectDraw_GetAvailableVidMem(LPDIRECTDRAW7 iface
, LPDDSCAPS2 ddscaps
,
410 LPDWORD total
, LPDWORD free
)
414 if((ret
= Hal_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
)) == DD_OK
)
417 if((ret
= Hel_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
)) == DD_OK
)
421 return DDERR_NOTINITIALIZED
;
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