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