Repository navigation
Started querying the app state for the gpu disabled sync switch - #171785
Conversation
…starting an engine without a view controller
|
This PR was tested manually with the following setup. The issue doesn't have reproduction code so I'm not sure this covers all cases: Steps:
I can't reproduce the original bug. I've tried variations where I lock the screen too as suggested in #166668 (comment) but I can't get it. According to #166668 (comment) the problem is non-deterministic though. import Flutter
import UIKit
import UserNotifications
import OSLog
@main
@objc class AppDelegate: FlutterAppDelegate, FlutterPluginRegistrant {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
pluginRegistrant = self
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if granted {
print("Notification permission granted.")
} else {
print("Notification permission denied.")
}
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func applicationDidEnterBackground(_ application: UIApplication) {
let content = UNMutableNotificationContent()
content.title = "Counter App"
content.body = "You have been away for 10 seconds."
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
let request = UNNotificationRequest(identifier: "backgroundNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { (error) in
if let error = error {
print("Error scheduling notification: \(error)")
}
}
}
override func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .badge, .sound])
}
func register(with registry: any FlutterPluginRegistry) {
GeneratedPluginRegistrant.register(with: registry)
}
} |
| self.isGpuDisabled = self.viewController | ||
| ? self.viewController.stateIsBackground | ||
| : FlutterSharedApplication.application && | ||
| FlutterSharedApplication.application.applicationState == | ||
| UIApplicationStateBackground; |
There was a problem hiding this comment.
Maintains existing behavior for app extensions.
There was a problem hiding this comment.
In app extensions, the FlutterSharedApplication.application is unavailable and you have to use the Scene instead. Should this attempt to use the Scene if the application is unavailable?
There was a problem hiding this comment.
In app extensions, the
FlutterSharedApplication.applicationis unavailable and you have to use the Scene instead. Should this attempt to use the Scene if the application is unavailable?
It does check for the scene in self.viewController.stateIsBackground. So the question is really, "Can you have an app extension that is in a background state with an engine that doesn't have an associated view controller, which needs GPU access?" For that situation we can say for this PR that we do whatever we used to do, there is no change. I don't know if that situation is practical or possible. For example, I know memory requirements for app extensions is tight so you may not even be able to fit a second engine.
There was a problem hiding this comment.
Here is a question: is there actually a code path to this code which sets viewController? I am trying to figure this out by looking at the code and I can't - I am starting to suspect it is always nil and can't be used at this point
e.g. ShareViewController calls [engine run] (which calls createShell) before it calls [self initWithEngine:...] which sets viewController.
There was a problem hiding this comment.
Here is a question: is there actually a code path to this code which sets
viewController?
These API's are hard to reason about because they are public. Anyone could be doing anything with them (eg add-to-app). For the simple case of loading a FlutterViewController from a storyboard, it looks like the view controller will be nil:
The FlutterViewController can be created before the FlutterEngine (
What that means to me is that it's safest to construct the PR like this so we don't break any add-to-app cases and we have a workaround for people if it becomes problematic. For app extensions, I'm skeptical that app extensions can be initialized while an app is in the background. I think the more prudent thing is to keep the existing behavior for that.
|
I actually managed to reproduce this today, after struggling through different variations yesterday. The key here is that the app (at least on iOS26 which I have installed on both available to me iOS devices) even when started in background due to notification arriving seems to initially have GPU access but then looses it after some delay. So any tests which submit GPU work fast enough will actually succeed. Device log with some additional debug printing addedHere is the setup that eventually allowed me to reproduce it:
void main() {
sleep(const Duration(seconds: 1));
runApp(
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
for (var i = 0; i <= 10; i++)
Image(image: AssetImage('assets/icon$i.png')),
],
),
),
);
}Once you have the app, you do the following:
That's it: if you have enough logging you will see in I have tested this code and it seems to do the trick. Now we correctly detect that we are running in background. |
|
Is there a way to generate a notification for iOS through tooling and if so, should we add a test to the device lab to make sure we don't regress? |
I don't think we have a mechanism that can kill processes. In our reproduction we are using the app switcher to kill the process. |
…ter#171785) Started querying the app state for the gpu disabled sync switch when starting an engine without a view controller fixes flutter#166668 Testing: Integration test is not possible since it would require manipulation of the operating system and killing / restoring the app. Unit tests would require executing in the background or mocking out background detection which is pretty contrived and will complicate engine initialization. The simple cases will be covered with integration tests like the wide gamut devicelab tests which loads an image at startup and grabs a screenshot of it. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Roll Flutter from 43657f3 to 35f197f (39 revisions) flutter/flutter@43657f3...35f197f 2025-07-12 [email protected] Roll Fuchsia Linux SDK from 8aoEy1hp2a9HI1pt-... to xQlbHCUI33kDvkew8... (flutter/flutter#172060) 2025-07-12 [email protected] Add RSuperellipse support to Web (global cache) (flutter/flutter#171489) 2025-07-12 [email protected] Fix grammar: Change 'A' to 'An' before IOSSystemContextMenuItemData (flutter/flutter#172019) 2025-07-11 [email protected] Manual roll Dart to b21dca1b89ff (flutter/flutter#172038) 2025-07-11 [email protected] Roll Skia from 2ea2ba09ef85 to 92354f64e37f (1 revision) (flutter/flutter#172039) 2025-07-11 [email protected] Fix CheckedPopupMenuItem semantics to use menuItemCheckbox role with checked state (flutter/flutter#171749) 2025-07-11 [email protected] adds gemini.md to `engine` and `licenses_cpp` (flutter/flutter#172022) 2025-07-11 [email protected] [Web] Implement disabling interactive selection (flutter/flutter#171935) 2025-07-11 [email protected] [tool] Make google3 have to override feature flags (flutter/flutter#171933) 2025-07-11 [email protected] License cpp 710 (flutter/flutter#171989) 2025-07-11 [email protected] add content description to tooltip-only nodes for android (flutter/flutter#171541) 2025-07-11 [email protected] [Web a11y]Update table cell to use LabelRepresentation.sizedSpan (flutter/flutter#172013) 2025-07-11 [email protected] [ Tool ] Enable `omit_obvious_*_types` and `specify_nonobvious_*_types` lints (flutter/flutter#172018) 2025-07-11 [email protected] Add SemanticsLabelBuilder for Accessible Label Concatenation (flutter/flutter#171683) 2025-07-11 [email protected] Run tests on either macOS 14 or 15 (flutter/flutter#171076) 2025-07-11 [email protected] Roll Skia from db1a5550c848 to 2ea2ba09ef85 (1 revision) (flutter/flutter#172017) 2025-07-11 [email protected] [Cupertino] Make some widgets no longer use RSuperellipse (flutter/flutter#171830) 2025-07-11 [email protected] Detach the resource context from the IO thread only if the shell's IO manager is no longer being used by any other spawned shells (flutter/flutter#171554) 2025-07-11 [email protected] Started querying the app state for the gpu disabled sync switch (flutter/flutter#171785) 2025-07-11 [email protected] License_cpp 7/02 (flutter/flutter#171558) 2025-07-11 [email protected] [web] Refactor clipboard. (flutter/flutter#171427) 2025-07-11 [email protected] Require 64-bit Windows (flutter/flutter#171925) 2025-07-11 [email protected] Run hot_reload_with_asset_web_test.dart on Mac/Windows (flutter/flutter#171280) 2025-07-11 [email protected] Roll Skia from da7e3eae7c2b to db1a5550c848 (2 revisions) (flutter/flutter#171999) 2025-07-11 [email protected] Roll Skia from 26571c3b1771 to da7e3eae7c2b (2 revisions) (flutter/flutter#171997) 2025-07-11 [email protected] Roll Skia from 34a40032ff0a to 26571c3b1771 (1 revision) (flutter/flutter#171995) 2025-07-11 [email protected] Roll Fuchsia Linux SDK from lO64ePNEGrGzs-MFC... to 8aoEy1hp2a9HI1pt-... (flutter/flutter#171993) 2025-07-10 [email protected] Remove redundant ThemeData(useMaterial3: true) from tests (flutter/flutter#171569) 2025-07-10 [email protected] [Android 16] Updated linux_android_emu to a 36 AVD in framework CI (flutter/flutter#169121) 2025-07-10 [email protected] [iOS] Add Live Text option to system context menu (flutter/flutter#170969) 2025-07-10 [email protected] Roll Skia from dc3da09ca905 to 34a40032ff0a (1 revision) (flutter/flutter#171982) 2025-07-10 [email protected] feat: Expose FocusNode of FocusTraversalGroup (flutter/flutter#171979) 2025-07-10 [email protected] `CupertinoDatePicker` and `CupertinoTimerPicker` new onChanged behavior (flutter/flutter#170793) 2025-07-10 [email protected] Manual roll Dart SDK from 8d69b07b9d9d to 07ea3aaaadf0 (32 revisions) (flutter/flutter#171969) 2025-07-10 [email protected] Style: Rename pageBuilder with builder in showCupertinoSheet (flutter/flutter#170625) 2025-07-10 [email protected] Roll Skia from bdb8bfcde7f3 to dc3da09ca905 (3 revisions) (flutter/flutter#171971) 2025-07-10 [email protected] Feat: Add foreground color for cupertino button (flutter/flutter#170898) 2025-07-10 [email protected] Roll Skia from 0fef076beec3 to bdb8bfcde7f3 (34 revisions) (flutter/flutter#171964) 2025-07-10 [email protected] Run stateless_stateful_hot_reload_web_test.dart on Mac/Windows (flutter/flutter#171283) 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. ...
|
Regarding automatically testing this... We should be able to terminate the app via the debugger connection or via test automation e.g. XCUIApplication.terminate() - I don't think that's the hardest part. I think setting up notifications is probably more challenging infrastructurally (because it requires APN authentication, these secrets need to be stored somewhere). Maybe setting up using background tasks is more viable. |
…ter#171785) Started querying the app state for the gpu disabled sync switch when starting an engine without a view controller fixes flutter#166668 Testing: Integration test is not possible since it would require manipulation of the operating system and killing / restoring the app. Unit tests would require executing in the background or mocking out background detection which is pretty contrived and will complicate engine initialization. The simple cases will be covered with integration tests like the wide gamut devicelab tests which loads an image at startup and grabs a screenshot of it. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…ter#171785) Started querying the app state for the gpu disabled sync switch when starting an engine without a view controller fixes flutter#166668 Testing: Integration test is not possible since it would require manipulation of the operating system and killing / restoring the app. Unit tests would require executing in the background or mocking out background detection which is pretty contrived and will complicate engine initialization. The simple cases will be covered with integration tests like the wide gamut devicelab tests which loads an image at startup and grabs a screenshot of it. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
My reproduction attempts used local notifications which doesn't require any authentication. Even if you did get them, how would you click on them to relaunch the app though and get a connection to the new process in order to grab the screenshot. |
|
I am not sure local notifications (those you click on) would do that - AFAIK they don't start the app in background, but in foreground. It is prerequisite for the reproduction that the app must be completely dead and it should start from scratch in background. I also think we can probably avoid screenshotting. Just kick off decoding of images into |
…ter#171785) Started querying the app state for the gpu disabled sync switch when starting an engine without a view controller fixes flutter#166668 Testing: Integration test is not possible since it would require manipulation of the operating system and killing / restoring the app. Unit tests would require executing in the background or mocking out background detection which is pretty contrived and will complicate engine initialization. The simple cases will be covered with integration tests like the wide gamut devicelab tests which loads an image at startup and grabs a screenshot of it. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Roll Flutter from 43657f3 to 35f197f (39 revisions) flutter/flutter@43657f3...35f197f 2025-07-12 [email protected] Roll Fuchsia Linux SDK from 8aoEy1hp2a9HI1pt-... to xQlbHCUI33kDvkew8... (flutter/flutter#172060) 2025-07-12 [email protected] Add RSuperellipse support to Web (global cache) (flutter/flutter#171489) 2025-07-12 [email protected] Fix grammar: Change 'A' to 'An' before IOSSystemContextMenuItemData (flutter/flutter#172019) 2025-07-11 [email protected] Manual roll Dart to b21dca1b89ff (flutter/flutter#172038) 2025-07-11 [email protected] Roll Skia from 2ea2ba09ef85 to 92354f64e37f (1 revision) (flutter/flutter#172039) 2025-07-11 [email protected] Fix CheckedPopupMenuItem semantics to use menuItemCheckbox role with checked state (flutter/flutter#171749) 2025-07-11 [email protected] adds gemini.md to `engine` and `licenses_cpp` (flutter/flutter#172022) 2025-07-11 [email protected] [Web] Implement disabling interactive selection (flutter/flutter#171935) 2025-07-11 [email protected] [tool] Make google3 have to override feature flags (flutter/flutter#171933) 2025-07-11 [email protected] License cpp 710 (flutter/flutter#171989) 2025-07-11 [email protected] add content description to tooltip-only nodes for android (flutter/flutter#171541) 2025-07-11 [email protected] [Web a11y]Update table cell to use LabelRepresentation.sizedSpan (flutter/flutter#172013) 2025-07-11 [email protected] [ Tool ] Enable `omit_obvious_*_types` and `specify_nonobvious_*_types` lints (flutter/flutter#172018) 2025-07-11 [email protected] Add SemanticsLabelBuilder for Accessible Label Concatenation (flutter/flutter#171683) 2025-07-11 [email protected] Run tests on either macOS 14 or 15 (flutter/flutter#171076) 2025-07-11 [email protected] Roll Skia from db1a5550c848 to 2ea2ba09ef85 (1 revision) (flutter/flutter#172017) 2025-07-11 [email protected] [Cupertino] Make some widgets no longer use RSuperellipse (flutter/flutter#171830) 2025-07-11 [email protected] Detach the resource context from the IO thread only if the shell's IO manager is no longer being used by any other spawned shells (flutter/flutter#171554) 2025-07-11 [email protected] Started querying the app state for the gpu disabled sync switch (flutter/flutter#171785) 2025-07-11 [email protected] License_cpp 7/02 (flutter/flutter#171558) 2025-07-11 [email protected] [web] Refactor clipboard. (flutter/flutter#171427) 2025-07-11 [email protected] Require 64-bit Windows (flutter/flutter#171925) 2025-07-11 [email protected] Run hot_reload_with_asset_web_test.dart on Mac/Windows (flutter/flutter#171280) 2025-07-11 [email protected] Roll Skia from da7e3eae7c2b to db1a5550c848 (2 revisions) (flutter/flutter#171999) 2025-07-11 [email protected] Roll Skia from 26571c3b1771 to da7e3eae7c2b (2 revisions) (flutter/flutter#171997) 2025-07-11 [email protected] Roll Skia from 34a40032ff0a to 26571c3b1771 (1 revision) (flutter/flutter#171995) 2025-07-11 [email protected] Roll Fuchsia Linux SDK from lO64ePNEGrGzs-MFC... to 8aoEy1hp2a9HI1pt-... (flutter/flutter#171993) 2025-07-10 [email protected] Remove redundant ThemeData(useMaterial3: true) from tests (flutter/flutter#171569) 2025-07-10 [email protected] [Android 16] Updated linux_android_emu to a 36 AVD in framework CI (flutter/flutter#169121) 2025-07-10 [email protected] [iOS] Add Live Text option to system context menu (flutter/flutter#170969) 2025-07-10 [email protected] Roll Skia from dc3da09ca905 to 34a40032ff0a (1 revision) (flutter/flutter#171982) 2025-07-10 [email protected] feat: Expose FocusNode of FocusTraversalGroup (flutter/flutter#171979) 2025-07-10 [email protected] `CupertinoDatePicker` and `CupertinoTimerPicker` new onChanged behavior (flutter/flutter#170793) 2025-07-10 [email protected] Manual roll Dart SDK from 8d69b07b9d9d to 07ea3aaaadf0 (32 revisions) (flutter/flutter#171969) 2025-07-10 [email protected] Style: Rename pageBuilder with builder in showCupertinoSheet (flutter/flutter#170625) 2025-07-10 [email protected] Roll Skia from bdb8bfcde7f3 to dc3da09ca905 (3 revisions) (flutter/flutter#171971) 2025-07-10 [email protected] Feat: Add foreground color for cupertino button (flutter/flutter#170898) 2025-07-10 [email protected] Roll Skia from 0fef076beec3 to bdb8bfcde7f3 (34 revisions) (flutter/flutter#171964) 2025-07-10 [email protected] Run stateless_stateful_hot_reload_web_test.dart on Mac/Windows (flutter/flutter#171283) 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. ...
…ter#171785) Started querying the app state for the gpu disabled sync switch when starting an engine without a view controller fixes flutter#166668 Testing: Integration test is not possible since it would require manipulation of the operating system and killing / restoring the app. Unit tests would require executing in the background or mocking out background detection which is pretty contrived and will complicate engine initialization. The simple cases will be covered with integration tests like the wide gamut devicelab tests which loads an image at startup and grabs a screenshot of it. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…ter#171785) Started querying the app state for the gpu disabled sync switch when starting an engine without a view controller fixes flutter#166668 Testing: Integration test is not possible since it would require manipulation of the operating system and killing / restoring the app. Unit tests would require executing in the background or mocking out background detection which is pretty contrived and will complicate engine initialization. The simple cases will be covered with integration tests like the wide gamut devicelab tests which loads an image at startup and grabs a screenshot of it. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…ter#171785) Started querying the app state for the gpu disabled sync switch when starting an engine without a view controller fixes flutter#166668 Testing: Integration test is not possible since it would require manipulation of the operating system and killing / restoring the app. Unit tests would require executing in the background or mocking out background detection which is pretty contrived and will complicate engine initialization. The simple cases will be covered with integration tests like the wide gamut devicelab tests which loads an image at startup and grabs a screenshot of it. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Roll Flutter from 43657f3 to 35f197f (39 revisions) flutter/flutter@43657f3...35f197f 2025-07-12 [email protected] Roll Fuchsia Linux SDK from 8aoEy1hp2a9HI1pt-... to xQlbHCUI33kDvkew8... (flutter/flutter#172060) 2025-07-12 [email protected] Add RSuperellipse support to Web (global cache) (flutter/flutter#171489) 2025-07-12 [email protected] Fix grammar: Change 'A' to 'An' before IOSSystemContextMenuItemData (flutter/flutter#172019) 2025-07-11 [email protected] Manual roll Dart to b21dca1b89ff (flutter/flutter#172038) 2025-07-11 [email protected] Roll Skia from 2ea2ba09ef85 to 92354f64e37f (1 revision) (flutter/flutter#172039) 2025-07-11 [email protected] Fix CheckedPopupMenuItem semantics to use menuItemCheckbox role with checked state (flutter/flutter#171749) 2025-07-11 [email protected] adds gemini.md to `engine` and `licenses_cpp` (flutter/flutter#172022) 2025-07-11 [email protected] [Web] Implement disabling interactive selection (flutter/flutter#171935) 2025-07-11 [email protected] [tool] Make google3 have to override feature flags (flutter/flutter#171933) 2025-07-11 [email protected] License cpp 710 (flutter/flutter#171989) 2025-07-11 [email protected] add content description to tooltip-only nodes for android (flutter/flutter#171541) 2025-07-11 [email protected] [Web a11y]Update table cell to use LabelRepresentation.sizedSpan (flutter/flutter#172013) 2025-07-11 [email protected] [ Tool ] Enable `omit_obvious_*_types` and `specify_nonobvious_*_types` lints (flutter/flutter#172018) 2025-07-11 [email protected] Add SemanticsLabelBuilder for Accessible Label Concatenation (flutter/flutter#171683) 2025-07-11 [email protected] Run tests on either macOS 14 or 15 (flutter/flutter#171076) 2025-07-11 [email protected] Roll Skia from db1a5550c848 to 2ea2ba09ef85 (1 revision) (flutter/flutter#172017) 2025-07-11 [email protected] [Cupertino] Make some widgets no longer use RSuperellipse (flutter/flutter#171830) 2025-07-11 [email protected] Detach the resource context from the IO thread only if the shell's IO manager is no longer being used by any other spawned shells (flutter/flutter#171554) 2025-07-11 [email protected] Started querying the app state for the gpu disabled sync switch (flutter/flutter#171785) 2025-07-11 [email protected] License_cpp 7/02 (flutter/flutter#171558) 2025-07-11 [email protected] [web] Refactor clipboard. (flutter/flutter#171427) 2025-07-11 [email protected] Require 64-bit Windows (flutter/flutter#171925) 2025-07-11 [email protected] Run hot_reload_with_asset_web_test.dart on Mac/Windows (flutter/flutter#171280) 2025-07-11 [email protected] Roll Skia from da7e3eae7c2b to db1a5550c848 (2 revisions) (flutter/flutter#171999) 2025-07-11 [email protected] Roll Skia from 26571c3b1771 to da7e3eae7c2b (2 revisions) (flutter/flutter#171997) 2025-07-11 [email protected] Roll Skia from 34a40032ff0a to 26571c3b1771 (1 revision) (flutter/flutter#171995) 2025-07-11 [email protected] Roll Fuchsia Linux SDK from lO64ePNEGrGzs-MFC... to 8aoEy1hp2a9HI1pt-... (flutter/flutter#171993) 2025-07-10 [email protected] Remove redundant ThemeData(useMaterial3: true) from tests (flutter/flutter#171569) 2025-07-10 [email protected] [Android 16] Updated linux_android_emu to a 36 AVD in framework CI (flutter/flutter#169121) 2025-07-10 [email protected] [iOS] Add Live Text option to system context menu (flutter/flutter#170969) 2025-07-10 [email protected] Roll Skia from dc3da09ca905 to 34a40032ff0a (1 revision) (flutter/flutter#171982) 2025-07-10 [email protected] feat: Expose FocusNode of FocusTraversalGroup (flutter/flutter#171979) 2025-07-10 [email protected] `CupertinoDatePicker` and `CupertinoTimerPicker` new onChanged behavior (flutter/flutter#170793) 2025-07-10 [email protected] Manual roll Dart SDK from 8d69b07b9d9d to 07ea3aaaadf0 (32 revisions) (flutter/flutter#171969) 2025-07-10 [email protected] Style: Rename pageBuilder with builder in showCupertinoSheet (flutter/flutter#170625) 2025-07-10 [email protected] Roll Skia from bdb8bfcde7f3 to dc3da09ca905 (3 revisions) (flutter/flutter#171971) 2025-07-10 [email protected] Feat: Add foreground color for cupertino button (flutter/flutter#170898) 2025-07-10 [email protected] Roll Skia from 0fef076beec3 to bdb8bfcde7f3 (34 revisions) (flutter/flutter#171964) 2025-07-10 [email protected] Run stateless_stateful_hot_reload_web_test.dart on Mac/Windows (flutter/flutter#171283) 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. ...
Roll Flutter from 43657f3 to 35f197f (39 revisions) flutter/flutter@43657f3...35f197f 2025-07-12 [email protected] Roll Fuchsia Linux SDK from 8aoEy1hp2a9HI1pt-... to xQlbHCUI33kDvkew8... (flutter/flutter#172060) 2025-07-12 [email protected] Add RSuperellipse support to Web (global cache) (flutter/flutter#171489) 2025-07-12 [email protected] Fix grammar: Change 'A' to 'An' before IOSSystemContextMenuItemData (flutter/flutter#172019) 2025-07-11 [email protected] Manual roll Dart to b21dca1b89ff (flutter/flutter#172038) 2025-07-11 [email protected] Roll Skia from 2ea2ba09ef85 to 92354f64e37f (1 revision) (flutter/flutter#172039) 2025-07-11 [email protected] Fix CheckedPopupMenuItem semantics to use menuItemCheckbox role with checked state (flutter/flutter#171749) 2025-07-11 [email protected] adds gemini.md to `engine` and `licenses_cpp` (flutter/flutter#172022) 2025-07-11 [email protected] [Web] Implement disabling interactive selection (flutter/flutter#171935) 2025-07-11 [email protected] [tool] Make google3 have to override feature flags (flutter/flutter#171933) 2025-07-11 [email protected] License cpp 710 (flutter/flutter#171989) 2025-07-11 [email protected] add content description to tooltip-only nodes for android (flutter/flutter#171541) 2025-07-11 [email protected] [Web a11y]Update table cell to use LabelRepresentation.sizedSpan (flutter/flutter#172013) 2025-07-11 [email protected] [ Tool ] Enable `omit_obvious_*_types` and `specify_nonobvious_*_types` lints (flutter/flutter#172018) 2025-07-11 [email protected] Add SemanticsLabelBuilder for Accessible Label Concatenation (flutter/flutter#171683) 2025-07-11 [email protected] Run tests on either macOS 14 or 15 (flutter/flutter#171076) 2025-07-11 [email protected] Roll Skia from db1a5550c848 to 2ea2ba09ef85 (1 revision) (flutter/flutter#172017) 2025-07-11 [email protected] [Cupertino] Make some widgets no longer use RSuperellipse (flutter/flutter#171830) 2025-07-11 [email protected] Detach the resource context from the IO thread only if the shell's IO manager is no longer being used by any other spawned shells (flutter/flutter#171554) 2025-07-11 [email protected] Started querying the app state for the gpu disabled sync switch (flutter/flutter#171785) 2025-07-11 [email protected] License_cpp 7/02 (flutter/flutter#171558) 2025-07-11 [email protected] [web] Refactor clipboard. (flutter/flutter#171427) 2025-07-11 [email protected] Require 64-bit Windows (flutter/flutter#171925) 2025-07-11 [email protected] Run hot_reload_with_asset_web_test.dart on Mac/Windows (flutter/flutter#171280) 2025-07-11 [email protected] Roll Skia from da7e3eae7c2b to db1a5550c848 (2 revisions) (flutter/flutter#171999) 2025-07-11 [email protected] Roll Skia from 26571c3b1771 to da7e3eae7c2b (2 revisions) (flutter/flutter#171997) 2025-07-11 [email protected] Roll Skia from 34a40032ff0a to 26571c3b1771 (1 revision) (flutter/flutter#171995) 2025-07-11 [email protected] Roll Fuchsia Linux SDK from lO64ePNEGrGzs-MFC... to 8aoEy1hp2a9HI1pt-... (flutter/flutter#171993) 2025-07-10 [email protected] Remove redundant ThemeData(useMaterial3: true) from tests (flutter/flutter#171569) 2025-07-10 [email protected] [Android 16] Updated linux_android_emu to a 36 AVD in framework CI (flutter/flutter#169121) 2025-07-10 [email protected] [iOS] Add Live Text option to system context menu (flutter/flutter#170969) 2025-07-10 [email protected] Roll Skia from dc3da09ca905 to 34a40032ff0a (1 revision) (flutter/flutter#171982) 2025-07-10 [email protected] feat: Expose FocusNode of FocusTraversalGroup (flutter/flutter#171979) 2025-07-10 [email protected] `CupertinoDatePicker` and `CupertinoTimerPicker` new onChanged behavior (flutter/flutter#170793) 2025-07-10 [email protected] Manual roll Dart SDK from 8d69b07b9d9d to 07ea3aaaadf0 (32 revisions) (flutter/flutter#171969) 2025-07-10 [email protected] Style: Rename pageBuilder with builder in showCupertinoSheet (flutter/flutter#170625) 2025-07-10 [email protected] Roll Skia from bdb8bfcde7f3 to dc3da09ca905 (3 revisions) (flutter/flutter#171971) 2025-07-10 [email protected] Feat: Add foreground color for cupertino button (flutter/flutter#170898) 2025-07-10 [email protected] Roll Skia from 0fef076beec3 to bdb8bfcde7f3 (34 revisions) (flutter/flutter#171964) 2025-07-10 [email protected] Run stateless_stateful_hot_reload_web_test.dart on Mac/Windows (flutter/flutter#171283) 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. ...
…#190445) Fixes [flutter#170599](flutter#170599). Metal image uploads currently wait synchronously for every upload command buffer to reach the scheduled state. That wait was added to protect an iOS backgrounding race, but paying it after every foreground upload unnecessarily blocks image decoding and can delay images becoming ready. This PR moves that synchronization to the lifecycle boundary where it is required: - foreground image uploads commit their Metal command buffer, register a scheduled-or-terminal receipt, and return without waiting; - when GPU access changes to disabled, `ContextMTL` synchronously drains any still-pending image-upload receipts before the transition returns; - receipt registration remains inside the enabled side of the GPU `SyncSwitch`, so a concurrent disable transition cannot miss an upload that was just committed; - existing GLES tracking-fence and `glFlush`/`glFinish` behavior is unchanged. This is a deeper, correctness-preserving follow-up to my deliberately oversimplified first experiment, [flutter#181601](flutter#181601). That PR demonstrated the performance opportunity by only changing `block_on_schedule` to `false`, but it did not replace the iOS lifecycle barrier and did not include the required tests. This PR implements the receipt-based design proposed during the original review and verifies it with deterministic concurrency tests and repeated physical-device measurements. Related lifecycle work includes the original magenta-image report [flutter#166668](flutter#166668), the scheduling wait in [flutter#169378](flutter#169378), the deferred-task race fix in [flutter#169596](flutter#169596), their stable cherry-pick [flutter#170846](flutter#170846), and the separate initial GPU-state fix [flutter#171785](flutter#171785). Older Impeller synchronization discussions [flutter#120399](flutter#120399), [flutter#120406](flutter#120406), and [flutter#131490](flutter#131490) are background context only and are not closed by this PR. ## Why was every upload waiting? The original report, [flutter#166668](flutter#166668), described images becoming pink/magenta after an iOS application was awakened in the background and later foregrounded. [flutter#169378](flutter#169378) addressed a narrow commit-versus-background transition race: 1. A notification can wake an application while it is still in the background. 2. Image decoding starts while the engine still considers GPU access available. 3. The decoder commits a Metal upload command buffer. 4. The application can re-enter the background before Metal acknowledges the command buffer as scheduled. 5. The upload can then fail under iOS background GPU restrictions, leaving a persistent magenta image. The fix submitted image uploads with `block_on_schedule=true`. Because the upload runs inside the shared side of the GPU `SyncSwitch`, waiting before that handler returns prevents the switch's exclusive disable transition from passing until the upload is scheduled. That is correct, but expensive: every normal upload performs the native `[MTLCommandBuffer waitUntilScheduled]`, even when no lifecycle transition is happening. This cost was called out in the original review. In particular: - [the review proposed retaining a submission receipt and waiting only when GPU access is lost](flutter#169378 (comment)); - [a follow-up clarified that ordinary asynchronous scheduling should only block during `applicationDidEnterBackground:`](flutter#169378 (comment)); - [the deadlock discussion warned against waiting after GPU access is already unavailable](flutter#169378 (comment)). The tech-debt issue [flutter#170599](flutter#170599) was then filed specifically to remove this extra foreground thread blocking. This PR implements that deferred design rather than removing synchronization. ## Relationship to the previous attempt [flutter#181601](flutter#181601) only disabled the per-upload wait. It found a very large reduction in the pathological `UploadTextureToPrivate` span, proving that the effective Metal wait was in the submission path. However, the review correctly identified two blockers: - [removing the wait risked reintroducing the magenta-image lifecycle race](flutter#181601 (comment)); - [the change needed significant deterministic test coverage](flutter#181601 (review)). It was [closed because there was no follow-up at that time](flutter#181601 (comment)). [An automated review also suggested removing a later generic `command_buffer->WaitUntilScheduled()` call](flutter#181601 (comment)). That suggestion does not account for backend behavior: Metal's generic `WaitUntilScheduled()` and `WaitUntilCompleted()` hooks are no-ops in this path, while the same block has real `glFlush`/`glFinish` behavior on GLES. This PR leaves that backend-specific visibility behavior intact. ## Correctness invariant When a transition to GPU-disabled returns, every tracked image-upload Metal command buffer committed while the GPU `SyncSwitch` was enabled must have reached either: - the scheduled state; or - a terminal completed/failed state from which it cannot later begin GPU work. At the same time, ordinary foreground image uploads must not synchronously wait for scheduling or completion. ## How the new ordering works - **Foreground:** while holding the enabled/shared `SyncSwitch` lock, install the Metal handlers, commit the upload, register its receipt, and return. - **GPU disable:** the exclusive switch transition first waits for those shared handlers to finish, then synchronously drains every pending receipt before returning. The `SyncSwitch` lock ordering is the proof that registration cannot be missed: `SetSwitch(true)` cannot acquire its unique lock until an upload's shared handler has committed and registered its receipt. Observer notification is synchronous, so the disable transition cannot return before those receipts are safe. Receipt waiting happens outside both the switch lock and tracker mutex. ## Implementation - `CommandBufferSchedulingReceipt` provides a thread-safe, idempotent scheduled-or-terminal signal. Scheduling, completion, and failure all wake waiters, and callbacks run outside its mutex. - `CommandBufferMTL` installs scheduled and completed handlers before `commit` and returns the receipt without waiting or creating a retain cycle. - `PendingImageUploadScheduleTracker` tracks every outstanding upload receipt, handles callback/registration races, uses weak callback state, and waits only after releasing its mutex. - `ContextMTL` drains the tracker when GPU access is disabled while preserving the existing deferred-task behavior when it is enabled again. - `SubmitWithReceipt` replaces the generic `block_on_schedule` Boolean. Metal returns a real receipt; Vulkan and generic fallbacks preserve their existing submission paths; GLES fence and flush/finish behavior is unchanged. - Focused traces cover foreground submission, lifecycle drains, pending counts, and individual waits. ## Positive impact This changes where synchronization is paid, rather than weakening it: - image-decode workers return after commit and receipt registration instead of stalling on Metal scheduling for every image; - batches become ready sooner, with the largest gains for generated pixels, camera buffers, and other upload-heavy sources; - ordinary JPEG and disk-cached image paths also show repeatable end-to-end gains; - the rare GPU-disable transition waits only for image uploads that are still unscheduled, and only until scheduled/terminal—not until GPU completion; - the original backgrounding guarantee is retained and GLES behavior is unchanged. There is no Dart or public Flutter framework API change. ## Performance All measurements below used profile builds with Impeller on the same wired physical iPhone 14 Pro Max running iOS 26.5. Lower is better. ### Existing `large_image_changer` macrobenchmark: 30-run A/B/A The repository macrobenchmark was run 10 times with the baseline, 10 times with this implementation, and 10 more times after returning to the baseline. The same trace surrounded the submission block in both variants. | Metric | Combined baseline | This PR | Change | |---|---:|---:|---:| | Foreground submit p50 | 2.098 ms | 0.024 ms | **−98.86%** | | Foreground submit p99 | 2.855 ms | 0.056 ms | **−98.04%** | | Complete `UploadTextureToPrivate` p50 | 2.654 ms | 0.559 ms | **−78.94%** | | Complete `UploadTextureToPrivate` p99 | 4.355 ms | 0.925 ms | **−78.76%** | The direct trace confirms that the native scheduling wait leaves the foreground critical path. ### Image-upload stress suite: repeated A/B/A A standalone A/B/A suite used three runs per engine and 120 image uploads per run. End-to-end values are run medians; native p50 values pool 360 events. | Workload | Median time until 120 images are ready | Synchronous `UploadTextureToPrivate` p50 | |---|---:|---:| | Bundled JPEG + `ResizeImage` | 768.692 → 726.815 ms (**−5.4%**) | 505.5 → 60.0 µs (**−88.1%**) | | Preseeded `CachedNetworkImageProvider` + `ResizeImage` | 847.037 → 799.973 ms (**−5.6%**) | 477.0 → 56.0 µs (**−88.3%**) | | Raw 512×512 RGBA + resize | 111.705 → 70.902 ms (**−36.5%**) | 547.5 → 141.0 µs (**−74.2%**) | Every changed run was faster than every baseline run. The raw-pixel result is an upload-heavy upper bound; the 5.4–5.6% JPEG results are more representative. Native percentages measure removed synchronous CPU blocking, not faster GPU copy throughput. ## Standalone benchmark reproduction This self-contained sample reproduces the upload-heavy raw-pixel workload. Run it in profile mode against baseline and PR engines on the same iOS device and compare `elapsed_micros` plus the `UploadTextureToPrivate` trace spans. <details> <summary>Expand standalone Flutter benchmark source and commands</summary> Create a project with `flutter create --platforms=ios impeller_upload_benchmark`, then replace/add the following files. ### `pubspec.yaml` ```yaml name: impeller_upload_benchmark publish_to: none environment: sdk: '>=3.4.0 <4.0.0' dependencies: flutter: sdk: flutter dev_dependencies: flutter_driver: sdk: flutter flutter_test: sdk: flutter test: any flutter: uses-material-design: true ``` ### `lib/main.dart` ```dart import 'dart:convert'; import 'dart:ui' as ui; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; final GlobalKey<BenchmarkPageState> benchmarkKey = GlobalKey<BenchmarkPageState>(); void main() { WidgetsFlutterBinding.ensureInitialized(); runApp(const BenchmarkApp()); } Future<String> handleDriverMessage(String? message) async { switch (message) { case 'warmup': await benchmarkKey.currentState!.warmup(); return 'ready'; case 'run': return jsonEncode(await benchmarkKey.currentState!.runBenchmark()); default: throw UnsupportedError('Unsupported driver message: $message'); } } class BenchmarkApp extends StatelessWidget { const BenchmarkApp({super.key}); @OverRide Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: SafeArea(child: BenchmarkPage(key: benchmarkKey)), ), ); } } class BenchmarkPage extends StatefulWidget { const BenchmarkPage({super.key}); @OverRide State<BenchmarkPage> createState() => BenchmarkPageState(); } class BenchmarkPageState extends State<BenchmarkPage> { static const int imageCount = 120; static const int sourceWidth = 512; static const int sourceHeight = 512; static const int targetWidth = 860; static const int targetHeight = 1864; late final Uint8List _pixels; late List<ImageProvider<Object>> _providers; int _generation = 0; @OverRide void initState() { super.initState(); _pixels = _makePixels(); _providers = _makeProviders(); } Uint8List _makePixels() { final Uint8List pixels = Uint8List(sourceWidth * sourceHeight * 4); for (var offset = 0; offset < pixels.length; offset += 4) { final int pixel = offset ~/ 4; pixels[offset] = pixel & 0xFF; pixels[offset + 1] = (pixel >> 8) & 0xFF; pixels[offset + 2] = 0x80; pixels[offset + 3] = 0xFF; } return pixels; } List<ImageProvider<Object>> _makeProviders() { return List<ImageProvider<Object>>.generate( imageCount, (int index) => RawPixelsImageProvider( id: _generation * imageCount + index, pixels: _pixels, width: sourceWidth, height: sourceHeight, targetWidth: targetWidth, targetHeight: targetHeight, ), growable: false, ); } Future<void> _reset() async { PaintingBinding.instance.imageCache ..clear() ..clearLiveImages(); _generation += 1; _providers = _makeProviders(); setState(() {}); await WidgetsBinding.instance.endOfFrame; } Future<void> warmup() async { for (final ImageProvider<Object> provider in _providers.take(40)) { await precacheImage(provider, context); } await _reset(); await Future<void>.delayed(const Duration(milliseconds: 500)); } Future<Map<String, Object>> runBenchmark() async { await _reset(); if (!mounted) { throw StateError('Benchmark page was disposed'); } final Stopwatch stopwatch = Stopwatch()..start(); for (final ImageProvider<Object> provider in _providers) { await precacheImage(provider, context); } stopwatch.stop(); return <String, Object>{ 'image_count': imageCount, 'elapsed_micros': stopwatch.elapsedMicroseconds, }; } @OverRide Widget build(BuildContext context) { return Center( key: const ValueKey<String>('benchmark-ready'), child: Text('Ready (generation $_generation)'), ); } } @immutable class RawPixelsImageProvider extends ImageProvider<RawPixelsImageProvider> { const RawPixelsImageProvider({ required this.id, required this.pixels, required this.width, required this.height, required this.targetWidth, required this.targetHeight, }); final int id; final Uint8List pixels; final int width; final int height; final int targetWidth; final int targetHeight; @OverRide Future<RawPixelsImageProvider> obtainKey(ImageConfiguration configuration) { return SynchronousFuture<RawPixelsImageProvider>(this); } @OverRide ImageStreamCompleter loadImage( RawPixelsImageProvider key, ImageDecoderCallback decode, ) { return MultiFrameImageStreamCompleter( codec: _loadCodec(), scale: 1, debugLabel: 'RawPixelsImageProvider($id)', ); } Future<ui.Codec> _loadCodec() async { final ui.ImmutableBuffer buffer = await ui.ImmutableBuffer.fromUint8List( pixels, ); final ui.ImageDescriptor descriptor = ui.ImageDescriptor.raw( buffer, width: width, height: height, pixelFormat: ui.PixelFormat.rgba8888, ); try { return await descriptor.instantiateCodec( targetWidth: targetWidth, targetHeight: targetHeight, ); } finally { descriptor.dispose(); buffer.dispose(); } } } ``` ### `test_driver/app.dart` ```dart import 'package:flutter_driver/driver_extension.dart'; import 'package:impeller_upload_benchmark/main.dart' as app; void main() { enableFlutterDriverExtension(handler: app.handleDriverMessage); app.main(); } ``` ### `test_driver/benchmark_test.dart` ```dart import 'dart:convert'; import 'dart:io'; import 'package:flutter_driver/flutter_driver.dart'; import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; Future<void> main() async { late FlutterDriver driver; setUpAll(() async { driver = await FlutterDriver.connect(); await driver.waitUntilFirstFrameRasterized(); await driver.waitFor(find.byValueKey('benchmark-ready')); }); tearDownAll(() async { await driver.close(); }); test('measure raw image upload scheduling', () async { expect(await driver.requestData('warmup'), 'ready'); await driver.forceGC(); late String response; final Timeline timeline = await driver.traceAction(() async { response = await driver.requestData( 'run', timeout: const Duration(minutes: 5), ); }, streams: const <TimelineStream>[TimelineStream.embedder]); final Map<String, dynamic> result = jsonDecode(response) as Map<String, dynamic>; expect(result['image_count'], 120); expect(result['elapsed_micros'], greaterThan(0)); await Directory('build').create(recursive: true); await File('build/raw_upload_result.json') .writeAsString(const JsonEncoder.withIndent(' ').convert(result)); await TimelineSummary.summarize(timeline) .writeTimelineToFile('raw_upload', pretty: true, includeSummary: false); // Also keep the value visible in CI/terminal logs. // ignore: avoid_print print(response); }, timeout: Timeout.none); } ``` ### Run against each local engine ```sh flutter pub get flutter drive \ --profile \ -d <device-id> \ --local-engine-src-path=<flutter-checkout>/engine/src \ --local-engine=<baseline-ios-profile-output-name> \ --local-engine-host=<host-profile-output-name> \ -t test_driver/app.dart \ --driver test_driver/benchmark_test.dart # Repeat with only --local-engine changed to the PR engine output. ``` Each run writes: ```text build/raw_upload_result.json build/raw_upload.timeline.json ``` Use at least three runs per engine and return to the baseline after the changed phase. In the timeline, pair `B`/`E` events named `UploadTextureToPrivate` by PID and thread ID before calculating percentiles. </details> ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: gaaclarke <[email protected]>
Started querying the app state for the gpu disabled sync switch when starting an engine without a view controller
fixes #166668
Testing: Integration test is not possible since it would require manipulation of the operating system and killing / restoring the app. Unit tests would require executing in the background or mocking out background detection which is pretty contrived and will complicate engine initialization. The simple cases will be covered with integration tests like the wide gamut devicelab tests which loads an image at startup and grabs a screenshot of it.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.