3 * COPYRIGHT: See COPYING in the top level directory
5 * FILE: lib/ddraw/main/ddraw.c
6 * PURPOSE: DirectDraw 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
;
74 if((ret
= Hel_DirectDraw_SetCooperativeLevel (iface
)) != DD_OK
)
77 if((ret
= Hal_DirectDraw_SetCooperativeLevel (iface
)) != DD_OK
)
83 HRESULT WINAPI
Main_DirectDraw_SetDisplayMode (LPDIRECTDRAW7 iface
, DWORD dwWidth
, DWORD dwHeight
,
84 DWORD dwBPP
, DWORD dwRefreshRate
, DWORD dwFlags
)
86 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
88 // this only for exclusive mode
89 if(!(This
->cooperative_level
& DDSCL_EXCLUSIVE
))
90 return DDERR_NOEXCLUSIVEMODE
;
92 // change the resolution using normal WinAPI function
94 mode
.dmSize
= sizeof(mode
);
95 mode
.dmPelsWidth
= dwWidth
;
96 mode
.dmPelsHeight
= dwHeight
;
97 mode
.dmBitsPerPel
= dwBPP
;
98 mode
.dmDisplayFrequency
= dwRefreshRate
;
102 mode
.dmFields
|= DM_PELSWIDTH
;
104 mode
.dmFields
|= DM_PELSHEIGHT
;
106 mode
.dmFields
|= DM_BITSPERPEL
;
108 mode
.dmFields
|= DM_DISPLAYFREQUENCY
;
110 if (ChangeDisplaySettings(&mode
, CDS_FULLSCREEN
) != DISP_CHANGE_SUCCESSFUL
)
111 return DDERR_UNSUPPORTEDMODE
;
113 // TODO: reactivate ddraw object, maximize window, set it in foreground
114 // and set excluive mode (if implemented by the driver)
117 This
->Height
= dwWidth
;
119 This
->Width
= dwHeight
;
126 HRESULT WINAPI
Main_DirectDraw_CreateSurface (LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
,
127 LPDIRECTDRAWSURFACE7
*ppSurf
, IUnknown
*pUnkOuter
)
130 return DDERR_INVALIDPARAMS
;
132 if(sizeof(DDSURFACEDESC2
)!=pDDSD
->dwSize
)
133 return DDERR_UNSUPPORTED
;
135 // the nasty com stuff
136 IDirectDrawSurfaceImpl
* That
;
138 That
= (IDirectDrawSurfaceImpl
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
141 return E_OUTOFMEMORY
;
143 That
->lpVtbl
= &DDrawSurface_VTable
;
145 *ppSurf
= (LPDIRECTDRAWSURFACE7
)That
;
147 // the real surface object creation
148 return That
->lpVtbl
->Initialize (*ppSurf
, (LPDIRECTDRAW
)iface
, pDDSD
);
151 ULONG WINAPI
Main_DirectDraw_AddRef (LPDIRECTDRAW7 iface
)
153 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
154 ULONG ref
= InterlockedIncrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
159 ULONG WINAPI
Main_DirectDraw_Release (LPDIRECTDRAW7 iface
)
161 IDirectDrawImpl
* This
= (IDirectDrawImpl
*)iface
;
162 ULONG ref
= InterlockedDecrement((PLONG
)&This
->DirectDrawGlobal
.dwRefCnt
);
166 // set resoltion back to the one in registry
167 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
168 ChangeDisplaySettings(NULL
, 0);
170 HeapFree(GetProcessHeap(), 0, This
);
178 HRESULT WINAPI
Main_DirectDraw_QueryInterface (LPDIRECTDRAW7 iface
,REFIID refiid
,LPVOID
*obj
)
183 HRESULT WINAPI
Main_DirectDraw_Compact(LPDIRECTDRAW7 iface
)
188 HRESULT WINAPI
Main_DirectDraw_CreateClipper(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
189 LPDIRECTDRAWCLIPPER
*ppClipper
, IUnknown
*pUnkOuter
)
193 HRESULT WINAPI
Main_DirectDraw_CreatePalette(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
194 LPPALETTEENTRY palent
,LPDIRECTDRAWPALETTE
* ppPalette
,LPUNKNOWN pUnknown
)
199 HRESULT WINAPI
Main_DirectDraw_DuplicateSurface(LPDIRECTDRAW7 iface
, LPDIRECTDRAWSURFACE7 src
,
200 LPDIRECTDRAWSURFACE7
* dst
)
205 HRESULT WINAPI
Main_DirectDraw_EnumDisplayModes(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
206 LPDDSURFACEDESC2 pDDSD
, LPVOID context
, LPDDENUMMODESCALLBACK2 callback
)
211 HRESULT WINAPI
Main_DirectDraw_EnumSurfaces(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
212 LPDDSURFACEDESC2 lpDDSD2
, LPVOID context
,
213 LPDDENUMSURFACESCALLBACK7 callback
)
218 HRESULT WINAPI
Main_DirectDraw_FlipToGDISurface(LPDIRECTDRAW7 iface
)
223 HRESULT WINAPI
Main_DirectDraw_GetCaps(LPDIRECTDRAW7 iface
, LPDDCAPS pDriverCaps
,
226 DWORD status
= DD_FALSE
;
227 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
229 if (pDriverCaps
!= NULL
)
231 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
235 if (pHELCaps
!= NULL
)
237 RtlCopyMemory(pDriverCaps
,&This
->DirectDrawGlobal
.ddHELCaps
,sizeof(DDCORECAPS
));
241 /* Both caps mixed ?? */
242 /* DDCORECAPS ddBothCaps; */
247 HRESULT WINAPI
Main_DirectDraw_GetDisplayMode(LPDIRECTDRAW7 iface
, LPDDSURFACEDESC2 pDDSD
)
249 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
256 pDDSD
->dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_PITCH
| DDSD_PIXELFORMAT
| DDSD_REFRESHRATE
| DDSD_WIDTH
;
257 pDDSD
->dwHeight
= This
->DirectDrawGlobal
.vmiData
.dwDisplayHeight
;
258 pDDSD
->dwWidth
= This
->DirectDrawGlobal
.vmiData
.dwDisplayWidth
;
260 /* FIXME Do not use DUMMYUNIONNAME1 some how union lPitch does not see by the compiler
261 but rest of the union are visable. more header problem ???
263 pDDSD
->DUMMYUNIONNAME1
.lPitch
= This
->DirectDrawGlobal
.vmiData
.lDisplayPitch
;
266 /* have not check where I should get hold of this info yet
267 DWORD dwBackBufferCount;
270 pDDSD
->dwRefreshRate
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
272 /* have not check where I should get hold of this info yet
273 DWORD dwAlphaBitDepth;
278 DDCOLORKEY ddckCKDestOverlay;
279 DWORD dwEmptyFaceColor;
281 DDCOLORKEY ddckCKDestBlt;
282 DDCOLORKEY ddckCKSrcOverlay;
283 DDCOLORKEY ddckCKSrcBlt;
286 RtlCopyMemory(&pDDSD
->ddpfPixelFormat
,&This
->DirectDrawGlobal
.vmiData
.ddpfDisplay
,sizeof(DDPIXELFORMAT
));
287 RtlCopyMemory(&pDDSD
->ddsCaps
,&This
->DirectDrawGlobal
.ddCaps
,sizeof(DDCORECAPS
));
289 /* have not check where I should get hold of this info yet
290 DWORD dwTextureStage;
297 HRESULT WINAPI
Main_DirectDraw_GetFourCCCodes(LPDIRECTDRAW7 iface
, LPDWORD pNumCodes
, LPDWORD pCodes
)
302 HRESULT WINAPI
Main_DirectDraw_GetGDISurface(LPDIRECTDRAW7 iface
,
303 LPDIRECTDRAWSURFACE7
*lplpGDIDDSSurface
)
308 HRESULT WINAPI
Main_DirectDraw_GetMonitorFrequency(LPDIRECTDRAW7 iface
,LPDWORD freq
)
310 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
317 *freq
= This
->DirectDrawGlobal
.dwMonitorFrequency
;
321 HRESULT WINAPI
Main_DirectDraw_GetScanLine(LPDIRECTDRAW7 iface
, LPDWORD lpdwScanLine
)
326 HRESULT WINAPI
Main_DirectDraw_GetVerticalBlankStatus(LPDIRECTDRAW7 iface
, LPBOOL status
)
331 HRESULT WINAPI
Main_DirectDraw_RestoreDisplayMode(LPDIRECTDRAW7 iface
)
336 HRESULT WINAPI
Main_DirectDraw_WaitForVerticalBlank(LPDIRECTDRAW7 iface
, DWORD dwFlags
,
343 HRESULT WINAPI
Main_DirectDraw_GetAvailableVidMem(LPDIRECTDRAW7 iface
, LPDDSCAPS2 ddscaps
,
344 LPDWORD total
, LPDWORD free
)
350 HRESULT WINAPI
Main_DirectDraw_GetSurfaceFromDC(LPDIRECTDRAW7 iface
, HDC hdc
,
351 LPDIRECTDRAWSURFACE7
*lpDDS
)
356 HRESULT WINAPI
Main_DirectDraw_RestoreAllSurfaces(LPDIRECTDRAW7 iface
)
361 HRESULT WINAPI
Main_DirectDraw_TestCooperativeLevel(LPDIRECTDRAW7 iface
)
366 HRESULT WINAPI
Main_DirectDraw_GetDeviceIdentifier(LPDIRECTDRAW7 iface
,
367 LPDDDEVICEIDENTIFIER2 pDDDI
, DWORD dwFlags
)
372 HRESULT WINAPI
Main_DirectDraw_StartModeTest(LPDIRECTDRAW7 iface
, LPSIZE pModes
,
373 DWORD dwNumModes
, DWORD dwFlags
)
378 HRESULT WINAPI
Main_DirectDraw_EvaluateMode(LPDIRECTDRAW7 iface
,DWORD a
,DWORD
* b
)
383 IDirectDraw7Vtbl DirectDraw_VTable
=
385 Main_DirectDraw_QueryInterface
,
386 Main_DirectDraw_AddRef
,
387 Main_DirectDraw_Release
,
388 Main_DirectDraw_Compact
,
389 Main_DirectDraw_CreateClipper
,
390 Main_DirectDraw_CreatePalette
,
391 Main_DirectDraw_CreateSurface
,
392 Main_DirectDraw_DuplicateSurface
,
393 Main_DirectDraw_EnumDisplayModes
,
394 Main_DirectDraw_EnumSurfaces
,
395 Main_DirectDraw_FlipToGDISurface
,
396 Main_DirectDraw_GetCaps
,
397 Main_DirectDraw_GetDisplayMode
,
398 Main_DirectDraw_GetFourCCCodes
,
399 Main_DirectDraw_GetGDISurface
,
400 Main_DirectDraw_GetMonitorFrequency
,
401 Main_DirectDraw_GetScanLine
,
402 Main_DirectDraw_GetVerticalBlankStatus
,
403 Main_DirectDraw_Initialize
,
404 Main_DirectDraw_RestoreDisplayMode
,
405 Main_DirectDraw_SetCooperativeLevel
,
406 Main_DirectDraw_SetDisplayMode
,
407 Main_DirectDraw_WaitForVerticalBlank
,
408 Main_DirectDraw_GetAvailableVidMem
,
409 Main_DirectDraw_GetSurfaceFromDC
,
410 Main_DirectDraw_RestoreAllSurfaces
,
411 Main_DirectDraw_TestCooperativeLevel
,
412 Main_DirectDraw_GetDeviceIdentifier
,
413 Main_DirectDraw_StartModeTest
,
414 Main_DirectDraw_EvaluateMode