* Made it possible to include both d3d9types.h and ddrawgdi.h at the same time
[reactos.git] / reactos / dll / directx / ddraw / startup.c
1 /* $Id: main.c 21434 2006-04-01 19:12:56Z greatlrd $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: lib/ddraw/ddraw.c
6 * PURPOSE: DirectDraw Library
7 * PROGRAMMER: Magnus Olsen (greatlrd)
8 *
9 */
10
11 #include "rosdraw.h"
12
13 DDRAWI_DIRECTDRAW_GBL ddgbl;
14 DDRAWI_DDRAWSURFACE_GBL ddSurfGbl;
15
16 WCHAR classname[128];
17 WNDCLASSW wnd_class;
18
19
20 HRESULT WINAPI
21 Create_DirectDraw (LPGUID pGUID, LPDIRECTDRAW* pIface,
22 REFIID id, BOOL reenable)
23 {
24 LPDDRAWI_DIRECTDRAW_INT This;
25
26 DX_WINDBG_trace();
27
28 if ((IsBadReadPtr(pIface,sizeof(LPDIRECTDRAW))) ||
29 (IsBadWritePtr(pIface,sizeof(LPDIRECTDRAW))))
30 {
31 return DDERR_INVALIDPARAMS;
32 }
33
34 This = (LPDDRAWI_DIRECTDRAW_INT)*pIface;
35
36 /* fixme linking too second link when we shall not doing it */
37 if (IsBadReadPtr(This,sizeof(LPDIRECTDRAW)))
38 {
39 /* We do not have a DirectDraw interface, we need alloc it*/
40 LPDDRAWI_DIRECTDRAW_INT memThis;
41
42 DX_STUB_str("1. no linking\n");
43
44 DxHeapMemAlloc(memThis, sizeof(DDRAWI_DIRECTDRAW_INT));
45 if (memThis == NULL)
46 {
47 return DDERR_OUTOFMEMORY;
48 }
49
50 This = memThis;
51
52 /* Fixme release memory alloc if we fail */
53
54 DxHeapMemAlloc(This->lpLcl, sizeof(DDRAWI_DIRECTDRAW_LCL));
55 if (This->lpLcl == NULL)
56 {
57 return DDERR_OUTOFMEMORY;
58 }
59 }
60 else
61 {
62 /* We got the DirectDraw interface alloc and we need create the link */
63 LPDDRAWI_DIRECTDRAW_INT newThis;
64
65 DX_STUB_str("2.linking\n");
66
67 /* step 1.Alloc the new DDRAWI_DIRECTDRAW_INT for the lnking */
68 DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT));
69 if (newThis == NULL)
70 {
71 return DDERR_OUTOFMEMORY;
72 }
73
74 /* step 2 check if it not DDCREATE_HARDWAREONLY we got if so we fail */
75 if ((pGUID) && (pGUID != (LPGUID)DDCREATE_HARDWAREONLY))
76 {
77 if (pGUID !=NULL)
78 {
79 This = newThis;
80 return DDERR_INVALIDDIRECTDRAWGUID;
81 }
82 }
83
84 /* step 3 do the link the old interface are store in the new one */
85 newThis->lpLink = This;
86
87 /* step 4 we need create new local directdraw struct for the new linked interface */
88 DxHeapMemAlloc(newThis->lpLcl, sizeof(DDRAWI_DIRECTDRAW_LCL));
89 if (newThis->lpLcl == NULL)
90 {
91 This = newThis;
92 return DDERR_OUTOFMEMORY;
93 }
94
95 This = newThis;
96 }
97
98 This->lpLcl->lpGbl = &ddgbl;
99
100 *pIface = (LPDIRECTDRAW)This;
101
102 /* Get right interface we whant */
103
104 This->lpVtbl = 0;
105 if (IsEqualGUID(&IID_IDirectDraw7, id))
106 {
107 /* DirectDraw7 Vtable */
108 This->lpVtbl = &DirectDraw7_Vtable;
109 This->lpLcl->dwLocalFlags = This->lpLcl->dwLocalFlags + DDRAWILCL_DIRECTDRAW7;
110 *pIface = (LPDIRECTDRAW)&This->lpVtbl;
111 Main_DirectDraw_AddRef(This);
112 }
113 else if (IsEqualGUID(&IID_IDirectDraw4, id))
114 {
115 /* DirectDraw4 Vtable */
116 This->lpVtbl = &DirectDraw4_Vtable;
117 *pIface = (LPDIRECTDRAW)&This->lpVtbl;
118 Main_DirectDraw_AddRef(This);
119 }
120 else if (IsEqualGUID(&IID_IDirectDraw2, id))
121 {
122 /* DirectDraw2 Vtable */
123 This->lpVtbl = &DirectDraw2_Vtable;
124 *pIface = (LPDIRECTDRAW)&This->lpVtbl;
125 Main_DirectDraw_AddRef(This);
126 }
127 else if (IsEqualGUID(&IID_IDirectDraw, id))
128 {
129 /* DirectDraw Vtable */
130 This->lpVtbl = &DirectDraw_Vtable;
131 *pIface = (LPDIRECTDRAW)&This->lpVtbl;
132 Main_DirectDraw_AddRef(This);
133 }
134
135 if ( This->lpVtbl != 0)
136 {
137 DX_STUB_str("Got iface\n");
138
139 if (StartDirectDraw((LPDIRECTDRAW)This, pGUID, FALSE) == DD_OK);
140 {
141 /*
142 RtlZeroMemory(&wnd_class, sizeof(wnd_class));
143 wnd_class.style = CS_HREDRAW | CS_VREDRAW;
144 wnd_class.lpfnWndProc = DefWindowProcW;
145 wnd_class.cbClsExtra = 0;
146 wnd_class.cbWndExtra = 0;
147 wnd_class.hInstance = GetModuleHandleW(0);
148 wnd_class.hIcon = 0;
149 wnd_class.hCursor = 0;
150 wnd_class.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
151 wnd_class.lpszMenuName = NULL;
152 wnd_class.lpszClassName = classname;
153 if(!RegisterClassW(&wnd_class))
154 {
155 DX_STUB_str("DDERR_GENERIC");
156 return DDERR_GENERIC;
157 }
158 */
159 This->lpLcl->hDD = ddgbl.hDD;
160 return DD_OK;
161 }
162 }
163
164 return DDERR_INVALIDPARAMS;
165 }
166
167
168 HRESULT WINAPI
169 StartDirectDraw(LPDIRECTDRAW iface, LPGUID lpGuid, BOOL reenable)
170 {
171 LPDDRAWI_DIRECTDRAW_INT This = (LPDDRAWI_DIRECTDRAW_INT)iface;
172 DWORD hal_ret = DD_FALSE;
173 DWORD hel_ret = DD_FALSE;
174 DWORD devicetypes = 0;
175 DWORD dwFlags = 0;
176
177
178 DX_WINDBG_trace();
179
180
181 /*
182 * ddgbl.dwPDevice is not longer in use in windows 2000 and higher
183 * I am using it for device type
184 * devicetypes = 1 : both hal and hel are enable
185 * devicetypes = 2 : both hal are enable
186 * devicetypes = 3 : both hel are enable
187 * devicetypes = 4 :loading a guid drv from the register
188 */
189
190 ddgbl.lpDriverHandle = &ddgbl;
191 ddgbl.hDDVxd = -1;
192
193
194
195
196 if (reenable == FALSE)
197 {
198 if ((!IsBadReadPtr(This->lpLink,sizeof(LPDIRECTDRAW))) && (This->lpLink == NULL))
199 {
200 RtlZeroMemory(&ddgbl, sizeof(DDRAWI_DIRECTDRAW_GBL));
201 This->lpLcl->lpGbl->dwRefCnt++;
202 if (ddgbl.lpDDCBtmp == NULL)
203 {
204 // LPDDHAL_CALLBACKS
205 DxHeapMemAlloc( ddgbl.lpDDCBtmp , sizeof(DDHAL_CALLBACKS));
206 if (ddgbl.lpDDCBtmp == NULL)
207 {
208 DX_STUB_str("Out of memmory\n");
209 return DD_FALSE;
210 }
211 }
212 }
213
214 DxHeapMemAlloc(ddgbl.lpModeInfo, sizeof(DDHALMODEINFO));
215 if (!ddgbl.lpModeInfo)
216 {
217 return DDERR_OUTOFMEMORY;
218 }
219
220 }
221 /* Windows handler are by set of SetCooperLevel
222 * so do not set it
223 */
224
225 if (reenable == FALSE)
226 {
227 if (lpGuid == NULL)
228 {
229 devicetypes= 1;
230
231 /* Create HDC for default, hal and hel driver */
232 // This->lpLcl->hWnd = (ULONG_PTR) GetActiveWindow();
233 This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
234
235 /* cObsolete is undoc in msdn it being use in CreateDCA */
236 RtlCopyMemory(&ddgbl.cObsolete,&"DISPLAY",7);
237 RtlCopyMemory(&ddgbl.cDriverName,&"DISPLAY",7);
238 dwFlags |= DDRAWI_DISPLAYDRV | DDRAWI_GDIDRV;
239
240
241 }
242 else if (lpGuid == (LPGUID) DDCREATE_HARDWAREONLY)
243 {
244 devicetypes = 2;
245 /* Create HDC for default, hal driver */
246 // This->lpLcl->hWnd =(ULONG_PTR) GetActiveWindow();
247 This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
248
249 /* cObsolete is undoc in msdn it being use in CreateDCA */
250 RtlCopyMemory(&ddgbl.cObsolete,&"DISPLAY",7);
251 RtlCopyMemory(&ddgbl.cDriverName,&"DISPLAY",7);
252 dwFlags |= DDRAWI_DISPLAYDRV | DDRAWI_GDIDRV;
253 }
254 else if (lpGuid == (LPGUID) DDCREATE_EMULATIONONLY)
255 {
256 devicetypes = 3;
257
258 /* Create HDC for default, hal and hel driver */
259 //This->lpLcl->hWnd = (ULONG_PTR) GetActiveWindow();
260 This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
261
262 /* cObsolete is undoc in msdn it being use in CreateDCA */
263 RtlCopyMemory(&ddgbl.cObsolete,&"DISPLAY",7);
264 RtlCopyMemory(&ddgbl.cDriverName,&"DISPLAY",7);
265
266 dwFlags |= DDRAWI_DISPLAYDRV | DDRAWI_GDIDRV;
267 }
268 else
269 {
270 /* FIXME : need getting driver from the GUID that have been pass in from
271 * the register. we do not support that yet
272 */
273 devicetypes = 4;
274 //This->lpLcl->hDC = (ULONG_PTR) NULL ;
275 //This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
276 }
277
278 /*
279 if ( (HDC)This->lpLcl->hDC == NULL)
280 {
281 DX_STUB_str("DDERR_OUTOFMEMORY\n");
282 return DDERR_OUTOFMEMORY ;
283 }
284 */
285 }
286
287 This->lpLcl->lpDDCB = ddgbl.lpDDCBtmp;
288
289 /* Startup HEL and HAL */
290 This->lpLcl->lpDDCB = This->lpLcl->lpGbl->lpDDCBtmp;
291 This->lpLcl->dwProcessId = GetCurrentProcessId();
292
293 switch (devicetypes)
294 {
295 case 2:
296 hal_ret = StartDirectDrawHal(iface, reenable);
297 This->lpLcl->lpDDCB->HELDD.dwFlags = 0;
298 break;
299
300 case 3:
301 hel_ret = StartDirectDrawHel(iface, reenable);
302 This->lpLcl->lpDDCB->HALDD.dwFlags = 0;
303 break;
304
305 default:
306 hal_ret = StartDirectDrawHal(iface, reenable);
307 hel_ret = StartDirectDrawHel(iface, reenable);
308 }
309
310 if (hal_ret!=DD_OK)
311 {
312 if (hel_ret!=DD_OK)
313 {
314 DX_STUB_str("DDERR_NODIRECTDRAWSUPPORT\n");
315 return DDERR_NODIRECTDRAWSUPPORT;
316 }
317 dwFlags |= DDRAWI_NOHARDWARE;
318 }
319
320 if (hel_ret!=DD_OK)
321 {
322 dwFlags |= DDRAWI_NOEMULATION;
323
324 }
325 else
326 {
327 dwFlags |= DDRAWI_EMULATIONINITIALIZED;
328 }
329
330 /* Fill some basic info for Surface */
331 This->lpLcl->lpGbl->dwFlags = This->lpLcl->lpGbl->dwFlags | dwFlags | DDRAWI_ATTACHEDTODESKTOP;
332 This->lpLcl->lpDDCB = This->lpLcl->lpGbl->lpDDCBtmp;
333 This->lpLcl->hDD = ddgbl.hDD;
334
335 ddgbl.rectDevice.top = 0;
336 ddgbl.rectDevice.left = 0;
337 ddgbl.rectDevice.right = ddgbl.vmiData.dwDisplayWidth;
338 ddgbl.rectDevice.bottom = ddgbl.vmiData.dwDisplayHeight;
339
340 ddgbl.rectDesktop.top = 0;
341 ddgbl.rectDesktop.left = 0;
342 ddgbl.rectDesktop.right = ddgbl.vmiData.dwDisplayWidth;
343 ddgbl.rectDesktop.bottom = ddgbl.vmiData.dwDisplayHeight;
344
345 ddgbl.dwMonitorFrequency = GetDeviceCaps(GetWindowDC(NULL),VREFRESH);
346 ddgbl.lpModeInfo->dwWidth = ddgbl.vmiData.dwDisplayWidth;
347 ddgbl.lpModeInfo->dwHeight = ddgbl.vmiData.dwDisplayHeight;
348 ddgbl.lpModeInfo->dwBPP = ddgbl.vmiData.ddpfDisplay.dwRGBBitCount;
349 ddgbl.lpModeInfo->lPitch = ddgbl.vmiData.lDisplayPitch;
350 ddgbl.lpModeInfo->wRefreshRate = ddgbl.dwMonitorFrequency;
351 ddgbl.lpModeInfo->dwRBitMask = ddgbl.vmiData.ddpfDisplay.dwRBitMask;
352 ddgbl.lpModeInfo->dwGBitMask = ddgbl.vmiData.ddpfDisplay.dwGBitMask;
353 ddgbl.lpModeInfo->dwBBitMask = ddgbl.vmiData.ddpfDisplay.dwBBitMask;
354 ddgbl.lpModeInfo->dwAlphaBitMask = ddgbl.vmiData.ddpfDisplay.dwRGBAlphaBitMask;
355
356 return DD_OK;
357 }
358
359
360 HRESULT WINAPI
361 StartDirectDrawHel(LPDIRECTDRAW iface, BOOL reenable)
362 {
363 LPDDRAWI_DIRECTDRAW_INT This = (LPDDRAWI_DIRECTDRAW_INT)iface;
364
365 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.CanCreateSurface = HelDdCanCreateSurface;
366 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.CreateSurface = HelDdCreateSurface;
367 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.CreatePalette = HelDdCreatePalette;
368 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.DestroyDriver = HelDdDestroyDriver;
369 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.FlipToGDISurface = HelDdFlipToGDISurface;
370 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.GetScanLine = HelDdGetScanLine;
371 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.SetColorKey = HelDdSetColorKey;
372 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.SetExclusiveMode = HelDdSetExclusiveMode;
373 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.SetMode = HelDdSetMode;
374 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.WaitForVerticalBlank = HelDdWaitForVerticalBlank;
375
376 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.dwFlags = DDHAL_CB32_CANCREATESURFACE |
377 DDHAL_CB32_CREATESURFACE |
378 DDHAL_CB32_CREATEPALETTE |
379 DDHAL_CB32_DESTROYDRIVER |
380 DDHAL_CB32_FLIPTOGDISURFACE |
381 DDHAL_CB32_GETSCANLINE |
382 DDHAL_CB32_SETCOLORKEY |
383 DDHAL_CB32_SETEXCLUSIVEMODE |
384 DDHAL_CB32_SETMODE |
385 DDHAL_CB32_WAITFORVERTICALBLANK ;
386
387 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.dwSize = sizeof(This->lpLcl->lpDDCB->HELDD);
388
389 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.AddAttachedSurface = HelDdSurfAddAttachedSurface;
390 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.Blt = HelDdSurfBlt;
391 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.DestroySurface = HelDdSurfDestroySurface;
392 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.Flip = HelDdSurfFlip;
393 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.GetBltStatus = HelDdSurfGetBltStatus;
394 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.GetFlipStatus = HelDdSurfGetFlipStatus;
395 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.Lock = HelDdSurfLock;
396 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.reserved4 = HelDdSurfreserved4;
397 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.SetClipList = HelDdSurfSetClipList;
398 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.SetColorKey = HelDdSurfSetColorKey;
399 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.SetOverlayPosition = HelDdSurfSetOverlayPosition;
400 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.SetPalette = HelDdSurfSetPalette;
401 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.Unlock = HelDdSurfUnlock;
402 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.UpdateOverlay = HelDdSurfUpdateOverlay;
403 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.dwFlags = DDHAL_SURFCB32_ADDATTACHEDSURFACE |
404 DDHAL_SURFCB32_BLT |
405 DDHAL_SURFCB32_DESTROYSURFACE |
406 DDHAL_SURFCB32_FLIP |
407 DDHAL_SURFCB32_GETBLTSTATUS |
408 DDHAL_SURFCB32_GETFLIPSTATUS |
409 DDHAL_SURFCB32_LOCK |
410 DDHAL_SURFCB32_RESERVED4 |
411 DDHAL_SURFCB32_SETCLIPLIST |
412 DDHAL_SURFCB32_SETCOLORKEY |
413 DDHAL_SURFCB32_SETOVERLAYPOSITION |
414 DDHAL_SURFCB32_SETPALETTE |
415 DDHAL_SURFCB32_UNLOCK |
416 DDHAL_SURFCB32_UPDATEOVERLAY;
417
418 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.dwSize = sizeof(This->lpLcl->lpDDCB->HELDDSurface);
419
420 /*
421 This->lpLcl->lpDDCB->HELDDPalette.DestroyPalette = HelDdPalDestroyPalette;
422 This->lpLcl->lpDDCB->HELDDPalette.SetEntries = HelDdPalSetEntries;
423 This->lpLcl->lpDDCB->HELDDPalette.dwSize = sizeof(This->lpLcl->lpDDCB->HELDDPalette);
424 */
425
426 /*
427 This->lpLcl->lpDDCB->HELDDExeBuf.CanCreateExecuteBuffer = HelDdExeCanCreateExecuteBuffer;
428 This->lpLcl->lpDDCB->HELDDExeBuf.CreateExecuteBuffer = HelDdExeCreateExecuteBuffer;
429 This->lpLcl->lpDDCB->HELDDExeBuf.DestroyExecuteBuffer = HelDdExeDestroyExecuteBuffer;
430 This->lpLcl->lpDDCB->HELDDExeBuf.LockExecuteBuffer = HelDdExeLockExecuteBuffer;
431 This->lpLcl->lpDDCB->HELDDExeBuf.UnlockExecuteBuffer = HelDdExeUnlockExecuteBuffer;
432 */
433
434 return DD_OK;
435 }
436
437
438 HRESULT WINAPI
439 StartDirectDrawHal(LPDIRECTDRAW iface, BOOL reenable)
440 {
441 LPDWORD mpFourCC = NULL;
442 DDHALINFO mHALInfo;
443 BOOL newmode = FALSE;
444 LPDDSURFACEDESC mpTextures;
445 D3DHAL_CALLBACKS mD3dCallbacks;
446 D3DHAL_GLOBALDRIVERDATA mD3dDriverData;
447 DDHAL_DDEXEBUFCALLBACKS mD3dBufferCallbacks;
448 LPDDRAWI_DIRECTDRAW_INT This = (LPDDRAWI_DIRECTDRAW_INT)iface;
449 DDHAL_GETDRIVERINFODATA DdGetDriverInfo = { 0 };
450
451 DX_WINDBG_trace();
452
453 RtlZeroMemory(&mHALInfo, sizeof(DDHALINFO));
454 RtlZeroMemory(&mD3dCallbacks, sizeof(D3DHAL_CALLBACKS));
455 RtlZeroMemory(&mD3dDriverData, sizeof(D3DHAL_GLOBALDRIVERDATA));
456 RtlZeroMemory(&mD3dBufferCallbacks, sizeof(DDHAL_DDEXEBUFCALLBACKS));
457
458 if (reenable == FALSE)
459 {
460 if (ddgbl.lpDDCBtmp == NULL)
461 {
462 DxHeapMemAlloc(ddgbl.lpDDCBtmp, sizeof(DDHAL_CALLBACKS));
463 if ( ddgbl.lpDDCBtmp == NULL)
464 {
465 return DD_FALSE;
466 }
467 }
468 }
469 else
470 {
471 RtlZeroMemory(ddgbl.lpDDCBtmp,sizeof(DDHAL_CALLBACKS));
472 }
473
474 /*
475 * Startup DX HAL step one of three
476 */
477 if (!DdCreateDirectDrawObject(This->lpLcl->lpGbl, (HDC)This->lpLcl->hDC))
478 {
479 DxHeapMemFree(ddgbl.lpDDCBtmp);
480 return DD_FALSE;
481 }
482
483 /* Some card disable the dx after it have been created so
484 * we are force reanble it
485 */
486 if (!DdReenableDirectDrawObject(This->lpLcl->lpGbl, &newmode))
487 {
488 DxHeapMemFree(ddgbl.lpDDCBtmp);
489 return DD_FALSE;
490 }
491
492 if (!DdQueryDirectDrawObject(This->lpLcl->lpGbl,
493 &mHALInfo,
494 &ddgbl.lpDDCBtmp->HALDD,
495 &ddgbl.lpDDCBtmp->HALDDSurface,
496 &ddgbl.lpDDCBtmp->HALDDPalette,
497 &mD3dCallbacks,
498 &mD3dDriverData,
499 &mD3dBufferCallbacks,
500 NULL,
501 mpFourCC,
502 NULL))
503 {
504 DxHeapMemFree(This->lpLcl->lpGbl->lpModeInfo);
505 DxHeapMemFree(ddgbl.lpDDCBtmp);
506 // FIXME Close DX first and second call
507 return DD_FALSE;
508 }
509
510 /* Alloc mpFourCC */
511 if (This->lpLcl->lpGbl->lpdwFourCC != NULL)
512 {
513 DxHeapMemFree(This->lpLcl->lpGbl->lpdwFourCC);
514 }
515
516 if (mHALInfo.ddCaps.dwNumFourCCCodes > 0 )
517 {
518
519 DxHeapMemAlloc(mpFourCC, sizeof(DWORD) * (mHALInfo.ddCaps.dwNumFourCCCodes + 2));
520
521 if (mpFourCC == NULL)
522 {
523 DxHeapMemFree(ddgbl.lpDDCBtmp);
524 // FIXME Close DX first and second call
525 return DD_FALSE;
526 }
527 }
528
529 /* Alloc mpTextures */
530 #if 0
531 DX_STUB_str("1 Here\n");
532
533 if (This->lpLcl->lpGbl->texture != NULL)
534 {
535 DxHeapMemFree(This->lpLcl->lpGbl->texture;
536 }
537
538 mpTextures = NULL;
539 if (mD3dDriverData.dwNumTextureFormats > 0)
540 {
541 mpTextures = (DDSURFACEDESC*) DxHeapMemAlloc(sizeof(DDSURFACEDESC) * mD3dDriverData.dwNumTextureFormats);
542 if (mpTextures == NULL)
543 {
544 DxHeapMemFree(mpFourCC);
545 DxHeapMemFree(ddgbl.lpDDCBtmp);
546 // FIXME Close DX first and second call
547 }
548 }
549
550 DX_STUB_str("2 Here\n");
551
552 #else
553 mpTextures = NULL;
554 #endif
555
556
557 /* Get all basic data from the driver */
558 if (!DdQueryDirectDrawObject(
559 This->lpLcl->lpGbl,
560 &mHALInfo,
561 &ddgbl.lpDDCBtmp->HALDD,
562 &ddgbl.lpDDCBtmp->HALDDSurface,
563 &ddgbl.lpDDCBtmp->HALDDPalette,
564 &mD3dCallbacks,
565 &mD3dDriverData,
566 &ddgbl.lpDDCBtmp->HALDDExeBuf,
567 (DDSURFACEDESC*)mpTextures,
568 mpFourCC,
569 NULL))
570 {
571 DxHeapMemFree(mpFourCC);
572 DxHeapMemFree(mpTextures);
573 DxHeapMemFree(ddgbl.lpDDCBtmp);
574 // FIXME Close DX first and second call
575 return DD_FALSE;
576 }
577
578 memcpy(&ddgbl.vmiData, &mHALInfo.vmiData,sizeof(VIDMEMINFO));
579
580
581 memcpy(&ddgbl.ddCaps, &mHALInfo.ddCaps,sizeof(DDCORECAPS));
582
583 This->lpLcl->lpGbl->dwNumFourCC = mHALInfo.ddCaps.dwNumFourCCCodes;
584 This->lpLcl->lpGbl->lpdwFourCC = mpFourCC;
585 // This->lpLcl->lpGbl->dwMonitorFrequency = mHALInfo.dwMonitorFrequency; // 0
586 This->lpLcl->lpGbl->dwModeIndex = mHALInfo.dwModeIndex;
587 // This->lpLcl->lpGbl->dwNumModes = mHALInfo.dwNumModes;
588 // This->lpLcl->lpGbl->lpModeInfo = mHALInfo.lpModeInfo;
589
590 /* FIXME convert mpTextures to DDHALMODEINFO */
591 // DxHeapMemFree( mpTextures);
592
593 /* FIXME D3D setup mD3dCallbacks and mD3dDriverData */
594
595
596
597
598 if (mHALInfo.dwFlags & DDHALINFO_GETDRIVERINFOSET)
599 {
600 DdGetDriverInfo.dwSize = sizeof (DDHAL_GETDRIVERINFODATA);
601 DdGetDriverInfo.guidInfo = GUID_MiscellaneousCallbacks;
602 DdGetDriverInfo.lpvData = (PVOID)&ddgbl.lpDDCBtmp->HALDDMiscellaneous;
603 DdGetDriverInfo.dwExpectedSize = sizeof (DDHAL_DDMISCELLANEOUSCALLBACKS);
604
605 if(mHALInfo.GetDriverInfo (&DdGetDriverInfo) == DDHAL_DRIVER_NOTHANDLED || DdGetDriverInfo.ddRVal != DD_OK)
606 {
607 DxHeapMemFree(mpFourCC);
608 DxHeapMemFree(mpTextures);
609 DxHeapMemFree(ddgbl.lpDDCBtmp);
610 // FIXME Close DX fristcall and second call
611 return DD_FALSE;
612 }
613
614 RtlZeroMemory(&DdGetDriverInfo, sizeof(DDHAL_GETDRIVERINFODATA));
615 DdGetDriverInfo.dwSize = sizeof (DDHAL_GETDRIVERINFODATA);
616 DdGetDriverInfo.guidInfo = GUID_Miscellaneous2Callbacks;
617
618 /* FIXME
619 DdGetDriverInfo.lpvData = (PVOID)&ddgbl.lpDDCBtmp->HALDDMiscellaneous;
620 DdGetDriverInfo.dwExpectedSize = sizeof (DDHAL_DDMISCELLANEOUS2CALLBACKS);
621
622 if(mHALInfo.GetDriverInfo (&DdGetDriverInfo) == DDHAL_DRIVER_NOTHANDLED || DdGetDriverInfo.ddRVal != DD_OK)
623 {
624 DxHeapMemFree(mpFourCC);
625 DxHeapMemFree(mpTextures);
626 DxHeapMemFree(ddgbl.lpDDCBtmp);
627 // FIXME Close DX fristcall and second call
628 return DD_FALSE;
629 }
630 DD_MISCELLANEOUS2CALLBACKS
631 {
632 DWORD dwSize;
633 DWORD dwFlags;
634 PDD_ALPHABLT AlphaBlt; // unsuse acoding msdn and always set to NULL
635 PDD_CREATESURFACEEX CreateSurfaceEx;
636 PDD_GETDRIVERSTATE GetDriverState;
637 PDD_DESTROYDDLOCAL DestroyDDLocal;
638 }
639 DDHAL_MISC2CB32_CREATESURFACEEX
640 DDHAL_MISC2CB32_GETDRIVERSTATE
641 DDHAL_MISC2CB32_DESTROYDDLOCAL
642 */
643 }
644
645 if (mHALInfo.dwFlags & DDHALINFO_GETDRIVERINFO2)
646 {
647 This->lpLcl->lpGbl->dwFlags = This->lpLcl->lpGbl->dwFlags | DDRAWI_DRIVERINFO2;
648 }
649
650
651 return DD_OK;
652 }