[ros-diffs] [tkreuzer] 41988: [WIN32K] Keep a shared lock on palettes selected into DCs. This allows us to get rid of a large number of lock and unlock operations and checks.

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Wed Jul 15 23:06:40 CEST 2009


Author: tkreuzer
Date: Wed Jul 15 23:06:40 2009
New Revision: 41988

URL: http://svn.reactos.org/svn/reactos?rev=41988&view=rev
Log:
[WIN32K] Keep a shared lock on palettes selected into DCs.
This allows us to get rid of a large number of lock and unlock operations and checks.

Modified:
    trunk/reactos/subsystems/win32/win32k/include/dc.h
    trunk/reactos/subsystems/win32/win32k/include/palette.h
    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=41988&r1=41987&r2=41988&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] Wed Jul 15 23:06:40 2009
@@ -1,9 +1,12 @@
 #ifndef __WIN32K_DC_H
 #define __WIN32K_DC_H
+
+typedef struct _DC *PDC;
 
 #include "brush.h"
 #include "bitmaps.h"
 #include "pdevobj.h"
+#include "palette.h"
 
 /* Constants ******************************************************************/
 
@@ -125,7 +128,7 @@
 
   /* Reactos specific members */
   ROS_DC_INFO rosdc;
-} DC, *PDC;
+} DC;
 
 /* Internal functions *********************************************************/
 
@@ -217,6 +220,18 @@
     pdc->dclevel.pbrLine = pbrLine;
 }
 
+VOID
+FORCEINLINE
+DC_vSelectPalette(PDC pdc, PPALETTE ppal)
+{
+    PPALETTE ppalOld = pdc->dclevel.ppal;
+    if (ppalOld)
+        PALETTE_ShareUnlockPalette(ppalOld);
+    if (ppal)
+        GDIOBJ_IncrementShareCount((POBJ)ppal);
+    pdc->dclevel.ppal = ppal;
+}
+
 BOOL FASTCALL
 IntPrepareDriverIfNeeded();
 extern PDEVOBJ PrimarySurface;

Modified: trunk/reactos/subsystems/win32/win32k/include/palette.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/include/palette.h?rev=41988&r1=41987&r2=41988&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/palette.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/include/palette.h [iso-8859-1] Wed Jul 15 23:06:40 2009
@@ -67,6 +67,12 @@
 #define  PALETTE_FreePaletteByHandle(hPalette)  GDIOBJ_FreeObjByHandle((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE)
 #define  PALETTE_LockPalette(hPalette) ((PPALETTE)GDIOBJ_LockObj((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE))
 #define  PALETTE_UnlockPalette(pPalette) GDIOBJ_UnlockObjByPtr((POBJ)pPalette)
+
+#define  PALETTE_ShareLockPalette(hpal) \
+  ((PPALETTE)GDIOBJ_ShareLockObj((HGDIOBJ)hpal, GDI_OBJECT_TYPE_PALETTE))
+#define  PALETTE_ShareUnlockPalette(ppal)  \
+  GDIOBJ_ShareUnlockObjByPtr(&ppal->BaseObject)
+
 BOOL INTERNAL_CALL PALETTE_Cleanup(PVOID ObjectBody);
 
 HPALETTE FASTCALL PALETTE_Init (VOID);

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=41988&r1=41987&r2=41988&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] Wed Jul 15 23:06:40 2009
@@ -120,7 +120,11 @@
     TextIntRealizeFont(pdcattr->hlfntNew,NULL);
 
     NewDC->dclevel.hpal = NtGdiGetStockObject(DEFAULT_PALETTE);
-    NewDC->dclevel.laPath.eMiterLimit = 10.0;
+    NewDC->dclevel.ppal = PALETTE_ShareLockPalette(NewDC->dclevel.hpal);
+    /* This should never fail */
+    ASSERT(NewDC->dclevel.ppal);
+
+    NewDC->dclevel.laPath.eMiterLimit = 10.0; // FIXME: use FLOATL or FLOATOBJ!
 
     NewDC->dclevel.lSaveDepth = 1;
 
@@ -153,10 +157,11 @@
     if (pDC->rosdc.DriverName.Buffer)
         ExFreePoolWithTag(pDC->rosdc.DriverName.Buffer, TAG_DC);
 
-    /* Clean up selected objects */
+    /* Deselect dc objects */
     DC_vSelectSurface(pDC, NULL);
     DC_vSelectFillBrush(pDC, NULL);
     DC_vSelectLineBrush(pDC, NULL);
+    DC_vSelectPalette(pDC, NULL);
 
     /* Dereference default brushes */
     BRUSH_ShareUnlockBrush(pDC->eboText.pbrush);

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=41988&r1=41987&r2=41988&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] Wed Jul 15 23:06:40 2009
@@ -200,7 +200,7 @@
     }
 
     /* Check if this is a valid palette handle */
-    ppal = PALETTE_LockPalette(hpal);
+    ppal = PALETTE_ShareLockPalette(hpal);
     if (!ppal)
     {
         DC_UnlockDc(pdc);
@@ -215,13 +215,14 @@
         /* Get old palette, set new one */
         oldPal = pdc->dclevel.hpal;
         pdc->dclevel.hpal = hpal;
+        DC_vSelectPalette(pdc, ppal);
 
         /* Mark the brushes invalid */
         pdc->pdcattr->ulDirty_ |= DIRTY_FILL | DIRTY_LINE |
                                   DIRTY_BACKGROUND | DIRTY_TEXT;
     }
 
-    PALETTE_UnlockPalette(ppal);
+    PALETTE_ShareUnlockPalette(ppal);
     DC_UnlockDc(pdc);
 
     return oldPal;

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=41988&r1=41987&r2=41988&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] Wed Jul 15 23:06:40 2009
@@ -36,15 +36,15 @@
     pdcDst->dclevel.efM11PtoD       = pdcSrc->dclevel.efM11PtoD;
     pdcDst->dclevel.efM22PtoD       = pdcSrc->dclevel.efM22PtoD;
     pdcDst->dclevel.sizl            = pdcSrc->dclevel.sizl;
+    pdcDst->dclevel.hpal            = pdcSrc->dclevel.hpal;
 
     /* Handle references here correctly */
     DC_vSelectSurface(pdcDst, pdcSrc->dclevel.pSurface);
     DC_vSelectFillBrush(pdcDst, pdcSrc->dclevel.pbrFill);
     DC_vSelectLineBrush(pdcDst, pdcSrc->dclevel.pbrLine);
+    DC_vSelectPalette(pdcDst, pdcSrc->dclevel.ppal);
 
     // FIXME: handle refs
-    pdcDst->dclevel.hpal            = pdcSrc->dclevel.hpal;
-    pdcDst->dclevel.ppal            = pdcSrc->dclevel.ppal;
     pdcDst->dclevel.plfnt           = pdcSrc->dclevel.plfnt;
 
     /* ROS hacks */
@@ -122,7 +122,7 @@
     /* Check if we have a valid instance */
     if (iSaveLevel <= 0 || iSaveLevel >= pdc->dclevel.lSaveDepth)
     {
-        DPRINT("Illegal save level, requested: %ld, current: %ld\n", 
+        DPRINT("Illegal save level, requested: %ld, current: %ld\n",
                iSaveLevel, pdc->dclevel.lSaveDepth);
         DC_UnlockDc(pdc);
         SetLastWin32Error(ERROR_INVALID_PARAMETER);
@@ -220,7 +220,7 @@
     }
     hdcSave = pdcSave->BaseObject.hHmgr;
 
-    /* Make it a kernel handle 
+    /* Make it a kernel handle
        (FIXME: windows handles this different, see wiki)*/
     GDIOBJ_SetOwnership(hdcSave, NULL);
 



More information about the Ros-diffs mailing list