#include "w32k.h" -> #include <w32k.h>
[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 /* get the object */
19 if(!DdCreateDirectDrawObject (&This->DirectDrawGlobal, This->hdc))
20 return DDERR_INVALIDPARAMS;
21
22 /* alloc some space */
23 This->DirectDrawGlobal.lpDDCBtmp = (LPDDHAL_CALLBACKS)HeapAlloc(GetProcessHeap(), 0, sizeof(DDHAL_CALLBACKS));
24 memset(This->DirectDrawGlobal.lpDDCBtmp, 0, sizeof(DDHAL_CALLBACKS));
25 This->HalInfo.lpDDCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->cbDDCallbacks;
26 This->HalInfo.lpDDSurfaceCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->cbDDSurfaceCallbacks;
27 This->HalInfo.lpDDExeBufCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->cbDDExeBufCallbacks;
28 This->HalInfo.lpDDPaletteCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->cbDDPaletteCallbacks;
29 This->DirectDrawGlobal.lpD3DHALCallbacks = (ULONG_PTR)HeapAlloc(GetProcessHeap(), 0, sizeof(D3DHAL_CALLBACKS));
30 This->DirectDrawGlobal.lpD3DGlobalDriverData = (ULONG_PTR)HeapAlloc(GetProcessHeap(), 0, sizeof(D3DHAL_GLOBALDRIVERDATA));
31
32 /* fill the sizeofs */
33 This->HalInfo.dwSize = sizeof(DDHALINFO);
34 This->HalInfo.lpDDCallbacks->dwSize = sizeof(DDHAL_DDCALLBACKS);
35 This->HalInfo.lpDDSurfaceCallbacks->dwSize = sizeof(DDHAL_DDSURFACECALLBACKS);
36 This->HalInfo.lpDDPaletteCallbacks->dwSize = sizeof(DDHAL_DDPALETTECALLBACKS);
37 This->HalInfo.lpDDExeBufCallbacks->dwSize = sizeof(DDHAL_DDEXEBUFCALLBACKS);
38 ((LPD3DHAL_CALLBACKS)This->DirectDrawGlobal.lpD3DHALCallbacks)->dwSize = sizeof(D3DHAL_CALLBACKS);
39 ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->dwSize = sizeof(D3DHAL_GLOBALDRIVERDATA);
40
41 /* query all kinds of infos from the driver */
42 if(!DdQueryDirectDrawObject (
43 &This->DirectDrawGlobal,
44 &This->HalInfo,
45 This->HalInfo.lpDDCallbacks,
46 This->HalInfo.lpDDSurfaceCallbacks,
47 This->HalInfo.lpDDPaletteCallbacks,
48 (LPD3DHAL_CALLBACKS)This->DirectDrawGlobal.lpD3DHALCallbacks,
49 (LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData,
50 This->HalInfo.lpDDExeBufCallbacks,
51 NULL,
52 NULL,
53 NULL ))
54 {
55 OutputDebugString(L"First DdQueryDirectDrawObject failed");
56 return 1;
57 }
58
59 /* ms wants us to call that function twice */
60 This->HalInfo.vmiData.pvmList = HeapAlloc(GetProcessHeap(), 0, sizeof(VIDMEM) * This->HalInfo.vmiData.dwNumHeaps);
61 This->DirectDrawGlobal.lpdwFourCC = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * This->HalInfo.ddCaps.dwNumFourCCCodes);
62 This->DirectDrawGlobal.lpZPixelFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDPIXELFORMAT) * This->DirectDrawGlobal.dwNumZPixelFormats);
63 ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDSURFACEDESC) * ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->dwNumTextureFormats);
64
65 if(!DdQueryDirectDrawObject (
66 &This->DirectDrawGlobal,
67 &This->HalInfo,
68 This->HalInfo.lpDDCallbacks,
69 This->HalInfo.lpDDSurfaceCallbacks,
70 This->HalInfo.lpDDPaletteCallbacks,
71 (LPD3DHAL_CALLBACKS)This->DirectDrawGlobal.lpD3DHALCallbacks,
72 (LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData,
73 This->HalInfo.lpDDExeBufCallbacks,
74 ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats,
75 This->DirectDrawGlobal.lpdwFourCC,
76 This->HalInfo.vmiData.pvmList
77 ))
78 {
79 OutputDebugString(L"Second DdQueryDirectDrawObject failed");
80 return 1;
81 }
82
83 /* Copy HalInfo to DirectDrawGlobal */
84
85 /* have not check where it should go into yet
86 LPDDHAL_DDCALLBACKS lpDDCallbacks;
87 LPDDHAL_DDSURFACECALLBACKS lpDDSurfaceCallbacks;
88 LPDDHAL_DDPALETTECALLBACKS lpDDPaletteCallbacks;
89 */
90
91 RtlCopyMemory(&This->DirectDrawGlobal.vmiData,&This->HalInfo.vmiData,sizeof(VIDMEMINFO));
92 RtlCopyMemory(&This->DirectDrawGlobal.ddCaps,&This->HalInfo.ddCaps,sizeof(DDCORECAPS));
93 This->DirectDrawGlobal.dwMonitorFrequency = This->HalInfo.dwMonitorFrequency;
94
95 /* have not check where it should go into yet
96 LPDDHAL_GETDRIVERINFO GetDriverInfo;
97 */
98
99 This->DirectDrawGlobal.dwModeIndex = This->HalInfo.dwModeIndex;
100
101 /* have not check where it should go into yet
102 LPDWORD lpdwFourCC;
103 */
104
105 This->DirectDrawGlobal.dwNumModes = This->HalInfo.dwNumModes;
106 This->DirectDrawGlobal.lpModeInfo = This->HalInfo.lpModeInfo;
107
108 /* have not check where it should go into yet
109 DWORD dwFlags;
110 */
111
112 /* Unsure which of these two for lpPDevice
113 This->DirectDrawGlobal.dwPDevice = This->HalInfo.lpPDevice;
114 This->lpDriverHandle = This->HalInfo.lpPDevice;
115 */
116
117 This->DirectDrawGlobal.hInstance = This->HalInfo.hInstance;
118
119 /* have not check where it should go into yet
120 ULONG_PTR lpD3DGlobalDriverData;
121 ULONG_PTR lpD3DHALCallbacks;
122 LPDDHAL_DDEXEBUFCALLBACKS lpDDExeBufCallbacks;
123 */
124
125
126
127 This->DirectDrawGlobal.lpDDCBtmp->HALDD = This->DirectDrawGlobal.lpDDCBtmp->cbDDCallbacks;
128 This->DirectDrawGlobal.lpDDCBtmp->HALDDSurface = This->DirectDrawGlobal.lpDDCBtmp->cbDDSurfaceCallbacks;
129 This->DirectDrawGlobal.lpDDCBtmp->HALDDExeBuf = This->DirectDrawGlobal.lpDDCBtmp->cbDDExeBufCallbacks;
130 This->DirectDrawGlobal.lpDDCBtmp->HALDDPalette = This->DirectDrawGlobal.lpDDCBtmp->cbDDPaletteCallbacks;
131
132 return DD_OK;
133 }
134
135 HRESULT Hal_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface)
136 {
137 return DD_OK;
138 }
139
140 VOID Hal_DirectDraw_Release (LPDIRECTDRAW7 iface)
141 {
142 IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
143
144 DdDeleteDirectDrawObject (&This->DirectDrawGlobal);
145
146 if(This->HalInfo.vmiData.pvmList)
147 HeapFree(GetProcessHeap(), 0, This->HalInfo.vmiData.pvmList);
148 if(This->DirectDrawGlobal.lpdwFourCC)
149 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpdwFourCC);
150 if(This->DirectDrawGlobal.lpZPixelFormats)
151 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpZPixelFormats);
152 if(((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats)
153 HeapFree(GetProcessHeap(), 0, ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats);
154
155 if(This->DirectDrawGlobal.lpDDCBtmp)
156 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpDDCBtmp);
157 if(This->DirectDrawGlobal.lpD3DHALCallbacks)
158 HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DHALCallbacks);
159 if(This->DirectDrawGlobal.lpD3DGlobalDriverData)
160 HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DGlobalDriverData);
161 }