winex11: Directly use win32u for GDI functions in palette.c.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2022-04-12 13:10:03 +02:00 committed by Alexandre Julliard
parent 4631b007c1
commit 37f31840b9
2 changed files with 25 additions and 19 deletions

View File

@ -337,7 +337,7 @@ int X11DRV_PALETTE_Init(void)
} }
else else
{ {
GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, NB_RESERVED_COLORS, sys_pal_template ); get_palette_entries( GetStockObject(DEFAULT_PALETTE), 0, NB_RESERVED_COLORS, sys_pal_template );
if ((mapping = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * NB_RESERVED_COLORS ))) if ((mapping = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * NB_RESERVED_COLORS )))
palette_set_mapping( GetStockObject(DEFAULT_PALETTE), mapping ); palette_set_mapping( GetStockObject(DEFAULT_PALETTE), mapping );
@ -881,20 +881,20 @@ static int X11DRV_SysPaletteLookupPixel( COLORREF col, BOOL skipReserved )
*/ */
COLORREF X11DRV_PALETTE_GetColor( X11DRV_PDEVICE *physDev, COLORREF color ) COLORREF X11DRV_PALETTE_GetColor( X11DRV_PDEVICE *physDev, COLORREF color )
{ {
HPALETTE hPal = GetCurrentObject(physDev->dev.hdc, OBJ_PAL ); HPALETTE hPal = NtGdiGetDCObject( physDev->dev.hdc, NTGDI_OBJ_PAL );
PALETTEENTRY entry; PALETTEENTRY entry;
if (color & (1 << 24)) /* PALETTEINDEX */ if (color & (1 << 24)) /* PALETTEINDEX */
{ {
unsigned int idx = LOWORD(color); unsigned int idx = LOWORD(color);
if (!GetPaletteEntries( hPal, idx, 1, &entry )) return 0; if (!get_palette_entries( hPal, idx, 1, &entry )) return 0;
return RGB( entry.peRed, entry.peGreen, entry.peBlue ); return RGB( entry.peRed, entry.peGreen, entry.peBlue );
} }
if (color >> 24 == 2) /* PALETTERGB */ if (color >> 24 == 2) /* PALETTERGB */
{ {
unsigned int idx = GetNearestPaletteIndex( hPal, color & 0xffffff ); unsigned int idx = NtGdiGetNearestPaletteIndex( hPal, color & 0xffffff );
if (!GetPaletteEntries( hPal, idx, 1, &entry )) return 0; if (!get_palette_entries( hPal, idx, 1, &entry )) return 0;
return RGB( entry.peRed, entry.peGreen, entry.peBlue ); return RGB( entry.peRed, entry.peGreen, entry.peBlue );
} }
@ -912,7 +912,7 @@ COLORREF X11DRV_PALETTE_GetColor( X11DRV_PDEVICE *physDev, COLORREF color )
int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color ) int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color )
{ {
WORD index = 0; WORD index = 0;
HPALETTE hPal = GetCurrentObject(physDev->dev.hdc, OBJ_PAL ); HPALETTE hPal = NtGdiGetDCObject( physDev->dev.hdc, NTGDI_OBJ_PAL );
int *mapping = palette_get_mapping( hPal ); int *mapping = palette_get_mapping( hPal );
PALETTEENTRY entry; PALETTEENTRY entry;
ColorShifts *shifts = &X11DRV_PALETTE_default_shifts; ColorShifts *shifts = &X11DRV_PALETTE_default_shifts;
@ -931,7 +931,7 @@ int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color )
{ {
unsigned int idx = LOWORD( color ); unsigned int idx = LOWORD( color );
if (!GetPaletteEntries( hPal, idx, 1, &entry )) if (!get_palette_entries( hPal, idx, 1, &entry ))
{ {
WARN("PALETTEINDEX(%x) : idx %d is out of bounds, assuming black\n", color, idx); WARN("PALETTEINDEX(%x) : idx %d is out of bounds, assuming black\n", color, idx);
return 0; return 0;
@ -990,13 +990,13 @@ int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color )
if (color & (1 << 24)) /* PALETTEINDEX */ if (color & (1 << 24)) /* PALETTEINDEX */
{ {
index = LOWORD( color ); index = LOWORD( color );
if (!GetPaletteEntries( hPal, index, 1, &entry )) if (!get_palette_entries( hPal, index, 1, &entry ))
WARN("PALETTEINDEX(%x) : index %i is out of bounds\n", color, index); WARN("PALETTEINDEX(%x) : index %i is out of bounds\n", color, index);
else if (mapping) index = mapping[index]; else if (mapping) index = mapping[index];
} }
else if (color >> 24 == 2) /* PALETTERGB */ else if (color >> 24 == 2) /* PALETTERGB */
{ {
index = GetNearestPaletteIndex( hPal, color ); index = NtGdiGetNearestPaletteIndex( hPal, color );
if (mapping) index = mapping[index]; if (mapping) index = mapping[index];
} }
else if (color >> 16 == 0x10ff) /* DIBINDEX */ else if (color >> 16 == 0x10ff) /* DIBINDEX */
@ -1197,7 +1197,7 @@ UINT CDECL X11DRV_RealizePalette( PHYSDEV dev, HPALETTE hpal, BOOL primary )
if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) return 0; if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) return 0;
if (!GetObjectW( hpal, sizeof(num_entries), &num_entries )) return 0; if (!NtGdiExtGetObjectW( hpal, sizeof(num_entries), &num_entries )) return 0;
/* initialize palette mapping table */ /* initialize palette mapping table */
prev_mapping = palette_get_mapping( hpal ); prev_mapping = palette_get_mapping( hpal );
@ -1217,7 +1217,7 @@ UINT CDECL X11DRV_RealizePalette( PHYSDEV dev, HPALETTE hpal, BOOL primary )
FIXME( "more than 256 entries not supported\n" ); FIXME( "more than 256 entries not supported\n" );
num_entries = 256; num_entries = 256;
} }
if (!(num_entries = GetPaletteEntries( hpal, 0, num_entries, entries ))) return 0; if (!(num_entries = get_palette_entries( hpal, 0, num_entries, entries ))) return 0;
/* reset dynamic system palette entries */ /* reset dynamic system palette entries */
@ -1361,19 +1361,19 @@ COLORREF CDECL X11DRV_GetNearestColor( PHYSDEV dev, COLORREF color )
UINT index; UINT index;
PALETTEENTRY entry; PALETTEENTRY entry;
HPALETTE hpal = GetCurrentObject( dev->hdc, OBJ_PAL ); HPALETTE hpal = NtGdiGetDCObject( dev->hdc, NTGDI_OBJ_PAL );
if (!hpal) hpal = GetStockObject( DEFAULT_PALETTE ); if (!hpal) hpal = GetStockObject( DEFAULT_PALETTE );
if (spec_type == 2) /* PALETTERGB */ if (spec_type == 2) /* PALETTERGB */
index = GetNearestPaletteIndex( hpal, color ); index = NtGdiGetNearestPaletteIndex( hpal, color );
else /* PALETTEINDEX */ else /* PALETTEINDEX */
index = LOWORD(color); index = LOWORD(color);
if (!GetPaletteEntries( hpal, index, 1, &entry )) if (!get_palette_entries( hpal, index, 1, &entry ))
{ {
WARN("RGB(%x) : idx %d is out of bounds, assuming NULL\n", color, index ); WARN("RGB(%x) : idx %d is out of bounds, assuming NULL\n", color, index );
if (!GetPaletteEntries( hpal, 0, 1, &entry )) return CLR_INVALID; if (!get_palette_entries( hpal, 0, 1, &entry )) return CLR_INVALID;
} }
color = RGB( entry.peRed, entry.peGreen, entry.peBlue ); color = RGB( entry.peRed, entry.peGreen, entry.peBlue );
} }
@ -1392,15 +1392,16 @@ COLORREF CDECL X11DRV_GetNearestColor( PHYSDEV dev, COLORREF color )
*/ */
UINT CDECL X11DRV_RealizeDefaultPalette( PHYSDEV dev ) UINT CDECL X11DRV_RealizeDefaultPalette( PHYSDEV dev )
{ {
DWORD is_memdc;
UINT ret = 0; UINT ret = 0;
if (palette_size && GetObjectType(dev->hdc) != OBJ_MEMDC) if (palette_size && NtGdiGetDCDword( dev->hdc, NtGdiIsMemDC, &is_memdc ) && is_memdc)
{ {
/* lookup is needed to account for SetSystemPaletteUse() stuff */ /* lookup is needed to account for SetSystemPaletteUse() stuff */
int i, index, *mapping = palette_get_mapping( GetStockObject(DEFAULT_PALETTE) ); int i, index, *mapping = palette_get_mapping( GetStockObject(DEFAULT_PALETTE) );
PALETTEENTRY entries[NB_RESERVED_COLORS]; PALETTEENTRY entries[NB_RESERVED_COLORS];
GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, NB_RESERVED_COLORS, entries ); get_palette_entries( GetStockObject(DEFAULT_PALETTE), 0, NB_RESERVED_COLORS, entries );
EnterCriticalSection( &palette_cs ); EnterCriticalSection( &palette_cs );
for( i = 0; i < NB_RESERVED_COLORS; i++ ) for( i = 0; i < NB_RESERVED_COLORS; i++ )
{ {

View File

@ -847,6 +847,11 @@ static inline BOOL lp_to_dp( HDC hdc, POINT *points, INT count )
return NtGdiTransformPoints( hdc, points, points, count, NtGdiLPtoDP ); return NtGdiTransformPoints( hdc, points, points, count, NtGdiLPtoDP );
} }
static inline UINT get_palette_entries( HPALETTE palette, UINT start, UINT count, PALETTEENTRY *entries )
{
return NtGdiDoPalette( palette, start, count, entries, NtGdiGetPaletteEntries, TRUE );
}
/* registry helpers */ /* registry helpers */
extern HKEY open_hkcu_key( const char *name ) DECLSPEC_HIDDEN; extern HKEY open_hkcu_key( const char *name ) DECLSPEC_HIDDEN;