gdi32: Add null driver entry points for the palette functions.

This commit is contained in:
Alexandre Julliard 2011-03-11 18:26:55 +01:00
parent e030b3ce56
commit 0d27e3c0ed
4 changed files with 71 additions and 62 deletions

View File

@ -274,7 +274,8 @@ static BOOL DC_DeleteObject( HGDIOBJ handle )
*/
void DC_InitDC( DC* dc )
{
if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizeDefaultPalette );
physdev->funcs->pRealizeDefaultPalette( physdev );
SetTextColor( dc->hSelf, dc->textColor );
SetBkColor( dc->hSelf, dc->backgroundColor );
SelectObject( dc->hSelf, dc->hPen );

View File

@ -413,6 +413,12 @@ static INT CDECL nulldrv_GetPixelFormat( PHYSDEV dev )
return 0;
}
static UINT CDECL nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start,
UINT count, PALETTEENTRY *entries )
{
return 0;
}
static BOOL CDECL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
{
return TRUE;
@ -456,6 +462,16 @@ static BOOL CDECL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count
return TRUE;
}
static UINT CDECL nulldrv_RealizeDefaultPalette( PHYSDEV dev )
{
return 0;
}
static UINT CDECL nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
{
return 0;
}
static BOOL CDECL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
{
return TRUE;
@ -706,10 +722,10 @@ const DC_FUNCTIONS null_driver =
NULL, /* pGetDeviceCaps */
nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
nulldrv_GetICMProfile, /* pGetICMProfile */
NULL, /* pGetNearestColor */
nulldrv_GetNearestColor, /* pGetNearestColor */
nulldrv_GetPixel, /* pGetPixel */
nulldrv_GetPixelFormat, /* pGetPixelFormat */
NULL, /* pGetSystemPaletteEntries */
nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
NULL, /* pGetTextExtentExPoint */
NULL, /* pGetTextMetrics */
nulldrv_IntersectClipRect, /* pIntersectClipRect */
@ -731,8 +747,8 @@ const DC_FUNCTIONS null_driver =
nulldrv_Polygon, /* pPolygon */
nulldrv_Polyline, /* pPolyline */
nulldrv_PolylineTo, /* pPolylineTo */
NULL, /* pRealizeDefaultPalette */
NULL, /* pRealizePalette */
nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
nulldrv_RealizePalette, /* pRealizePalette */
nulldrv_Rectangle, /* pRectangle */
NULL, /* pResetDC */
NULL, /* pRestoreDC */

View File

@ -520,6 +520,7 @@ extern INT CDECL nulldrv_ExcludeClipRect( PHYSDEV dev, INT left, INT top, INT r
extern INT CDECL nulldrv_ExtSelectClipRgn( PHYSDEV dev, HRGN rgn, INT mode ) DECLSPEC_HIDDEN;
extern BOOL CDECL nulldrv_FillRgn( PHYSDEV dev, HRGN rgn, HBRUSH brush ) DECLSPEC_HIDDEN;
extern BOOL CDECL nulldrv_FrameRgn( PHYSDEV dev, HRGN rgn, HBRUSH brush, INT width, INT height ) DECLSPEC_HIDDEN;
extern COLORREF CDECL nulldrv_GetNearestColor( PHYSDEV dev, COLORREF color ) DECLSPEC_HIDDEN;
extern INT CDECL nulldrv_IntersectClipRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom ) DECLSPEC_HIDDEN;
extern BOOL CDECL nulldrv_InvertRgn( PHYSDEV dev, HRGN rgn ) DECLSPEC_HIDDEN;
extern INT CDECL nulldrv_OffsetClipRgn( PHYSDEV dev, INT x, INT y ) DECLSPEC_HIDDEN;

View File

@ -513,8 +513,8 @@ UINT WINAPI GetSystemPaletteEntries(
if ((dc = get_dc_ptr( hdc )))
{
if (dc->funcs->pGetSystemPaletteEntries)
ret = dc->funcs->pGetSystemPaletteEntries( dc->physDev, start, count, entries );
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetSystemPaletteEntries );
ret = physdev->funcs->pGetSystemPaletteEntries( physdev, start, count, entries );
release_dc_ptr( dc );
}
return ret;
@ -563,6 +563,38 @@ UINT WINAPI GetNearestPaletteIndex(
}
/* null driver fallback implementation for GetNearestColor */
COLORREF CDECL nulldrv_GetNearestColor( PHYSDEV dev, COLORREF color )
{
unsigned char spec_type;
if (!(GetDeviceCaps( dev->hdc, RASTERCAPS ) & RC_PALETTE)) return color;
spec_type = color >> 24;
if (spec_type == 1 || spec_type == 2)
{
/* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */
UINT index;
PALETTEENTRY entry;
HPALETTE hpal = GetCurrentObject( dev->hdc, OBJ_PAL );
if (!hpal) hpal = GetStockObject( DEFAULT_PALETTE );
if (spec_type == 2) /* PALETTERGB */
index = GetNearestPaletteIndex( hpal, color );
else /* PALETTEINDEX */
index = LOWORD(color);
if (!GetPaletteEntries( hpal, index, 1, &entry ))
{
WARN("RGB(%x) : idx %d is out of bounds, assuming NULL\n", color, index );
if (!GetPaletteEntries( hpal, 0, 1, &entry )) return CLR_INVALID;
}
color = RGB( entry.peRed, entry.peGreen, entry.peBlue );
}
return color & 0x00ffffff;
}
/***********************************************************************
* GetNearestColor [GDI32.@]
*
@ -576,54 +608,15 @@ COLORREF WINAPI GetNearestColor(
HDC hdc, /* [in] Handle of device context */
COLORREF color) /* [in] Color to be matched */
{
unsigned char spec_type;
COLORREF nearest;
DC *dc;
COLORREF nearest = CLR_INVALID;
DC *dc;
if (!(dc = get_dc_ptr( hdc ))) return CLR_INVALID;
if (dc->funcs->pGetNearestColor)
if ((dc = get_dc_ptr( hdc )))
{
nearest = dc->funcs->pGetNearestColor( dc->physDev, color );
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetNearestColor );
nearest = physdev->funcs->pGetNearestColor( physdev, color );
release_dc_ptr( dc );
return nearest;
}
if (!(GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE))
{
release_dc_ptr( dc );
return color;
}
spec_type = color >> 24;
if (spec_type == 1 || spec_type == 2)
{
/* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */
UINT index;
PALETTEENTRY entry;
HPALETTE hpal = dc->hPalette ? dc->hPalette : GetStockObject( DEFAULT_PALETTE );
if (spec_type == 2) /* PALETTERGB */
index = GetNearestPaletteIndex( hpal, color );
else /* PALETTEINDEX */
index = LOWORD(color);
if (!GetPaletteEntries( hpal, index, 1, &entry ))
{
WARN("RGB(%x) : idx %d is out of bounds, assuming NULL\n", color, index );
if (!GetPaletteEntries( hpal, 0, 1, &entry ))
{
release_dc_ptr( dc );
return CLR_INVALID;
}
}
color = RGB( entry.peRed, entry.peGreen, entry.peBlue );
}
nearest = color & 0x00ffffff;
release_dc_ptr( dc );
TRACE("(%06x): returning %06x\n", color, nearest );
return nearest;
}
@ -729,21 +722,19 @@ UINT WINAPI GDIRealizePalette( HDC hdc )
if( dc->hPalette == GetStockObject( DEFAULT_PALETTE ))
{
if (dc->funcs->pRealizeDefaultPalette)
realized = dc->funcs->pRealizeDefaultPalette( dc->physDev );
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizeDefaultPalette );
realized = physdev->funcs->pRealizeDefaultPalette( physdev );
}
else if (InterlockedExchangePointer( (void **)&hLastRealizedPalette, dc->hPalette ) != dc->hPalette)
{
if (dc->funcs->pRealizePalette)
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizePalette );
PALETTEOBJ *palPtr = GDI_GetObjPtr( dc->hPalette, OBJ_PAL );
if (palPtr)
{
PALETTEOBJ *palPtr = GDI_GetObjPtr( dc->hPalette, OBJ_PAL );
if (palPtr)
{
realized = dc->funcs->pRealizePalette( dc->physDev, dc->hPalette,
(dc->hPalette == hPrimaryPalette) );
palPtr->funcs = dc->funcs;
GDI_ReleaseObj( dc->hPalette );
}
realized = physdev->funcs->pRealizePalette( physdev, dc->hPalette,
(dc->hPalette == hPrimaryPalette) );
palPtr->funcs = dc->funcs;
GDI_ReleaseObj( dc->hPalette );
}
}
else TRACE(" skipping (hLastRealizedPalette = %p)\n", hLastRealizedPalette);