small ceanup in hal startup process
[reactos.git] / reactos / lib / ddraw / hal / ddraw_hal.c
index 8b769e8..22a7863 100644 (file)
@@ -15,7 +15,6 @@ HRESULT Hal_DirectDraw_Initialize (LPDIRECTDRAW7 iface)
 {
     IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
  
-
        /* point to it self */
        This->DirectDrawGlobal.lp16DD = &This->DirectDrawGlobal;
 
@@ -29,7 +28,6 @@ HRESULT Hal_DirectDraw_Initialize (LPDIRECTDRAW7 iface)
        This->DirectDrawGlobal.lpD3DHALCallbacks = (ULONG_PTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, sizeof(D3DHAL_CALLBACKS));   
        This->DirectDrawGlobal.lpD3DGlobalDriverData = (ULONG_PTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DHAL_GLOBALDRIVERDATA));                       
        
-
        /* Fill in some info */
        This->HalInfo.lpD3DGlobalDriverData = This->DirectDrawGlobal.lpD3DGlobalDriverData;
        This->HalInfo.lpD3DHALCallbacks = This->DirectDrawGlobal.lpD3DHALCallbacks;
@@ -37,8 +35,6 @@ HRESULT Hal_DirectDraw_Initialize (LPDIRECTDRAW7 iface)
        This->HalInfo.lpDDExeBufCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDDExeBuf;
        This->HalInfo.lpDDPaletteCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDDPalette;
        This->HalInfo.lpDDSurfaceCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDDSurface;
-
-       /* FIXME The insate is not right we need the info that the three NULL return */
        
        /* query all kinds of infos from the driver */
        if(!DdQueryDirectDrawObject (
@@ -53,19 +49,12 @@ HRESULT Hal_DirectDraw_Initialize (LPDIRECTDRAW7 iface)
                NULL, 
                NULL, 
                NULL ))
-       {
-               OutputDebugString(L"First DdQueryDirectDrawObject failed");
-               return 1;
+       {       
+               return DD_FALSE;
        }
-
-       /* FIXME The insate is not right we need the info that the three NULL return and use it here*/
-
-       /* Fixme shall we selected the pixel type before we call the DdQueryDirectDrawObject second time 
-         and fill in more info ?? */
-
+       
        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);
+       This->DirectDrawGlobal.lpdwFourCC = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * This->HalInfo.ddCaps.dwNumFourCCCodes);      
        ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDSURFACEDESC) * ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->dwNumTextureFormats);
 
        if(!DdQueryDirectDrawObject (
@@ -81,9 +70,8 @@ HRESULT Hal_DirectDraw_Initialize (LPDIRECTDRAW7 iface)
                This->DirectDrawGlobal.lpdwFourCC, 
                This->HalInfo.vmiData.pvmList 
                ))
-       {
-               OutputDebugString(L"Second DdQueryDirectDrawObject failed");
-               return 1;
+       {               
+               return DD_FALSE;
        }
                
        /* Copy HalInfo to DirectDrawGlobal (Not complete)*/
@@ -91,23 +79,11 @@ HRESULT Hal_DirectDraw_Initialize (LPDIRECTDRAW7 iface)
        RtlCopyMemory(&This->DirectDrawGlobal.vmiData,&This->HalInfo.vmiData,sizeof(VIDMEMINFO));
        RtlCopyMemory(&This->DirectDrawGlobal.ddCaps,&This->HalInfo.ddCaps,sizeof(DDCORECAPS));
        This->DirectDrawGlobal.dwMonitorFrequency = This->HalInfo.dwMonitorFrequency;
-        
-    /* have not check where it should go into yet
-       This->HalInfo.GetDriverInfo datatype LPDDHAL_GETDRIVERINFO      
-    */
-
+            
     This->DirectDrawGlobal.dwModeIndex = This->HalInfo.dwModeIndex;
-
-       /* have not check where it should go into yet
-          This->HalInfo.lpdwFourCC datatype LPDWORD                    
-     */
-
     This->DirectDrawGlobal.dwNumModes =  This->HalInfo.dwNumModes;
     This->DirectDrawGlobal.lpModeInfo =  This->HalInfo.lpModeInfo;
 
-       /* have not check where it should go into yet
-          This->HalInfo.dwFlags data type DWORD
-       */
 
        /* Unsure which of these two for lpPDevice 
       This->DirectDrawGlobal.dwPDevice = This->HalInfo.lpPDevice;
@@ -115,12 +91,8 @@ HRESULT Hal_DirectDraw_Initialize (LPDIRECTDRAW7 iface)
        */
 
     This->DirectDrawGlobal.hInstance = This->HalInfo.hInstance;    
-    
-       /* have not check where it should go into yet
-       This->lpD3DGlobalDriverData datatype ULONG_PTR
-       This->lpD3DHALCallbacks datatype  ULONG_PTR
-    */ 
-        RtlCopyMemory(&This->DirectDrawGlobal.lpDDCBtmp->HALDDExeBuf,&This->HalInfo.lpDDExeBufCallbacks,sizeof(DDHAL_DDEXEBUFCALLBACKS));
+     
+       RtlCopyMemory(&This->DirectDrawGlobal.lpDDCBtmp->HALDDExeBuf,&This->HalInfo.lpDDExeBufCallbacks,sizeof(DDHAL_DDEXEBUFCALLBACKS));
 
        
         
@@ -297,38 +269,46 @@ HRESULT Hal_DirectDraw_Initialize (LPDIRECTDRAW7 iface)
        
 
        /* Get the ZPixelFormats */
-       This->DirectDrawGlobal.lpZPixelFormats = (LPDDPIXELFORMAT)HeapAlloc(GetProcessHeap(), 0, sizeof(DDPIXELFORMAT));        
+       This->DirectDrawGlobal.lpZPixelFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDPIXELFORMAT) * This->DirectDrawGlobal.dwNumZPixelFormats);
        DriverInfo.guidInfo = GUID_ZPixelFormats;
        DriverInfo.lpvData = (PVOID)This->DirectDrawGlobal.lpZPixelFormats;
        DriverInfo.dwExpectedSize = sizeof(DDPIXELFORMAT);
        This->HalInfo.GetDriverInfo( &DriverInfo);
        
+       /* Setup some info from the callbacks we got  */        
+       DDHAL_GETAVAILDRIVERMEMORYDATA  mem;
+       mem.lpDD = &This->DirectDrawGlobal;
        
-       
-        /* Setup some info from the callbacks we got  */
-
-        /* FIXME do more callbacks and fill the gpl struct */
+       This->DirectDrawGlobal.lpDDCBtmp->HALDDMiscellaneous.GetAvailDriverMemory(&mem); 
 
-        DDHAL_GETAVAILDRIVERMEMORYDATA  mem;
-        mem.lpDD = &This->DirectDrawGlobal;
+       This->DirectDrawGlobal.ddCaps.dwVidMemFree = mem.dwFree;
+       This->DirectDrawGlobal.ddCaps.dwVidMemTotal = mem.dwTotal;
        
-        This->DirectDrawGlobal.lpDDCBtmp->HALDDMiscellaneous.GetAvailDriverMemory(&mem); 
-
-        This->DirectDrawGlobal.ddCaps.dwVidMemFree = mem.dwFree;
-        This->DirectDrawGlobal.ddCaps.dwVidMemTotal = mem.dwTotal;
-               
+       /* Now all setup for HAL is done */
+       return DD_OK;
+}
 
+HRESULT Hal_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface)
+{
+       IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
 
+       DDHAL_SETEXCLUSIVEMODEDATA SetExclusiveMode;
 
+       if (!(This->DirectDrawGlobal.lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_SETEXCLUSIVEMODE)) 
+       {
+               return DDERR_NODRIVERSUPPORT;
+       }
 
-       /* Now all setup for HAL is done and we hopply do not have forget anything */
+       SetExclusiveMode.lpDD = &This->DirectDrawGlobal;
+    SetExclusiveMode.ddRVal = DDERR_NOTPALETTIZED;
+       SetExclusiveMode.dwEnterExcl = This->cooperative_level;
 
-       return DD_OK;
-}
+       if (This->DirectDrawGlobal.lpDDCBtmp->HALDD.SetExclusiveMode(&SetExclusiveMode) != DDHAL_DRIVER_HANDLED)
+       {
+          return DDERR_NODRIVERSUPPORT;
+       }
 
-HRESULT Hal_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface)
-{
-       return DD_OK;
+       return SetExclusiveMode.ddRVal;
 }