fc7bf968ecf30f5adb151dd247e77a7677b13e06
[reactos.git] / reactos / lib / ddraw / hal / ddraw.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS
5 * FILE: lib/ddraw/hal/ddraw.c
6 * PURPOSE: DirectDraw HAL Implementation
7 * PROGRAMMER: Magnus Olsen, Maarten Bosma
8 *
9 */
10
11 #include "rosdraw.h"
12
13
14 HRESULT Hal_DirectDraw_Initialize (LPDIRECTDRAW7 iface)
15 {
16 IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
17
18
19 /* point to it self */
20 This->DirectDrawGlobal.lp16DD = &This->DirectDrawGlobal;
21
22 /* get the object */
23 if(!DdCreateDirectDrawObject (&This->DirectDrawGlobal, This->hdc))
24 return DDERR_INVALIDPARAMS;
25
26
27
28
29 /* alloc all the space */
30 This->DirectDrawGlobal.lpDDCBtmp = (LPDDHAL_CALLBACKS)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DDHAL_CALLBACKS));
31 This->DirectDrawGlobal.lpD3DHALCallbacks = (ULONG_PTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, sizeof(D3DHAL_CALLBACKS));
32 This->DirectDrawGlobal.lpD3DGlobalDriverData = (ULONG_PTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DHAL_GLOBALDRIVERDATA));
33
34
35 /* Fill in some info */
36 This->HalInfo.lpD3DGlobalDriverData = This->DirectDrawGlobal.lpD3DGlobalDriverData;
37 This->HalInfo.lpD3DHALCallbacks = This->DirectDrawGlobal.lpD3DHALCallbacks;
38 This->HalInfo.lpDDCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDD;
39 This->HalInfo.lpDDExeBufCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDDExeBuf;
40 This->HalInfo.lpDDPaletteCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDDPalette;
41 This->HalInfo.lpDDSurfaceCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDDSurface;
42
43
44 /* query all kinds of infos from the driver */
45 if(!DdQueryDirectDrawObject (
46 &This->DirectDrawGlobal,
47 &This->HalInfo,
48 This->HalInfo.lpDDCallbacks,
49 This->HalInfo.lpDDSurfaceCallbacks,
50 This->HalInfo.lpDDPaletteCallbacks,
51 (LPD3DHAL_CALLBACKS)This->DirectDrawGlobal.lpD3DHALCallbacks,
52 (LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData,
53 This->HalInfo.lpDDExeBufCallbacks,
54 NULL,
55 NULL,
56 NULL ))
57 {
58 OutputDebugString(L"First DdQueryDirectDrawObject failed");
59 return 1;
60 }
61
62 /* ms wants us to call that function twice */
63 This->HalInfo.vmiData.pvmList = HeapAlloc(GetProcessHeap(), 0, sizeof(VIDMEM) * This->HalInfo.vmiData.dwNumHeaps);
64 This->DirectDrawGlobal.lpdwFourCC = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * This->HalInfo.ddCaps.dwNumFourCCCodes);
65 This->DirectDrawGlobal.lpZPixelFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDPIXELFORMAT) * This->DirectDrawGlobal.dwNumZPixelFormats);
66 ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDSURFACEDESC) * ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->dwNumTextureFormats);
67
68 if(!DdQueryDirectDrawObject (
69 &This->DirectDrawGlobal,
70 &This->HalInfo,
71 This->HalInfo.lpDDCallbacks,
72 This->HalInfo.lpDDSurfaceCallbacks,
73 This->HalInfo.lpDDPaletteCallbacks,
74 (LPD3DHAL_CALLBACKS)This->DirectDrawGlobal.lpD3DHALCallbacks,
75 (LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData,
76 This->HalInfo.lpDDExeBufCallbacks,
77 ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats,
78 This->DirectDrawGlobal.lpdwFourCC,
79 This->HalInfo.vmiData.pvmList
80 ))
81 {
82 OutputDebugString(L"Second DdQueryDirectDrawObject failed");
83 return 1;
84 }
85
86 /* Copy HalInfo to DirectDrawGlobal */
87
88 /* have not check where it should go into yet
89 LPDDHAL_DDCALLBACKS lpDDCallbacks;
90 LPDDHAL_DDSURFACECALLBACKS lpDDSurfaceCallbacks;
91 LPDDHAL_DDPALETTECALLBACKS lpDDPaletteCallbacks;
92 */
93
94 RtlCopyMemory(&This->DirectDrawGlobal.vmiData,&This->HalInfo.vmiData,sizeof(VIDMEMINFO));
95 RtlCopyMemory(&This->DirectDrawGlobal.ddCaps,&This->HalInfo.ddCaps,sizeof(DDCORECAPS));
96 This->DirectDrawGlobal.dwMonitorFrequency = This->HalInfo.dwMonitorFrequency;
97
98 /* have not check where it should go into yet
99 LPDDHAL_GETDRIVERINFO GetDriverInfo;
100 */
101
102 This->DirectDrawGlobal.dwModeIndex = This->HalInfo.dwModeIndex;
103
104 /* have not check where it should go into yet
105 LPDWORD lpdwFourCC;
106 */
107
108 This->DirectDrawGlobal.dwNumModes = This->HalInfo.dwNumModes;
109 This->DirectDrawGlobal.lpModeInfo = This->HalInfo.lpModeInfo;
110
111 /* have not check where it should go into yet
112 DWORD dwFlags;
113 */
114
115 /* Unsure which of these two for lpPDevice
116 This->DirectDrawGlobal.dwPDevice = This->HalInfo.lpPDevice;
117 This->lpDriverHandle = This->HalInfo.lpPDevice;
118 */
119
120 This->DirectDrawGlobal.hInstance = This->HalInfo.hInstance;
121
122 /* have not check where it should go into yet
123 ULONG_PTR lpD3DGlobalDriverData;
124 ULONG_PTR lpD3DHALCallbacks;
125 LPDDHAL_DDEXEBUFCALLBACKS lpDDExeBufCallbacks;
126 */
127
128
129
130 This->DirectDrawGlobal.lpDDCBtmp->HALDD = This->DirectDrawGlobal.lpDDCBtmp->cbDDCallbacks;
131 This->DirectDrawGlobal.lpDDCBtmp->HALDDSurface = This->DirectDrawGlobal.lpDDCBtmp->cbDDSurfaceCallbacks;
132 This->DirectDrawGlobal.lpDDCBtmp->HALDDExeBuf = This->DirectDrawGlobal.lpDDCBtmp->cbDDExeBufCallbacks;
133 This->DirectDrawGlobal.lpDDCBtmp->HALDDPalette = This->DirectDrawGlobal.lpDDCBtmp->cbDDPaletteCallbacks;
134
135 return DD_OK;
136 }
137
138 HRESULT Hal_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface)
139 {
140 return DD_OK;
141 }
142
143
144 VOID Hal_DirectDraw_Release (LPDIRECTDRAW7 iface)
145 {
146 IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
147
148 DdDeleteDirectDrawObject (&This->DirectDrawGlobal);
149
150 if(This->HalInfo.vmiData.pvmList)
151 HeapFree(GetProcessHeap(), 0, This->HalInfo.vmiData.pvmList);
152 if(This->DirectDrawGlobal.lpdwFourCC)
153 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpdwFourCC);
154 if(This->DirectDrawGlobal.lpZPixelFormats)
155 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpZPixelFormats);
156 if(((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats)
157 HeapFree(GetProcessHeap(), 0, ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats);
158
159 if(This->DirectDrawGlobal.lpDDCBtmp)
160 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpDDCBtmp);
161 if(This->DirectDrawGlobal.lpD3DHALCallbacks)
162 HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DHALCallbacks);
163 if(This->DirectDrawGlobal.lpD3DGlobalDriverData)
164 HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DGlobalDriverData);
165 }