Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Nov 4, 2020

Description

External view embedders may be doing work on the GPU and they have to make sure they don't do so while the app is in the background.

I considered first making this a parameter to the ios_external_view_embedder but decided against it because:

  1. If this external embedder needs to consider the gpu switch than another implementation of the ExternalViewEmbedder would probably have to consider it.
  2. Creation of the iOS external view embedder happens before the shell is created so we'd have to use a setter instead of a constructor argument and there is the chance to introduce bugs.

Related Issues

fixes flutter/flutter#69642

Tests

I added the following tests:

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Reviewer Checklist

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

@google-cla google-cla bot added the cla: yes label Nov 4, 2020
@gaaclarke gaaclarke force-pushed the sync-switch-canvas-flush branch from a47b796 to d4cd120 Compare November 4, 2020 21:26
@gaaclarke gaaclarke marked this pull request as ready for review November 4, 2020 22:23
@gaaclarke gaaclarke requested a review from cyanglaz November 4, 2020 22:24
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

Code looks good. I have no clue what does gpu_disable_sync_switch do and how it works. Let's add another reviewer who knows this better?

@chinmaygarde chinmaygarde self-requested a review November 9, 2020 18:44
@chinmaygarde
Copy link
Member

cc @jason-simmons

const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) {
bool result = false;
gpu_disable_sync_switch->Execute(
fml::SyncSwitch::Handlers().SetIfTrue([&] { result = false; }).SetIfFalse([&] {
Copy link
Member

Choose a reason for hiding this comment

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

Is the SetIfTrue handler necessary? result is already set to false by default

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, it shouldn't be necessary. Once I get things sorted out I'll try removing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, shoot I forgot to do this before it landed. I was in a rush. It's probably not a big deal, if you want it gone I can do it in a separate PR. Sorry.

@gaaclarke gaaclarke force-pushed the sync-switch-canvas-flush branch from d1a355a to e272675 Compare November 18, 2020 00:11
@gaaclarke gaaclarke added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Nov 18, 2020
@fluttergithubbot fluttergithubbot merged commit 1c3bc02 into flutter:master Nov 18, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 18, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 18, 2020
@blasten
Copy link

blasten commented Nov 18, 2020

@gaaclarke , @cyanglaz - I came across this change. Do you know why not clearing the current pending raster tasks in Shell.OnPlatformViewDestroyed?

Shell.OnPlatformViewDestroyed is called from the same lifecycle event applicationWillResignActive

@gaaclarke
Copy link
Member Author

@blasten If we synchronously flushed all outstanding GPU tasks on the raster thread for the external view embedder when we got the ResignActive notification and guaranteed that it will never attempt another GPU tasks until the app has become active again that would be a valid way to solve this issue, too. Is that what you are asking?

@blasten
Copy link

blasten commented Nov 18, 2020

@gaaclarke yep. @cyanglaz mentioned that the crash would happen here https://github.com/flutter/engine/blob/master/shell/common/rasterizer.cc#L438 because we teared down the surface from the link I mentioned above.

It sounds like we need a primitive to ensure that all pending tasks are flushed and that the queue is disabled.

@gaaclarke
Copy link
Member Author

@blasten Check out the issue this PR addresses, the stacktrace of the crash is there. It's from the external view embedder executing GPU operations. This PR causes the platform thread to wait for GPU operations to execute before exiting, then turns them off atomically. Any other attempts at creating frames in the background will be dropped. It's the same mechanism we use elsewhere like the decoding of images on background threads.

@blasten
Copy link

blasten commented Nov 18, 2020

right. I guess my question is more about defining some primitives that work well across platforms. Do you know if we need to do this for Android too?

@gaaclarke
Copy link
Member Author

I believe iOS is the only platform we currently support that has the requirement that GPU access may be blocked. Android at least doesn't crash, for energy reason we might want to disable GPU operations in the background if the operating system isn't already handling that gracefully.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 19, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 19, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 19, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 19, 2020
mehmetf added a commit that referenced this pull request Nov 26, 2020
) (#22760)

Co-authored-by: gaaclarke <30870216+gaaclarke@users.noreply.github.com>
ColdPaleLight added a commit to ColdPaleLight/engine that referenced this pull request Sep 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-android platform-ios waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skia crash in customer:money

6 participants