[ros-diffs] [tkreuzer] 40243: Move NtGdiSelectBitmap to dcobjs.c, implement DC_vSelectFillBrush and DC_vSelectLineBrush, use them in IntGdiSelectBrush and IntGdiSelectPen, DC_Cleanup and DC_vCopyState. Should fix leaking brushes/pens on process cleanup. Remove the flag checks from DC_vUpdateXxxBrush functions.

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Thu Mar 26 01:56:47 CET 2009


Author: tkreuzer
Date: Thu Mar 26 03:56:46 2009
New Revision: 40243

URL: http://svn.reactos.org/svn/reactos?rev=40243&view=rev
Log:
Move NtGdiSelectBitmap to dcobjs.c, implement DC_vSelectFillBrush and DC_vSelectLineBrush, use them in IntGdiSelectBrush and IntGdiSelectPen, DC_Cleanup and DC_vCopyState. Should fix leaking brushes/pens on process cleanup.
Remove the flag checks from DC_vUpdateXxxBrush functions.

Modified:
    trunk/reactos/subsystems/win32/win32k/include/dc.h
    trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c
    trunk/reactos/subsystems/win32/win32k/objects/dclife.c
    trunk/reactos/subsystems/win32/win32k/objects/dcobjs.c
    trunk/reactos/subsystems/win32/win32k/objects/dcstate.c

Modified: trunk/reactos/subsystems/win32/win32k/include/dc.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/include/dc.h?rev=40243&r1=40242&r2=40243&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/dc.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/include/dc.h [iso-8859-1] Thu Mar 26 03:56:46 2009
@@ -278,11 +278,33 @@
     PSURFACE psurfOld = pdc->dclevel.pSurface;
     if (psurfOld)
         SURFACE_ShareUnlockSurface(psurfOld);
-    
     if (psurfNew)
         GDIOBJ_IncrementShareCount((POBJ)psurfNew);
-
     pdc->dclevel.pSurface = psurfNew;
+}
+
+VOID
+FORCEINLINE
+DC_vSelectFillBrush(PDC pdc, PBRUSH pbrFill)
+{
+    PBRUSH pbrFillOld = pdc->dclevel.pbrFill;
+    if (pbrFillOld)
+        BRUSH_ShareUnlockBrush(pbrFillOld);
+    if (pbrFill)
+        GDIOBJ_IncrementShareCount((POBJ)pbrFill);
+    pdc->dclevel.pbrFill = pbrFill;
+}
+
+VOID
+FORCEINLINE
+DC_vSelectLineBrush(PDC pdc, PBRUSH pbrLine)
+{
+    PBRUSH pbrLineOld = pdc->dclevel.pbrLine;
+    if (pbrLineOld)
+        BRUSH_ShareUnlockBrush(pbrLineOld);
+    if (pbrLine)
+        GDIOBJ_IncrementShareCount((POBJ)pbrLine);
+    pdc->dclevel.pbrLine = pbrLine;
 }
 
 BOOL FASTCALL

Modified: trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c?rev=40243&r1=40242&r2=40243&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c [iso-8859-1] Thu Mar 26 03:56:46 2009
@@ -920,115 +920,4 @@
     return hDC;
 }
 
-/*
- * @implemented
- */
-HBITMAP
-APIENTRY
-NtGdiSelectBitmap(
-    IN HDC hDC,
-    IN HBITMAP hBmp)
-{
-    PDC pDC;
-    PDC_ATTR pdcattr;
-    HBITMAP hOrgBmp;
-    PSURFACE psurfBmp, psurfOld;
-    HRGN hVisRgn;
-    BOOLEAN bFailed;
-    PBRUSH pbrush;
-
-    if (hDC == NULL || hBmp == NULL) return NULL;
-
-    pDC = DC_LockDc(hDC);
-    if (!pDC)
-    {
-        return NULL;
-    }
-
-    pdcattr = pDC->pdcattr;
-
-    /* must be memory dc to select bitmap */
-    if (pDC->dctype != DC_TYPE_MEMORY)
-    {
-        DC_UnlockDc(pDC);
-        return NULL;
-    }
-
-    psurfBmp = SURFACE_LockSurface(hBmp);
-    if (!psurfBmp)
-    {
-        DC_UnlockDc(pDC);
-        return NULL;
-    }
-
-    /* Get the handle for the old bitmap */
-    psurfOld = pDC->dclevel.pSurface;
-    hOrgBmp = psurfOld ? psurfOld->BaseObject.hHmgr : NULL;
-
-    /* FIXME: ros hack */
-    hOrgBmp = pDC->rosdc.hBitmap;
-
-    pDC->rosdc.hBitmap = hBmp;
-
-    /* Release the old bitmap, reference the new */
-    DC_vSelectSurface(pDC, psurfBmp);
-
-    // If Info DC this is zero and pSurface is moved to DC->pSurfInfo.
-    psurfBmp->hDC = hDC;
-
-    // if we're working with a DIB, get the palette 
-    // [fixme: only create if the selected palette is null]
-    if (psurfBmp->hSecure)
-    {
-//        pDC->rosdc.bitsPerPixel = psurfBmp->dib->dsBmih.biBitCount; ???
-        pDC->rosdc.bitsPerPixel = BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat);
-    }
-    else
-    {
-        pDC->rosdc.bitsPerPixel = BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat);
-    }
-
-    /* FIXME; improve by using a region without a handle and selecting it */
-    hVisRgn = NtGdiCreateRectRgn(0,
-                                 0,
-                                 psurfBmp->SurfObj.sizlBitmap.cx,
-                                 psurfBmp->SurfObj.sizlBitmap.cy);
-
-    /* Release the exclusive lock */
-    SURFACE_UnlockSurface(psurfBmp);
-
-    /* Regenerate the XLATEOBJs. (hack!) */
-    pbrush = BRUSH_LockBrush(pdcattr->hbrush);
-    if (pbrush)
-    {
-        if (pDC->rosdc.XlateBrush)
-        {
-            EngDeleteXlate(pDC->rosdc.XlateBrush);
-        }
-        pDC->rosdc.XlateBrush = IntGdiCreateBrushXlate(pDC, pbrush, &bFailed);
-        BRUSH_UnlockBrush(pbrush);
-    }
-
-    pbrush = PEN_LockPen(pdcattr->hpen);
-    if (pbrush)
-    {
-        if (pDC->rosdc.XlatePen)
-        {
-            EngDeleteXlate(pDC->rosdc.XlatePen);
-        }
-        pDC->rosdc.XlatePen = IntGdiCreateBrushXlate(pDC, pbrush, &bFailed);
-        PEN_UnlockPen(pbrush);
-    }
-
-    DC_UnlockDc(pDC);
-
-    if (hVisRgn)
-    {
-        GdiSelectVisRgn(hDC, hVisRgn);
-        GreDeleteObject(hVisRgn);
-    }
-
-    return hOrgBmp;
-}
-
 /* EOF */

Modified: trunk/reactos/subsystems/win32/win32k/objects/dclife.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/objects/dclife.c?rev=40243&r1=40242&r2=40243&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/dclife.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/dclife.c [iso-8859-1] Thu Mar 26 03:56:46 2009
@@ -139,9 +139,16 @@
 DC_Cleanup(PVOID ObjectBody)
 {
     PDC pDC = (PDC)ObjectBody;
+
+    /* Free driver name (HACK) */
     if (pDC->rosdc.DriverName.Buffer)
         ExFreePoolWithTag(pDC->rosdc.DriverName.Buffer, TAG_DC);
+
+    /* Clean up selected objects */
     DC_vSelectSurface(pDC, NULL);
+    DC_vSelectFillBrush(pDC, NULL);
+    DC_vSelectLineBrush(pDC, NULL);
+
     return TRUE;
 }
 

Modified: trunk/reactos/subsystems/win32/win32k/objects/dcobjs.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/objects/dcobjs.c?rev=40243&r1=40242&r2=40243&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/dcobjs.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/dcobjs.c [iso-8859-1] Thu Mar 26 03:56:46 2009
@@ -21,46 +21,42 @@
     XLATEOBJ *pxlo;
     ULONG iSolidColor;
 
-    /* Check if update of eboFill is needed */
-    if (pdcattr->ulDirty_ & DIRTY_FILL)
-    {
-        /* ROS HACK, should use surf xlate */
-        pxlo = pdc->rosdc.XlatePen;
-
-        /* Check if the brush handle has changed */
-        if (pdcattr->hbrush != pdc->dclevel.pbrFill->BaseObject.hHmgr)
+    /* ROS HACK, should use surf xlate */
+    pxlo = pdc->rosdc.XlatePen;
+
+    /* Check if the brush handle has changed */
+    if (pdcattr->hbrush != pdc->dclevel.pbrFill->BaseObject.hHmgr)
+    {
+        /* Try to lock the new brush */
+        pbrFill = BRUSH_ShareLockBrush(pdcattr->hbrush);
+        if (pbrFill)
         {
-            /* Try to lock the new brush */
-            pbrFill = BRUSH_ShareLockBrush(pdcattr->hbrush);
-            if (pbrFill)
-            {
-                /* Unlock old brush, set new brush */
-                BRUSH_ShareUnlockBrush(pdc->dclevel.pbrFill);
-                pdc->dclevel.pbrFill = pbrFill;
-
-                /* Update eboFill, realizing it, if needed */
-                EBRUSHOBJ_vUpdate(&pdc->eboFill, pbrFill, pxlo);
-            }
-            else
-            {
-                /* Invalid brush handle, restore old one */
-                pdcattr->hbrush = pdc->dclevel.pbrFill->BaseObject.hHmgr;
-            }
+            /* Unlock old brush, set new brush */
+            BRUSH_ShareUnlockBrush(pdc->dclevel.pbrFill);
+            pdc->dclevel.pbrFill = pbrFill;
+
+            /* Update eboFill, realizing it, if needed */
+            EBRUSHOBJ_vUpdate(&pdc->eboFill, pbrFill, pxlo);
         }
-
-        /* Check for DC brush */
-        if (pdcattr->hbrush == StockObjects[DC_BRUSH])
+        else
         {
-            /* Translate the color to the target format */
-            iSolidColor = XLATEOBJ_iXlate(pxlo, pdcattr->crPenClr);
-
-            /* Update the eboFill's solid color */
-            EBRUSHOBJ_vSetSolidBrushColor(&pdc->eboFill, iSolidColor);
+            /* Invalid brush handle, restore old one */
+            pdcattr->hbrush = pdc->dclevel.pbrFill->BaseObject.hHmgr;
         }
-
-        /* Clear flag */
-        pdcattr->ulDirty_ &= ~DIRTY_FILL;
-    }
+    }
+
+    /* Check for DC brush */
+    if (pdcattr->hbrush == StockObjects[DC_BRUSH])
+    {
+        /* Translate the color to the target format */
+        iSolidColor = XLATEOBJ_iXlate(pxlo, pdcattr->crPenClr);
+
+        /* Update the eboFill's solid color */
+        EBRUSHOBJ_vSetSolidBrushColor(&pdc->eboFill, iSolidColor);
+    }
+
+    /* Clear flags */
+    pdcattr->ulDirty_ &= ~(DIRTY_FILL | DC_BRUSH_DIRTY);
 }
 
 VOID
@@ -72,46 +68,42 @@
     XLATEOBJ *pxlo;
     ULONG iSolidColor;
 
-    /* Check if update of eboLine is needed */
-    if (pdcattr->ulDirty_ & DIRTY_LINE)
-    {
-        /* ROS HACK, should use surf xlate */
-        pxlo = pdc->rosdc.XlatePen;
-
-        /* Check if the pen handle has changed */
-        if (pdcattr->hpen != pdc->dclevel.pbrLine->BaseObject.hHmgr)
+    /* ROS HACK, should use surf xlate */
+    pxlo = pdc->rosdc.XlatePen;
+
+    /* Check if the pen handle has changed */
+    if (pdcattr->hpen != pdc->dclevel.pbrLine->BaseObject.hHmgr)
+    {
+        /* Try to lock the new pen */
+        pbrLine = BRUSH_ShareLockBrush(pdcattr->hpen);
+        if (pbrLine)
         {
-            /* Try to lock the new pen */
-            pbrLine = BRUSH_ShareLockBrush(pdcattr->hpen);
-            if (pbrLine)
-            {
-                /* Unlock old brush, set new brush */
-                BRUSH_ShareUnlockBrush(pdc->dclevel.pbrLine);
-                pdc->dclevel.pbrLine = pbrLine;
-
-                /* Update eboLine, realizing it, if needed */
-                EBRUSHOBJ_vUpdate(&pdc->eboLine, pbrLine, pxlo);
-            }
-            else
-            {
-                /* Invalid pen handle, restore old one */
-                pdcattr->hpen = pdc->dclevel.pbrLine->BaseObject.hHmgr;
-            }
+            /* Unlock old brush, set new brush */
+            BRUSH_ShareUnlockBrush(pdc->dclevel.pbrLine);
+            pdc->dclevel.pbrLine = pbrLine;
+
+            /* Update eboLine, realizing it, if needed */
+            EBRUSHOBJ_vUpdate(&pdc->eboLine, pbrLine, pxlo);
         }
-
-        /* Check for DC pen */
-        if (pdcattr->hpen == StockObjects[DC_PEN])
+        else
         {
-            /* Translate the color to the target format */
-            iSolidColor = XLATEOBJ_iXlate(pxlo, pdcattr->crPenClr);
-
-            /* Update the eboLine's solid color */
-            EBRUSHOBJ_vSetSolidBrushColor(&pdc->eboLine, iSolidColor);
+            /* Invalid pen handle, restore old one */
+            pdcattr->hpen = pdc->dclevel.pbrLine->BaseObject.hHmgr;
         }
-
-        /* Clear flag */
-        pdcattr->ulDirty_ &= ~DIRTY_LINE;
-    }
+    }
+
+    /* Check for DC pen */
+    if (pdcattr->hpen == StockObjects[DC_PEN])
+    {
+        /* Translate the color to the target format */
+        iSolidColor = XLATEOBJ_iXlate(pxlo, pdcattr->crPenClr);
+
+        /* Update the eboLine's solid color */
+        EBRUSHOBJ_vSetSolidBrushColor(&pdc->eboLine, iSolidColor);
+    }
+
+    /* Clear flag */
+    pdcattr->ulDirty_ &= ~DIRTY_LINE;
 }
 
 VOID
@@ -122,21 +114,17 @@
     XLATEOBJ *pxlo;
     ULONG iSolidColor;
 
-    /* Check if update of eboText is needed */
-    if (pdcattr->ulDirty_ & DIRTY_TEXT)
-    {
-        /* ROS HACK, should use surf xlate */
-        pxlo = pdc->rosdc.XlatePen;
-
-        /* Translate the color to the target format */
-        iSolidColor = XLATEOBJ_iXlate(pxlo, pdcattr->crForegroundClr);
-
-        /* Update the eboText's solid color */
-        EBRUSHOBJ_vSetSolidBrushColor(&pdc->eboText, iSolidColor);
-
-        /* Clear flag */
-        pdcattr->ulDirty_ &= ~DIRTY_TEXT;
-    }
+    /* ROS HACK, should use surf xlate */
+    pxlo = pdc->rosdc.XlatePen;
+
+    /* Translate the color to the target format */
+    iSolidColor = XLATEOBJ_iXlate(pxlo, pdcattr->crForegroundClr);
+
+    /* Update the eboText's solid color */
+    EBRUSHOBJ_vSetSolidBrushColor(&pdc->eboText, iSolidColor);
+
+    /* Clear flag */
+    pdcattr->ulDirty_ &= ~DIRTY_TEXT;
 }
 
 VOID
@@ -147,21 +135,17 @@
     XLATEOBJ *pxlo;
     ULONG iSolidColor;
 
-    /* Check if update of eboBackground is needed */
-    if (pdcattr->ulDirty_ & DIRTY_BACKGROUND)
-    {
-        /* ROS HACK, should use surf xlate */
-        pxlo = pdc->rosdc.XlatePen;
-
-        /* Translate the color to the target format */
-        iSolidColor = XLATEOBJ_iXlate(pxlo, pdcattr->crBackgroundClr);
-
-        /* Update the eboBackground's solid color */
-        EBRUSHOBJ_vSetSolidBrushColor(&pdc->eboBackground, iSolidColor);
-
-        /* Clear flag */
-        pdcattr->ulDirty_ &= ~DIRTY_BACKGROUND;
-    }
+    /* ROS HACK, should use surf xlate */
+    pxlo = pdc->rosdc.XlatePen;
+
+    /* Translate the color to the target format */
+    iSolidColor = XLATEOBJ_iXlate(pxlo, pdcattr->crBackgroundClr);
+
+    /* Update the eboBackground's solid color */
+    EBRUSHOBJ_vSetSolidBrushColor(&pdc->eboBackground, iSolidColor);
+
+    /* Clear flag */
+    pdcattr->ulDirty_ &= ~DIRTY_BACKGROUND;
 }
 
 HPALETTE 
@@ -232,6 +216,8 @@
         return NULL;
     }
 
+    DC_vSelectFillBrush(pDC, pbrush);
+
     XlateObj = IntGdiCreateBrushXlate(pDC, pbrush, &bFailed);
     BRUSH_UnlockBrush(pbrush);
     if(bFailed)
@@ -274,6 +260,8 @@
     {
         return NULL;
     }
+
+    DC_vSelectLineBrush(pDC, pbrushPen);
 
     XlateObj = IntGdiCreateBrushXlate(pDC, pbrushPen, &bFailed);
     PEN_UnlockPen(pbrushPen);
@@ -352,6 +340,117 @@
     return hOrgPen;
 }
 
+/*
+ * @implemented
+ */
+HBITMAP
+APIENTRY
+NtGdiSelectBitmap(
+    IN HDC hDC,
+    IN HBITMAP hBmp)
+{
+    PDC pDC;
+    PDC_ATTR pdcattr;
+    HBITMAP hOrgBmp;
+    PSURFACE psurfBmp, psurfOld;
+    HRGN hVisRgn;
+    BOOLEAN bFailed;
+    PBRUSH pbrush;
+
+    if (hDC == NULL || hBmp == NULL) return NULL;
+
+    pDC = DC_LockDc(hDC);
+    if (!pDC)
+    {
+        return NULL;
+    }
+    pdcattr = pDC->pdcattr;
+
+    /* must be memory dc to select bitmap */
+    if (pDC->dctype != DC_TYPE_MEMORY)
+    {
+        DC_UnlockDc(pDC);
+        return NULL;
+    }
+
+    psurfBmp = SURFACE_LockSurface(hBmp);
+    if (!psurfBmp)
+    {
+        DC_UnlockDc(pDC);
+        return NULL;
+    }
+
+    /* Get the handle for the old bitmap */
+    psurfOld = pDC->dclevel.pSurface;
+    hOrgBmp = psurfOld ? psurfOld->BaseObject.hHmgr : NULL;
+
+    /* FIXME: ros hack */
+    hOrgBmp = pDC->rosdc.hBitmap;
+
+    pDC->rosdc.hBitmap = hBmp;
+
+    /* Release the old bitmap, reference the new */
+    DC_vSelectSurface(pDC, psurfBmp);
+
+    // If Info DC this is zero and pSurface is moved to DC->pSurfInfo.
+    psurfBmp->hDC = hDC;
+
+    // if we're working with a DIB, get the palette 
+    // [fixme: only create if the selected palette is null]
+    if (psurfBmp->hSecure)
+    {
+//        pDC->rosdc.bitsPerPixel = psurfBmp->dib->dsBmih.biBitCount; ???
+        pDC->rosdc.bitsPerPixel = BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat);
+    }
+    else
+    {
+        pDC->rosdc.bitsPerPixel = BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat);
+    }
+
+    /* FIXME; improve by using a region without a handle and selecting it */
+    hVisRgn = NtGdiCreateRectRgn(0,
+                                 0,
+                                 psurfBmp->SurfObj.sizlBitmap.cx,
+                                 psurfBmp->SurfObj.sizlBitmap.cy);
+
+    /* Release the exclusive lock */
+    SURFACE_UnlockSurface(psurfBmp);
+
+    /* Regenerate the XLATEOBJs. (hack!) */
+    pbrush = BRUSH_LockBrush(pdcattr->hbrush);
+    if (pbrush)
+    {
+        if (pDC->rosdc.XlateBrush)
+        {
+            EngDeleteXlate(pDC->rosdc.XlateBrush);
+        }
+        pDC->rosdc.XlateBrush = IntGdiCreateBrushXlate(pDC, pbrush, &bFailed);
+        BRUSH_UnlockBrush(pbrush);
+    }
+
+    pbrush = PEN_LockPen(pdcattr->hpen);
+    if (pbrush)
+    {
+        if (pDC->rosdc.XlatePen)
+        {
+            EngDeleteXlate(pDC->rosdc.XlatePen);
+        }
+        pDC->rosdc.XlatePen = IntGdiCreateBrushXlate(pDC, pbrush, &bFailed);
+        PEN_UnlockPen(pbrush);
+    }
+
+    DC_UnlockDc(pDC);
+
+    if (hVisRgn)
+    {
+        GdiSelectVisRgn(hDC, hVisRgn);
+        GreDeleteObject(hVisRgn);
+    }
+
+    return hOrgBmp;
+}
+
+
 BOOL
 APIENTRY
 NtGdiSelectClipPath(

Modified: trunk/reactos/subsystems/win32/win32k/objects/dcstate.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/objects/dcstate.c?rev=40243&r1=40242&r2=40243&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/dcstate.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/dcstate.c [iso-8859-1] Thu Mar 26 03:56:46 2009
@@ -39,12 +39,12 @@
 
     /* Handle references here correctly */
     DC_vSelectSurface(pdcDst, pdcSrc->dclevel.pSurface);
+    DC_vSelectFillBrush(pdcDst, pdcSrc->dclevel.pbrFill);
+    DC_vSelectLineBrush(pdcDst, pdcSrc->dclevel.pbrLine);
 
     // FIXME: handle refs
     pdcDst->dclevel.hpal            = pdcSrc->dclevel.hpal;
     pdcDst->dclevel.ppal            = pdcSrc->dclevel.ppal;
-    pdcDst->dclevel.pbrFill         = pdcSrc->dclevel.pbrFill;
-    pdcDst->dclevel.pbrLine         = pdcSrc->dclevel.pbrLine;
     pdcDst->dclevel.plfnt           = pdcSrc->dclevel.plfnt;
 
     /* ROS hacks */



More information about the Ros-diffs mailing list