[WIN32K]
[reactos.git] / subsystems / win32 / win32k / objects / dclife.c
index 1a354f3..9df6683 100644 (file)
@@ -90,7 +90,7 @@ void
 DC_InitHack(PDC pdc)
 {
     HRGN hVisRgn;
-    if (!pdc) return;
+
     TextIntRealizeFont(pdc->pdcattr->hlfntNew,NULL);
     pdc->pdcattr->iCS_CP = ftGdiGetTextCharsetInfo(pdc,NULL,0);
 
@@ -105,7 +105,7 @@ DC_InitHack(PDC pdc)
     ASSERT(hVisRgn);
     GdiSelectVisRgn(pdc->BaseObject.hHmgr, hVisRgn);
     GreDeleteObject(hVisRgn);
-    ASSERT(pdc->rosdc.hVisRgn);
+    ASSERT(pdc->prgnVis);
     pdc->rosdc.bitsPerPixel = pdc->ppdev->gdiinfo.cBitsPixel *
                               pdc->ppdev->gdiinfo.cPlanes;
 }
@@ -117,6 +117,8 @@ DC_vInitDc(
     DCTYPE dctype,
     PPDEVOBJ ppdev)
 {
+    /* Lock ppdev */
+    EngAcquireSemaphoreShared(ppdev->hsemDevLock);
 
     /* Setup some basic fields */
     pdc->dctype = dctype;
@@ -362,8 +364,8 @@ DC_Cleanup(PVOID ObjectBody)
     /*  Free regions */
     if (pdc->rosdc.hClipRgn)
         GreDeleteObject(pdc->rosdc.hClipRgn);
-    if (pdc->rosdc.hVisRgn)
-        GreDeleteObject(pdc->rosdc.hVisRgn);
+    if (pdc->prgnVis)
+        REGION_FreeRgnByHandle(((PROSRGNDATA)pdc->prgnVis)->BaseObject.hHmgr);
 ASSERT(pdc->rosdc.hGCClipRgn);
     if (pdc->rosdc.hGCClipRgn)
         GreDeleteObject(pdc->rosdc.hGCClipRgn);
@@ -382,6 +384,7 @@ DC_SetOwnership(HDC hDC, PEPROCESS Owner)
     INT Index;
     PGDI_TABLE_ENTRY Entry;
     PDC pDC;
+    BOOL ret;
 
     /* FIXME: This function has broken error handling */
 
@@ -403,40 +406,43 @@ DC_SetOwnership(HDC hDC, PEPROCESS Owner)
           These regions do not use attribute sections and when allocated, use
           gdiobj level functions.
     */
-        if (pDC->rosdc.hClipRgn)
-        {   // FIXME! HAX!!!
-            Index = GDI_HANDLE_GET_INDEX(pDC->rosdc.hClipRgn);
-            Entry = &GdiHandleTable->Entries[Index];
-            if (Entry->UserData) FreeObjectAttr(Entry->UserData);
-            Entry->UserData = NULL;
-            //
-            if (!GDIOBJ_SetOwnership(pDC->rosdc.hClipRgn, Owner)) return FALSE;
-        }
-        if (pDC->rosdc.hVisRgn)
-        {   // FIXME! HAX!!!
-            Index = GDI_HANDLE_GET_INDEX(pDC->rosdc.hVisRgn);
-            Entry = &GdiHandleTable->Entries[Index];
-            if (Entry->UserData) FreeObjectAttr(Entry->UserData);
-            Entry->UserData = NULL;
-            //
-            if (!GDIOBJ_SetOwnership(pDC->rosdc.hVisRgn, Owner)) return FALSE;
-        }
-        if (pDC->rosdc.hGCClipRgn)
-        {   // FIXME! HAX!!!
-            Index = GDI_HANDLE_GET_INDEX(pDC->rosdc.hGCClipRgn);
-            Entry = &GdiHandleTable->Entries[Index];
-            if (Entry->UserData) FreeObjectAttr(Entry->UserData);
-            Entry->UserData = NULL;
-            //
-            if (!GDIOBJ_SetOwnership(pDC->rosdc.hGCClipRgn, Owner)) return FALSE;
-        }
-        if (pDC->dclevel.hPath)
-        {
-            if (!GDIOBJ_SetOwnership(pDC->dclevel.hPath, Owner)) return FALSE;
-        }
-        DC_UnlockDc(pDC);
+    if (pDC->rosdc.hClipRgn)
+    {   // FIXME! HAX!!!
+        Index = GDI_HANDLE_GET_INDEX(pDC->rosdc.hClipRgn);
+        Entry = &GdiHandleTable->Entries[Index];
+        if (Entry->UserData) FreeObjectAttr(Entry->UserData);
+        Entry->UserData = NULL;
+        //
+        if (!GDIOBJ_SetOwnership(pDC->rosdc.hClipRgn, Owner)) goto leave;
+    }
+    if (pDC->prgnVis)
+    {   // FIXME! HAX!!!
+        Index = GDI_HANDLE_GET_INDEX(((PROSRGNDATA)pDC->prgnVis)->BaseObject.hHmgr);
+        Entry = &GdiHandleTable->Entries[Index];
+        if (Entry->UserData) FreeObjectAttr(Entry->UserData);
+        Entry->UserData = NULL;
+        //
+        if (!GDIOBJ_SetOwnership(((PROSRGNDATA)pDC->prgnVis)->BaseObject.hHmgr, Owner)) goto leave;
+    }
+    if (pDC->rosdc.hGCClipRgn)
+    {   // FIXME! HAX!!!
+        Index = GDI_HANDLE_GET_INDEX(pDC->rosdc.hGCClipRgn);
+        Entry = &GdiHandleTable->Entries[Index];
+        if (Entry->UserData) FreeObjectAttr(Entry->UserData);
+        Entry->UserData = NULL;
+        //
+        if (!GDIOBJ_SetOwnership(pDC->rosdc.hGCClipRgn, Owner)) goto leave;
+    }
+    if (pDC->dclevel.hPath)
+    {
+        if (!GDIOBJ_SetOwnership(pDC->dclevel.hPath, Owner)) goto leave;
+    }
+    ret = TRUE;
 
-    return TRUE;
+leave:
+    DC_UnlockDc(pDC);
+
+    return ret;
 }
 
 HDC
@@ -477,6 +483,7 @@ GreOpenDCW(
     }
     hdc = pdc->BaseObject.hHmgr;
 
+    /* Lock ppdev and initialize the new DC */
     DC_vInitDc(pdc, iType, ppdev);
     /* FIXME: HACK! */
     DC_InitHack(pdc);
@@ -594,7 +601,7 @@ NtGdiCreateCompatibleDC(HDC hdc)
 {
     HDC hdcNew;
     PPDEVOBJ ppdev;
-    PDC pdc = NULL, pdcNew;
+    PDC pdc, pdcNew;
 
     DPRINT("NtGdiCreateCompatibleDC(0x%p)\n", hdc);
 
@@ -638,7 +645,7 @@ NtGdiCreateCompatibleDC(HDC hdc)
     }
     hdcNew = pdcNew->BaseObject.hHmgr;
 
-    /* Initialize the new DC */
+    /* Lock ppdev and initialize the new DC */
     DC_vInitDc(pdcNew, DCTYPE_MEMORY, ppdev);
     /* FIXME: HACK! */
     DC_InitHack(pdcNew);