Skip to content

feat(window): transparent framebuffer support for rounded custom chrome - #92

Closed
Linductor-alkaid wants to merge 1 commit into
sudoevolve:devfrom
Linductor-alkaid:feat/window-transparent
Closed

Linductor-alkaid wants to merge 1 commit into
sudoevolve:devfrom
Linductor-alkaid:feat/window-transparent

Conversation

@Linductor-alkaid

Copy link
Copy Markdown
Contributor

问题

  • 复现方式或用户需求:见 支持透明 framebuffer,让无边框窗口可以实现圆角 #90(Ubuntu 24.04 / GNOME 46 Wayland + XWayland 实测)。.decorated(false) 应用自绘圆角窗口需要带 alpha 的 framebuffer:WindowCreateRequest 没有透明选项、GLFW 后端从不设置 GLFW_TRANSPARENT_FRAMEBUFFER,clearColor 的 alpha 写进的是不透明表面,圆角窗口无法实现。
  • 根因:窗口层缺少透明 framebuffer 能力。渲染侧已就绪(圆角矩形抗锯齿、clear 遵循 alpha、GL 混合可正确累积 alpha,(0,0,0,0) 清屏上恰好产出合成器期望的 premultiplied 内容)。

修改

  • 实现方案:
    • WindowCreateRequest.transparent(默认 false):GLFW 后端映射为 glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, ...)(该常量自 GLFW 3.3 起存在,且同时是窗口属性,可查询实际授予状态);SDL2 后端忽略(SDL2 无透明窗口 flag,SDL3 才加入),framebufferTransparent() 如实返回 false。
    • framebufferTransparent(Handle):报告平台实际授予状态(X11 无合成器时 GLFW 会拒绝)。
    • DslAppConfig.transparent(bool) → app::windowTransparent() → 两个 *_app_main 的主窗口请求与 createRenderBackend 第三参。
    • Vulkan:swapchain compositeAlpha 不再硬编码 OPAQUE,transparent 时从 capabilities.supportedCompositeAlpha 优先选 POST_MULTIPLIED(渲染内容为 premultiplied),次选 INHERIT,否则退回 OPAQUE,不会因不支持而创建失败。
    • 新 fixture tests/fixtures/transparent_window_viewer.cpp:透明无边框窗口 + 圆角面板 + framebufferTransparent 状态展示。
    • docs/DSL.md:.transparent(true) 说明;原文"全屏、透明窗口和 VSync 不属于 DslAppConfig"中透明窗口属创建期属性(与 decorated 同类),移出该清单并说明查询方式。
  • 为什么符合简单、快速、易上手:一个创建期布尔属性 + 一个查询函数,默认值不变;未启用 .transparent() 的应用行为逐像素等价。

影响

  • 修改/新增/删除文件数:14 修改、1 新增(fixture)
  • 代码净增行数:+131,-9
  • 仓库追踪内容净增体积:约 6 KiB
  • 新增依赖或资源:无

本机环境

  • OS:Ubuntu 24.04(GNOME 46 Wayland 会话 + XWayland,Mutter 46.2)
  • CPU:Intel Core Ultra 5 225H
  • GPU:Intel Arrow Lake-P 核显
  • 编译器:g++ 13.3.0(fixtures 以 -std=gnu++17 -Os -fno-exceptions -fno-rtti 编译)

验证

  • GLFW + OpenGL:Release 构建和测试通过(零错误零警告;ctest -L unit 25/25,DISPLAY=:0 ctest -L probe 8/8)
  • SDL2 + OpenGL:本机未执行(缺 libsdl2-dev;SDL2 分支改动为一个恒 false 函数,待 CI 覆盖)
  • GLFW + Vulkan:本机未执行(缺 libvulkan-dev / glslang-tools;compositeAlpha 选择路径待 CI 编译覆盖)
  • SDL2 + Vulkan:本机未执行(同上)
  • 已运行与改动相关的示例或 fixture(transparent_window_viewer 以 X11 平台运行 12s 无错误退出,窗口存在;真机 GNOME/XWayland 下窗口深度 32 ARGB,四角像素 alpha=0,圆角外透出桌面)
  • Bug 修复包含回归测试,或已解释无法添加的原因:透明授予依赖合成器与平台视觉,headless 单测只能覆盖常量路径;以 fixture + 真机像素采样验收
  • 性能声明包含修改前后数据和复现方法:不涉及

备注

  • 真机像素证据:bundled GLFW X11 + GNOME 合成器下 glfwGetWindowAttrib(GLFW_TRANSPARENT_FRAMEBUFFER) 为 true,窗口 composite pixmap 四角 rgba=(0,0,0,0),背景矩形以 radius 12 绘制后圆角边缘抗锯齿正常。
  • Vulkan POST_MULTIPLIED/INHERIT 回退链未做运行时验证(本机无 Vulkan 头文件环境),需 CI 编译与后续运行确认。

DslAppConfig gains .transparent(bool) plumbed into WindowCreateRequest:
GLFW requests GLFW_TRANSPARENT_FRAMEBUFFER, Vulkan selects a supported
composite-alpha mode (POST_MULTIPLIED preferred) instead of hardcoding
OPAQUE, and framebufferTransparent() reports what the platform granted.
SDL2 has no transparent-window flag (SDL3-only) and reports false. The
renderer already produces premultiplied content, so apps can clear to
transparent and draw their own rounded root surface.

Issue: sudoevolve#90
@sudoevolve

Copy link
Copy Markdown
Owner

Superseded by #98, which includes the same transparency change rebased onto current dev and resolves the #91 API conflict.

@sudoevolve sudoevolve closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants