Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook ImageReaderSurfaceProducer to the onTrimMemory listener interface #50792

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

johnmccutchan
Copy link
Contributor

@johnmccutchan johnmccutchan commented Feb 20, 2024

  • Close all ImageReaders and Images when we get an onTrimMemory callback.
  • Remove the first frame fix based around caching the last image displayed because it isn't safe to do on some platforms. Leave a TODO to revisit this.

We have seen some reports of platform views not working after an application is backgrounded and then resumed. According to Android GPU folks ImageReader/Image/HardwareBuffers should be valid after an application has been resumed. However on Samsung we know that isn't the case and there are (unconfirmed) reports of it also impacting Pixel devices.

Should fix flutter/flutter#142978 and flutter/flutter#139039

Also fixes flutter/flutter#143720

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

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.

@johnmccutchan johnmccutchan force-pushed the image_reader_trim_memory branch 2 times, most recently from 99feb46 to 35556a1 Compare February 20, 2024 20:25
imageReaderQueue.clear();
}
createNewReader = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This code looks similar to the code below in releaseInternal, but maybe more complete. Can/should we combine these?

Is this something we want to do on all trim levels, or only critical/UI hidden?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've factored the common code out. As a separate change we might want to relax this and only purge this on specific trim levels- I can't reproduce the issue though. Maybe you could grab a dump of the sequence of trim levels on the Samsung phone?

Copy link
Contributor

Choose a reason for hiding this comment

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

Going to the background will always give the https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_UI_HIDDEN

We could do it for the RUNNING_CRITICAL level out of politeness :). The other ones are probably fine to leave, but we can do this as a follow up.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

This should have a test, at least on the java side should be pretty testable?

@johnmccutchan
Copy link
Contributor Author

This should have a test, at least on the java side should be pretty testable?

Added test.

@johnmccutchan johnmccutchan force-pushed the image_reader_trim_memory branch 2 times, most recently from 3095383 to b25d118 Compare February 20, 2024 21:33
Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

We still may want to relax this slightly so that we only do the cleanup on RUNNING_CRITICAL or UI_HIDDEN, but LGTM

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -607,7 +611,15 @@ PerImage dequeueImage() {
lastDequeueTime = System.nanoTime();
}
}
// We have dequeued the first image from reader.
if (lastDequeuedImage != null) {
Copy link
Member

Choose a reason for hiding this comment

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

How do we know that we're done presenting the image when we dequeueImage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the contract between image_external_texture* and this class. Making this more explicit is probably a good cleanup to do.

- Close all ImageReaders and Images when we get an onTrimMemory callback.
- Remove the first frame fix based around caching the last image displayed
  because it isn't safe to do on some platforms. Leave a TODO to revisit
  this.
@johnmccutchan johnmccutchan merged commit 9fd72bd into flutter:main Feb 21, 2024
23 of 24 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 21, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 21, 2024
…143875)

flutter/engine@52ffcaa...bf5c003

2024-02-21 skia-flutter-autoroll@skia.org Roll Skia from 9d86359b5fe8 to 8fa858855820 (15 revisions) (flutter/engine#50827)
2024-02-21 matanlurey@users.noreply.github.com Add the `scenario_app` `'solid_blue'` golden to the Android test suite (flutter/engine#50801)
2024-02-21 matanlurey@users.noreply.github.com Ignore EOF newline characters and added tests to `dir_contents_diff` tool (flutter/engine#50805)
2024-02-21 jason-simmons@users.noreply.github.com Make the GL context current in EmbedderSurfaceGLImpeller before creating the GPU surface (flutter/engine#50807)
2024-02-21 matanlurey@users.noreply.github.com Fail engine post-submit on skia-gold comparions. (flutter/engine#50826)
2024-02-21 34871572+gmackall@users.noreply.github.com Remove WindowManager reflection in SingleViewPresentation.java (flutter/engine#49996)
2024-02-21 30870216+gaaclarke@users.noreply.github.com [Impeller] applied the lerp hack to blur (roughly 2x speedup?) (flutter/engine#50790)
2024-02-21 jason-simmons@users.noreply.github.com Migrate the Fuchsia embedder to the Dart_RecordTimelineEvent API (flutter/engine#50823)
2024-02-21 john@johnmccutchan.com Hook ImageReaderSurfaceProducer to the onTrimMemory listener interface (flutter/engine#50792)
2024-02-21 matanlurey@users.noreply.github.com Fix the local-only lint errors due to an unexpected `GeneratedPluginRegistrant.java` (flutter/engine#50795)
2024-02-21 jonahwilliams@google.com [Impeller] cache onscreen render targets. (flutter/engine#50751)
2024-02-21 zanderso@users.noreply.github.com Use 'et format' in CI. Check formatting of all files in CI (flutter/engine#50810)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jimgraham@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: 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
Projects
None yet
3 participants