Skip to content

Conversation

jason-simmons
Copy link
Member

MAX_IMAGES was set to 5 by flutter/engine@7a58dac in order to fix "client tried to acquire more than maxImages buffers" warnings from ImageReader_JNI.

696251d then converted lastDequeuedImage into a queue that retains up to MAX_DEQUEUED_IMAGES in-flight images plus the latest dequeued image. MAX_DEQUEUED_IMAGES was set to 2, but MAX_IMAGES was only incremented by 1. So the ImageReader_JNI warning may reappear in some cases.

This PR ensures that MAX_IMAGES provides enough capacity in the ImageReader for the total number of images that may be in use.

…umber of retained dequeued images

MAX_IMAGES was set to 5 by flutter/engine@7a58dac in order to fix "client tried to acquire more than maxImages buffers" warnings from ImageReader_JNI.

flutter@696251d then converted lastDequeuedImage into a queue that retains up to MAX_DEQUEUED_IMAGES in-flight images plus the latest dequeued image.  MAX_DEQUEUED_IMAGES was set to 2, but MAX_IMAGES was only incremented by 1.  So the ImageReader_JNI warning may reappear in some cases.

This PR ensures that MAX_IMAGES provides enough capacity in the ImageReader for the total number of images that may be in use.
@jason-simmons jason-simmons requested a review from a team as a code owner September 5, 2025 01:07
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@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 Sep 5, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 MAX_IMAGES constant in ImageReaderSurfaceProducer to correctly account for the maximum number of retained dequeued images. This change improves the correctness of the buffer allocation and prevents potential warnings. My feedback focuses on enhancing the readability of the new calculation by addressing a magic number.

@@ -422,6 +421,7 @@ final class ImageReaderSurfaceProducer
// the frame that references them has finished rendering can result in
// tearing or other incorrect rendering.
private static final int MAX_DEQUEUED_IMAGES = 2;
private static final int MAX_IMAGES = 5 + MAX_DEQUEUED_IMAGES;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This calculation is much clearer than the previous hardcoded value. To further improve readability and avoid the magic number 5, consider adding an inline comment explaining what 5 represents.1 An even better approach would be to extract it into a named constant like BASE_MAX_IMAGES.

Suggested change
private static final int MAX_IMAGES = 5 + MAX_DEQUEUED_IMAGES;
private static final int MAX_IMAGES = 5 /* base images */ + MAX_DEQUEUED_IMAGES;

Style Guide References

Footnotes

  1. The style guide recommends optimizing for readability. Using named constants or comments instead of magic numbers improves code readability and maintainability. (link)

@jason-simmons jason-simmons added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 8, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Sep 8, 2025
Merged via the queue into flutter:master with commit d221519 Sep 8, 2025
180 of 181 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 9, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Sep 10, 2025
flutter/flutter@973320c...a082096

2025-09-09 engine-flutter-autoroll@skia.org Roll Packages from 24588c6 to 2d651b2 (2 revisions) (flutter/flutter#175130)
2025-09-09 engine-flutter-autoroll@skia.org Roll Skia from ab13fd19dd32 to 19ba56dde579 (2 revisions) (flutter/flutter#175127)
2025-09-09 engine-flutter-autoroll@skia.org Roll Skia from 29a015f8712b to ab13fd19dd32 (2 revisions) (flutter/flutter#175108)
2025-09-09 engine-flutter-autoroll@skia.org Roll Skia from 6a4613b83365 to 29a015f8712b (5 revisions) (flutter/flutter#175106)
2025-09-09 engine-flutter-autoroll@skia.org Roll Dart SDK from 7b645442db0f to f446144fb7c9 (2 revisions) (flutter/flutter#175104)
2025-09-08 victorsanniay@gmail.com Nav bar static components respect ambient MediaQueryData (flutter/flutter#174673)
2025-09-08 mohellebiabdessalem@gmail.com fix typo in test documentation #2 (flutter/flutter#174707)
2025-09-08 jason-simmons@users.noreply.github.com Update ImageReaderSurfaceProducer.MAX_IMAGES to include the maximum number of retained dequeued images (flutter/flutter#174971)
2025-09-08 49699333+dependabot[bot]@users.noreply.github.com Bump actions/labeler from 5.0.0 to 6.0.1 in the all-github-actions group (flutter/flutter#175093)
2025-09-08 engine-flutter-autoroll@skia.org Roll Skia from 25f00cb247f2 to 6a4613b83365 (3 revisions) (flutter/flutter#175087)
2025-09-08 engine-flutter-autoroll@skia.org Roll Dart SDK from 83c6b6124380 to 7b645442db0f (1 revision) (flutter/flutter#175086)
2025-09-08 oreofesolarin@gmail.com Impeller: Convert GLProc name field and GLErrorToString to std::string_view (flutter/flutter#173771)
2025-09-08 chinmaygarde@google.com Depend on operator overload synthesis for three-way and equality comparisons. (flutter/flutter#174892)
2025-09-08 chinmaygarde@google.com Define a concept for UniqueObjectTraits. (flutter/flutter#174905)
2025-09-08 engine-flutter-autoroll@skia.org Roll Skia from 0c2b0a00b7b5 to 25f00cb247f2 (1 revision) (flutter/flutter#175077)
2025-09-08 magder@google.com Fix GitHub labeler platform-android typo (flutter/flutter#175076)
2025-09-08 jessiewong401@gmail.com [Gradle 9] Removed `minSdkVersion` and only use `minSdk` (flutter/flutter#173892)

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 stuartmorgan@google.com,tarrinneal@google.com 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
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.

2 participants