fixing more value that are not beig fill in, now we getting back the freq
[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 DEVMODE devmode;
178
179 DX_WINDBG_trace();
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 if (reenable == FALSE)
194 {
195 if ((!IsBadReadPtr(This->lpLink,sizeof(LPDIRECTDRAW))) && (This->lpLink == NULL))
196 {
197 RtlZeroMemory(&ddgbl, sizeof(DDRAWI_DIRECTDRAW_GBL));
198 This->lpLcl->lpGbl->dwRefCnt++;
199 if (ddgbl.lpDDCBtmp == NULL)
200 {
201 // LPDDHAL_CALLBACKS
202 DxHeapMemAlloc( ddgbl.lpDDCBtmp , sizeof(DDHAL_CALLBACKS));
203 if (ddgbl.lpDDCBtmp == NULL)
204 {
205 DX_STUB_str("Out of memmory\n");
206 return DD_FALSE;
207 }
208 }
209 }
210 }
211 /* Windows handler are by set of SetCooperLevel
212 * so do not set it
213 */
214
215 if (reenable == FALSE)
216 {
217 if (lpGuid == NULL)
218 {
219 DX_STUB_str("lpGuid == NULL\n");
220 devicetypes= 1;
221
222 /* Create HDC for default, hal and hel driver */
223 // This->lpLcl->hWnd = (ULONG_PTR) GetActiveWindow();
224 This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
225
226 /* cObsolete is undoc in msdn it being use in CreateDCA */
227 RtlCopyMemory(&ddgbl.cObsolete,&"DISPLAY",7);
228 RtlCopyMemory(&ddgbl.cDriverName,&"DISPLAY",7);
229 dwFlags |= DDRAWI_DISPLAYDRV | DDRAWI_GDIDRV;
230
231
232 }
233 else if (lpGuid == (LPGUID) DDCREATE_HARDWAREONLY)
234 {
235 devicetypes = 2;
236 /* Create HDC for default, hal driver */
237 // This->lpLcl->hWnd =(ULONG_PTR) GetActiveWindow();
238 This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
239
240 /* cObsolete is undoc in msdn it being use in CreateDCA */
241 RtlCopyMemory(&ddgbl.cObsolete,&"DISPLAY",7);
242 RtlCopyMemory(&ddgbl.cDriverName,&"DISPLAY",7);
243 dwFlags |= DDRAWI_DISPLAYDRV | DDRAWI_GDIDRV;
244 }
245 else if (lpGuid == (LPGUID) DDCREATE_EMULATIONONLY)
246 {
247 devicetypes = 3;
248
249 /* Create HDC for default, hal and hel driver */
250 //This->lpLcl->hWnd = (ULONG_PTR) GetActiveWindow();
251 This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
252
253 /* cObsolete is undoc in msdn it being use in CreateDCA */
254 RtlCopyMemory(&ddgbl.cObsolete,&"DISPLAY",7);
255 RtlCopyMemory(&ddgbl.cDriverName,&"DISPLAY",7);
256
257 dwFlags |= DDRAWI_DISPLAYDRV | DDRAWI_GDIDRV;
258 }
259 else
260 {
261 /* FIXME : need getting driver from the GUID that have been pass in from
262 * the register. we do not support that yet
263 */
264 devicetypes = 4;
265 //This->lpLcl->hDC = (ULONG_PTR) NULL ;
266 //This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
267 }
268
269 /*
270 if ( (HDC)This->lpLcl->hDC == NULL)
271 {
272 DX_STUB_str("DDERR_OUTOFMEMORY\n");
273 return DDERR_OUTOFMEMORY ;
274 }
275 */
276 }
277
278 This->lpLcl->lpDDCB = ddgbl.lpDDCBtmp;
279
280 /* Startup HEL and HAL */
281 This->lpLcl->lpDDCB = This->lpLcl->lpGbl->lpDDCBtmp;
282 This->lpLcl->dwProcessId = GetCurrentProcessId();
283
284 switch (devicetypes)
285 {
286 case 2:
287 hal_ret = StartDirectDrawHal(iface, reenable);
288 This->lpLcl->lpDDCB->HELDD.dwFlags = 0;
289 break;
290
291 case 3:
292 hel_ret = StartDirectDrawHel(iface, reenable);
293 This->lpLcl->lpDDCB->HALDD.dwFlags = 0;
294 break;
295
296 default:
297 hal_ret = StartDirectDrawHal(iface, reenable);
298 hel_ret = StartDirectDrawHel(iface, reenable);
299 }
300
301 DX_STUB_str("return\n");
302
303 if (hal_ret!=DD_OK)
304 {
305 if (hel_ret!=DD_OK)
306 {
307 DX_STUB_str("DDERR_NODIRECTDRAWSUPPORT\n");
308 return DDERR_NODIRECTDRAWSUPPORT;
309 }
310 dwFlags |= DDRAWI_NOHARDWARE;
311 }
312
313 if (hel_ret!=DD_OK)
314 {
315 dwFlags |= DDRAWI_NOEMULATION;
316
317 }
318 else
319 {
320 dwFlags |= DDRAWI_EMULATIONINITIALIZED;
321 }
322
323 /* Fill some basic info for Surface */
324 This->lpLcl->lpGbl->dwFlags = This->lpLcl->lpGbl->dwFlags | dwFlags | DDRAWI_ATTACHEDTODESKTOP;
325 This->lpLcl->lpDDCB = This->lpLcl->lpGbl->lpDDCBtmp;
326 This->lpLcl->hDD = ddgbl.hDD;
327
328 ddgbl.rectDevice.bottom = 0;
329 ddgbl.rectDevice.left= 0;
330 ddgbl.rectDevice.right = ddgbl.vmiData.dwDisplayWidth;
331 ddgbl.rectDevice.right = ddgbl.vmiData.dwDisplayHeight;
332
333 ddgbl.rectDesktop.bottom = 0;
334 ddgbl.rectDesktop.left= 0;
335 ddgbl.rectDesktop.right = ddgbl.vmiData.dwDisplayWidth;
336 ddgbl.rectDesktop.right = ddgbl.vmiData.dwDisplayHeight;
337
338
339 /* HALINFO always returen false for lpModeInfo */
340 DxHeapMemAlloc(ddgbl.lpModeInfo, sizeof(DDHALMODEINFO));
341 if (!ddgbl.lpModeInfo)
342 {
343 return DDERR_OUTOFMEMORY;
344 }
345
346
347 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode);
348 ddgbl.lpModeInfo->dwWidth = devmode.dmPelsWidth;
349 ddgbl.lpModeInfo->dwHeight = devmode.dmPelsHeight;
350 ddgbl.lpModeInfo->dwBPP = devmode.dmBitsPerPel;
351 ddgbl.lpModeInfo->lPitch = ddgbl.vmiData.lDisplayPitch;
352 ddgbl.lpModeInfo->wRefreshRate = (WORD)devmode.dmDisplayFrequency;
353 ddgbl.lpModeInfo->dwRBitMask = ddgbl.vmiData.ddpfDisplay.dwRBitMask;
354 ddgbl.lpModeInfo->dwGBitMask = ddgbl.vmiData.ddpfDisplay.dwGBitMask;
355 ddgbl.lpModeInfo->dwBBitMask = ddgbl.vmiData.ddpfDisplay.dwBBitMask;
356 ddgbl.lpModeInfo->dwAlphaBitMask = ddgbl.vmiData.ddpfDisplay.dwRGBAlphaBitMask;
357 ddgbl.dwMonitorFrequency = ddgbl.lpModeInfo->wRefreshRate;
358 ddgbl.dwNumModes = 1;
359 ddgbl.dwSaveNumModes = 1;
360
361 DX_STUB_str("DD_OK\n");
362 return DD_OK;
363 }
364
365 HRESULT WINAPI
366 StartDirectDrawHel(LPDIRECTDRAW iface, BOOL reenable)
367 {
368 LPDDRAWI_DIRECTDRAW_INT This = (LPDDRAWI_DIRECTDRAW_INT)iface;
369
370 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.CanCreateSurface = HelDdCanCreateSurface;
371 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.CreateSurface = HelDdCreateSurface;
372 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.CreatePalette = HelDdCreatePalette;
373 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.DestroyDriver = HelDdDestroyDriver;
374 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.FlipToGDISurface = HelDdFlipToGDISurface;
375 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.GetScanLine = HelDdGetScanLine;
376 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.SetColorKey = HelDdSetColorKey;
377 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.SetExclusiveMode = HelDdSetExclusiveMode;
378 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.SetMode = HelDdSetMode;
379 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.WaitForVerticalBlank = HelDdWaitForVerticalBlank;
380
381 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.dwFlags = DDHAL_CB32_CANCREATESURFACE |
382 DDHAL_CB32_CREATESURFACE |
383 DDHAL_CB32_CREATEPALETTE |
384 DDHAL_CB32_DESTROYDRIVER |
385 DDHAL_CB32_FLIPTOGDISURFACE |
386 DDHAL_CB32_GETSCANLINE |
387 DDHAL_CB32_SETCOLORKEY |
388 DDHAL_CB32_SETEXCLUSIVEMODE |
389 DDHAL_CB32_SETMODE |
390 DDHAL_CB32_WAITFORVERTICALBLANK ;
391
392 This->lpLcl->lpGbl->lpDDCBtmp->HELDD.dwSize = sizeof(This->lpLcl->lpDDCB->HELDD);
393
394 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.AddAttachedSurface = HelDdSurfAddAttachedSurface;
395 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.Blt = HelDdSurfBlt;
396 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.DestroySurface = HelDdSurfDestroySurface;
397 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.Flip = HelDdSurfFlip;
398 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.GetBltStatus = HelDdSurfGetBltStatus;
399 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.GetFlipStatus = HelDdSurfGetFlipStatus;
400 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.Lock = HelDdSurfLock;
401 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.reserved4 = HelDdSurfreserved4;
402 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.SetClipList = HelDdSurfSetClipList;
403 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.SetColorKey = HelDdSurfSetColorKey;
404 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.SetOverlayPosition = HelDdSurfSetOverlayPosition;
405 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.SetPalette = HelDdSurfSetPalette;
406 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.Unlock = HelDdSurfUnlock;
407 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.UpdateOverlay = HelDdSurfUpdateOverlay;
408 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.dwFlags = DDHAL_SURFCB32_ADDATTACHEDSURFACE |
409 DDHAL_SURFCB32_BLT |
410 DDHAL_SURFCB32_DESTROYSURFACE |
411 DDHAL_SURFCB32_FLIP |
412 DDHAL_SURFCB32_GETBLTSTATUS |
413 DDHAL_SURFCB32_GETFLIPSTATUS |
414 DDHAL_SURFCB32_LOCK |
415 DDHAL_SURFCB32_RESERVED4 |
416 DDHAL_SURFCB32_SETCLIPLIST |
417 DDHAL_SURFCB32_SETCOLORKEY |
418 DDHAL_SURFCB32_SETOVERLAYPOSITION |
419 DDHAL_SURFCB32_SETPALETTE |
420 DDHAL_SURFCB32_UNLOCK |
421 DDHAL_SURFCB32_UPDATEOVERLAY;
422
423 This->lpLcl->lpGbl->lpDDCBtmp->HELDDSurface.dwSize = sizeof(This->lpLcl->lpDDCB->HELDDSurface);
424
425 /*
426 This->lpLcl->lpDDCB->HELDDPalette.DestroyPalette = HelDdPalDestroyPalette;
427 This->lpLcl->lpDDCB->HELDDPalette.SetEntries = HelDdPalSetEntries;
428 This->lpLcl->lpDDCB->HELDDPalette.dwSize = sizeof(This->lpLcl->lpDDCB->HELDDPalette);
429 */
430
431 /*
432 This->lpLcl->lpDDCB->HELDDExeBuf.CanCreateExecuteBuffer = HelDdExeCanCreateExecuteBuffer;
433 This->lpLcl->lpDDCB->HELDDExeBuf.CreateExecuteBuffer = HelDdExeCreateExecuteBuffer;
434 This->lpLcl->lpDDCB->HELDDExeBuf.DestroyExecuteBuffer = HelDdExeDestroyExecuteBuffer;
435 This->lpLcl->lpDDCB->HELDDExeBuf.LockExecuteBuffer = HelDdExeLockExecuteBuffer;
436 This->lpLcl->lpDDCB->HELDDExeBuf.UnlockExecuteBuffer = HelDdExeUnlockExecuteBuffer;
437 */
438
439 return DD_OK;
440 }
441
442
443 HRESULT WINAPI
444 StartDirectDrawHal(LPDIRECTDRAW iface, BOOL reenable)
445 {
446 LPDWORD mpFourCC = NULL;
447 DDHALINFO mHALInfo;
448 BOOL newmode = FALSE;
449 LPDDSURFACEDESC mpTextures;
450 D3DHAL_CALLBACKS mD3dCallbacks;
451 D3DHAL_GLOBALDRIVERDATA mD3dDriverData;
452 DDHAL_DDEXEBUFCALLBACKS mD3dBufferCallbacks;
453 LPDDRAWI_DIRECTDRAW_INT This = (LPDDRAWI_DIRECTDRAW_INT)iface;
454 DDHAL_GETDRIVERINFODATA DdGetDriverInfo = { 0 };
455
456 DX_WINDBG_trace();
457
458 RtlZeroMemory(&mHALInfo, sizeof(DDHALINFO));
459 RtlZeroMemory(&mD3dCallbacks, sizeof(D3DHAL_CALLBACKS));
460 RtlZeroMemory(&mD3dDriverData, sizeof(D3DHAL_GLOBALDRIVERDATA));
461 RtlZeroMemory(&mD3dBufferCallbacks, sizeof(DDHAL_DDEXEBUFCALLBACKS));
462
463 if (reenable == FALSE)
464 {
465 if (ddgbl.lpDDCBtmp == NULL)
466 {
467 DxHeapMemAlloc(ddgbl.lpDDCBtmp, sizeof(DDHAL_CALLBACKS));
468 if ( ddgbl.lpDDCBtmp == NULL)
469 {
470 return DD_FALSE;
471 }
472 }
473 }
474 else
475 {
476 RtlZeroMemory(ddgbl.lpDDCBtmp,sizeof(DDHAL_CALLBACKS));
477 }
478
479 /*
480 * Startup DX HAL step one of three
481 */
482 if (!DdCreateDirectDrawObject(This->lpLcl->lpGbl, (HDC)This->lpLcl->hDC))
483 {
484 DxHeapMemFree(ddgbl.lpDDCBtmp);
485 return DD_FALSE;
486 }
487
488 /* Some card disable the dx after it have been created so
489 * we are force reanble it
490 */
491 if (!DdReenableDirectDrawObject(This->lpLcl->lpGbl, &newmode))
492 {
493 DxHeapMemFree(ddgbl.lpDDCBtmp);
494 return DD_FALSE;
495 }
496
497 if (!DdQueryDirectDrawObject(This->lpLcl->lpGbl,
498 &mHALInfo,
499 &ddgbl.lpDDCBtmp->HALDD,
500 &ddgbl.lpDDCBtmp->HALDDSurface,
501 &ddgbl.lpDDCBtmp->HALDDPalette,
502 &mD3dCallbacks,
503 &mD3dDriverData,
504 &mD3dBufferCallbacks,
505 NULL,
506 mpFourCC,
507 NULL))
508 {
509 DxHeapMemFree(This->lpLcl->lpGbl->lpModeInfo);
510 DxHeapMemFree(ddgbl.lpDDCBtmp);
511 // FIXME Close DX fristcall and second call
512 return DD_FALSE;
513 }
514
515 DX_STUB_str("Trying alloc FourCCC \n");
516
517 /* Alloc mpFourCC */
518 if (This->lpLcl->lpGbl->lpdwFourCC != NULL)
519 {
520 DxHeapMemFree(This->lpLcl->lpGbl->lpdwFourCC);
521 }
522
523 if (mHALInfo.ddCaps.dwNumFourCCCodes > 0 )
524 {
525
526 DxHeapMemAlloc(mpFourCC, sizeof(DWORD) * (mHALInfo.ddCaps.dwNumFourCCCodes + 2));
527
528 if (mpFourCC == NULL)
529 {
530 DxHeapMemFree(ddgbl.lpDDCBtmp);
531 // FIXME Close DX fristcall and second call
532 return DD_FALSE;
533 }
534 }
535
536 DX_STUB_str("End Trying alloc FourCCC\n");
537
538
539
540
541
542 /* Alloc mpTextures */
543
544 DX_STUB_str("1 Here\n");
545
546 /*
547 if (This->lpLcl->lpGbl->texture != NULL)
548 {
549 DxHeapMemFree(This->lpLcl->lpGbl->);
550 }
551 */
552
553 mpTextures = NULL;
554 if (mD3dDriverData.dwNumTextureFormats > 0)
555 {
556 DxHeapMemAlloc(mpTextures, sizeof(DDSURFACEDESC) * mD3dDriverData.dwNumTextureFormats);
557 if (mpTextures == NULL)
558 {
559 DxHeapMemFree(mpFourCC);
560 DxHeapMemFree(ddgbl.lpDDCBtmp);
561 // FIXME Close DX fristcall and second call
562 }
563 }
564
565 DX_STUB_str("2 Here\n");
566
567
568
569
570 /* Get all basic data from the driver */
571 if (!DdQueryDirectDrawObject(
572 This->lpLcl->lpGbl,
573 &mHALInfo,
574 &ddgbl.lpDDCBtmp->HALDD,
575 &ddgbl.lpDDCBtmp->HALDDSurface,
576 &ddgbl.lpDDCBtmp->HALDDPalette,
577 &mD3dCallbacks,
578 &mD3dDriverData,
579 &ddgbl.lpDDCBtmp->HALDDExeBuf,
580 (DDSURFACEDESC*)mpTextures,
581 mpFourCC,
582 NULL))
583 {
584 DxHeapMemFree(mpFourCC);
585 DxHeapMemFree(mpTextures);
586 DxHeapMemFree(ddgbl.lpDDCBtmp);
587 // FIXME Close DX fristcall and second call
588 return DD_FALSE;
589 }
590
591 memcpy(&ddgbl.vmiData, &mHALInfo.vmiData,sizeof(VIDMEMINFO));
592
593
594 memcpy(&ddgbl.ddCaps, &mHALInfo.ddCaps,sizeof(DDCORECAPS));
595
596 This->lpLcl->lpGbl->dwNumFourCC = mHALInfo.ddCaps.dwNumFourCCCodes;
597 This->lpLcl->lpGbl->lpdwFourCC = mpFourCC;
598 // This->lpLcl->lpGbl->dwMonitorFrequency = mHALInfo.dwMonitorFrequency; // 0
599 This->lpLcl->lpGbl->dwModeIndex = mHALInfo.dwModeIndex;
600 // This->lpLcl->lpGbl->dwNumModes = mHALInfo.dwNumModes;
601 // This->lpLcl->lpGbl->lpModeInfo = mHALInfo.lpModeInfo;
602
603 DX_STUB_str("Here\n");
604
605 /* FIXME convert mpTextures to DDHALMODEINFO */
606 // DxHeapMemFree( mpTextures);
607
608 /* FIXME D3D setup mD3dCallbacks and mD3dDriverData */
609
610
611
612
613 if (mHALInfo.dwFlags & DDHALINFO_GETDRIVERINFOSET)
614 {
615 DdGetDriverInfo.dwSize = sizeof (DDHAL_GETDRIVERINFODATA);
616 DdGetDriverInfo.guidInfo = GUID_MiscellaneousCallbacks;
617 DdGetDriverInfo.lpvData = (PVOID)&ddgbl.lpDDCBtmp->HALDDMiscellaneous;
618 DdGetDriverInfo.dwExpectedSize = sizeof (DDHAL_DDMISCELLANEOUSCALLBACKS);
619
620 if(mHALInfo.GetDriverInfo (&DdGetDriverInfo) == DDHAL_DRIVER_NOTHANDLED || DdGetDriverInfo.ddRVal != DD_OK)
621 {
622 DxHeapMemFree(mpFourCC);
623 DxHeapMemFree(mpTextures);
624 DxHeapMemFree(ddgbl.lpDDCBtmp);
625 // FIXME Close DX fristcall and second call
626 return DD_FALSE;
627 }
628
629 RtlZeroMemory(&DdGetDriverInfo, sizeof(DDHAL_GETDRIVERINFODATA));
630 DdGetDriverInfo.dwSize = sizeof (DDHAL_GETDRIVERINFODATA);
631 DdGetDriverInfo.guidInfo = GUID_Miscellaneous2Callbacks;
632
633 /* FIXME
634 DdGetDriverInfo.lpvData = (PVOID)&ddgbl.lpDDCBtmp->HALDDMiscellaneous;
635 DdGetDriverInfo.dwExpectedSize = sizeof (DDHAL_DDMISCELLANEOUS2CALLBACKS);
636
637 if(mHALInfo.GetDriverInfo (&DdGetDriverInfo) == DDHAL_DRIVER_NOTHANDLED || DdGetDriverInfo.ddRVal != DD_OK)
638 {
639 DxHeapMemFree(mpFourCC);
640 DxHeapMemFree(mpTextures);
641 DxHeapMemFree(ddgbl.lpDDCBtmp);
642 // FIXME Close DX fristcall and second call
643 return DD_FALSE;
644 }
645 DD_MISCELLANEOUS2CALLBACKS
646 {
647 DWORD dwSize;
648 DWORD dwFlags;
649 PDD_ALPHABLT AlphaBlt; // unsuse acoding msdn and always set to NULL
650 PDD_CREATESURFACEEX CreateSurfaceEx;
651 PDD_GETDRIVERSTATE GetDriverState;
652 PDD_DESTROYDDLOCAL DestroyDDLocal;
653 }
654 DDHAL_MISC2CB32_CREATESURFACEEX
655 DDHAL_MISC2CB32_GETDRIVERSTATE
656 DDHAL_MISC2CB32_DESTROYDDLOCAL
657 */
658 }
659
660 if (mHALInfo.dwFlags & DDHALINFO_GETDRIVERINFO2)
661 {
662 This->lpLcl->lpGbl->dwFlags = This->lpLcl->lpGbl->dwFlags | DDRAWI_DRIVERINFO2;
663 }
664
665
666 return DD_OK;
667 }