[CMAKE]
[reactos.git] / subsystems / win32 / win32k / objects / dclife.c
index c57346f..589e92c 100644 (file)
@@ -58,7 +58,9 @@ static const MATRIX   gmxWorldToPageDefault =
 
 /** Internal functions ********************************************************/
 
+INIT_FUNCTION
 NTSTATUS
+NTAPI
 InitDcImpl()
 {
     psurfDefaultBitmap = SURFACE_ShareLockSurface(StockObjects[DEFAULT_BITMAP]);
@@ -89,8 +91,6 @@ DC_AllocDcWithHandle()
 void
 DC_InitHack(PDC pdc)
 {
-    HRGN hVisRgn;
-
     TextIntRealizeFont(pdc->pdcattr->hlfntNew,NULL);
     pdc->pdcattr->iCS_CP = ftGdiGetTextCharsetInfo(pdc,NULL,0);
 
@@ -98,14 +98,8 @@ DC_InitHack(PDC pdc)
     ASSERT(pdc->dclevel.ppal);
 
     /* Select regions */
-    // FIXME: too complicated, broken error handling
     pdc->rosdc.hClipRgn = NULL;
     pdc->rosdc.hGCClipRgn = NULL;
-    hVisRgn = NtGdiCreateRectRgn(0, 0, pdc->dclevel.sizl.cx, pdc->dclevel.sizl.cy);
-    ASSERT(hVisRgn);
-    GdiSelectVisRgn(pdc->BaseObject.hHmgr, hVisRgn);
-    GreDeleteObject(hVisRgn);
-    ASSERT(pdc->prgnVis);
 }
 
 VOID
@@ -115,14 +109,6 @@ DC_vInitDc(
     DCTYPE dctype,
     PPDEVOBJ ppdev)
 {
-#if 0
-    if (dctype == DCTYPE_DIRECT)
-    {
-        /* Lock ppdev */
-        EngAcquireSemaphoreShared(ppdev->hsemDevLock);
-    }
-#endif
-
     /* Setup some basic fields */
     pdc->dctype = dctype;
     pdc->ppdev = ppdev;
@@ -233,17 +219,20 @@ DC_vInitDc(
        pdc->dcattr.ptlViewportOrg.y = 0;
        pdc->dcattr.szlViewportExt.cx = 1;
        pdc->dcattr.szlViewportExt.cy = 1;
-    pdc->dcattr.szlVirtualDevicePixel.cx = 0;
-    pdc->dcattr.szlVirtualDevicePixel.cy = 0;
-    pdc->dcattr.szlVirtualDeviceMm.cx = 0;
-    pdc->dcattr.szlVirtualDeviceMm.cy = 0;
+    pdc->dcattr.szlVirtualDevicePixel.cx = ppdev->gdiinfo.ulHorzRes;
+    pdc->dcattr.szlVirtualDevicePixel.cy = ppdev->gdiinfo.ulVertRes;
+    pdc->dcattr.szlVirtualDeviceMm.cx = ppdev->gdiinfo.ulHorzSize;
+    pdc->dcattr.szlVirtualDeviceMm.cy = ppdev->gdiinfo.ulVertSize;
     pdc->dcattr.szlVirtualDeviceSize.cx = 0;
     pdc->dcattr.szlVirtualDeviceSize.cy = 0;
 
     /* Setup regions */
     pdc->prgnAPI = NULL;
-    pdc->prgnVis = NULL; // FIXME
-    pdc->prgnRao = NULL;
+       pdc->prgnRao = NULL;
+    /* Allocate a Vis region */
+    pdc->prgnVis = IntSysCreateRectpRgn(0, 0, pdc->dclevel.sizl.cx, pdc->dclevel.sizl.cy);
+       ASSERT(pdc->prgnVis);
+       GDIOBJ_CopyOwnership(pdc->BaseObject.hHmgr, pdc->prgnVis->BaseObject.hHmgr);
 
     /* Setup palette */
     pdc->dclevel.hpal = StockObjects[DEFAULT_PALETTE];
@@ -393,8 +382,6 @@ DC_SetOwnership(HDC hDC, PEPROCESS Owner)
     PDC pDC;
     BOOL ret = FALSE;
 
-    /* FIXME: This function has broken error handling */
-
     if (!GDIOBJ_SetOwnership(hDC, Owner))
     {
         DPRINT1("GDIOBJ_SetOwnership failed\n");
@@ -496,7 +483,7 @@ DC_vPrepareDCsForBlit(PDC pdc1,
     /* Lock them in good order */
     if(pdc2)
     {
-        if((ULONG_PTR)pdc1->BaseObject.hHmgr >= (ULONG_PTR)pdc2->BaseObject.hHmgr)
+        if((ULONG_PTR)pdc1->ppdev->hsemDevLock >= (ULONG_PTR)pdc2->ppdev->hsemDevLock)
         {
             pdcFirst = pdc1;
             prcFirst = &rc1;
@@ -801,11 +788,28 @@ IntGdiDeleteDC(HDC hDC, BOOL Force)
 
     if (!Force)
     {
+        /* Windows permits NtGdiDeleteObjectApp to delete a permanent DC
+         * For some reason, it's still a valid handle, pointing to some kernel data.
+         * Not sure if this is a bug, a feature, some cache stuff... Who knows?
+         * See NtGdiDeleteObjectApp test for details */
         if (DCToDelete->fs & DC_FLAG_PERMANENT)
         {
-            DPRINT1("No! You Naughty Application!\n");
             DC_UnlockDc(DCToDelete);
-            return UserReleaseDC(NULL, hDC, FALSE);
+            if(UserReleaseDC(NULL, hDC, FALSE))
+            {
+                /* ReactOs feature : call UserReleaseDC
+                 * I don't think windows does it.
+                 * Still, complain, no one should ever call DeleteDC
+                 * on a window DC */
+                 DPRINT1("No, you naughty application!\n");
+                 return TRUE;
+            }
+            else
+            {
+                /* This is not a window owned DC.
+                 * Force its deletion */
+                return IntGdiDeleteDC(hDC, TRUE);
+            }
         }
     }
 
@@ -822,7 +826,7 @@ IntGdiDeleteDC(HDC hDC, BOOL Force)
     {
         DPRINT1("Attempted to Delete 0x%x currently being destroyed!!!\n", hDC);
     }
-
+    
     return TRUE;
 }