Skip to content

fix(whiteboard): defer invalidate to vsync to avoid flicker#21043

Open
hdream0322 wants to merge 1 commit into
ankidroid:mainfrom
hdream0322:fix/whiteboard-flicker-19364
Open

fix(whiteboard): defer invalidate to vsync to avoid flicker#21043
hdream0322 wants to merge 1 commit into
ankidroid:mainfrom
hdream0322:fix/whiteboard-flicker-19364

Conversation

@hdream0322
Copy link
Copy Markdown

@hdream0322 hdream0322 commented May 14, 2026

Purpose / Description

fix card flikering issue while using whiteboard (legacy study screen)

Fixes

Approach

Force the Whiteboard view to a software layer so its invalidate calls don't disrupt the Webview's GPU.
Webview still on hardware.

How Has This Been Tested?

Tested on Samsung Galaxy TabS9+, Android 13 (SDK 33), WebView 148.0.7778.120.

Steps to reproduce:

  1. Use the legacy review screen
  2. "Disable card hardware render" off
  3. Open a Basic-template card and enable the Whiteboard.
  4. Draw short strokes on the card.

Before: card content flashes white during short strokes.
After: no flicker. (Long strokes, single dots, eraser....)

Screen_Recording_20260514_144014_AnkiDroid.mp4

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@welcome
Copy link
Copy Markdown

welcome Bot commented May 14, 2026

First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible.

@hdream0322 hdream0322 closed this May 14, 2026
@hdream0322 hdream0322 deleted the fix/whiteboard-flicker-19364 branch May 14, 2026 06:48
@hdream0322 hdream0322 restored the fix/whiteboard-flicker-19364 branch May 14, 2026 07:37
@hdream0322
Copy link
Copy Markdown
Author

sorry, my mistake

@hdream0322 hdream0322 reopened this May 14, 2026
Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

TL;DR: Let's use git bisectfirst

Thanks for the PR!

This implementation causes a performance regression. Given we know this was introduced between 2.23 and 2.24, we should understand the bug before fixing it, so we can fix it in an effective manner

Given you can reproduce this on your phone, and I can't, please perform git bisect to find the commit which introduced this issue. From there, we can put in a targeted fix.

If you need anything, please let me know

@hdream0322 hdream0322 force-pushed the fix/whiteboard-flicker-19364 branch from d7b2dab to edf1dbb Compare May 14, 2026 16:27
@hdream0322
Copy link
Copy Markdown
Author

Dug into this some more. The invalidate() calls in handleDrawEvent have been there since 2021, so it's not really a regression — and on my phone every older release flickers too, so I couldn't bisect locally.

But @ZornHadNoChoice confirmed 2.23.3 OK / 2.24.0 NG on Xiaomi, so there's clearly some environment trigger I just can't repro here.

Ran a bunch of layer-type combos on upstream/main to pin down the mechanism:

  • WebView with SW layer → no flicker
  • Whiteboard with SW layer (the old fix) → also no flicker
  • Whiteboard with HW layer set explicitly → flicker, AND in that case the color-picker / split-screen workarounds stop helping too

That last one pretty much confirmed it for me — the trigger is the synchronous invalidate() on the touch path racing with WebView surface composition.

So instead of going back to the SW-layer workaround I switched the stroke hot path to postInvalidateOnAnimation() — same effect, vsync-coalesced, no layer type changes, no perf hit.

Would really appreciate it if someone on the affected side (Xiaomi folks especially) could confirm this fixes it for them too.


Since this is my first PR, there may be some rough edges or things I've missed. I'd really appreciate it if you could point them out — any feedback would be very helpful. Thank you so much for taking the time to review.

@hdream0322 hdream0322 requested a review from david-allison May 14, 2026 16:39
@hdream0322 hdream0322 changed the title fix(whiteboard): prevent flicker with SW layer fix(whiteboard): defer invalidate to vsync to avoid flicker May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Card flickers when drawing on whiteboard

2 participants