Skip to content

Fix hcpp cliprect being behind by 1 frame when scrolling - #189946

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
gmackall:fix_hcpp_scroll_cliprect_behindby1frame
Jul 28, 2026
Merged

Fix hcpp cliprect being behind by 1 frame when scrolling#189946
auto-submit[bot] merged 7 commits into
flutter:masterfrom
gmackall:fix_hcpp_scroll_cliprect_behindby1frame

Conversation

@gmackall

@gmackall gmackall commented Jul 23, 2026

Copy link
Copy Markdown
Member

Previously, the clipping was behind by 1 frame.

This is because onDisplayPlatformView2() was getting called after jni_facade->swapTransaction(), and so was adding new pending transactions after the swap from pending to active (and so the clips were lagging for a frame, waiting till next frame to be made active). We need to call jni_facade->swapTransaction() last.

The ordering (c++ bug) was introduced in #181009 in combination with #184732

See videos:

With Change (After) Without Change (Before)
Screen_recording_20260723_130531.mp4
Screen_recording_20260723_130847.mp4

@gmackall gmackall added the CICD Run CI/CD label Jul 23, 2026
@gmackall
gmackall marked this pull request as ready for review July 23, 2026 20:29
@gmackall
gmackall requested a review from a team as a code owner July 23, 2026 20:29
@gmackall
gmackall requested review from reidbaker and removed request for a team July 23, 2026 20:30
@github-actions github-actions Bot added platform-android Android applications specifically engine flutter/engine related. See also e: labels. team-android Owned by Android platform team labels Jul 23, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the Android external view embedder to swap transactions before ending a frame, adds a corresponding unit test, and introduces a mechanism in PlatformViewsController2 to track and apply pending surface clips using a new PendingSurfaceClip class. The review feedback highlights a critical issue where the created SurfaceControl.Transaction is never applied, and suggests refactoring the lambda in external_view_embedder_2.cc to use the captured jni_facade for safety, as well as simplifying the logic for updating pendingSurfaceClips to avoid redundant operations.

Comment on lines 603 to 617
float opacity = mutatorsStack.getFinalOpacity();
if (viewsWithPendingSurfaceCallback.contains(viewId)) {
pendingSurfaceClips.put(viewId, new PendingSurfaceClip(opacity, screenRect));
}
SurfaceControl sc = surfaceView.getSurfaceControl();
if (sc == null) {
pendingSurfaceClips.put(viewId, new PendingSurfaceClip(opacity, screenRect));
if (viewsWithPendingSurfaceCallback.contains(viewId)) {
return;
}
viewsWithPendingSurfaceCallback.add(viewId);
SurfaceHolder.Callback cb =
createSurfaceClipCallback(surfaceView, opacity, screenRect, viewId);
SurfaceHolder.Callback cb = createSurfaceClipCallback(surfaceView, viewId);
surfaceView.getHolder().addCallback(cb);
return;
}

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.

medium

The logic for updating pendingSurfaceClips can be simplified to avoid redundant put operations when sc == null and viewsWithPendingSurfaceCallback already contains the viewId.

    float opacity = mutatorsStack.getFinalOpacity();
    SurfaceControl sc = surfaceView.getSurfaceControl();
    if (sc == null || viewsWithPendingSurfaceCallback.contains(viewId)) {
      pendingSurfaceClips.put(viewId, new PendingSurfaceClip(opacity, screenRect));
    }
    if (sc == null) {
      if (viewsWithPendingSurfaceCallback.contains(viewId)) {
        return;
      }
      viewsWithPendingSurfaceCallback.add(viewId);
      SurfaceHolder.Callback cb = createSurfaceClipCallback(surfaceView, viewId);
      surfaceView.getHolder().addCallback(cb);
      return;
    }

gmackall added 2 commits July 23, 2026 13:32
…prect_behindby1frame' into fix_hcpp_scroll_cliprect_behindby1frame
reidbaker
reidbaker previously approved these changes Jul 24, 2026

@reidbaker reidbaker 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.

LGTM but I feel far from qualified to critique your .cc code. I would encourage you to get a readability review.

@gmackall
gmackall requested a review from reidbaker July 27, 2026 23:24
@gmackall gmackall added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 27, 2026
@gmackall

Copy link
Copy Markdown
Member Author

LGTM but I feel far from qualified to critique your .cc code. I would encourage you to get a readability review.

I am going to merge this one because it's a one liner outside of the test (hopefully that's fine), but will do for any more involved prs

@auto-submit
auto-submit Bot added this pull request to the merge queue Jul 28, 2026
Merged via the queue into flutter:master with commit 1efa3bc Jul 28, 2026
22 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 28, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jul 28, 2026
flutter/flutter@9988960...0f02463

2026-07-28 [email protected] Roll Fuchsia Test Scripts from E8hJ1AfK8CtGtaES0... to 1frGe_KltAJKkeyPg... (flutter/flutter#190134)
2026-07-28 [email protected] iOS: Reject merged-platform-ui-thread=mergeAfterLaunch (flutter/flutter#190051)
2026-07-28 [email protected] iOS: Migrate TaskRunner tests to Swift Testing (flutter/flutter#190055)
2026-07-28 [email protected] Run Mac golden tests on ARM bots (flutter/flutter#189465)
2026-07-28 [email protected] iOS,macOS: Rename Swift test files to end in Tests.swift (flutter/flutter#190063)
2026-07-28 [email protected] Fix hcpp cliprect being behind by 1 frame when scrolling (flutter/flutter#189946)
2026-07-28 [email protected] Roll Fuchsia Linux SDK from vpboK5fPPIoFteqRq... to OZkZC_2CZ_G5rbMIS... (flutter/flutter#190115)
2026-07-27 [email protected] Add Ishaq Hassan to AUTHORS (flutter/flutter#190064)
2026-07-27 [email protected] [wimp] fixes ubo padding size issue (flutter/flutter#189958)
2026-07-27 [email protected] Roll pub packages (flutter/flutter#189872)
2026-07-27 [email protected] Move tool host_cross_arch tests into different shards (flutter/flutter#189470)
2026-07-27 49699333+dependabot[bot]@users.noreply.github.com Bump actions/labeler from 6.2.0 to 7.0.0 in the all-github-actions group (flutter/flutter#190099)
2026-07-27 [email protected] [ios]do not nuke user input path when running uiscene integration test (flutter/flutter#186436)
2026-07-27 [email protected] ci: verify_binaries_pre_codesigned part 2 (flutter/flutter#190078)
2026-07-27 [email protected] Roll Abseil to ff6e8ce3e932 (flutter/flutter#189998)
2026-07-27 [email protected] Android_hardware_smoke_test: clean up golden copy in CI (flutter/flutter#189948)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants