Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 3rd/glfw/src/win32_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,21 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
case WM_PAINT:
{
_glfwInputWindowDamage(window);
// Backport glfw/glfw#2815 (jeweg): initialize the DWM
// redirection surface's alpha independently of the GL buffer.
if (window->win32.transparent)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
PatBlt(hdc,
ps.rcPaint.left,
ps.rcPaint.top,
ps.rcPaint.right - ps.rcPaint.left,
ps.rcPaint.bottom - ps.rcPaint.top,
BLACKNESS);
EndPaint(hWnd, &ps);
return 0;
}
break;
}

Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,9 @@ if(EUI_BUILD_TEST_FIXTURES)
get_filename_component(probe_name "${probe_source}" NAME_WE)
add_executable(${probe_name} "${probe_source}")
target_link_libraries(${probe_name} PRIVATE eui::neo)
if(WIN32 AND probe_name STREQUAL "transparent_cache_probe")
target_link_libraries(${probe_name} PRIVATE dwmapi)
endif()
eui_apply_compile_options(${probe_name})
eui_neo_copy_assets(${probe_name})
eui_neo_copy_runtime_dependencies(${probe_name})
Expand All @@ -650,6 +653,9 @@ if(EUI_BUILD_TEST_FIXTURES)
target_compile_definitions(${probe_name} PRIVATE EUI_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
add_test(NAME ${probe_name} COMMAND ${probe_name} --frames 3)
set_tests_properties(${probe_name} PROPERTIES LABELS "probe")
if(probe_name STREQUAL "transparent_cache_probe")
set_tests_properties(${probe_name} PROPERTIES SKIP_RETURN_CODE 77)
endif()
if(probe_name STREQUAL "gpu_image_probe")
set_tests_properties(${probe_name} PROPERTIES FAIL_REGULAR_EXPRESSION "Validation Error;VUID-")
endif()
Expand Down
2 changes: 1 addition & 1 deletion core/window/window_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ const X11ResourceApi& x11ResourceApi() {
static const X11ResourceApi api = loadX11ResourceApi();
return api;
}
#endif

bool sendX11MoveResizeForWindow(Handle window, int direction) {
SDL_Window* sdlWindow = static_cast<SDL_Window*>(window);
Expand All @@ -295,7 +296,6 @@ bool sendX11MoveResizeForWindow(Handle window, int direction) {
return false;
#endif
}
#endif


} // namespace
Expand Down
24 changes: 24 additions & 0 deletions docs/platform/windows-transparent-framebuffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Windows transparent framebuffer presentation

The bundled GLFW Win32 backend includes the small WM_PAINT repair proposed in
[glfw/glfw#2815](https://github.com/glfw/glfw/pull/2815) by jeweg. A transparent
window has two distinct alpha surfaces: the renderer's framebuffer and DWM's
redirection surface. Correct GL alpha alone does not initialize the latter.
Undefined redirection alpha can produce intermittent black transparent margins,
including on NVIDIA or virtual display paths.

For transparent windows, WM_PAINT clears the invalidated redirection area with
PatBlt(BLACKNESS), which defines its RGB and alpha as zero. The normal GLFW damage
notification still requests renderer repaint. Opaque windows keep their previous
paint handling. No window region, color key or geometry crop is introduced.

External GLFW targets do not receive this bundled-source fix automatically.
Consumers supplying GLFW must carry the corresponding repair themselves.
SDL2 continues to report framebufferTransparent=false; its transparency contract
is unchanged. Vulkan swapchain composite-alpha support remains device-dependent.

`transparent_cache_probe` checks the Win32 GLFW/OpenGL path against an owned,
known-color background, including initial paint and subsequent cached frames.
It returns CTest skip code 77 on other backend combinations. `--manual` retains
the test windows for visual inspection; normal CTest `--frames` arguments do not.
The separate `transparent_window_viewer` fixture shows actual desktop margins.
137 changes: 137 additions & 0 deletions tests/probes/transparent_cache_probe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#include "core/render/render_backend.h"
#include "core/window/window_backend.h"
#include "core/app/main_window_runtime.h"
#include "eui/detail/dsl_app_impl.h"
#include "eui_neo.h"

namespace app {
const DslAppConfig& dslAppConfig() {
static const auto config = DslAppConfig{}.iconPath("").tray(false).transparent(true)
.clearColor({0, 0, 0, 0});
return config;
}
void compose(eui::Ui& ui, const eui::Screen&) {
ui.rect("panel").position(40, 40).size(240, 140).radius(28).color({0.8f, 0.2f, 0.1f, 1}).build();
}
}

#if defined(_WIN32) && defined(EUI_RENDER_BACKEND_OPENGL) && !defined(EUI_WINDOW_BACKEND_SDL2)
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#include <GLFW/glfw3native.h>
#include <dwmapi.h>
#include <cstdio>
#include <cstring>

#if defined(_MSC_VER)
namespace {
int redirectionClears = 0;
BOOL WINAPI observeRedirectionClear(HDC dc, int x, int y, int width, int height, DWORD operation) {
using Blit = BOOL(WINAPI *)(HDC, int, int, int, int, DWORD);
const auto actual = reinterpret_cast<Blit>(GetProcAddress(GetModuleHandleW(L"gdi32.dll"), "PatBlt"));
const BOOL result = actual(dc, x, y, width, height, operation);
if (result && operation == BLACKNESS && width > 0 && height > 0) ++redirectionClears;
return result;
}
}
// Observe and forward the real GDI clear. Without the Win32 repair, correctly
// zeroed allocations could make a pixels-only regression accidentally pass.
extern "C" { BOOL(WINAPI *__imp_PatBlt)(HDC, int, int, int, int, DWORD) = observeRedirectionClear; }
#endif

int main(int argc, char** argv) {
if (!glfwInit()) return 1;
const COLORREF backingColor = RGB(80, 160, 100);
HBRUSH brush = CreateSolidBrush(backingColor);
WNDCLASSW wc{};
wc.hInstance = GetModuleHandleW(nullptr);
wc.lpfnWndProc = DefWindowProcW;
wc.lpszClassName = L"EuiAlphaProbeBacking";
wc.hbrBackground = brush;
RegisterClassW(&wc);
HWND backing = CreateWindowExW(WS_EX_TOPMOST, wc.lpszClassName, L"EUI alpha probe backing", WS_POPUP,
120, 120, 420, 320, nullptr, nullptr, wc.hInstance, nullptr);
if (!backing) return 2;
ShowWindow(backing, SW_SHOWNOACTIVATE);
UpdateWindow(backing);

core::window::WindowCreateRequest request;
request.width = 320;
request.height = 220;
request.title = "EUI transparent cache probe";
request.decorated = false;
request.transparent = true;
request.visible = false;
request.alwaysOnTop = true;
request.positionSet = true;
request.x = 160;
request.y = 160;
auto window = core::window::createWindow(request);
if (!window || !core::window::framebufferTransparent(window)) return 3;
auto backend = core::render::createRenderBackend(window, nullptr, true);
if (!backend || !backend->initialize()) return 4;
auto *glfw = static_cast<GLFWwindow *>(window);
const HWND native = glfwGetWin32Window(glfw);
// Model a newly allocated redirection surface containing opaque black.
// This is separate from the GL framebuffer's correctly zeroed alpha.
BITMAPINFO info{};
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biWidth = 1;
info.bmiHeader.biHeight = 1;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biBitCount = 32;
info.bmiHeader.biCompression = BI_RGB;
const unsigned int opaqueBlack = 0xff000000u;
HDC redirection = GetDC(native);
StretchDIBits(redirection, 0, 0, 320, 220, 0, 0, 1, 1, &opaqueBlack, &info,
DIB_RGB_COLORS, SRCCOPY);
ReleaseDC(native, redirection);
InvalidateRect(native, nullptr, FALSE);
SetWindowPos(backing, HWND_TOP, 120, 120, 420, 320, SWP_NOACTIVATE);
app::initialize(window);
app::AppRunner runner;
app::MainWindowRuntime runtime(runner, [&] {
glfwShowWindow(glfw);
SetWindowPos(native, HWND_TOP, 160, 160, 320, 220, SWP_NOACTIVATE);
InvalidateRect(native, nullptr, FALSE);
UpdateWindow(native);
});
int failures = 0;
for (int frame = 0; frame < 6; ++frame) {
runner.paintRequested = true;
runtime.updateAndRender(window, *backend, {320, 220, 1, 1}, 0, false, true,
[] {}, [] { return app::MainWindowMetrics{320, 220, 1, 1}; });
glfwPollEvents();
DwmFlush();
POINT origin{};
ClientToScreen(native, &origin);
HDC screen = GetDC(nullptr);
const COLORREF margin = GetPixel(screen, origin.x + 8, origin.y + 8);
const COLORREF center = GetPixel(screen, origin.x + 160, origin.y + 110);
ReleaseDC(nullptr, screen);
std::printf("frame %d: margin=%06lx expected=%06lx center=%06lx\n",
frame, margin, backingColor, center);
// WM_PAINT initializes the redirection surface and requests a GL
// repaint. From the next frame onward the panel must also be visible.
if (margin != backingColor || (frame > 0 && (GetRValue(center) < 180 || GetGValue(center) > 80))) ++failures;
}
#if defined(_MSC_VER)
std::printf("redirection initialization clears: %d\n", redirectionClears);
if (redirectionClears == 0) ++failures;
#endif
if (argc > 1 && std::strcmp(argv[1], "--manual") == 0) {
while (!glfwWindowShouldClose(glfw)) glfwWaitEvents();
}
app::shutdown();
backend.reset();
core::window::destroyWindow(window);
DestroyWindow(backing);
UnregisterClassW(wc.lpszClassName, wc.hInstance);
DeleteObject(brush);
glfwTerminate();
return failures ? 1 : 0;
}
#else
int main() { return 77; } // Not applicable without the Win32 GLFW/OpenGL compositor.
#endif
5 changes: 5 additions & 0 deletions tests/probes/window_only_probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ bool pollOnce(core::window::Handle window) {
#if defined(EUI_WINDOW_BACKEND_SDL2)
bool verifySdlWindowInput(core::window::Handle firstWindow,
const core::window::WindowCreateRequest& request) {
// Non-X11 builds must compile and honestly decline WM move/resize.
if (core::window::beginWindowMove(nullptr) ||
core::window::beginWindowResize(nullptr, core::window::WindowResizeEdge::TopLeft)) {
return false;
}
core::window::Handle secondWindow = core::window::createWindow(request);
if (secondWindow == nullptr) {
return false;
Expand Down
Loading