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

Alexandre Julliard julliard at winehq.org
Tue Apr 12 15:35:16 CDT 2022


Module: wine
Branch: master
Commit: 37f31840b90f9de83052c7fe377b4f8c1d5daed2
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=37f31840b90f9de83052c7fe377b4f8c1d5daed2

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue Apr 12 13:10:03 2022 +0200

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

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winex11.drv/palette.c | 39 ++++++++++++++++++++-------------------
 dlls/winex11.drv/x11drv.h  |  5 +++++
 2 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/dlls/winex11.drv/palette.c b/dlls/winex11.drv/palette.c
index 8fbd7820c95..ffed08d1f35 100644
--- a/dlls/winex11.drv/palette.c
+++ b/dlls/winex11.drv/palette.c
@@ -337,7 +337,7 @@ int X11DRV_PALETTE_Init(void)
     }
     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 )))
             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 )
 {
-    HPALETTE             hPal = GetCurrentObject(physDev->dev.hdc, OBJ_PAL );
-    PALETTEENTRY         entry;
+    HPALETTE hPal = NtGdiGetDCObject( physDev->dev.hdc, NTGDI_OBJ_PAL );
+    PALETTEENTRY entry;
 
     if (color & (1 << 24))  /* PALETTEINDEX */
     {
         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 );
     }
 
     if (color >> 24 == 2)  /* PALETTERGB */
     {
-        unsigned int idx = GetNearestPaletteIndex( hPal, color & 0xffffff );
-        if (!GetPaletteEntries( hPal, idx, 1, &entry )) return 0;
+        unsigned int idx = NtGdiGetNearestPaletteIndex( hPal, color & 0xffffff );
+        if (!get_palette_entries( hPal, idx, 1, &entry )) return 0;
         return RGB( entry.peRed, entry.peGreen, entry.peBlue );
     }
 
@@ -911,8 +911,8 @@ COLORREF X11DRV_PALETTE_GetColor( X11DRV_PDEVICE *physDev, COLORREF color )
  */
 int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color )
 {
-    WORD 		 index = 0;
-    HPALETTE 		 hPal = GetCurrentObject(physDev->dev.hdc, OBJ_PAL );
+    WORD index = 0;
+    HPALETTE hPal = NtGdiGetDCObject( physDev->dev.hdc, NTGDI_OBJ_PAL );
     int *mapping = palette_get_mapping( hPal );
     PALETTEENTRY entry;
     ColorShifts *shifts = &X11DRV_PALETTE_default_shifts;
@@ -931,7 +931,7 @@ int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF 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);
                 return 0;
@@ -990,13 +990,13 @@ int X11DRV_PALETTE_ToPhysical( X11DRV_PDEVICE *physDev, COLORREF color )
         if (color & (1 << 24))  /* PALETTEINDEX */
         {
             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);
             else if (mapping) index = mapping[index];
         }
         else if (color >> 24 == 2)  /* PALETTERGB */
         {
-            index = GetNearestPaletteIndex( hPal, color );
+            index = NtGdiGetNearestPaletteIndex( hPal, color );
             if (mapping) index = mapping[index];
         }
         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 (!GetObjectW( hpal, sizeof(num_entries), &num_entries )) return 0;
+    if (!NtGdiExtGetObjectW( hpal, sizeof(num_entries), &num_entries )) return 0;
 
     /* initialize palette mapping table */
     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" );
         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 */
 
@@ -1361,19 +1361,19 @@ COLORREF CDECL X11DRV_GetNearestColor( PHYSDEV dev, COLORREF color )
 
         UINT index;
         PALETTEENTRY entry;
-        HPALETTE hpal = GetCurrentObject( dev->hdc, OBJ_PAL );
+        HPALETTE hpal = NtGdiGetDCObject( dev->hdc, NTGDI_OBJ_PAL );
 
         if (!hpal) hpal = GetStockObject( DEFAULT_PALETTE );
 
         if (spec_type == 2) /* PALETTERGB */
-            index = GetNearestPaletteIndex( hpal, color );
+            index = NtGdiGetNearestPaletteIndex( hpal, color );
         else  /* PALETTEINDEX */
             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 );
-            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 );
     }
@@ -1392,15 +1392,16 @@ COLORREF CDECL X11DRV_GetNearestColor( PHYSDEV dev, COLORREF color )
  */
 UINT CDECL X11DRV_RealizeDefaultPalette( PHYSDEV dev )
 {
+    DWORD is_memdc;
     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 */
         int i, index, *mapping = palette_get_mapping( GetStockObject(DEFAULT_PALETTE) );
         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 );
         for( i = 0; i < NB_RESERVED_COLORS; i++ )
         {
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index 18afc0e133d..2112980aab5 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -847,6 +847,11 @@ static inline BOOL lp_to_dp( HDC hdc, POINT *points, INT count )
     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 */
 
 extern HKEY open_hkcu_key( const char *name ) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list