Skip to content

fix: prevent cursor flicker during screen recording#509

Merged
zccrs merged 2 commits intolinuxdeepin:masterfrom
zccrs:master
Aug 12, 2025
Merged

fix: prevent cursor flicker during screen recording#509
zccrs merged 2 commits intolinuxdeepin:masterfrom
zccrs:master

Conversation

@zccrs
Copy link
Member

@zccrs zccrs commented Aug 12, 2025

  1. Removed the WBufferRenderer::resetTextureProvider function, which was inadvertently clearing the cached buffer in WBufferRenderer when switching from a software cursor to a hardware cursor during screen recording.
  2. The root cause was identified as the BufferRendererProxy referencing a null buffer after the cache was cleared. This happened because resetTextureProvider was called even though lockCacheBuffer had been invoked without a corresponding unlockCacheBuffer. The lock/ unlock mechanism should have ensured the buffer's persistence.
  3. Updated WBufferRenderer::updateTextureProvider to ensure buffer is only updated when shouldCacheBuffer state is changed. If not, the buffer should be updated in WBufferRenderer::render.
  4. Updated WSGTextureProvider::setBuffer to emit the textureChanged() signal when buffer content changed.

Influence:

  1. Test screen recording functionality to ensure the cursor no longer flickers.
  2. Verify the correct buffer is displayed during screen recording sessions.
  3. Ensure that other parts of the system are unaffected by the removal of resetTextureProvider.
  4. Test different cursor types (software and hardware) during screen recording to ensure smooth transitions.
  5. Test different resolutions and scaling factors during screen recording.

fix: 修复录屏时光标闪烁问题

  1. 删除了 WBufferRenderer::resetTextureProvider 函数,该函数会在录屏 期间从软件光标切换到硬件光标时,意外地清除 WBufferRenderer 中的缓存
    buffer,导致光标闪烁。
  2. 根本原因是,在缓存被清除后,BufferRendererProxy 引用了一个空 buffer。发生这种情况的原因是,即使调用了 lockCacheBuffer 但没有相应的
    unlockCacheBuffer,也会调用 resetTextureProvider。lock/unlock 机制应 该确保 buffer 的持久性。
  3. 更新了 WBufferRenderer::updateTextureProvider 以确保仅 在 shouldCacheBuffer 状态更改时才更新buffer。 否则,应在
    WBufferRenderer::render 中更新buffer。
  4. 更新 WSGTextureProvider::setBuffer 在buffer 内容更改时,触发 textureChanged() 信号。

Influence:

  1. 测试屏幕录制功能,确保光标不再闪烁。
  2. 验证在屏幕录制会话期间是否显示正确的 buffer。
  3. 确保系统的其他部分不受删除 resetTextureProvider 的影响。
  4. 在屏幕录制期间测试不同的光标类型(软件和硬件),以确保平滑过渡。
  5. 在屏幕录制期间测试不同的分辨率和缩放因子。

Summary by Sourcery

Prevent cursor flicker during screen recording by retaining the cached buffer and refining buffer update logic.

Bug Fixes:

  • Preserve the cached buffer when switching between software and hardware cursors to stop flickering.
  • Emit textureChanged signal when buffer content changes even if the buffer object remains the same.

Enhancements:

  • Only update the texture provider buffer when the caching state actually changes to avoid unnecessary resets.
  • Remove the obsolete resetTextureProvider function and its invocations to prevent unintended cache clears.

@zccrs zccrs requested review from Copilot and zzxyb August 12, 2025 10:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes cursor flickering during screen recording by addressing buffer caching issues in the WBufferRenderer system. The fix removes the problematic resetTextureProvider function and improves buffer management to prevent the cursor from disappearing when switching between software and hardware cursors.

Key changes:

  • Removed WBufferRenderer::resetTextureProvider function that was causing buffer cache clearing
  • Updated buffer update logic to only modify cache when shouldCacheBuffer state changes
  • Enhanced texture change signaling to handle content updates even when buffer object remains the same

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
wsgtextureprovider.cpp Enhanced texture change signaling for buffer content updates
woutputrenderwindow.cpp Removed call to resetTextureProvider during layer compositor cleanup
wbufferrenderer_p.h Removed resetTextureProvider function declaration
wbufferrenderer.cpp Removed resetTextureProvider implementation and improved updateTextureProvider logic

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @zccrs - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 12, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refactors the buffer provider logic to stop clearing the cached buffer during cursor transitions, restricts texture provider updates to when caching state changes, and ensures texture change signals fire on content updates—eliminating cursor flicker during screen recording.

File-Level Changes

Change Details Files
Removed resetTextureProvider and its invocations to avoid unintended buffer clears
  • Deleted resetTextureProvider definition in WBufferRenderer
  • Removed declaration from WBufferRenderer private header
  • Pruned calls in cleanLayerCompositor within WOutputRenderWindow
waylib/src/server/qtquick/private/wbufferrenderer.cpp
waylib/src/server/qtquick/private/wbufferrenderer_p.h
waylib/src/server/qtquick/woutputrenderwindow.cpp
Refined updateTextureProvider to update buffer only on cache-state changes
  • Added hasCachedBuffer check before setting new buffer
  • Moved buffer update responsibility to render when state unchanged
  • Inlined explanatory comments about deferred updates
waylib/src/server/qtquick/private/wbufferrenderer.cpp
Enhanced WSGTextureProvider::setBuffer to emit textureChanged on content updates
  • Adjusted early-return logic to still emit textureChanged when buffer matches but content may differ
  • Added null check before emitting the signal
waylib/src/server/qtquick/wsgtextureprovider.cpp

Possibly linked issues


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

1.  Remove `WBufferRenderer::resetTextureProvider` to avoid accidentally
cleaning the cached buffer in `WBufferRenderer` when switching from a
software cursor to a hardware cursor.
2.  The root cause was that switching from a software cursor
to a hardware cursor inadvertently cleared the cached buffer
in `WBufferRenderer`, causing the buffer referenced by
`BufferRendererProxy` to become null.
3.  The `resetTextureProvider` function was originally introduced in
the `WOutputLayer` implementation (https://github.com/vioken/waylib/
commit/ea814c44), and the buffer lock/unlock mechanism was introduced
in vioken/waylib@35fdcb72. The lock/unlock
mechanism is a new design, so manually resetting the buffer is no longer
necessary.
4.  Update `WSGTextureProvider::setBuffer` to emit `textureChanged()`
signal when `buffer` is not null and the buffer object is not changed,
but maybe the buffer's content is changed.

Influence:
1.  Verify that the cursor no longer flickers during screen recording,
especially when switching between software and hardware cursors.
2.  Test screen sharing and ensure that the shared content is displayed
correctly without any visual artifacts.
3.  Check the buffer management to ensure that buffers are properly
locked and unlocked, and that no memory leaks occur.

fix: 修复录屏时光标闪烁问题

1.  移除 `WBufferRenderer::resetTextureProvider` 以避免在从软光标切换到
硬光标时意外清理 `WBufferRenderer` 中的缓存 buffer。
2.  根本原因是,从软光标切换到硬光标时,无意中清除了 `WBufferRenderer`
中的缓存 buffer,导致 `BufferRendererProxy` 引用的 buffer 变为 null。
3.  `resetTextureProvider` 函数最初是在 `WOutputLayer` 实现中引入的
(https://github.com/vioken/waylib/commit/ea814c44),buffer 锁/解锁机制是
在 vioken/waylib@35fdcb72 中引入的。 锁/解锁机
制是一种新的设计,因此不再需要手动重置 buffer。
4.  更新 `WSGTextureProvider::setBuffer`,当 `buffer` 不为 null 且
buffer 对象没有更改时,发出 `textureChanged()` 信号,但 buffer 的内容可
能会更改。

Influence:
1.  验证在屏幕录制过程中,尤其是在软件和硬件光标之间切换时,光标不再
闪烁。
2.  测试屏幕共享,确保共享内容显示正确,没有任何视觉伪影。
3.  检查 buffer 管理,确保 buffer 被正确锁定和解锁,并且没有发生内存
泄漏。
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zccrs, zzxyb

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

@zccrs zccrs merged commit 10652f2 into linuxdeepin:master Aug 12, 2025
14 of 18 checks passed
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.

4 participants