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