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
)
88 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
90 // this only for exclusive mode
91 if(!(This
->cooperative_level
& DDSCL_EXCLUSIVE
))
92 return DDERR_NOEXCLUSIVEMODE
;
94 // change the resolution using normal WinAPI function
96 mode
.dmSize
= sizeof(mode
);
97 mode
.dmPelsWidth
= dwWidth
;
98 mode
.dmPelsHeight
= dwHeight
;
99 mode
.dmBitsPerPel
= dwBPP
;
100 mode
.dmDisplayFrequency
= dwRefreshRate
;
104 mode
.dmFields
|= DM_PELSWIDTH
;
106 mode
.dmFields
|= DM_PELSHEIGHT
;
108 mode
.dmFields
|= DM_BITSPERPEL
;
110 mode
.dmFields
|= DM_DISPLAYFREQUENCY
;
112 if (ChangeDisplaySettings(&mode
, CDS_FULLSCREEN
) != DISP_CHANGE_SUCCESSFUL
)
113 return DDERR_UNSUPPORTEDMODE
;
115 // TODO: reactivate ddraw object, maximize window, set it in foreground
116 // and set excluive mode (if implemented by the driver)
119 This
->Height
= dwWidth
;
121 This
->Width
= dwHeight
;
128 ULONG WINAPI
Main_DirectDraw_AddRef (LPDIRECTDRAW7 iface
)
130 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
131 ULONG ref
= InterlockedIncrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
136 ULONG WINAPI
Main_DirectDraw_Release (LPDIRECTDRAW7 iface
)
138 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
139 ULONG ref
= InterlockedDecrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
143 // set resoltion back to the one in registry
144 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
145 ChangeDisplaySettings(NULL
, 0);
147 HeapFree(GetProcessHeap(), 0, This
);
153 HRESULT WINAPI
Main_DirectDraw_QueryInterface (
154 LPDIRECTDRAW7 iface
, REFIID id
, LPVOID
*obj
)
156 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
158 if (IsEqualGUID(&IID_IDirectDraw7
, id
))
160 *obj
= &This
->lpVtbl
;
162 else if (IsEqualGUID(&IID_IDirectDraw
, id
))
164 *obj
= &This
->lpVtbl_v1
;
166 else if (IsEqualGUID(&IID_IDirectDraw2
, id
))
168 *obj
= &This
->lpVtbl_v2
;
170 else if (IsEqualGUID(&IID_IDirectDraw4
, id
))
172 *obj
= &This
->lpVtbl_v4
;
177 return E_NOINTERFACE
;
180 Main_DirectDraw_AddRef(iface
);
184 HRESULT WINAPI
Main_DirectDraw_CreateSurface (LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
,
185 LPDIRECTDRAWSURFACE7
*ppSurf
, IUnknown
*pUnkOuter
)
188 return DDERR_INVALIDPARAMS
;
190 if(sizeof(DDSURFACEDESC2
)!=pDDSD
->dwSize
)
191 return DDERR_UNSUPPORTED
;
193 // the nasty com stuff
194 IDirectDrawSurfaceImpl
* That
;
196 That
= (IDirectDrawSurfaceImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawSurfaceImpl
));
199 return E_OUTOFMEMORY
;
201 ZeroMemory(That
, sizeof(IDirectDrawSurfaceImpl
));
203 That
->lpVtbl
= &DirectDrawSurface7_Vtable
;
204 That
->lpVtbl_v3
= &DDRAW_IDDS3_Thunk_VTable
;
207 *ppSurf
= (LPDIRECTDRAWSURFACE7
)That
;
209 // the real surface object creation
210 return That
->lpVtbl
->Initialize (*ppSurf
, (LPDIRECTDRAW
)iface
, pDDSD
);
213 HRESULT WINAPI
Main_DirectDraw_CreateClipper(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
214 LPDIRECTDRAWCLIPPER
*ppClipper
, IUnknown
*pUnkOuter
)
217 return DDERR_INVALIDPARAMS
;
219 IDirectDrawClipperImpl
* That
;
220 That
= (IDirectDrawClipperImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawClipperImpl
));
223 return E_OUTOFMEMORY
;
225 ZeroMemory(That
, sizeof(IDirectDrawClipperImpl
));
227 That
->lpVtbl
= &DirectDrawClipper_Vtable
;
229 *ppClipper
= (LPDIRECTDRAWCLIPPER
)That
;
231 return That
->lpVtbl
->Initialize (*ppClipper
, (LPDIRECTDRAW
)iface
, dwFlags
);
234 // This function is exported by the dll
235 HRESULT WINAPI
DirectDrawCreateClipper (DWORD dwFlags
,
236 LPDIRECTDRAWCLIPPER
* lplpDDClipper
, LPUNKNOWN pUnkOuter
)
238 return Main_DirectDraw_CreateClipper(NULL
, dwFlags
, lplpDDClipper
, pUnkOuter
);
241 HRESULT WINAPI
Main_DirectDraw_CreatePalette(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
242 LPPALETTEENTRY palent
, LPDIRECTDRAWPALETTE
* ppPalette
, LPUNKNOWN pUnkOuter
)
245 return DDERR_INVALIDPARAMS
;
247 IDirectDrawPaletteImpl
* That
;
248 That
= (IDirectDrawPaletteImpl
*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
251 return E_OUTOFMEMORY
;
253 ZeroMemory(That
, sizeof(IDirectDrawPaletteImpl
));
255 That
->lpVtbl
= &DirectDrawPalette_Vtable
;
257 *ppPalette
= (LPDIRECTDRAWPALETTE
)That
;
259 return That
->lpVtbl
->Initialize (*ppPalette
, (LPDIRECTDRAW
)iface
, dwFlags
, palent
);
264 HRESULT WINAPI
Main_DirectDraw_Compact(LPDIRECTDRAW7 iface
)
269 HRESULT WINAPI
Main_DirectDraw_DuplicateSurface(LPDIRECTDRAW7 iface
, LPDIRECTDRAWSURFACE7 src
,
270 LPDIRECTDRAWSURFACE7
* dst
)
275 HRESULT WINAPI
Main_DirectDraw_EnumDisplayModes(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
276 LPDDSURFACEDESC2 pDDSD
, LPVOID context
, LPDDENUMMODESCALLBACK2 callback
)
281 HRESULT WINAPI
Main_DirectDraw_EnumSurfaces(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
282 LPDDSURFACEDESC2 lpDDSD2
, LPVOID context
,
283 LPDDENUMSURFACESCALLBACK7 callback
)
288 HRESULT WINAPI
Main_DirectDraw_FlipToGDISurface(LPDIRECTDRAW7 iface
)
293 HRESULT WINAPI
Main_DirectDraw_GetCaps(LPDIRECTDRAW7 iface
, LPDDCAPS pDriverCaps
,
296 DWORD status
= DD_FALSE
;
297 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
299 if (pDriverCaps
!= NULL
)
301 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
305 if (pHELCaps
!= NULL
)
307 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddHELCaps
,sizeof(DDCORECAPS
));
311 /* Both caps mixed ?? */
312 /* DDCORECAPS ddBothCaps; */
317 HRESULT WINAPI
Main_DirectDraw_GetDisplayMode(LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
)
319 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
326 pDDSD
->dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_PITCH
| DDSD_PIXELFORMAT
| DDSD_REFRESHRATE
| DDSD_WIDTH
;
327 pDDSD
->dwHeight
= This
->DirectDrawGlobal
.vmiData
.dwDisplayHeight
;
328 pDDSD
->dwWidth
= This
->DirectDrawGlobal
.vmiData
.dwDisplayWidth
;
330 /* FIXME Do not use DUMMYUNIONNAME1 some how union lPitch does not see by the compiler
331 but rest of the union are visable. more header problem ???
333 pDDSD
->DUMMYUNIONNAME1
.lPitch
= This
->DirectDrawGlobal
.vmiData
.lDisplayPitch
;
336 /* have not check where I should get hold of this info yet
337 DWORD dwBackBufferCount;
340 pDDSD
->dwRefreshRate
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
342 /* have not check where I should get hold of this info yet
343 DWORD dwAlphaBitDepth;
348 DDCOLORKEY ddckCKDestOverlay;
349 DWORD dwEmptyFaceColor;
351 DDCOLORKEY ddckCKDestBlt;
352 DDCOLORKEY ddckCKSrcOverlay;
353 DDCOLORKEY ddckCKSrcBlt;
357 RtlCopyMemory(&pDDSD
->ddpfPixelFormat
,&This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
,sizeof(DDPIXELFORMAT
));
358 RtlCopyMemory(&pDDSD
->ddsCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
360 /* have not check where I should get hold of this info yet
361 DWORD dwTextureStage;
368 HRESULT WINAPI
Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface
, LPDWORD pNumCodes
, LPDWORD pCodes
)
373 HRESULT WINAPI
Main_DirectDraw_GetGDISurface(LPDIRECTDRAW7 iface
,
374 LPDIRECTDRAWSURFACE7
*lplpGDIDDSSurface
)
379 HRESULT WINAPI
Main_DirectDraw_GetMonitorFrequency(LPDIRECTDRAW7 iface
,LPDWORD freq
)
381 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
388 *freq
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
392 HRESULT WINAPI
Main_DirectDraw_GetScanLine(LPDIRECTDRAW7 iface
, LPDWORD lpdwScanLine
)
397 HRESULT WINAPI
Main_DirectDraw_GetVerticalBlankStatus(LPDIRECTDRAW7 iface
, LPBOOL status
)
402 HRESULT WINAPI
Main_DirectDraw_RestoreDisplayMode(LPDIRECTDRAW7 iface
)
407 HRESULT WINAPI
Main_DirectDraw_WaitForVerticalBlank(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
414 HRESULT WINAPI
Main_DirectDraw_GetAvailableVidMem(LPDIRECTDRAW7 iface
, LPDDSCAPS2 ddscaps
,
415 LPDWORD total
, LPDWORD free
)
419 if((ret
= Hal_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
)) == DD_OK
)
422 if((ret
= Hel_DirectDraw_GetAvailableVidMem (iface
,ddscaps
,total
,free
)) == DD_OK
)
426 return DDERR_NOTINITIALIZED
;
430 HRESULT WINAPI
Main_DirectDraw_GetSurfaceFromDC(LPDIRECTDRAW7 iface
, HDC hdc
,
431 LPDIRECTDRAWSURFACE7
*lpDDS
)
436 HRESULT WINAPI
Main_DirectDraw_RestoreAllSurfaces(LPDIRECTDRAW7 iface
)
441 HRESULT WINAPI
Main_DirectDraw_TestCooperativeLevel(LPDIRECTDRAW7 iface
)
446 HRESULT WINAPI
Main_DirectDraw_GetDeviceIdentifier(LPDIRECTDRAW7 iface
,
447 LPDDDEVICEIDENTIFIER2 pDDDI
, DWORD dwFlags
)
452 HRESULT WINAPI
Main_DirectDraw_StartModeTest(LPDIRECTDRAW7 iface
, LPSIZE pModes
,
453 DWORD dwNumModes
, DWORD dwFlags
)
458 HRESULT WINAPI
Main_DirectDraw_EvaluateMode(LPDIRECTDRAW7 iface
,DWORD a
,DWORD
* b
)
463 IDirectDraw7Vtbl DirectDraw7_Vtable
=
465 Main_DirectDraw_QueryInterface
,
466 Main_DirectDraw_AddRef
,
467 Main_DirectDraw_Release
,
468 Main_DirectDraw_Compact
,
469 Main_DirectDraw_CreateClipper
,
470 Main_DirectDraw_CreatePalette
,
471 Main_DirectDraw_CreateSurface
,
472 Main_DirectDraw_DuplicateSurface
,
473 Main_DirectDraw_EnumDisplayModes
,
474 Main_DirectDraw_EnumSurfaces
,
475 Main_DirectDraw_FlipToGDISurface
,
476 Main_DirectDraw_GetCaps
,
477 Main_DirectDraw_GetDisplayMode
,
478 Main_DirectDraw_GetFourCCCodes
,
479 Main_DirectDraw_GetGDISurface
,
480 Main_DirectDraw_GetMonitorFrequency
,
481 Main_DirectDraw_GetScanLine
,
482 Main_DirectDraw_GetVerticalBlankStatus
,
483 Main_DirectDraw_Initialize
,
484 Main_DirectDraw_RestoreDisplayMode
,
485 Main_DirectDraw_SetCooperativeLevel
,
486 Main_DirectDraw_SetDisplayMode
,
487 Main_DirectDraw_WaitForVerticalBlank
,
488 Main_DirectDraw_GetAvailableVidMem
,
489 Main_DirectDraw_GetSurfaceFromDC
,
490 Main_DirectDraw_RestoreAllSurfaces
,
491 Main_DirectDraw_TestCooperativeLevel
,
492 Main_DirectDraw_GetDeviceIdentifier
,
493 Main_DirectDraw_StartModeTest
,
494 Main_DirectDraw_EvaluateMode