Skip to content

Apply rect clipping to surface views#184471

Merged
auto-submit[bot] merged 21 commits into
flutter:masterfrom
gmackall:again_we_try_to_fix_surfaceviews
Apr 6, 2026
Merged

Apply rect clipping to surface views#184471
auto-submit[bot] merged 21 commits into
flutter:masterfrom
gmackall:again_we_try_to_fix_surfaceviews

Conversation

@gmackall

@gmackall gmackall commented Apr 1, 2026

Copy link
Copy Markdown
Member

Fixes #175546

Upper image is unclipped, bottom is clipped:

With Change Without Change

@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 Apr 1, 2026
@gmackall gmackall added the CICD Run CI/CD label Apr 1, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@gmackall gmackall marked this pull request as ready for review April 1, 2026 18:34
@gmackall gmackall requested a review from a team as a code owner April 1, 2026 18:34
@gmackall gmackall added the CICD Run CI/CD label Apr 1, 2026
@gmackall

gmackall commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

Note in the image that there is a small green bar on the right in the clipped image.

Some thoughts on the source: onDisplayPlatformView uses an int, when the actual position has sub-pixel values. Perhaps there is a rounding error there.
Could also be coming from an off by one error in the calculation of the offset, or perhaps we are rounding down the paths we calculate somehow?

I'm of the opinion we can fix this in a follow up issue, as it is pretty minor and this is a strict improvement to the clipping for surfaceviews, but let me know if you feel otherwise.

@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 introduces clipping support for SurfaceView platform views on Android API 34 and above by applying crops to the SurfaceControl based on the mutator stack. It also adds a corresponding integration test with screenshot comparison. Review feedback highlights that SurfaceControl transactions are currently not being applied or closed, which is critical for functionality and resource management. Additionally, the implementation should be updated to prevent redundant SurfaceHolder callback registrations and to remove unnecessary coordinate validation logic.

Comment on lines +579 to +581
if (screenRect.width() < 0 || screenRect.height() < 0) {
screenRect.setEmpty();
}

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

This check is redundant. The screenRect is initialized from a RectF using roundOut, which ensures right >= left and bottom >= top. Subsequent intersect operations either maintain this property or result in an empty rect (where width and height are 0) via the setEmpty() call on line 570. The offset operation does not change the dimensions of the rectangle.

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@gmackall gmackall added the CICD Run CI/CD label Apr 1, 2026
@gmackall

gmackall commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 introduces clipping support for SurfaceView platform views on Android (API 34+) by applying crops via SurfaceControl transactions and adds a new integration test. Feedback identifies that the SurfaceControl transactions are missing the required apply() call and should be managed using try-with-resources for proper resource disposal. Additionally, it is recommended to use the Flutter-assigned viewId rather than the Android View ID to track pending surface callbacks reliably.

@github-actions github-actions Bot added d: docs/ flutter/flutter/docs, for contributors CICD Run CI/CD and removed CICD Run CI/CD labels Apr 1, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@gmackall

gmackall commented Apr 7, 2026

Copy link
Copy Markdown
Member Author

It looks like this is creating golden file image tests on all open PRs right now. They test is suppressed on the dashboard and failing since this landed.

I don't think surpressing is helpful here, and the test is only failing because the gold images weren't approved. I approved them when the pr was initially put up (when the bot made this comment) but for some reason this seems to have been undone after the pr landed

All that needs to be done is for the images to be approved, which looks like it has happened.

@gmackall

gmackall commented Apr 7, 2026

Copy link
Copy Markdown
Member Author

Reason for revert: Skia gold seems seriously confused about this PR (likely a bug). I think the only solution we can easily come up with is to just revert and re land

@gmackall gmackall added the revert Autorevert PR (with "Reason for revert:" comment) label Apr 7, 2026
auto-submit Bot pushed a commit that referenced this pull request Apr 7, 2026
@auto-submit auto-submit Bot removed the revert Autorevert PR (with "Reason for revert:" comment) label Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
@gmackall gmackall added the revert Autorevert PR (with "Reason for revert:" comment) label Apr 7, 2026
@auto-submit

auto-submit Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Unable to create the revert pull request due to ProcessException: Standard error
Pushing to https://github.com/flutter/flutter.git
To https://github.com/flutter/flutter.git
! [rejected] revert_a488da38c3d96e3c1331ba98c2de3a09e484886b -> revert_a488da38c3d96e3c1331ba98c2de3a09e484886b (non-fast-forward)
error: failed to push some refs to 'https://github.com/flutter/flutter.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Command: git push --verbose origin revert_a488da38c3d96e3c1331ba98c2de3a09e484886b

@auto-submit auto-submit Bot removed the revert Autorevert PR (with "Reason for revert:" comment) label Apr 7, 2026
gmackall added a commit to gmackall/flutter that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 7, 2026
github-merge-queue Bot pushed a commit that referenced this pull request Apr 7, 2026
This reverts commit a488da3 because the
bot is failing to do so in
#184724

Revert because skia gold seems bugged w.r.t. the original pr, so try
relanding it to reset skia gold state
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Apr 7, 2026
flutter/flutter@9cd60b5...a0924c7

2026-04-07 [email protected] Reland "[data_assets] Cleanup tests" (flutter/flutter#184714)
2026-04-07 [email protected] Use the WindowRegistry in the multiple_windows example app (flutter/flutter#184579)
2026-04-07 [email protected] Introduce command to build a swift package for SwiftPM add to app integration (flutter/flutter#184660)
2026-04-07 [email protected] Have `flutter create` create a pubspec.lock to ensure pinned versions are being used. (flutter/flutter#175352)
2026-04-07 [email protected] [widgets/raw_menu_anchor.dart] Always call onClose and onCloseRequested on descendants before parent. (flutter/flutter#182357)
2026-04-07 [email protected] `WindowsPlugin` should not crash when ffiPlugin enabled (flutter/flutter#184695)
2026-04-06 [email protected] Use full goto.google.com hostname for go/ links (flutter/flutter#184679)
2026-04-06 [email protected] Apply rect clipping to surface views (flutter/flutter#184471)
2026-04-06 [email protected] [A11y] Allow percentage strings like "50%" as `SemanticsValue` for `ProgressIndicator` (flutter/flutter#183670)
2026-04-06 [email protected] Fix invisible accessibility element before scroll view (flutter/flutter#184155)
2026-04-06 [email protected] Roll Skia from 163dfdf500c7 to e264d870a380 (2 revisions) (flutter/flutter#184674)
2026-04-06 [email protected] Keep last character obscured when toggling obscureText (flutter/flutter#183488)
2026-04-06 [email protected] Parse scheme file with XML parser for SwiftPM migrator (flutter/flutter#184525)

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],[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
gmackall added a commit to gmackall/flutter that referenced this pull request Apr 7, 2026
github-merge-queue Bot pushed a commit that referenced this pull request Apr 8, 2026
Relands #184471 which [was
reverted](#184728) because of
suspected skia gold bug where the triage button was not working for the
created digests.

I also changed the names of the output files just in case, to make sure
the state doesn't collide with old.
mbcorona pushed a commit to mbcorona/flutter that referenced this pull request Apr 15, 2026
Fixes flutter#175546 

Upper image is unclipped, bottom is clipped:

<table width="100%">
  <thead>
    <tr>
      <th align="center">With Change</th>
      <th align="center">Without Change</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td align="center" width="50%">
<img
src="https://github.com/user-attachments/assets/c713dd0f-8cfd-4e7d-9070-3bf51a89f50a"
style="max-width: 50%;"></img>
      </td>
      <td align="center" width="50%">
<img
src="https://github.com/user-attachments/assets/fc23ff88-bd64-44d0-a840-e7ba58638943"
style="max-width: 50%;"></img>
      </td>
    </tr>
    <tr>
      <td align="center">
<img
src="https://github.com/user-attachments/assets/fef237f1-9e4f-4376-a251-22335cf7a324"
style="max-width: 50%;"></img>
      </td>
      <td align="center">
<img
src="https://github.com/user-attachments/assets/db707bf1-2bd8-4c39-a510-ca45f7730a0a"
style="max-width: 50%;"></img>
      </td>
    </tr>
  </tbody>
</table>
mbcorona pushed a commit to mbcorona/flutter that referenced this pull request Apr 15, 2026
…er#184728)

This reverts commit a488da3 because the
bot is failing to do so in
flutter#184724

Revert because skia gold seems bugged w.r.t. the original pr, so try
relanding it to reset skia gold state
mbcorona pushed a commit to mbcorona/flutter that referenced this pull request Apr 15, 2026
Relands flutter#184471 which [was
reverted](flutter#184728) because of
suspected skia gold bug where the triage button was not working for the
created digests.

I also changed the names of the output files just in case, to make sure
the state doesn't collide with old.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD d: docs/ flutter/flutter/docs, for contributors engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HCPP platform view overlays elements it shouldn't when native view is a SurfaceView

4 participants