Fill some more structs, that ms ddraw fill as well.
Modified: trunk/reactos/lib/ddraw/hal/ddraw.c
Modified: trunk/reactos/lib/ddraw/main/ddraw.c
Modified: trunk/reactos/lib/ddraw/main/surface.c
Modified: trunk/reactos/lib/ddraw/main.c
Modified: trunk/reactos/lib/ddraw/rosdraw.h

Modified: trunk/reactos/lib/ddraw/hal/ddraw.c
--- trunk/reactos/lib/ddraw/hal/ddraw.c	2005-08-25 12:33:37 UTC (rev 17538)
+++ trunk/reactos/lib/ddraw/hal/ddraw.c	2005-08-25 15:31:28 UTC (rev 17539)
@@ -15,60 +15,88 @@
 {
     IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
  
+	/* get the object */
 	if(!DdCreateDirectDrawObject (&This->DirectDrawGlobal, This->hdc))
 		return DDERR_INVALIDPARAMS;
- 
+
+ 	/* alloc some space */
+	This->DirectDrawGlobal.lpDDCBtmp = (LPDDHAL_CALLBACKS)HeapAlloc(GetProcessHeap(), 0, sizeof(DDHAL_CALLBACKS));
+	memset(This->DirectDrawGlobal.lpDDCBtmp, 0, sizeof(DDHAL_CALLBACKS));
+	This->HalInfo.lpDDCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->cbDDCallbacks;
+	This->HalInfo.lpDDSurfaceCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->cbDDSurfaceCallbacks;
+	This->HalInfo.lpDDExeBufCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->cbDDExeBufCallbacks;
+	This->HalInfo.lpDDPaletteCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->cbDDPaletteCallbacks;
+	This->DirectDrawGlobal.lpD3DHALCallbacks = (ULONG_PTR)HeapAlloc(GetProcessHeap(), 0, sizeof(D3DHAL_CALLBACKS));
+	This->DirectDrawGlobal.lpD3DGlobalDriverData = (ULONG_PTR)HeapAlloc(GetProcessHeap(), 0, sizeof(D3DHAL_GLOBALDRIVERDATA));
+
+	/* fill the sizeofs */
 	This->HalInfo.dwSize = sizeof(DDHALINFO);
-	This->D3dDriverData.dwSize = sizeof(D3DHAL_GLOBALDRIVERDATA);
-    This->DriverCallbacks.DdMain.dwSize = sizeof(DDHAL_DDCALLBACKS);
-	This->DriverCallbacks.DdSurface.dwSize = sizeof(DDHAL_DDSURFACECALLBACKS);
-	This->DriverCallbacks.DdPalette.dwSize = sizeof(DDHAL_DDPALETTECALLBACKS);
-	This->DriverCallbacks.D3dMain.dwSize = sizeof(D3DHAL_CALLBACKS);
-	This->DriverCallbacks.D3dBufferCallbacks.dwSize = sizeof(DDHAL_DDEXEBUFCALLBACKS);
- 
+	This->HalInfo.lpDDCallbacks->dwSize = sizeof(DDHAL_DDCALLBACKS);
+	This->HalInfo.lpDDSurfaceCallbacks->dwSize = sizeof(DDHAL_DDSURFACECALLBACKS);
+	This->HalInfo.lpDDPaletteCallbacks->dwSize = sizeof(DDHAL_DDPALETTECALLBACKS);
+	This->HalInfo.lpDDExeBufCallbacks->dwSize = sizeof(DDHAL_DDEXEBUFCALLBACKS);
+	((LPD3DHAL_CALLBACKS)This->DirectDrawGlobal.lpD3DHALCallbacks)->dwSize = sizeof(D3DHAL_CALLBACKS);
+	((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->dwSize = sizeof(D3DHAL_GLOBALDRIVERDATA);	
+
+	/* query all kinds of infos from the driver */
 	if(!DdQueryDirectDrawObject (
 		&This->DirectDrawGlobal, 
 		&This->HalInfo, 
-		&This->DriverCallbacks.DdMain,
-		&This->DriverCallbacks.DdSurface,
-		&This->DriverCallbacks.DdPalette,
-		&This->DriverCallbacks.D3dMain,
-		&This->D3dDriverData,
-		&This->DriverCallbacks.D3dBufferCallbacks, 
+		This->HalInfo.lpDDCallbacks,
+		This->HalInfo.lpDDSurfaceCallbacks,
+		This->HalInfo.lpDDPaletteCallbacks,
+		(LPD3DHAL_CALLBACKS)This->DirectDrawGlobal.lpD3DHALCallbacks,
+		(LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData,
+		This->HalInfo.lpDDExeBufCallbacks, 
 		NULL, 
 		NULL, 
 		NULL ))
-		return DDERR_INVALIDPARAMS;
+	{
+		OutputDebugString(L"First DdQueryDirectDrawObject failed");
+		return 1;
+	}
 
-	This->pD3dTextureFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDSURFACEDESC) * This->D3dDriverData.dwNumTextureFormats);
+	/* ms wants us to call that function twice */	
 	This->HalInfo.vmiData.pvmList = HeapAlloc(GetProcessHeap(), 0, sizeof(VIDMEM) * This->HalInfo.vmiData.dwNumHeaps);
 	This->DirectDrawGlobal.lpdwFourCC = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * This->HalInfo.ddCaps.dwNumFourCCCodes);
 	This->DirectDrawGlobal.lpZPixelFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDPIXELFORMAT) * This->DirectDrawGlobal.dwNumZPixelFormats);
+	((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDSURFACEDESC) * ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->dwNumTextureFormats);
 
 	if(!DdQueryDirectDrawObject (
 		&This->DirectDrawGlobal, 
 		&This->HalInfo, 
-		&This->DriverCallbacks.DdMain,
-		&This->DriverCallbacks.DdSurface,
-		&This->DriverCallbacks.DdPalette,
-		&This->DriverCallbacks.D3dMain,
-		&This->D3dDriverData,
-		&This->DriverCallbacks.D3dBufferCallbacks, 
-		This->pD3dTextureFormats, 
+		This->HalInfo.lpDDCallbacks,
+		This->HalInfo.lpDDSurfaceCallbacks,
+		This->HalInfo.lpDDPaletteCallbacks,
+		(LPD3DHAL_CALLBACKS)This->DirectDrawGlobal.lpD3DHALCallbacks,
+		(LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData,
+		This->HalInfo.lpDDExeBufCallbacks, 
+		((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats, 
 		This->DirectDrawGlobal.lpdwFourCC, 
-		This->HalInfo.vmiData.pvmList ))
-		return DDERR_INVALIDPARAMS;
+		This->HalInfo.vmiData.pvmList 
+		))
+	{
+		OutputDebugString(L"Second DdQueryDirectDrawObject failed");
+		return 1;
+	}
 		
+	/* fill some extra data */	
 	This->DirectDrawGlobal.vmiData.dwDisplayWidth = This->Width;
 	This->DirectDrawGlobal.vmiData.dwDisplayHeight = This->Height;
 	This->DirectDrawGlobal.vmiData.lDisplayPitch =  This->Width * This->Bpp/8;
-	//This->DirectDrawGlobal.vmiData.ddpfDisplay; // This has to be filled
 	This->DirectDrawGlobal.vmiData.dwOffscreenAlign = 64;
 	This->DirectDrawGlobal.vmiData.dwOverlayAlign = 64;
 	This->DirectDrawGlobal.vmiData.dwTextureAlign = 64;
 	This->DirectDrawGlobal.vmiData.dwZBufferAlign = 64;
 	This->DirectDrawGlobal.vmiData.dwAlphaAlign = 64;
+	//This->DirectDrawGlobal.vmiData.ddpfDisplay; // This has to be filled
 
+	This->DirectDrawGlobal.ddCaps = This->HalInfo.ddCaps;
+	This->DirectDrawGlobal.lpDDCBtmp->HALDD = This->DirectDrawGlobal.lpDDCBtmp->cbDDCallbacks;
+	This->DirectDrawGlobal.lpDDCBtmp->HALDDSurface = This->DirectDrawGlobal.lpDDCBtmp->cbDDSurfaceCallbacks;
+	This->DirectDrawGlobal.lpDDCBtmp->HALDDExeBuf = This->DirectDrawGlobal.lpDDCBtmp->cbDDExeBufCallbacks;
+	This->DirectDrawGlobal.lpDDCBtmp->HALDDPalette = This->DirectDrawGlobal.lpDDCBtmp->cbDDPaletteCallbacks;
+
 	return DD_OK;
 }
 
@@ -82,11 +110,20 @@
     IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
 
 	DdDeleteDirectDrawObject (&This->DirectDrawGlobal);
-			
-	if(This->pD3dTextureFormats)
-		HeapFree(GetProcessHeap(), 0, This->pD3dTextureFormats);
+
+	if(This->HalInfo.vmiData.pvmList)
+		HeapFree(GetProcessHeap(), 0, This->HalInfo.vmiData.pvmList);
 	if(This->DirectDrawGlobal.lpdwFourCC)
 		HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpdwFourCC);
-	if(This->HalInfo.vmiData.pvmList)
-		HeapFree(GetProcessHeap(), 0, This->HalInfo.vmiData.pvmList);
+	if(This->DirectDrawGlobal.lpZPixelFormats)
+		HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpZPixelFormats);
+	if(((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats)
+		HeapFree(GetProcessHeap(), 0, ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats);			
+	
+	if(This->DirectDrawGlobal.lpDDCBtmp)
+		HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpDDCBtmp);
+	if(This->DirectDrawGlobal.lpD3DHALCallbacks)
+		HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DHALCallbacks);
+	if(This->DirectDrawGlobal.lpD3DGlobalDriverData)
+		HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DGlobalDriverData);
 }

Modified: trunk/reactos/lib/ddraw/main/ddraw.c
--- trunk/reactos/lib/ddraw/main/ddraw.c	2005-08-25 12:33:37 UTC (rev 17538)
+++ trunk/reactos/lib/ddraw/main/ddraw.c	2005-08-25 15:31:28 UTC (rev 17539)
@@ -25,8 +25,8 @@
 
 	// get the HDC
 	This->hdc = GetWindowDC(GetDesktopWindow());
-	This->Height = GetDeviceCaps(This->hdc, HORZRES);
-	This->Width = GetDeviceCaps(This->hdc, VERTRES);
+	This->Height = GetDeviceCaps(This->hdc, VERTRES);
+	This->Width = GetDeviceCaps(This->hdc, HORZRES);
 	This->Bpp = GetDeviceCaps(This->hdc, BITSPIXEL);
 
 	// call software first
@@ -151,7 +151,7 @@
 ULONG WINAPI Main_DirectDraw_AddRef (LPDIRECTDRAW7 iface) 
 {
     IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
-    ULONG ref = InterlockedIncrement(&This->ref);
+    ULONG ref = InterlockedIncrement(&This->DirectDrawGlobal.dwRefCnt);
 
    	return ref;
 }
@@ -159,7 +159,7 @@
 ULONG WINAPI Main_DirectDraw_Release (LPDIRECTDRAW7 iface) 
 {
     IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
-    ULONG ref = InterlockedDecrement(&This->ref);
+    ULONG ref = InterlockedDecrement(&This->DirectDrawGlobal.dwRefCnt);
     
     if (ref == 0)
     {

Modified: trunk/reactos/lib/ddraw/main/surface.c
--- trunk/reactos/lib/ddraw/main/surface.c	2005-08-25 12:33:37 UTC (rev 17538)
+++ trunk/reactos/lib/ddraw/main/surface.c	2005-08-25 15:31:28 UTC (rev 17539)
@@ -25,74 +25,71 @@
 		return DDERR_INVALIDPARAMS;
 
 	This->owner = (IDirectDrawImpl*)pDD;
+   
+	/* can the driver create the surface */
+	DDHAL_CANCREATESURFACEDATA CanCreateData;
+	memset(&CanCreateData, 0, sizeof(DD_CANCREATESURFACEDATA));
+	CanCreateData.lpDD = &This->owner->DirectDrawGlobal; 
+	CanCreateData.lpDDSurfaceDesc = (DDSURFACEDESC*)pDDSD;
+	CanCreateData.CanCreateSurface = This->owner->HalInfo.lpDDCallbacks->CanCreateSurface;
+	
+	if (CanCreateData.CanCreateSurface(&CanCreateData) == DDHAL_DRIVER_NOTHANDLED)
+        return DDERR_INVALIDPARAMS;
+	
+	if(CanCreateData.ddRVal != DD_OK)
+		return CanCreateData.ddRVal;
 
-	// Surface Global Struct
+	/* surface global struct */
 	DDRAWI_DDRAWSURFACE_GBL Global;
 	memset(&Global, 0, sizeof(DDRAWI_DDRAWSURFACE_GBL));
-	
-	if(pDDSD->ddsCaps.dwCaps == DDSCAPS_PRIMARYSURFACE)
-		Global.dwGlobalFlags |= DDRAWISURFGBL_ISGDISURFACE;
-	
 	Global.lpDD = &This->owner->DirectDrawGlobal;	
 	Global.wHeight = This->owner->Height;
 	Global.wWidth = This->owner->Width;
 	Global.dwLinearSize =  Global.wWidth * This->owner->Bpp/8;
 	
-	// Surface More Struct
+	/* surface more struct */
 	DDRAWI_DDRAWSURFACE_MORE More;
 	memset(&More, 0, sizeof(DDRAWI_DDRAWSURFACE_MORE));
 	More.dwSize = sizeof(DDRAWI_DDRAWSURFACE_MORE);
 
-	// Surface Local Struct
+	/* surface local struct */
 	DDRAWI_DDRAWSURFACE_LCL Local;
 	memset(&Local, 0, sizeof(DDRAWI_DDRAWSURFACE_LCL));
 	Local.lpGbl = &Global;
 	Local.lpSurfMore = &More;
 	Local.ddsCaps = *(DDSCAPS*)&pDDSD->ddsCaps;
-	
-	// BitDepth = DDSurf_BitDepth(psurf); ?
 
-
+	/* we need to set some flags if we create the primary surface */
 	if(pDDSD->ddsCaps.dwCaps == DDSCAPS_PRIMARYSURFACE)
+	{
 		Local.dwFlags |= DDRAWISURF_FRONTBUFFER;
+		Global.dwGlobalFlags |= DDRAWISURFGBL_ISGDISURFACE;
+	}
 
-	DDRAWI_DDRAWSURFACE_LCL *pLocal[2]; // for stupid double pointer below
+	/* for the double pointer below */
+	DDRAWI_DDRAWSURFACE_LCL *pLocal[2]; 
+	pLocal[0] = &Local; 
+    pLocal[1] = NULL;  // we need this one for bad written drivers
 
-	pLocal[0] = &Local;
-    pLocal[1] = NULL;
-
-	// The Parameter Struct
+	/* the parameter struct */
 	DDHAL_CREATESURFACEDATA CreateData;
 	memset(&CreateData, 0, sizeof(DDHAL_CREATESURFACEDATA));
 	CreateData.lpDD = &This->owner->DirectDrawGlobal; 
 	CreateData.lpDDSurfaceDesc = (DDSURFACEDESC*)pDDSD;
 	CreateData.dwSCnt = 1;
 	CreateData.lplpSList = pLocal;
-   
+	CreateData.CreateSurface = This->owner->HalInfo.lpDDCallbacks->CreateSurface;
 	
-
-	DDHAL_CANCREATESURFACEDATA CanCreateData;
-	memset(&CanCreateData, 0, sizeof(DD_CANCREATESURFACEDATA));
-	CanCreateData.lpDD = &This->owner->DirectDrawGlobal; 
-	CanCreateData.lpDDSurfaceDesc = (DDSURFACEDESC*)pDDSD;
-
-	
-	if (This->owner->DriverCallbacks.DdMain.CanCreateSurface (&CanCreateData) == DDHAL_DRIVER_NOTHANDLED)
-        return DDERR_INVALIDPARAMS;
-	
-	if(CanCreateData.ddRVal != DD_OK)
-		return CanCreateData.ddRVal;
-	
-
-	if(This->owner->DriverCallbacks.DdMain.CreateSurface (&CreateData) == DDHAL_DRIVER_NOTHANDLED)
+	/* this is the call we were waiting for */
+	if(CreateData.CreateSurface(&CreateData) == DDHAL_DRIVER_NOTHANDLED)
 		return DDERR_INVALIDPARAMS;
 	
 	if(CreateData.ddRVal != DD_OK)
 		return CreateData.ddRVal;
 
+	OutputDebugString(L"This does not get hit :( ");
+	OutputDebugString(L"Yet ;)");
 
-	OutputDebugString(L"This does not get hit.");
-
    	return DD_OK;
 }
 
@@ -122,7 +119,7 @@
 
 ULONG WINAPI Main_DDrawSurface_Release(LPDIRECTDRAWSURFACE7 iface)
 {
-    IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
+    IDirectDrawSurfaceImpl* This = (IDirectDrawSurfaceImpl*)iface;
     ULONG ref = InterlockedDecrement(&This->ref);
     
     if (ref == 0)

Modified: trunk/reactos/lib/ddraw/main.c
--- trunk/reactos/lib/ddraw/main.c	2005-08-25 12:33:37 UTC (rev 17538)
+++ trunk/reactos/lib/ddraw/main.c	2005-08-25 15:31:28 UTC (rev 17539)
@@ -24,7 +24,7 @@
 	ZeroMemory(This,sizeof(IDirectDrawImpl));
 
 	This->lpVtbl = &DirectDraw_VTable;
-	This->ref = 1;
+	This->DirectDrawGlobal.dwRefCnt = 1;
 	*pIface = (LPDIRECTDRAW)This;
 
 	return This->lpVtbl->Initialize ((LPDIRECTDRAW7)This, pGUID);
@@ -39,7 +39,6 @@
 		return DDERR_INVALIDPARAMS; 
 	}
 	
-	
 	return Create_DirectDraw (lpGUID, lplpDD, pUnkOuter, FALSE);
 }
  

Modified: trunk/reactos/lib/ddraw/rosdraw.h
--- trunk/reactos/lib/ddraw/rosdraw.h	2005-08-25 12:33:37 UTC (rev 17538)
+++ trunk/reactos/lib/ddraw/rosdraw.h	2005-08-25 15:31:28 UTC (rev 17539)
@@ -18,23 +18,9 @@
 
 typedef struct 
 {
-	DDHAL_DDCALLBACKS DdMain;
-    DDHAL_DDSURFACECALLBACKS DdSurface;
-    DDHAL_DDPALETTECALLBACKS DdPalette;
-    D3DHAL_CALLBACKS D3dMain;
-    DDHAL_DDEXEBUFCALLBACKS	D3dBufferCallbacks;
-
-} DRIVERCALLBACKS;
-
-typedef struct 
-{
 	IDirectDraw7Vtbl* lpVtbl;
-	DRIVERCALLBACKS DriverCallbacks;
-    DWORD ref;
-
+	DDRAWI_DIRECTDRAW_GBL DirectDrawGlobal;
 	DDHALINFO HalInfo;	
-    D3DHAL_GLOBALDRIVERDATA	D3dDriverData;
-	LPDDSURFACEDESC pD3dTextureFormats;
 
     HWND window;
     DWORD cooperative_level;
@@ -42,7 +28,6 @@
 	int Height, Width, Bpp;
 
 	GUID* lpGUID;
-	DDRAWI_DIRECTDRAW_GBL DirectDrawGlobal;
 
 } IDirectDrawImpl;