On Fri Oct 17 06:57:35 2025 +0000, Rémi Bernon wrote:
This isn't right, surfaces bitmaps should not be used without locking them. What we should do here, is to detect that the src DC is the windows's DC, in which case it should be unnecessary to create a new one, and unnecessary to lock the surface Something like this maybe, but I'm not completely sure about it:
if (NtUserWindowFromDC( hdc_src ) == hwnd) hdc = hdc_src; else { if (!(hdc = NtGdiCreateCompatibleDC( 0 ))) goto done; if (surface != &dummy_surface) pthread_mutex_lock( &surfaces_lock ); NtGdiSelectBitmap( hdc, surface->color_bitmap ); }You would need something similar on the unlock side.
Just wrote a test program as follows: Test1: ``` HDC hdc = GetDC(hWndA);
BOOL ret = UpdateLayeredWindow(hWndA, NULL, NULL, &si, hdc, &pi, 0, &bf, ULW_ALPHA);
ReleaseDC(hWndA, hdc); ``` Test2: ``` HDC hdc = CreateCompatibleDC(NULL);
BOOL ret = UpdateLayeredWindow(hWndA, NULL, NULL, &si, hdc, &pi, 0, &bf, ULW_ALPHA);
ReleaseDC(NULL, hdc); ``` The test results confirm what you said:
The window DC created in Test1 doesn't unnecessary to lock the surface, and calling window_surface_lock would cause a deadlock.
The compatible DC created in Test2 requires locking.