* Made it possible to include both d3d9types.h and ddrawgdi.h at the same time
[reactos.git] / reactos / dll / win32 / gdi32 / misc / gdientry.c
index c72a0fb..84e7c19 100644 (file)
@@ -15,6 +15,7 @@
 #include <ddrawint.h>
 #include <ddrawgdi.h>
 #include <ntgdi.h>
+#include <d3dhal.h>
 
 /* DATA **********************************************************************/
 
@@ -72,7 +73,7 @@ DdDestroySurface(LPDDHAL_DESTROYSURFACEDATA pDestroySurface)
         {
             RealDestroy = FALSE;
         }
-        
+
         /* Call win32k */
         Return = NtGdiDdDestroySurface((HANDLE)pSurfaceLocal->hDDSurface,
                                        RealDestroy);
@@ -86,10 +87,10 @@ WINAPI
 DdFlip(LPDDHAL_FLIPDATA Flip)
 {
     /* Call win32k */
-       
+
     return NtGdiDdFlip( (HANDLE)Flip->lpSurfCurr->hDDSurface,
                         (HANDLE)Flip->lpSurfTarg->hDDSurface,
-   /* FIXME  the two last should be current left handler */ 
+   /* FIXME  the two last should be current left handler */
                                                (HANDLE)Flip->lpSurfCurr->hDDSurface,
                         (HANDLE)Flip->lpSurfTarg->hDDSurface,
                         (PDD_FLIPDATA)Flip);
@@ -99,7 +100,7 @@ DWORD
 WINAPI
 DdLock(LPDDHAL_LOCKDATA Lock)
 {
-    /* Call win32k */  
+    /* Call win32k */
     return NtGdiDdLock((HANDLE)Lock->lpDDSurface->hDDSurface,
                         (PDD_LOCKDATA)Lock,
                                                (HANDLE)Lock->lpDDSurface->hDC);
@@ -209,16 +210,20 @@ DdCreateSurface(LPDDHAL_CREATESURFACEDATA pCreateSurface)
     DD_SURFACE_LOCAL DdSurfaceLocal;
     DD_SURFACE_MORE DdSurfaceMore;
     DD_SURFACE_GLOBAL DdSurfaceGlobal;
+
     HANDLE hPrevSurface, hSurface;
-    DD_SURFACE_LOCAL* pDdSurfaceLocal;
-    DD_SURFACE_MORE* pDdSurfaceMore;
-    DD_SURFACE_GLOBAL* pDdSurfaceGlobal;
-    LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal;
-    //LPDDRAWI_DDRAWSURFACE_MORE pSurfaceMore;
-    LPDDRAWI_DDRAWSURFACE_GBL pSurfaceGlobal;
+
+
+    PDD_SURFACE_LOCAL pDdSurfaceLocal = NULL;
+    PDD_SURFACE_MORE pDdSurfaceMore = NULL;
+    PDD_SURFACE_GLOBAL pDdSurfaceGlobal = NULL;
+
+    PDD_SURFACE_LOCAL ptmpDdSurfaceLocal = NULL;
+    PDD_SURFACE_MORE ptmpDdSurfaceMore = NULL;
+    PDD_SURFACE_GLOBAL ptmpDdSurfaceGlobal = NULL;
     PHANDLE phSurface = NULL, puhSurface = NULL;
     ULONG i;
-    LPDDSURFACEDESC pSurfaceDesc;
+    LPDDSURFACEDESC pSurfaceDesc = NULL;
 
     /* Check how many surfaces there are */
     if (SurfaceCount != 1)
@@ -234,74 +239,149 @@ DdCreateSurface(LPDDHAL_CREATESURFACEDATA pCreateSurface)
         pDdSurfaceGlobal = &DdSurfaceGlobal;
         phSurface = &hPrevSurface;
         puhSurface = &hSurface;
-        
+
         /* Clear the structures */
         RtlZeroMemory(&DdSurfaceLocal, sizeof(DdSurfaceLocal));
         RtlZeroMemory(&DdSurfaceGlobal, sizeof(DdSurfaceGlobal));
-        RtlZeroMemory(&DdSurfaceMore, sizeof(DdSurfaceMore));  
+        RtlZeroMemory(&DdSurfaceMore, sizeof(DdSurfaceMore));
     }
 
-    /* Loop for each surface */
-    for (i = 0; i < pCreateSurface->dwSCnt; i++)
+    /* check if we got a surface or not */
+    if (SurfaceCount!=0)
     {
-        /* Get data */
-        pSurfaceLocal = pCreateSurface->lplpSList[i];
-        pSurfaceGlobal = pSurfaceLocal->lpGbl;
+        /* Loop for each surface */
+        ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
+        ptmpDdSurfaceLocal = pDdSurfaceLocal;
+        ptmpDdSurfaceMore = pDdSurfaceMore;
         pSurfaceDesc = pCreateSurface->lpDDSurfaceDesc;
 
-        /* Check if it has pixel data */
-        if (pSurfaceDesc->dwFlags & DDRAWISURF_HASPIXELFORMAT)
+        for (i = 0; i < SurfaceCount; i++)
         {
-            /* Use its pixel data */
-            DdSurfaceGlobal.ddpfSurface = pSurfaceDesc->ddpfPixelFormat;
-            DdSurfaceGlobal.ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
-        }
-        else
-        {
-            /* Use the one from the global surface */
-            DdSurfaceGlobal.ddpfSurface = pSurfaceGlobal->lpDD->vmiData.ddpfDisplay;
+            LPDDRAWI_DDRAWSURFACE_LCL lcl = pCreateSurface->lplpSList[i];
+            LPDDRAWI_DDRAWSURFACE_GBL gpl = pCreateSurface->lplpSList[i]->lpGbl;
+
+            phSurface[i] = (HANDLE)lcl->hDDSurface;
+            ptmpDdSurfaceLocal->ddsCaps.dwCaps = lcl->ddsCaps.dwCaps;
+
+            ptmpDdSurfaceLocal->dwFlags = (ptmpDdSurfaceLocal->dwFlags &
+                                          (0xB0000000 | DDRAWISURF_INMASTERSPRITELIST |
+                                           DDRAWISURF_HELCB | DDRAWISURF_FRONTBUFFER |
+                                           DDRAWISURF_BACKBUFFER | DDRAWISURF_INVALID |
+                                           DDRAWISURF_DCIBUSY | DDRAWISURF_DCILOCK)) |
+                                          (lcl->dwFlags & DDRAWISURF_DRIVERMANAGED);
+
+            ptmpDdSurfaceGlobal->wWidth = gpl->wWidth;
+            ptmpDdSurfaceGlobal->wHeight = gpl->wHeight;
+            ptmpDdSurfaceGlobal->lPitch = gpl->lPitch;
+            ptmpDdSurfaceGlobal->fpVidMem = gpl->fpVidMem;
+            ptmpDdSurfaceGlobal->dwBlockSizeX = gpl->dwBlockSizeX;
+            ptmpDdSurfaceGlobal->dwBlockSizeY = gpl->dwBlockSizeY;
+
+            if (lcl->dwFlags & DDRAWISURF_HASPIXELFORMAT)
+            {
+                RtlCopyMemory( &ptmpDdSurfaceGlobal->ddpfSurface ,
+                               &gpl->ddpfSurface,
+                               sizeof(DDPIXELFORMAT));
+
+                ptmpDdSurfaceGlobal->ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
+            }
+            else
+            {
+                RtlCopyMemory( &ptmpDdSurfaceGlobal->ddpfSurface ,
+                               &gpl->lpDD->vmiData.ddpfDisplay,
+                               sizeof(DDPIXELFORMAT));
+            }
+
+            if (lcl->lpSurfMore)
+            {
+                ptmpDdSurfaceMore->ddsCapsEx.dwCaps2 = lcl->lpSurfMore->ddsCapsEx.dwCaps2;
+                ptmpDdSurfaceMore->ddsCapsEx.dwCaps3 = lcl->lpSurfMore->ddsCapsEx.dwCaps3;
+                ptmpDdSurfaceMore->ddsCapsEx.dwCaps4 = lcl->lpSurfMore->ddsCapsEx.dwCaps4;
+                ptmpDdSurfaceMore->dwSurfaceHandle = (DWORD) pCreateSurface->lplpSList[i]->dbnOverlayNode.object_int;
+            }
+
+            /* FIXME count to next SurfaceCount for
+               ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
+               ptmpDdSurfaceLocal = pDdSurfaceLocal;
+               ptmpDdSurfaceMore = pDdSurfaceMore;
+
+               we only support one surface create at moment
+             */
         }
+    }
+
+    /* Call win32k now */
+    pCreateSurface->ddRVal = DDERR_GENERIC;
 
-        /* Convert data */
-        DdSurfaceGlobal.wWidth = pSurfaceGlobal->wWidth;
-        DdSurfaceGlobal.wHeight = pSurfaceGlobal->wHeight;
-        DdSurfaceGlobal.lPitch = pSurfaceGlobal->lPitch;
-        DdSurfaceGlobal.fpVidMem = pSurfaceGlobal->fpVidMem;
-        DdSurfaceGlobal.dwBlockSizeX = pSurfaceGlobal->dwBlockSizeX;
-        DdSurfaceGlobal.dwBlockSizeY = pSurfaceGlobal->dwBlockSizeY;
-        // DdSurfaceGlobal.ddsCaps = pSurfaceLocal->ddsCaps | 0xBF0000;
-
-        /* FIXME: Ddscapsex stuff missing */
-
-        /* Call win32k now */
-        pCreateSurface->ddRVal = E_FAIL;
-               
-        Return = NtGdiDdCreateSurface(GetDdHandle(pCreateSurface->lpDD->hDD),
-                                     (HANDLE *)phSurface,
+    Return = NtGdiDdCreateSurface(GetDdHandle(pCreateSurface->lpDD->hDD),
+                                    (HANDLE *)phSurface,
                                      pSurfaceDesc,
-                                     &DdSurfaceGlobal,
-                                     &DdSurfaceLocal,
-                                     &DdSurfaceMore,
+                                     pDdSurfaceGlobal,
+                                     pDdSurfaceLocal,
+                                     pDdSurfaceMore,
                                      (PDD_CREATESURFACEDATA)pCreateSurface,
                                      puhSurface);
-          
-          
-        /* FIXME: Ddscapsex stuff missing */
-        
-        /* Convert the data back */
-        pSurfaceGlobal->lPitch = DdSurfaceGlobal.lPitch;
-        pSurfaceGlobal->fpVidMem = DdSurfaceGlobal.fpVidMem;
-        pSurfaceGlobal->dwBlockSizeX = DdSurfaceGlobal.dwBlockSizeX;
-        pSurfaceGlobal->dwBlockSizeY = DdSurfaceGlobal.dwBlockSizeY;
-        pCreateSurface->lplpSList[i]->hDDSurface = (DWORD) hSurface;
-
-        /* FIXME: Ddscapsex stuff missing */
+
+    if (SurfaceCount == 0)
+    {
+        pCreateSurface->ddRVal = DDERR_GENERIC;
     }
-    
+    else
+    {
+        ptmpDdSurfaceMore = pDdSurfaceMore;
+        ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
+        ptmpDdSurfaceLocal = pDdSurfaceLocal;
+
+        for (i=0;i<SurfaceCount;i++)
+        {
+            LPDDRAWI_DDRAWSURFACE_LCL lcl = pCreateSurface->lplpSList[i];
+            LPDDRAWI_DDRAWSURFACE_GBL gpl = pCreateSurface->lplpSList[i]->lpGbl;
+
+            gpl->lPitch = ptmpDdSurfaceGlobal->lPitch;
+            gpl->fpVidMem = ptmpDdSurfaceGlobal->fpVidMem;
+            gpl->dwBlockSizeX = ptmpDdSurfaceGlobal->dwBlockSizeX;
+            gpl->dwBlockSizeY = ptmpDdSurfaceGlobal->dwBlockSizeY;
+
+            if (lcl->dwFlags & DDRAWISURF_HASPIXELFORMAT)
+            {
+                RtlCopyMemory( &gpl->ddpfSurface, &ptmpDdSurfaceGlobal->ddpfSurface , sizeof(DDPIXELFORMAT));
+            }
+
+            if (pCreateSurface->ddRVal != DD_OK)
+            {
+                gpl->fpVidMem = 0;
+                if (lcl->hDDSurface)
+                {
+                    NtGdiDdDeleteSurfaceObject( (HANDLE)lcl->hDDSurface);
+                }
+                lcl->hDDSurface = 0;
+            }
+            else
+            {
+
+                lcl->hDDSurface = (ULONG_PTR) puhSurface[i];
+            }
+
+            lcl->ddsCaps.dwCaps = ptmpDdSurfaceLocal->ddsCaps.dwCaps;
+            if (lcl->lpSurfMore)
+            {
+                lcl->lpSurfMore->ddsCapsEx.dwCaps2 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps2;
+                lcl->lpSurfMore->ddsCapsEx.dwCaps3 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps3;
+                lcl->lpSurfMore->ddsCapsEx.dwCaps4 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps4;
+            }
+            /* FIXME count to next SurfaceCount for
+               ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
+               ptmpDdSurfaceLocal = pDdSurfaceLocal;
+               ptmpDdSurfaceMore = pDdSurfaceMore;
+               we only support one surface create at moment
+             */
+        }
+    }
+
     /* Check if we have to free all our local allocations */
     if (SurfaceCount > 1)
     {
-     /* FIXME: */
+        /* FIXME: */
     }
 
     /* Return */
@@ -327,11 +407,10 @@ DdGetScanLine(LPDDHAL_GETSCANLINEDATA pGetScanLine)
 }
 
 /* PRIVATE FUNCTIONS *********************************************************/
-static ULONG RemberDdQueryDisplaySettingsUniquenessID = 0;
 
 BOOL
 WINAPI
-bDDCreateSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface, 
+bDDCreateSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
                  BOOL bComplete)
 {
     DD_SURFACE_LOCAL SurfaceLocal;
@@ -361,7 +440,7 @@ bDDCreateSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
 
     /* Check if we have a pixel format */
     if (pSurface->dwFlags & DDSD_PIXELFORMAT)
-    {  
+    {
         /* Use global one */
         SurfaceGlobal.ddpfSurface = pSurface->lpGbl->lpDD->vmiData.ddpfDisplay;
         SurfaceGlobal.ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
@@ -390,13 +469,13 @@ bDDCreateSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
 /*
  * @implemented
  *
- * GDIEntry 1 
+ * GDIEntry 1
  */
-BOOL 
-WINAPI 
+BOOL
+WINAPI
 DdCreateDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
                          HDC hdc)
-{  
+{
     BOOL Return = FALSE;
 
     /* Check if the global hDC (hdc == 0) is being used */
@@ -406,13 +485,13 @@ DdCreateDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
         if (!ghDirectDraw)
         {
             /* Create the DC */
-            if ((hdc = CreateDC(L"Display", NULL, NULL, NULL)))
+            if ((hdc = CreateDCW(L"Display", NULL, NULL, NULL)))
             {
                 /* Create the DDraw Object */
                 ghDirectDraw = NtGdiDdCreateDirectDrawObject(hdc);
 
-                /* Delete our DC */                
-                               NtGdiDeleteObjectApp(hdc);
+                /* Delete our DC */
+                NtGdiDeleteObjectApp(hdc);
             }
         }
 
@@ -430,8 +509,8 @@ DdCreateDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
     else
     {
         /* Using the per-process object, so create it */
-    pDirectDrawGlobal->hDD = (ULONG_PTR)NtGdiDdCreateDirectDrawObject(hdc); 
-    
+         pDirectDrawGlobal->hDD = (ULONG_PTR)NtGdiDdCreateDirectDrawObject(hdc);
+
         /* Set the return value */
         Return = pDirectDrawGlobal->hDD ? TRUE : FALSE;
     }
@@ -465,25 +544,19 @@ DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
     D3DNTHAL_GLOBALDRIVERDATA D3dDriverData;
     DD_D3DBUFCALLBACKS D3dBufferCallbacks;
     DWORD CallbackFlags[3];
-    DWORD dwNumHeaps=0, FourCCs;
+    DWORD dwNumHeaps=0, FourCCs=0;
     DWORD Flags;
 
-    /* Check if we got a list pointer */
-    if (pvmList)
-    {
-        /* Allocate memory for it */
-        VidMemList = LocalAlloc(LMEM_ZEROINIT,
-                                sizeof(VIDEOMEMORY) *
-                                pHalInfo->vmiData.dwNumHeaps);
-    }
-
     /* Clear the structures */
     RtlZeroMemory(&HalInfo, sizeof(DD_HALINFO));
     RtlZeroMemory(&D3dCallbacks, sizeof(D3DNTHAL_CALLBACKS));
     RtlZeroMemory(&D3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA));
     RtlZeroMemory(&D3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS));
+    RtlZeroMemory(CallbackFlags, sizeof(DWORD)*3);
+
+    pvmList = NULL;
 
-    //* Do the query */
+    /* Do the query */
     if (!NtGdiDdQueryDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
                                       &HalInfo,
                                       CallbackFlags,
@@ -497,7 +570,6 @@ DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
                                       pdwFourCC))
     {
         /* We failed, free the memory and return */
-        if (VidMemList) LocalFree(VidMemList);
         return FALSE;
     }
 
@@ -531,19 +603,27 @@ DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
     pHalInfo->vmiData.dwDisplayHeight = HalInfo.vmiData.dwDisplayHeight;
     pHalInfo->vmiData.lDisplayPitch = HalInfo.vmiData.lDisplayPitch;
     pHalInfo->vmiData.fpPrimary = 0;
-    pHalInfo->vmiData.ddpfDisplay = HalInfo.vmiData.ddpfDisplay;
+
+    RtlCopyMemory( &pHalInfo->vmiData.ddpfDisplay,
+                   &HalInfo.vmiData.ddpfDisplay,
+                   sizeof(DDPIXELFORMAT));
+
     pHalInfo->vmiData.dwOffscreenAlign = HalInfo.vmiData.dwOffscreenAlign;
     pHalInfo->vmiData.dwOverlayAlign = HalInfo.vmiData.dwOverlayAlign;
     pHalInfo->vmiData.dwTextureAlign = HalInfo.vmiData.dwTextureAlign;
     pHalInfo->vmiData.dwZBufferAlign = HalInfo.vmiData.dwZBufferAlign;
     pHalInfo->vmiData.dwAlphaAlign = HalInfo.vmiData.dwAlphaAlign;
-    pHalInfo->vmiData.dwNumHeaps = dwNumHeaps;
+    pHalInfo->vmiData.dwNumHeaps = 0;
     pHalInfo->vmiData.pvmList = pvmList;
-    // pHalInfo->ddCaps = HalInfo.ddCaps;
-    //  pHalInfo->ddCaps.dwNumFourCCCodes = FourCCs;
+
+    RtlCopyMemory( &pHalInfo->ddCaps, &HalInfo.ddCaps,sizeof(DDCORECAPS ));
+
+    pHalInfo->ddCaps.dwNumFourCCCodes = FourCCs;
     pHalInfo->lpdwFourCC = pdwFourCC;
     pHalInfo->ddCaps.dwRops[6] = 0x1000;
-    pHalInfo->dwFlags = HalInfo.dwFlags | DDHALINFO_GETDRIVERINFOSET;
+
+    /* FIXME implement DdGetDriverInfo */
+    //  pHalInfo->dwFlags = HalInfo.dwFlags | DDHALINFO_GETDRIVERINFOSET;
     //  pHalInfo->GetDriverInfo = DdGetDriverInfo;
 
     /* Now check if we got any DD callbacks */
@@ -557,8 +637,8 @@ DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
 
         /* Write the header */
         pDDCallbacks->dwSize = sizeof(DDHAL_DDCALLBACKS);
-               pDDCallbacks->dwFlags = Flags;
-        
+        pDDCallbacks->dwFlags = Flags;
+
         /* Now write the pointers, if applicable */
         if (Flags & DDHAL_CB32_CREATESURFACE)
         {
@@ -586,13 +666,12 @@ DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
 
         /* Set the flags for this one */
         Flags = CallbackFlags[1];
-               
 
         /* Write the header, note that some functions are always exposed */
         pDDSurfaceCallbacks->dwSize  = sizeof(DDHAL_DDSURFACECALLBACKS);
-               
-               pDDSurfaceCallbacks->dwFlags = Flags;
-               /*
+
+        pDDSurfaceCallbacks->dwFlags = Flags;
+        /*
         pDDSurfaceCallBacks->dwFlags = (DDHAL_SURFCB32_LOCK |
                                         DDHAL_SURFCB32_UNLOCK |
                                         DDHAL_SURFCB32_SETCOLORKEY |
@@ -652,7 +731,7 @@ DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
 
     /* Check for D3D Callbacks */
     if (pD3dCallbacks)
-  {       
+    {
         /* Zero the struct */
         RtlZeroMemory(pD3dCallbacks, sizeof(D3DHAL_CALLBACKS));
 
@@ -665,9 +744,9 @@ DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
             /* Now check for each callback */
             if (D3dCallbacks.ContextCreate)
             {
-                                /* FIXME
-                 pD3dCallbacks->ContextCreate = D3dContextCreate; 
-                                */
+                /* FIXME
+                 pD3dCallbacks->ContextCreate = D3dContextCreate;
+                 */
             }
             if (D3dCallbacks.ContextDestroy)
             {
@@ -675,9 +754,9 @@ DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
             }
             if (D3dCallbacks.ContextDestroyAll)
             {
-                               /* FIXME 
+                /* FIXME
                 pD3dCallbacks->ContextDestroyAll = (LPD3DHAL_CONTEXTDESTROYALLCB) NtGdiD3dContextDestroyAll;
-                               */
+                */
             }
         }
     }
@@ -696,33 +775,6 @@ DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
 
     /* FIXME: Check for D3D Buffer Callbacks */
 
-    /* Check if we have a video memory list */
-    if (VidMemList)
-    {
-        /* Start a loop here */
-        PVIDEOMEMORY VidMem = VidMemList;
-
-        /* Loop all the heaps we have */
-        while (dwNumHeaps--)
-        {
-            /* Copy from one format to the other */
-            pvmList->dwFlags = VidMem->dwFlags;
-            pvmList->fpStart = VidMem->fpStart;
-            pvmList->fpEnd = VidMem->fpEnd;
-            pvmList->ddsCaps = VidMem->ddsCaps;
-            pvmList->ddsCapsAlt = VidMem->ddsCapsAlt;
-            pvmList->dwHeight = VidMem->dwHeight;
-
-            /* Advance in both structures */
-            pvmList++;
-            VidMem++;
-        }
-
-        /* Free our structure */
-        LocalFree(VidMemList);
-    }
-
-  
   return TRUE;
 }
 
@@ -731,7 +783,7 @@ DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
  *
  * GDIEntry 3
  */
-BOOL 
+BOOL
 WINAPI
 DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
 {
@@ -773,13 +825,12 @@ DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
  *
  * GDIEntry 4
  */
-BOOL 
-WINAPI 
+BOOL
+WINAPI
 DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
                        BOOL bPrimarySurface)
 {
-       return bDDCreateSurface(pSurfaceLocal, TRUE);
-    //return bDdCreateSurfaceObject(pSurfaceLocal, TRUE);
+    return bDDCreateSurface(pSurfaceLocal, TRUE);
 }
 
 
@@ -788,8 +839,8 @@ DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
  *
  * GDIEntry 5
  */
-BOOL 
-WINAPI 
+BOOL
+WINAPI
 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
 {
     BOOL Return = FALSE;
@@ -810,9 +861,9 @@ DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
  *
  * GDIEntry 6
  */
-BOOL 
-WINAPI 
-DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal, 
+BOOL
+WINAPI
+DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
               HWND hWnd)
 {
     /* Call win32k directly */
@@ -859,8 +910,8 @@ DdCreateDIBSection(HDC hdc,
                    HANDLE hSectionApp,
                    DWORD dwOffset)
 {
-       SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-       return 0;
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return 0;
 }
 
 /*
@@ -868,15 +919,15 @@ DdCreateDIBSection(HDC hdc,
  *
  * GDIEntry 10
  */
-BOOL 
-WINAPI 
+BOOL
+WINAPI
 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
                            BOOL *pbNewMode)
 {
     /* Call win32k directly */
     return NtGdiDdReenableDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
                                            pbNewMode);
-} 
+}
 
 
 /*
@@ -884,13 +935,13 @@ DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
  *
  * GDIEntry 11
  */
-BOOL 
-STDCALL 
+BOOL
+STDCALL
 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
                  LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
 {
     /* Create Surface if it does not exits one */
-    if (pSurfaceFrom->hDDSurface)
+    if (!pSurfaceFrom->hDDSurface)
     {
         if (!bDDCreateSurface(pSurfaceFrom, FALSE))
         {
@@ -899,7 +950,7 @@ DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
     }
 
     /* Create Surface if it does not exits one */
-    if (pSurfaceTo->hDDSurface)
+    if (!pSurfaceTo->hDDSurface)
     {
         if (!bDDCreateSurface(pSurfaceTo, FALSE))
         {
@@ -933,10 +984,10 @@ DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
  * GDIEntry 13
  */
 ULONG
-STDCALL 
+STDCALL
 DdQueryDisplaySettingsUniqueness()
 {
- return RemberDdQueryDisplaySettingsUniquenessID;
+ return GdiSharedHandleTable->flDeviceUniq;
 }
 
 /*
@@ -944,8 +995,8 @@ DdQueryDisplaySettingsUniqueness()
  *
  * GDIEntry 14
  */
-HANDLE 
-WINAPI 
+HANDLE
+WINAPI
 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
               LPDDRAWI_DDRAWSURFACE_LCL pSurface,
               BOOL bRelease)
@@ -981,20 +1032,7 @@ DdSetGammaRamp(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
                                hdc,
                                lpGammaRamp);
 }
-/*
- * @implemented
- *
- * GDIEntry 16
- */
-DWORD
-WINAPI
-DdSwapTextureHandles(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
-                     LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl1,
-                     LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl2)
-{
-    /* Always returns success */
-    return TRUE;
-}
+