Fix some crach in ddraw.dll startup process for surface, we still got crach and surfa...
[reactos.git] / reactos / lib / ddraw / main / ddraw_main.c
index 295afe5..49e84a3 100644 (file)
@@ -16,6 +16,8 @@ HRESULT WINAPI Main_DirectDraw_Initialize (LPDIRECTDRAW7 iface, LPGUID lpGUID)
     IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
        HRESULT ret;
 
+       
+
        // this if it is not called by DirectDrawCreate
        if(FALSE)
                return DDERR_ALREADYINITIALIZED;
@@ -36,7 +38,8 @@ HRESULT WINAPI Main_DirectDraw_Initialize (LPDIRECTDRAW7 iface, LPGUID lpGUID)
        // ... then overwrite with hal
        if((ret = Hel_DirectDraw_Initialize (iface)) != DD_OK)
                return ret;
-
+       
+   
        return DD_OK;
 }
 
@@ -48,7 +51,6 @@ HRESULT WINAPI Main_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface, HWND hw
        // - allow more Flags
 
     IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
-       HRESULT ret;
 
        // check the parameters
        if (This->cooperative_level == cooplevel && This->window == hwnd)
@@ -72,20 +74,21 @@ HRESULT WINAPI Main_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface, HWND hw
        This->cooperative_level = cooplevel;
 
        
+    if (This->DirectDrawGlobal.lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_SETEXCLUSIVEMODE) 
+       {
+           return Hal_DirectDraw_SetCooperativeLevel (iface);          
+       }
 
-       if((ret = Hal_DirectDraw_SetCooperativeLevel (iface)) != DD_OK)
-               return ret;
-
-       if((ret = Hel_DirectDraw_SetCooperativeLevel (iface)) != DD_OK)
-               return ret;
+       return Hel_DirectDraw_SetCooperativeLevel(iface);
 
-       return DD_OK;
 }
 
 HRESULT WINAPI Main_DirectDraw_SetDisplayMode (LPDIRECTDRAW7 iface, DWORD dwWidth, DWORD dwHeight, 
                                                                                                                                DWORD dwBPP, DWORD dwRefreshRate, DWORD dwFlags)
 {
        DWORD ret;
+
+    /* FIXME implement hal setMode */
        if((ret = Hal_DirectDraw_SetDisplayMode(iface,  dwWidth,  dwHeight, 
                                             dwBPP,  dwRefreshRate,  dwFlags)) == DD_OK)
        {
@@ -163,18 +166,30 @@ HRESULT WINAPI Main_DirectDraw_CreateSurface (LPDIRECTDRAW7 iface, LPDDSURFACEDE
                return DDERR_UNSUPPORTED;
 
        // the nasty com stuff
+       IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
+
        IDirectDrawSurfaceImpl* That; 
 
        That = (IDirectDrawSurfaceImpl*)HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawSurfaceImpl));
-
+       
        if (That == NULL) 
                return E_OUTOFMEMORY;
 
        ZeroMemory(That, sizeof(IDirectDrawSurfaceImpl));
-
+       
        That->lpVtbl = &DirectDrawSurface7_Vtable;
        That->lpVtbl_v3 = &DDRAW_IDDS3_Thunk_VTable;
-       That->ref = 1;
+
+       This->DirectDrawGlobal.dsList = (LPDDRAWI_DDRAWSURFACE_INT)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 
+                                                                                   sizeof(DDRAWI_DDRAWSURFACE_INT));           
+
+       That->owner = (IDirectDrawImpl *)This;
+
+       That->owner->DirectDrawGlobal.dsList->dwIntRefCnt =1;
+
+       /* we alwasy set to use the DirectDrawSurface7_Vtable as internel */
+       That->owner->DirectDrawGlobal.dsList->lpVtbl = (PVOID) &DirectDrawSurface7_Vtable;
+       
 
        *ppSurf = (LPDIRECTDRAWSURFACE7)That;
 
@@ -259,15 +274,14 @@ HRESULT WINAPI Main_DirectDraw_EnumSurfaces(LPDIRECTDRAW7 iface, DWORD dwFlags,
 
 HRESULT WINAPI Main_DirectDraw_FlipToGDISurface(LPDIRECTDRAW7 iface) 
 {
-       DWORD ret;
-
-       if((ret = Hal_DirectDraw_FlipToGDISurface( iface)) == DD_OK)
-               return ret;
+       IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
 
-       if((ret = Hel_DirectDraw_FlipToGDISurface( iface)) == DD_OK)
-               return ret;
+       if (This->DirectDrawGlobal.lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_FLIPTOGDISURFACE) 
+       {
+               return Hal_DirectDraw_FlipToGDISurface( iface);
+       }
 
-       return DDERR_NOTINITIALIZED;  
+       return Hel_DirectDraw_FlipToGDISurface( iface);
 }
 
 HRESULT WINAPI Main_DirectDraw_GetCaps(LPDIRECTDRAW7 iface, LPDDCAPS pDriverCaps,
@@ -370,16 +384,15 @@ HRESULT WINAPI Main_DirectDraw_GetMonitorFrequency(LPDIRECTDRAW7 iface,LPDWORD f
 }
 
 HRESULT WINAPI Main_DirectDraw_GetScanLine(LPDIRECTDRAW7 iface, LPDWORD lpdwScanLine)
-{
-       DWORD ret;
-
-       if((ret = Hal_DirectDraw_GetScanLine( iface,  lpdwScanLine)) == DD_OK)
-               return ret;
+{      
+       IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
 
-       if((ret = Hel_DirectDraw_GetScanLine( iface,  lpdwScanLine)) == DD_OK)
-               return ret;
+       if (This->DirectDrawGlobal.lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_GETSCANLINE) 
+       {
+           return Hal_DirectDraw_GetScanLine( iface,  lpdwScanLine);           
+       }
 
-       return DDERR_NOTINITIALIZED;    
+       return Hel_DirectDraw_GetScanLine( iface,  lpdwScanLine);
 }
 
 HRESULT WINAPI Main_DirectDraw_GetVerticalBlankStatus(LPDIRECTDRAW7 iface, LPBOOL status)
@@ -395,31 +408,27 @@ HRESULT WINAPI Main_DirectDraw_RestoreDisplayMode(LPDIRECTDRAW7 iface)
 HRESULT WINAPI Main_DirectDraw_WaitForVerticalBlank(LPDIRECTDRAW7 iface, DWORD dwFlags,
                                                                                                   HANDLE h)
 {
-    DWORD ret;
+       IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
 
-    if((ret = Hal_DirectDraw_WaitForVerticalBlank( iface,  dwFlags, h)) == DD_OK)
-               return ret;
-
-       if((ret = Hel_DirectDraw_WaitForVerticalBlank( iface,  dwFlags, h)) == DD_OK)
-               return ret;
+    if (This->DirectDrawGlobal.lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_WAITFORVERTICALBLANK) 
+       {
+       return Hal_DirectDraw_WaitForVerticalBlank( iface,  dwFlags, h);                
+       }
 
-       return DDERR_NOTINITIALIZED;    
+       return Hel_DirectDraw_WaitForVerticalBlank( iface,  dwFlags, h);                
 }
 
 HRESULT WINAPI Main_DirectDraw_GetAvailableVidMem(LPDIRECTDRAW7 iface, LPDDSCAPS2 ddscaps,
                                   LPDWORD total, LPDWORD free)                                                                                    
 {      
-       DWORD ret;
-
-    if((ret = Hal_DirectDraw_GetAvailableVidMem (iface,ddscaps,total,free)) == DD_OK)
-               return ret;
-
-       if((ret = Hel_DirectDraw_GetAvailableVidMem (iface,ddscaps,total,free)) == DD_OK)
-               return ret;
+       IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
 
+       if (This->DirectDrawGlobal.lpDDCBtmp->HALDDMiscellaneous.dwFlags & DDHAL_MISCCB32_GETAVAILDRIVERMEMORY) 
+       {
+               return Hal_DirectDraw_GetAvailableVidMem (iface,ddscaps,total,free);
+       }
 
-       return DDERR_NOTINITIALIZED;
-
+       return Hel_DirectDraw_GetAvailableVidMem (iface,ddscaps,total,free);
 }
                                                                                                   
 HRESULT WINAPI Main_DirectDraw_GetSurfaceFromDC(LPDIRECTDRAW7 iface, HDC hdc,