[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.

svn path=/trunk/; revision=41988
This commit is contained in:
Timo Kreuzer 2009-07-15 21:06:40 +00:00
parent 6255ce1380
commit fe5c1a52ce
5 changed files with 36 additions and 9 deletions

View file

@ -1,9 +1,12 @@
#ifndef __WIN32K_DC_H #ifndef __WIN32K_DC_H
#define __WIN32K_DC_H #define __WIN32K_DC_H
typedef struct _DC *PDC;
#include "brush.h" #include "brush.h"
#include "bitmaps.h" #include "bitmaps.h"
#include "pdevobj.h" #include "pdevobj.h"
#include "palette.h"
/* Constants ******************************************************************/ /* Constants ******************************************************************/
@ -125,7 +128,7 @@ typedef struct _DC
/* Reactos specific members */ /* Reactos specific members */
ROS_DC_INFO rosdc; ROS_DC_INFO rosdc;
} DC, *PDC; } DC;
/* Internal functions *********************************************************/ /* Internal functions *********************************************************/
@ -217,6 +220,18 @@ DC_vSelectLineBrush(PDC pdc, PBRUSH pbrLine)
pdc->dclevel.pbrLine = pbrLine; 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 BOOL FASTCALL
IntPrepareDriverIfNeeded(); IntPrepareDriverIfNeeded();
extern PDEVOBJ PrimarySurface; extern PDEVOBJ PrimarySurface;

View file

@ -67,6 +67,12 @@ HPALETTE FASTCALL PALETTE_AllocPaletteIndexedRGB(ULONG NumColors,
#define PALETTE_FreePaletteByHandle(hPalette) GDIOBJ_FreeObjByHandle((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE) #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_LockPalette(hPalette) ((PPALETTE)GDIOBJ_LockObj((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE))
#define PALETTE_UnlockPalette(pPalette) GDIOBJ_UnlockObjByPtr((POBJ)pPalette) #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); BOOL INTERNAL_CALL PALETTE_Cleanup(PVOID ObjectBody);
HPALETTE FASTCALL PALETTE_Init (VOID); HPALETTE FASTCALL PALETTE_Init (VOID);

View file

@ -120,7 +120,11 @@ DC_AllocDC(PUNICODE_STRING Driver)
TextIntRealizeFont(pdcattr->hlfntNew,NULL); TextIntRealizeFont(pdcattr->hlfntNew,NULL);
NewDC->dclevel.hpal = NtGdiGetStockObject(DEFAULT_PALETTE); 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; NewDC->dclevel.lSaveDepth = 1;
@ -153,10 +157,11 @@ DC_Cleanup(PVOID ObjectBody)
if (pDC->rosdc.DriverName.Buffer) if (pDC->rosdc.DriverName.Buffer)
ExFreePoolWithTag(pDC->rosdc.DriverName.Buffer, TAG_DC); ExFreePoolWithTag(pDC->rosdc.DriverName.Buffer, TAG_DC);
/* Clean up selected objects */ /* Deselect dc objects */
DC_vSelectSurface(pDC, NULL); DC_vSelectSurface(pDC, NULL);
DC_vSelectFillBrush(pDC, NULL); DC_vSelectFillBrush(pDC, NULL);
DC_vSelectLineBrush(pDC, NULL); DC_vSelectLineBrush(pDC, NULL);
DC_vSelectPalette(pDC, NULL);
/* Dereference default brushes */ /* Dereference default brushes */
BRUSH_ShareUnlockBrush(pDC->eboText.pbrush); BRUSH_ShareUnlockBrush(pDC->eboText.pbrush);

View file

@ -200,7 +200,7 @@ GdiSelectPalette(
} }
/* Check if this is a valid palette handle */ /* Check if this is a valid palette handle */
ppal = PALETTE_LockPalette(hpal); ppal = PALETTE_ShareLockPalette(hpal);
if (!ppal) if (!ppal)
{ {
DC_UnlockDc(pdc); DC_UnlockDc(pdc);
@ -215,13 +215,14 @@ GdiSelectPalette(
/* Get old palette, set new one */ /* Get old palette, set new one */
oldPal = pdc->dclevel.hpal; oldPal = pdc->dclevel.hpal;
pdc->dclevel.hpal = hpal; pdc->dclevel.hpal = hpal;
DC_vSelectPalette(pdc, ppal);
/* Mark the brushes invalid */ /* Mark the brushes invalid */
pdc->pdcattr->ulDirty_ |= DIRTY_FILL | DIRTY_LINE | pdc->pdcattr->ulDirty_ |= DIRTY_FILL | DIRTY_LINE |
DIRTY_BACKGROUND | DIRTY_TEXT; DIRTY_BACKGROUND | DIRTY_TEXT;
} }
PALETTE_UnlockPalette(ppal); PALETTE_ShareUnlockPalette(ppal);
DC_UnlockDc(pdc); DC_UnlockDc(pdc);
return oldPal; return oldPal;

View file

@ -36,15 +36,15 @@ DC_vCopyState(PDC pdcSrc, PDC pdcDst)
pdcDst->dclevel.efM11PtoD = pdcSrc->dclevel.efM11PtoD; pdcDst->dclevel.efM11PtoD = pdcSrc->dclevel.efM11PtoD;
pdcDst->dclevel.efM22PtoD = pdcSrc->dclevel.efM22PtoD; pdcDst->dclevel.efM22PtoD = pdcSrc->dclevel.efM22PtoD;
pdcDst->dclevel.sizl = pdcSrc->dclevel.sizl; pdcDst->dclevel.sizl = pdcSrc->dclevel.sizl;
pdcDst->dclevel.hpal = pdcSrc->dclevel.hpal;
/* Handle references here correctly */ /* Handle references here correctly */
DC_vSelectSurface(pdcDst, pdcSrc->dclevel.pSurface); DC_vSelectSurface(pdcDst, pdcSrc->dclevel.pSurface);
DC_vSelectFillBrush(pdcDst, pdcSrc->dclevel.pbrFill); DC_vSelectFillBrush(pdcDst, pdcSrc->dclevel.pbrFill);
DC_vSelectLineBrush(pdcDst, pdcSrc->dclevel.pbrLine); DC_vSelectLineBrush(pdcDst, pdcSrc->dclevel.pbrLine);
DC_vSelectPalette(pdcDst, pdcSrc->dclevel.ppal);
// FIXME: handle refs // FIXME: handle refs
pdcDst->dclevel.hpal = pdcSrc->dclevel.hpal;
pdcDst->dclevel.ppal = pdcSrc->dclevel.ppal;
pdcDst->dclevel.plfnt = pdcSrc->dclevel.plfnt; pdcDst->dclevel.plfnt = pdcSrc->dclevel.plfnt;
/* ROS hacks */ /* ROS hacks */