Skip to content

feat(session): capture toplevels by rendering an offscreen viewport - #1663

Open
glyvut wants to merge 2 commits into
linuxdeepin:master-backup-20261124from
glyvut:rec-01
Open

glyvut wants to merge 2 commits into
linuxdeepin:master-backup-20261124from
glyvut:rec-01

Conversation

@glyvut

@glyvut glyvut commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Render the captured window into a private offscreen viewport and swapchain instead of copying the client surface buffer, so recursive subsurfaces, SSD titlebar and border are captured and constraints follow real window bounds.

用私有离屏视口与 swapchain 渲染被捕获窗口,替代直接拷贝客户端 surface
buffer,从而包含递归子面、SSD 标题栏与外边框,约束按真实窗口边界发布。

Log: 窗口捕获改为离屏渲染整窗
PMS: BUG-374941
Influence: 窗口截图/录屏包含 SSD 与子面,且捕获不再改变真实输出与窗口状态。

Summary by Sourcery

Render foreign toplevel captures in isolated offscreen viewports so complete window contents and decorations are captured without changing the live desktop.

New Features:

  • Capture foreign toplevel windows through dedicated offscreen rendering, including recursive subsurfaces and server-side decorations.
  • Support window-sized capture constraints that track movement, resizing, maximization, and restoration without affecting the live window or output.

Bug Fixes:

  • Prevent capture rendering from modifying real output pixels, live scene state, or accumulating translucent decoration artifacts.
  • Ensure capture sessions continue correctly across source-resource destruction, repeated requests, resizing, and compositor renders between frames.

Enhancements:

  • Manage capture viewport and source lifetimes per client session, creating pipelines lazily and releasing them when no sessions remain.
  • Extend offscreen viewport and renderer support for independent buffer sizes, source visibility, frame signaling, and capture-specific swapchains.

Documentation:

  • Document capture fixture requirements, lifecycle expectations, pixel-validation methodology, and known test boundaries.

Tests:

  • Add end-to-end protocol coverage for toplevel capture pixels, recursive subsurfaces, SSD decorations, occlusion isolation, movement, resizing, maximize/restore, multiple sessions, resource destruction, and cleanup.
  • Add optional GLES2 GPU capture coverage alongside repeated headless software-renderer validation.

@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: glyvut

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Extend viewport state and expose buffer sizing, source visibility, swapchain access, and frame notifications needed by independent offscreen captures.

  • waylib/src/server/qtquick/private/woutputviewport_p.h L24, L83-87
  • waylib/src/server/qtquick/woutputviewport.h L26-27, L68-79, L127-129

Generalize the capture-source abstraction to own a lazily created viewport, track source resources and sessions, and provide lifecycle hooks for concrete capture sources.

  • waylib/src/server/utils/wextimagecapturesourcev1impl.h L23-40, L57-67, L72-79 (+3 small edits)

Expose the renderer swapchain required to publish constraints from the private capture pipeline.

  • waylib/src/server/qtquick/private/wbufferrenderer_p.h L74

Uses of the API

Replace eager surface-buffer capture construction with a per-request source whose viewport is created only when a capture session starts.

  • src/session/sessionprotocols.cpp L7, L23 (removed lines), L122-131

Implementation

Implement a read-only, window-sized viewport that renders a private surface tree and SSD decorations while tracking source geometry and output scale.

  • src/session/toplevelcaptureviewport.cpp L1-183
  • src/session/toplevelcaptureviewport.h L1-33

Implement the foreign-toplevel source factory that resolves the window's current output when a session creates its viewport.

  • src/session/toplevelcapturesource.cpp L1-23
  • src/session/toplevelcapturesource.h L1-27

Rework capture-source lifecycle, constraint publication, frame scheduling, and copying around per-session offscreen viewports and safe resource recycling.

  • waylib/src/server/utils/wextimagecapturesourcev1impl.cpp L5-8, L21-36, L53-364 (+5 small edits)

Render offscreen viewports at their own dimensions without output commits, correctly finish render lifetimes, and notify viewport consumers after rendering.

  • waylib/src/server/qtquick/woutputrenderwindow.cpp L1516-1527, L1648-1653, L1680-1683 (+4 small edits)
  • waylib/src/server/qtquick/woutputviewport.cpp L92, L256-305, L438

Correct software rendering for negative source rectangles and clear offscreen targets before each capture render.

  • waylib/src/server/qtquick/private/wbufferrenderer.cpp L73-79, L522-524

UI

Allow capture surface content to use a private source-surface wrapper and avoid updating the live surface size ratio.

  • src/core/qml/CaptureSurfaceContent.qml L1-9
  • src/core/qml/SurfaceContent.qml L14-15, L91

Configuration

Register the new capture source, viewport, and QML component with the library build.

  • src/CMakeLists.txt L247-250, L333

Add the toplevel capture protocol test target and optional GLES2 variant with its required dependencies and environment.

  • tests/protocols/wayland-ext-image-copy-capture-v1/CMakeLists.txt L2-5, L14-48

Documentation

Document fixture requirements and lifecycle constraints for pixel-based capture protocol tests.

  • .agents/skills/treeland-protocol-test/SKILL.md L73-109

Record the expanded capture coverage, architecture, validation evidence, and remaining limits in the protocol test documentation and index.

  • tests/protocols/INDEX.md L85, L164-167, L198-205
  • tests/protocols/wayland-ext-image-copy-capture-v1/README.md L7-19, L27-117

Tests

Track maximized state in the shared xdg-toplevel test fixture so maximize and restore capture scenarios can verify configure results.

  • tests/protocols/framework/xdg-toplevel-client.c L41 (removed lines), L44-49
  • tests/protocols/framework/xdg-toplevel-client.h L27

Add a production-backed server fixture for isolated window rendering, output and QSG integrity checks, real pointer-driven SSD dragging, and capture lifecycle observations.

  • tests/protocols/wayland-ext-image-copy-capture-v1/toplevel-setup.cpp L1-504
  • tests/protocols/wayland-ext-image-copy-capture-v1/wayland-ext-toplevel-image-capture-v1.h L1-47

Exercise foreign-toplevel capture pixels and metadata across recursive subsurfaces, decorations, occlusion, movement, resize, maximize/restore, multiple sessions, and resource teardown.

  • tests/protocols/wayland-ext-image-copy-capture-v1/wayland-ext-toplevel-image-capture-v1.c L1-765

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-wm deepin-wm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI 代码审查(复审 · 内联)

结论:通过(可合并)。 上一轮的阻塞项(每个捕获请求一套离屏管线、生命周期绑在窗口上)已按「客户端资源 + 会话」双条件接管并补了协议级回归,方向正确。下面 10 条内联意见里只有第 1 条(一行守卫)建议合入前补,其余为非阻塞。

审查基线:9ef3a0da5(base 194b391ce),全 PR 25 文件 +2212 / −441。

上轮问题闭环情况

上轮 上轮结论 本轮状态
B1 每请求一套离屏管线、生命周期绑在窗口 必须修 已修复:ensureViewport() 在首个 start() 才建视口;stop() 在最后一个会话结束时 releaseViewport();resourceDestroyed() → maybeRecycle() 在「无会话且资源表为空」时回收整个包装对象,「接受了但从不捕获的 source 不分配任何 GPU/QSG 资源」成立
B2 共享渲染路径改动无测试 必须补 已补:新增 toplevel-setup.cpp + wayland-ext-toplevel-image-capture-v1.c,覆盖 render(doCommit=false) 不改 commit_seq、随后真实 commit 做整屏像素对比、半透明 SSD 边框重复帧不叠加
N1 / N3 / N5 / N7 / Q1–Q3 建议 未处理,见内联意见

一个需要补的流程缺口(非阻塞,但影响 B2 的闭环强度)

新增的约 1520 行协议测试挂在 BUILD_TREELAND_PROTOCOL_TESTS 下(tests/CMakeLists.txt),而 CI 没有打开它:gh pr checks 里通过的 container 作业只跑了 9 个 waylib 单测(test_qsgrenderer_accessor … test_wobject_listeners),本次新增的 wayland_ext_toplevel_image_capture_v1 一次都没有被执行。

也就是说 B2 的闭环目前只由本地手跑记录支撑。合入后如果共享渲染路径回归,CI 仍然发现不了。建议在本 PR 里加一个开启 BUILD_TREELAND_PROTOCOL_TESTS(pixman 后端口)的 CI 作业,或确认已有作业能覆盖到。

CI 现状

gh pr checks 1663:9 项中 8 项通过。唯一失败的是 Arch 容器里 src/greeter/greeterproxy.cpp:580,592 报 DDM::DaemonMessages::LastLogin / SessionDirs 不存在——CI 镜像的 ddm 版本较老,与本 PR 无关。

但要注意这个失败让该作业停在 1078/1987,src/session/ 还没编译到,所以 toplevelcaptureviewport.cpp / toplevelcapturesource.cpp 的 CI 构建证据仍然缺一次全绿构建。

Comment thread src/session/toplevelcapturesource.cpp Resolved
Comment thread src/session/toplevelcaptureviewport.cpp Resolved
Comment thread src/session/toplevelcaptureviewport.cpp Resolved
Comment thread src/session/toplevelcaptureviewport.cpp Resolved
@deepin-bot

deepin-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.12.0
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1686

@glyvut
glyvut force-pushed the rec-01 branch 2 times, most recently from e6bcc5f to 3a5bec8 Compare November 24, 2026 02:49

@deepin-wm deepin-wm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test

@deepin-wm deepin-wm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test2

@deepin-wm deepin-wm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

中文测试

@deepin-wm deepin-wm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审(第 3 轮)· head 3a5bec849

  • 对象:PR #1663,head 3a5bec849,base master 17b790aa4(已 rebase,无需再同步),25 文件 +2699 / −426
  • 上一轮审到的 head:9ef3a0da5;本次只看增量(关屏兜底渲染、渲染失败上报、新增用例),并复核上轮未闭环项
  • 结论:建议补 1 行后合并。上一轮唯一的「必须修改」(createViewport() 缺 window() 守卫)仍未处理;本轮新增 1 处非阻塞缺陷 + 2 条建议。作者对 3 条旧意见的反驳,我逐条核对后接受 2 条、另 1 条只保留建议。

上一轮问题闭环

编号 上轮结论 本轮状态
B1 每请求一套管线、生命周期绑在窗口 必须修 已修(上一轮已确认,本轮未退化)
B2 共享渲染路径无测试 必须补 已补,但仍不在 CI 里跑(见下)
B1' createViewport() 缺 window() 守卫 建议合入前补(一行) 未处理,见内联评论
S1 跨会话 dmabuf_device/dmabuf_formats 陈旧 非阻塞 未处理(releaseViewport() 仍只清 m_constraintsFromSwapchain)
S2 stop() 同步删除视口 非阻塞 未处理
N3 Border/CaptureSurfaceContent 每会话重建组件 非阻塞 未处理(现在每会话一条管线,编译次数更频繁)
N7 getContentGeometry() 未判空 shellSurface() 非阻塞 未处理

对作者 3 条回复的核对

  • size_t m_numStarted(「不成立」)— 我撤回。 核对 3rdparty/wlroots/types/wlr_ext_image_copy_capture_v1.c:421-470:session_create() 在 calloc(session) 之后、挂 listener 之前必然调一次 impl->start();session_destroy() 无条件调一次 impl->stop()。start() 只在 m_finished 时提前返回,而 wlr_ext_image_capture_source_v1_finish() 已把每条的 resource 的 user_data 置 NULL,此后 create_session 走 source == NULL 分支直接 send_stopped,不会再进本类。因此 stop() 与 start() 严格成对,下溢不可达;上一轮结论属于过度防御。
  • Q_ASSERT(self)(「?」)— 我撤回「必须补」的定性。 s_captureSourceMap 只在本类析构里移除,而析构前 invalidate() 已经 finish() 掉全部 resource 与 session,回调进来时 self 必非空。Q_ASSERT 在这里是把不变量写出来的正确用法,lint LCY-4 是风格规则,不是本 PR 的缺陷。若想彻底消音,可以在这 4 处旁边写一句「resource 已 finish,map 项仍有效」的注释;不写也可以。
  • 光标捕获(「以前也没支持」)— 我撤回。 已核对 base 版本,get_pointer_cursor() 同样恒返回 nullptr。唯一建议(可选):在 PR 描述里补一句「光标捕获未实现」,省得客户端把它当 bug。

本轮增量:方向确认

  • 关屏兜底:输出 enabled 时沿用输出 frame 时钟,disabled 时排队 render(false),并处理了 inRendering 重入(renderEnd 后 resumeRender() 再调度);enabledChanged 补调度、releaseViewport() 清排队状态,闭环是完整的。
  • 失败上报:beginRender() 返回空 → failedViewports → frameRenderFailed → sendFrame(nullptr) → 每会话 failed(unknown),不再让客户端永久等待;copy_frame() 的 STOPPED 早退与 buffer 判空顺序也对。
  • 清理后置:frameRendered/frameRenderFailed 都在 endRender() + resetState() 之后、inRendering == false 时发出,没有在缓冲区仍被渲染器占有时回传给客户端。

仍建议修改(非阻塞)

  1. renderEnabled == false 时没有失败上报,兜底路径会静默丢帧。 见 woutputrenderwindow.cpp:1691 的内联评论。影响面小(disable_render 只在 DDM 切会话时出现,捕获 source 通常同时被回收),但失败语义既然已经建立,这里补上更一致。
  2. handleFrameRendered() 未像 handleFrameRenderFailed() 一样检查 m_renderPending。 现在离屏视口在 contentIsDirty 时也会被普通合成趟渲染,于是可能发出一次「客户端没请求」的成功帧并顺带清掉 m_renderPending。当前无害(wlroots 在 session->frame->capturing 为假时不会 copy),但两侧判据不对称,后续若有副作用会很难解释;建议统一成「只有 m_renderPending 为真才发帧」。
  3. 新增的约 1500 行协议测试仍不在 CI 中执行。 本 PR 没有改 CI,BUILD_TREELAND_PROTOCOL_TESTS 依旧只在本地打开;--summary 里的 pixman/GLES2 各 20 次通过还是本地证据。另外 CI 里唯一失败的 Arch 容器仍停在 greeterproxy.cpp 的 ddm 版本漂移,src/session/ 尚未编到,toplevelcapturesource.cpp / toplevelcaptureviewport.cpp 仍缺一次全绿 CI 构建。

本地验证(本次实跑)

在 head 3a5bec849 上配置并编译,-Wall -Wextra(未加 -Werror):

cmake -S . -B build-review -G Ninja -DBUILD_TREELAND_PROTOCOL_TESTS=ON \
      -DDISABLE_DDM=ON -DTreelandProtocols_DIR=<treeland-protocols@283c57d 的 install 前缀>
ninja -j16        # 1589/2129 目标
  • 改动文件全部编译通过,0 告警:wextimagecapturesourcev1impl.cpp.o、woutputviewport.cpp.o、woutputrenderwindow.cpp.o、private/wbufferrenderer.cpp.o、sessionprotocols.cpp.o、toplevelcapturesource.cpp.o、toplevelcaptureviewport.cpp.o,以及 CaptureSurfaceContent.qml / SurfaceContent.qml 的 qmlcachegen 产物。全量日志里唯一告警来自 3rdparty/wlroots/util/log.c(与本 PR 无关)。
  • 未完成:最终 src/treeland 链接失败,因为镜像里只有 DDM 0.4.0,我用 -DDISABLE_DDM=ON 绕过时 greeter/usermodel.cpp、greeterproxy.cpp 被排除而 waylandserver/sessionmanager 仍引用它们(这是仓库既有的 DISABLE_DDM 组合缺陷,base 同样存在,与本 PR 无关)。因此 libtreeland.so 带未定义符号,测试可执行文件链接不上,新增协议测试一个都没有实际执行。
  • 结论:本轮的构建证据只覆盖「改动能编译」,捕获行为、像素与关屏兜底的成功/失败路径仍以作者 README 里的本地记录为准 —— 我这边没能独立复现。

需要澄清(沿用上一轮,仍未在 PR 描述中回应)

  • 截图是否包含窗口阴影(当前显式不创建 XdgShadow)、装饰动画期间取 wrapper->radius() 还是 presentationFrameGeometry.radius。建议在 PR 描述里写明验收口径。

Comment thread src/session/toplevelcapturesource.cpp Resolved
}
for (const auto &viewport : std::as_const(failedViewports)) {
if (viewport)
Q_EMIT viewport->frameRenderFailed();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

失败上报只覆盖了「beginRender() 拿不到 buffer」,漏掉「这一趟根本没有渲染」。

doRender() 开头有一句 if (!renderEnabled) return;(:1587)。当它成立时(DDM 协议的 disable_render,src/modules/ddm/ddminterfacev1.cpp:76)这一趟既不发 frameRendered 也不发 frameRenderFailed,而 renderFallback() 的 m_viewport->render(false) 恰好走的就是这里:m_fallbackQueued 已经在 renderFallback() 入口清回 false,m_renderPending 仍是 true,之后没有任何东西会重新调度 —— 只有客户端再 request_frame、或输出 enabledChanged,才有下一次机会;而 portal 截图类客户端一般只 capture 一次就阻塞等待。

失败语义既然已经建立,建议把「渲染没发生」也纳进来,两种改法任选:

  1. 在 doRender() 早退前,对本次请求范围内的 offscreen(或 forceRender 的)viewport 补发 frameRenderFailed();
  2. 或在 WExtImageCaptureSourceV1Impl::renderFallback() 里先判 renderWindow->renderEnabled()(需要新增只读访问器),为假时按「下个事件循环重试 + 有上限」处理,而不是当作已经渲染过。

影响面不大(disable_render 期间捕获 source 通常也在回收),所以标为非阻塞;但它会让「失败一定会通知」这条约定出现一个空洞。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复,而且比建议的方案更明确:暂停 = 保持挂起,不是失败。

WOutputRenderWindow 增加 renderEnabled() / renderEnabledChanged(),setRenderEnabled() 同值早退、恢复时先置位再发信号并 update();捕获侧连接该信号重排,schedulePendingRender() / renderFallback() 在 !renderEnabled 时保留 m_renderPending 直接返回。所以「这一趟根本没渲染」不再吞掉请求,也不需要额外补发失败。

新增的 DDM 用例覆盖了四种组合:输出启用时暂停/恢复、输出关屏时暂停/恢复、已排队 fallback 遇暂停、暂停期间取消与 toplevel 销毁后恢复不重绘;head b2917c7a5 的 CI 上 test_wayland_ext_toplevel_image_capture_v1 通过(1.13s)。本线程关闭。

@deepin-wm deepin-wm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☀ AI审核结果(复审 · 第 4 轮)

★ 总体评分:92分(大于70分通过)

  • 审查对象:PR #1663,base master 17b790aa4,head b2917c7a5(squash 后为 cf41186ce feat(capture): render isolated toplevel capture pipelines + b2917c7a5 test(capture): cover isolated toplevel capture and recovery)

  • 本轮增量:相对上轮审到的 3a5bec849,共 12 文件 +196 / −17;源码只有 4 处——src/core/qmlengine.{h,cpp}、src/session/toplevelcaptureviewport.cpp、waylib/src/server/qtquick/woutputrenderwindow.{h,cpp}、waylib/src/server/utils/wextimagecapturesourcev1impl.cpp,其余是测试与测试文档

  • 结论:通过(可合并)。上轮剩余的两条意见都用「代码 + 测试」闭环;另外两条我撤回(一条接受作者反驳,一条是我自己的误判);没有新增阻塞项。

■ 【上轮意见逐条闭环】

上轮编号 上轮定性 本轮状态 依据
N3 组件每会话重新编译 建议 已修复 QmlEngine 新增 borderComponent / captureSurfaceContent 缓存成员,createBorder(QQuickItem*) 与 captureSurfaceContentComponent() 走统一工厂;顺带去掉 Border.qml 里不存在的 surface 初始属性,并补上 base 里 borderComponent 从未进入构造初始化列表的老问题
doRender 在 renderEnabled == false 时既不成功也不失败 非阻塞缺陷 已修复 新增 renderEnabled() / renderEnabledChanged();捕获侧连接该信号重排挂起请求,schedulePendingRender() / renderFallback() 在关闭渲染时保留 m_renderPending 直接返回;新增 4 个 DDM disable_render 场景用例
createViewport() 缺 window() 守卫 建议合入前补 撤回(接受反驳) 工厂只接受会话 foreign-toplevel 列表解析出的 wrapper;aboutToBeInvalidated → invalidate() → releaseViewport() 在 item 离开场景之前就同步销毁了视口
getContentGeometry() 缺 shellSurface() 判空 非阻塞 撤回(我的误判) 同类重写全部直接解引用,基类 WSurfaceItem::getContentGeometry() 也是 d->surface->size(),我上轮「基类判空」是错记
作者已自行 resolved 的 8 条(LCY-4、size_t 下溢、同步 delete 视口、dmabuf 约束跨会话、拿不到 buffer 静默返回、光标、装饰几何、window 守卫旧线程) — 复核认可 其中 3 条是我在上一轮就已经撤回的;handleFrameRendered() 现在走 handleFrameRenderFailed() 发失败帧,bzxB 也真的修了;stop() 同步释放与 dmabuf 约束跨会话两条,作者给出的「finish() 会重入 session 销毁,释放视口未证明有同样问题」「正常输出共用 renderer/allocator」是可接受的工程判断

■ 【本轮增量的实现审查(确认正确)】

  1. 组件缓存:borderComponent(this, "Treeland", "Border") 与 captureSurfaceContent(this, "Treeland", "CaptureSurfaceContent") 按头文件成员顺序初始化,无 -Wreorder;WSurfaceItem::setDelegate() 只存裸指针、不接管所有权,把引擎持有的组件交给它比之前「视口持有组件」更安全(组件生命周期从此不再跟着视口走)。
  2. createBorder() 语义变化是正确的收紧:src/core/qml/Border.qml 没有 surface 属性,原实现的 { { "surface", ... } } 初始属性是一条无效路径;现在只传 parent。
  3. 暂停语义比原来更明确:renderEnabled=false 被定义为「保持挂起」,而不是「本帧失败」——m_renderPending 不清、不发 frameRenderFailed、不轮询;setRenderEnabled(true) 先置位再发信号(槽看到的已是新值)并 update(),renderEnabledChanged 触发重排,包括「输出仍关闭、需走离屏兜底」的那条路径(renderFallback() 里同样先判 renderEnabled(),回到 schedulePendingRender() 后仍会重新入队兜底)。
  4. 测试确实覆盖到争议点:check_render_pause() 在暂停期间断言 !ready && !failed && !stopped && render_attempts 不变 && viewport_unchanged,恢复后只观察原帧结果、不补发 capture;另有「暂停期间取消」「暂停期间 toplevel 销毁」两个反向用例,以及 shared_delegates == offscreen_viewports 的组件复用断言。方向与实现一致。

■ 【我本地的验证】

  • 编译(-DDISABLE_DDM=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Wall -Wextra",pixman/Qt6.8 环境):8 个受影响 TU 全部通过、0 告警;随后全量 ninja -k 0 跑完所有编译步骤(1468 步)无一失败。

  • 链接/本地跑测试不可用(既有缺陷,与本 PR 无关):镜像只有 DDM 0.4.0,-DDISABLE_DDM=ON 只排除 src/greeter/*,而 src/core/waylandserver.cpp 仍引用 UserModel/User,libtreeland.so 带未定义符号,81 个可执行目标全部链接失败。我用 -Wl,--allow-shlib-undefined 能链上捕获测试,但运行时 QML 缺少 UserModel 单例,合成器启动阶段就崩在 TreelandPrivate::init。所以本地没能执行任何协议测试。

■ 【CI(本轮补正上一轮的错误结论)】

head b2917c7a5 的 9 项检查全绿。其中 Arch 容器作业以 cmake --preset ci -DBUILD_TREELAND_PROTOCOL_TESTS=ON 配置,跑完 94 项测试,包含 test_wayland_ext_toplevel_image_capture_v1,Passed 1.13s,另 test_drm 按惯例 SKIP,100% tests passed out of 94。

也就是说我上一轮写的「新增协议测试在 CI 里一次都没执行」是错的——我当时看的是 deepin 打包作业(treeland-deepin-build.yml 里 BUILD_TREELAND_PROTOCOL_TESTS: "OFF"),Arch 作业是开着的。撤回该结论,B2 的闭环强度不足这一条也随之关闭。

■ 【仍然要提一句(不阻塞)】

  • CI 里的协议测试只跑 pixman 软件渲染;TREELAND_ENABLE_GPU_PROTOCOL_TESTS 的 GPU 变体没有作业覆盖,GLES2 下的捕获行为仍只有作者本地记录。这是仓库既有的 CI 覆盖面问题,不必在本 PR 解决,但值得单开一条。

  • PR 描述仍未回应三点:不创建窗口阴影、背景透明、光标捕获未实现(get_pointer_cursor() 恒返回 nullptr,base 版本同样如此)。协议客户端很难区分「合成器不支持」和「自己请求写错」,建议描述里各补一句。

■ 【lint】

  • 本轮增量未见新的 lint 报点;qt_review_lint.py 对 wextimagecapturesourcev1impl.cpp 全文的 4 条 LCY-4 已在前几轮撤回(不变量成立)。

■ 【跳过文件统计】

无。本轮增量 12 个文件全部为 C++/C 测试/CMake/文档,无二进制、生成物或锁文件。

@deepin-wm

Copy link
Copy Markdown
Contributor

复审(第 4 轮)的逐条结论已发在各自 thread 里,汇总见上面的 review。

我的审查账号在这个仓库没有写权限,resolveReviewThread 返回 FORBIDDEN,所以下面 4 条需要作者点一下 Resolve:

线程 本轮结论
src/session/toplevelcaptureviewport.cpp:33 getContentGeometry() 判空 撤回(我的误报:同类重写与基类都不判空)
src/session/toplevelcaptureviewport.cpp(outdated)组件每会话重新编译 已修复(QmlEngine 缓存 + 测试断言)
src/session/toplevelcapturesource.cpp:22 window() 守卫 撤回(接受你的说明)
waylib/src/server/qtquick/woutputrenderwindow.cpp:1691 暂停时既不成功也不失败 已修复(renderEnabledChanged 重排 + 4 个 DDM 用例)

另外更正我上一轮的一个错误结论:新增的协议测试确实在 CI 里跑。Arch 作业以 BUILD_TREELAND_PROTOCOL_TESTS=ON 配置,b2917c7a5 上 test_wayland_ext_toplevel_image_capture_v1 Passed(1.13s),94 项全过;我上一轮看的是 deepin 打包作业(那里是 OFF)。

Render foreign toplevels from a read-only surface-tree copy with recursive
subsurfaces and server-side decorations. Use local buffer bounds and an
independent swapchain without reparenting or hiding live windows. Fix
software-renderer clearing to prevent translucent SSD pixel accumulation.

Create a shared viewport on the first session start and release it on the
last stop. Recycle unused sources asynchronously and stop sessions when
their window or output is invalidated.

Queue non-committing capture renders when the borrowed output is disabled,
resume pending requests after rendering or output changes, and cancel
queued work when the pipeline is released. End offscreen buffer lifetimes
and report viewport failures after render cleanup. Fail pending frames
with UNKNOWN without stopping sessions or sending duplicate failures.

Keep a pending request instead of failing it while global rendering is
paused, and resume it from the render-window state change. Share the
CaptureSurfaceContent and Border component definitions through QmlEngine
while every capture viewport still owns its own item instances.

通过独立只读的 surface tree 捕获窗口、递归子面和服务端装饰,使用
窗口局部边界及独立 swapchain,不重父项或隐藏真实窗口。修正软件
渲染的清屏覆盖,避免半透明服务端边框像素跨帧累积。

首个 session 启动时创建共享视口,最后一个 session 停止时释放。
未使用的 source 延迟回收,避免重入会话销毁;窗口或输出失效时
停止相关捕获会话。

借用输出关闭时排队执行不提交真实输出的离屏渲染,渲染结束或输出
状态变化后重新安排挂起请求,释放管线时取消排队任务。结束离屏
buffer 生命周期,清理渲染状态后报告视口失败;挂起帧返回 UNKNOWN,
保留会话供重试,避免重复通知已被复制函数销毁的帧。

全局暂停渲染时保留挂起请求,由渲染窗口状态变化恢复,不轮询重试。
CaptureSurfaceContent 与 Border 的组件定义由 QmlEngine 缓存复用,
每个捕获视口仍创建自己的内容、标题栏和边框实例。

Log: 完善独立窗口捕获、管线回收及失败处理
PMS: BUG-374941
Influence: 支持独立窗口捕获,减少空闲管线残留并明确失败帧结果。
Use real C Wayland clients to verify capture pixels for the main surface,
recursive subsurfaces, stacking, SSD, transparent gaps, occlusion
isolation, moves, resize and maximized drag-to-restore. Check live window
geometry, QSG state and committed screen pixels for capture side effects.

Cover shared sessions, source/session ownership, pipeline recycling,
source-resource destruction and window teardown. Test pending requests
across output power changes, disabled-output rendering, re-enabling,
queued-work cancellation and output selection after session recreation.

Pause rendering through the real DDM global and assert that one pending
request survives pause and resume on both enabled and disabled outputs,
that a cancelled session is not drawn after resume, and that a destroyed
window ends with a stopped frame. Verify capture inputs share the cached
CaptureSurfaceContent component.

Exhaust real swapchain buffers and assert one UNKNOWN failure per pending
frame after cleanup, no success metadata, preserved sessions/viewports
and successful retry after buffer release. Run the same scenarios with
pixman and GLES2 and update the test specification, index and skill.

使用真实 C Wayland 客户端验证主面、递归子面、堆叠、服务端装饰、
透明间隙、遮挡隔离、移动、尺寸变化及最大化拖动还原的捕获像素。
检查真实窗口几何、QSG 状态和已提交屏幕像素,确认捕获无副作用。

覆盖多会话共享、source/session 归属、管线回收、source 资源提前
销毁和窗口失效。验证关屏期间的挂起请求、新内容、复电、排队取消,
以及重建会话时重新选择窗口当前输出。

通过真实 DDM 全局暂停渲染,断言启用和关闭输出时单次挂起请求都能
在恢复后完成;暂停期间取消会话或销毁窗口后不再绘制旧视口。另检查
捕获 input 复用引擎缓存的 CaptureSurfaceContent 组件定义。

耗尽真实 swapchain 缓冲区,断言清理后每个挂起帧仅收到一次 UNKNOWN,
不发送成功元数据,会话和视口仍有效,释放缓冲区后能重试成功。
pixman 与 GLES2 共用场景,并更新测试规范、覆盖索引和 skill 指引。

Log: 完善窗口捕获的协议及像素回归测试
PMS: BUG-374941
Influence: 为窗口捕获的隔离、生命周期和异常恢复提供回归保护。
@glyvut
glyvut marked this pull request as ready for review November 24, 2026 09:32
@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Sorry @glyvut, your pull request is larger than the review limit of 150,000 diff characters

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.

3 participants