[PATCH 4/6] uxtheme: Do not transfer glyph alpha values when drawing opaque background.

Zhiyi Zhang wine at gitlab.winehq.org
Mon Jun 27 01:35:05 CDT 2022


From: Zhiyi Zhang <zzhang at codeweavers.com>

Fix QSpinBox artifacts for Qt5 applications.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53066
Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
 dlls/uxtheme/draw.c         | 38 +++++++++++++++++++++++++++++++++++++
 dlls/uxtheme/tests/system.c |  1 -
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/dlls/uxtheme/draw.c b/dlls/uxtheme/draw.c
index 3ddb9b3bf4d..2f5a161c988 100644
--- a/dlls/uxtheme/draw.c
+++ b/dlls/uxtheme/draw.c
@@ -523,6 +523,39 @@ static inline void get_transparency (HTHEME hTheme, int iPartId, int iStateId,
     }
 }
 
+/* Reset alpha values in hdc to 0xFF if the background is opaque */
+static void reset_dc_alpha_values(HTHEME htheme, HDC hdc, int part_id, int state_id,
+                                  const RECT *rect)
+{
+    static const RGBQUAD bitmap_bits = {0x0, 0x0, 0x0, 0xFF};
+    BITMAPINFO bitmap_info = {0};
+    RECT image_rect;
+    BOOL has_alpha;
+    HBITMAP hbmp;
+    int bg_type;
+
+    if (GetDeviceCaps(hdc, BITSPIXEL) != 32)
+        return;
+
+    if (FAILED(GetThemeEnumValue(htheme, part_id, state_id, TMT_BGTYPE, &bg_type))
+        || bg_type != BT_IMAGEFILE)
+        return;
+
+    if (FAILED(UXTHEME_LoadImage(htheme, part_id, state_id, rect, FALSE, &hbmp, &image_rect,
+                                 &has_alpha, NULL)) || has_alpha)
+        return;
+
+    bitmap_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+    bitmap_info.bmiHeader.biWidth = 1;
+    bitmap_info.bmiHeader.biHeight = 1;
+    bitmap_info.bmiHeader.biPlanes = 1;
+    bitmap_info.bmiHeader.biBitCount = 32;
+    bitmap_info.bmiHeader.biCompression = BI_RGB;
+    StretchDIBits(hdc, rect->left, rect->top, abs(rect->right - rect->left),
+                  abs(rect->bottom - rect->top), 0, 0, 1, 1, &bitmap_bits, &bitmap_info,
+                  DIB_RGB_COLORS, SRCPAINT);
+}
+
 /***********************************************************************
  *      UXTHEME_DrawImageGlyph
  *
@@ -581,6 +614,11 @@ static HRESULT UXTHEME_DrawImageGlyph(HTHEME hTheme, HDC hdc, int iPartId,
 
     SelectObject(hdcSrc, oldSrc);
     DeleteDC(hdcSrc);
+
+    /* Don't transfer alpha values from the glyph when drawing opaque background */
+    if (SUCCEEDED(hr) && hasAlpha)
+        reset_dc_alpha_values(hTheme, hdc, iPartId, iStateId, pRect);
+
     return hr;
 }
 
diff --git a/dlls/uxtheme/tests/system.c b/dlls/uxtheme/tests/system.c
index e9191de1507..cbaf4b51258 100644
--- a/dlls/uxtheme/tests/system.c
+++ b/dlls/uxtheme/tests/system.c
@@ -2322,7 +2322,6 @@ static void test_DrawThemeBackgroundEx(void)
 
         ptr += 4;
     }
-    todo_wine
     ok(i == width * height || broken(ptr[3] == 0) /* Spin button glyphs on XP don't use alpha */,
        "Unexpected alpha value %#x at (%d,%d).\n", ptr[3], i % height, i / height);
 
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/317



More information about the wine-devel mailing list