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