Hallo,
there are several loops in wine/graphics/x11drv/dib.c that call
X11DRV_PALETTE_ToPhysical inside the loop. X11DRV_PALETTE_ToPhysical always
does a GDI_GetObjPtr at entry and a Release at exit. E.g. with MS
pinball.exe I sees a look querying 256 entries in a row. If we do the
GDI_GetObjPtr/Release outside the loop and have a ..._ToPhysical call that
takes palPtr we would save a loot those Get/ReleasePtr calls. Is this worth
doing? I the approach below right?
Bye
--
Uwe Bonnes bon(a)elektron.ikp.physik.tu-darmstadt.de
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
Index: wine/dlls/x11drv/x11drv.h
===================================================================
RCS file: /home/wine/wine/dlls/x11drv/x11drv.h,v
retrieving revision 1.1
diff -u -r1.1 x11drv.h
--- wine/dlls/x11drv/x11drv.h 22 Apr 2003 04:05:08 -0000 1.1
+++ wine/dlls/x11drv/x11drv.h 5 May 2003 17:43:44 -0000
@@ -43,6 +43,8 @@
#include "user.h"
#include "win.h"
#include "thread.h"
+#include "palette.h"
+#include "windef.h"
#define MAX_PIXELFORMATS 8
@@ -314,6 +316,7 @@
extern COLORREF X11DRV_PALETTE_ToLogical(int pixel);
extern int X11DRV_PALETTE_ToPhysical(X11DRV_PDEVICE *physDev, COLORREF color);
+extern int X11DRV_PALETTEOBJ_ToPhysical( DC *dc, HPALETTE hPal, PALETTEOBJ *palPtr, COLORREF color);
/* GDI escapes */
Index: wine/graphics/x11drv/dib.c
===================================================================
RCS file: /home/wine/wine/graphics/x11drv/dib.c,v
retrieving revision 1.108
diff -u -r1.108 dib.c
--- wine/graphics/x11drv/dib.c 31 Mar 2003 01:32:47 -0000 1.108
+++ wine/graphics/x11drv/dib.c 5 May 2003 17:43:58 -0000
@@ -174,6 +174,9 @@
const void *colorPtr, int start, int end )
{
int i;
+ DC *dc = physDev ? physDev->dc : NULL;
+ HPALETTE hPal = (dc)? dc->hPalette: GetStockObject(DEFAULT_PALETTE);
+ PALETTEOBJ* palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
if (coloruse == DIB_RGB_COLORS)
{
@@ -191,7 +194,7 @@
rgb->rgbBlue > 255*3/2);
else
for (i = start; i < end; i++, rgb++)
- colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, RGB(rgb->rgbRed,
+ colorMapping[i] = X11DRV_PALETTEOBJ_ToPhysical( dc, hPal, palPtr, RGB(rgb->rgbRed,
rgb->rgbGreen,
rgb->rgbBlue));
}
@@ -205,7 +208,7 @@
rgb->rgbtBlue > 255*3/2);
else
for (i = start; i < end; i++, rgb++)
- colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, RGB(rgb->rgbtRed,
+ colorMapping[i] = X11DRV_PALETTEOBJ_ToPhysical( dc, hPal, palPtr, RGB(rgb->rgbtRed,
rgb->rgbtGreen,
rgb->rgbtBlue));
}
@@ -216,13 +219,15 @@
WORD * index = (WORD *)colorPtr;
for (i = start; i < end; i++, index++)
- colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, PALETTEINDEX(*index) );
+ colorMapping[i] = X11DRV_PALETTEOBJ_ToPhysical( dc, hPal, palPtr, PALETTEINDEX(*index) );
} else {
for (i = start; i < end; i++)
- colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, PALETTEINDEX(i) );
+ colorMapping[i] = X11DRV_PALETTEOBJ_ToPhysical( dc, hPal, palPtr, PALETTEINDEX(i) );
}
}
+ if (palPtr)
+ GDI_ReleaseObj( palPtr );
return colorMapping;
}
@@ -3176,6 +3181,9 @@
int rShift1,gShift1,bShift1;
int rShift2,gShift2,bShift2;
BYTE gMask1,gMask2;
+ DC *dc = physDev ? physDev->dc : NULL;
+ HPALETTE hPal = (dc)? dc->hPalette: GetStockObject(DEFAULT_PALETTE);
+ PALETTEOBJ* palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
/* Set color scaling values */
rShift1=16+X11DRV_DIB_MaskToShift(rSrc)-3;
@@ -3214,11 +3222,13 @@
blue= ((srcval >> bShift1) & 0xf8) |
((srcval >> bShift2) & 0x07);
XPutPixel(bmpImage, x, h,
- X11DRV_PALETTE_ToPhysical
- (physDev, RGB(red,green,blue)));
+ X11DRV_PALETTEOBJ_ToPhysical
+ (dc, hPal, palPtr, RGB(red,green,blue)));
}
srcbits += linebytes;
}
+ if(palPtr)
+ GDI_ReleaseObj( palPtr );
}
break;
}
@@ -3697,6 +3707,9 @@
{
/* ==== rgb 888 dib -> any bmp bormat ==== */
const BYTE* srcbyte;
+ DC *dc = physDev ? physDev->dc : NULL;
+ HPALETTE hPal = (dc)? dc->hPalette: GetStockObject(DEFAULT_PALETTE);
+ PALETTEOBJ* palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
/* Windows only supports one 24bpp DIB format: RGB888 */
srcbits+=left*3;
@@ -3704,12 +3717,14 @@
srcbyte=(const BYTE*)srcbits;
for (x = left; x < dstwidth+left; x++) {
XPutPixel(bmpImage, x, h,
- X11DRV_PALETTE_ToPhysical
- (physDev, RGB(srcbyte[2], srcbyte[1], srcbyte[0])));
+ X11DRV_PALETTEOBJ_ToPhysical
+ (dc, hPal, palPtr, RGB(srcbyte[2], srcbyte[1], srcbyte[0])));
srcbyte+=3;
}
srcbits += linebytes;
}
+ if(palPtr)
+ GDI_ReleaseObj( palPtr );
}
break;
}
@@ -4171,6 +4186,9 @@
/* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */
const DWORD* srcpixel;
int rShift,gShift,bShift;
+ DC *dc = physDev ? physDev->dc : NULL;
+ HPALETTE hPal = (dc)? dc->hPalette: GetStockObject(DEFAULT_PALETTE);
+ PALETTEOBJ* palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
rShift=X11DRV_DIB_MaskToShift(rSrc);
gShift=X11DRV_DIB_MaskToShift(gSrc);
@@ -4185,12 +4203,14 @@
red= (srcvalue >> rShift) & 0xff;
green=(srcvalue >> gShift) & 0xff;
blue= (srcvalue >> bShift) & 0xff;
- XPutPixel(bmpImage, x, h, X11DRV_PALETTE_ToPhysical
- (physDev, RGB(red,green,blue)));
+ XPutPixel(bmpImage, x, h, X11DRV_PALETTEOBJ_ToPhysical
+ (dc, hPal, palPtr, RGB(red,green,blue)));
}
srcbits += linebytes;
- }
- }
+ }
+ if (palPtr)
+ GDI_ReleaseObj( palPtr );
+ }
break;
}
Index: wine/graphics/x11drv/palette.c
===================================================================
RCS file: /home/wine/wine/graphics/x11drv/palette.c,v
retrieving revision 1.36
diff -u -r1.36 palette.c
--- wine/graphics/x11drv/palette.c 31 Oct 2002 02:38:20 -0000 1.36
+++ wine/graphics/x11drv/palette.c 5 May 2003 17:44:00 -0000
@@ -819,23 +819,32 @@
return best;
}
-
-/***********************************************************************
- * X11DRV_PALETTE_ToPhysical
- *
- * Return the physical color closest to 'color'.
- */
int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color )
{
DC *dc = physDev ? physDev->dc : NULL;
- WORD index = 0;
HPALETTE hPal = (dc)? dc->hPalette: GetStockObject(DEFAULT_PALETTE);
- unsigned char spec_type = color >> 24;
PALETTEOBJ* palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
+ int ret;
/* palPtr can be NULL when DC is being destroyed */
if( !palPtr ) return 0;
+ ret = X11DRV_PALETTEOBJ_ToPhysical(dc, hPal, palPtr, color);
+ GDI_ReleaseObj( hPal );
+ return ret;
+}
+
+/***********************************************************************
+ * X11DRV_PALETTEOBJ_ToPhysical
+ *
+ * Return the physical color closest to 'color'.
+ */
+int X11DRV_PALETTEOBJ_ToPhysical( DC *dc, HPALETTE hPal, PALETTEOBJ* palPtr, COLORREF color )
+{
+ WORD index = 0;
+ unsigned char spec_type = color >> 24;
+
+ if (!palPtr) return 0;
if ( X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED )
{
/* there is no colormap limitation; we are going to have to compute
@@ -852,14 +861,12 @@
if( (idx = color & 0xffff) >= palPtr->logpalette.palNumEntries)
{
WARN("RGB(%lx) : idx %d is out of bounds, assuming black\n", color, idx);
- GDI_ReleaseObj( hPal );
return 0;
}
if( palPtr->mapping )
{
int ret = palPtr->mapping[idx];
- GDI_ReleaseObj( hPal );
return ret;
}
color = *(COLORREF*)(palPtr->logpalette.palPalEntry + idx);
@@ -872,7 +879,6 @@
case 0: /* RGB */
if( dc && (dc->bitsPerPixel == 1) )
{
- GDI_ReleaseObj( hPal );
return (((color >> 16) & 0xff) +
((color >> 8) & 0xff) + (color & 0xff) > 255*3/2) ? 1 : 0;
}
@@ -884,7 +890,6 @@
if (X11DRV_PALETTE_Graymax)
{
/* grayscale only; return scaled value */
- GDI_ReleaseObj( hPal );
return ( (red * 30 + green * 59 + blue * 11) * X11DRV_PALETTE_Graymax) / 25500;
}
else
@@ -906,7 +911,6 @@
blue = blue << (X11DRV_PALETTE_PBlue.scale-8) |
blue >> (16-X11DRV_PALETTE_PBlue.scale);
- GDI_ReleaseObj( hPal );
return (red << X11DRV_PALETTE_PRed.shift) | (green << X11DRV_PALETTE_PGreen.shift) | (blue << X11DRV_PALETTE_PBlue.shift);
}
}
@@ -925,7 +929,6 @@
case 0: /* RGB */
if( dc && (dc->bitsPerPixel == 1) )
{
- GDI_ReleaseObj( hPal );
return (((color >> 16) & 0xff) +
((color >> 8) & 0xff) + (color & 0xff) > 255*3/2) ? 1 : 0;
}
@@ -955,7 +958,6 @@
}
}
- GDI_ReleaseObj( hPal );
return index;
}