Repository navigation
iOS: Don't discard GPU state set before an engine runs - #191055
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors how the GPU availability state is updated and synchronized with the lifecycle state in FlutterEngine, moving the logic into a dedicated updateGpuAvailabilityFromLifecycleState method and adding corresponding unit tests. The review feedback correctly identifies a potential runtime crash on iOS 12 due to the unguarded use of scene-based APIs, suggesting wrapping the scene check in an @available(iOS 13.0, *) block.
cbracken
force-pushed
the
test-gpu-state
branch
from
August 13, 2026 09:39
425df81 to
c4a08d9
Compare
cbracken
force-pushed
the
test-gpu-state
branch
2 times, most recently
from
August 14, 2026 23:40
0e2d1f4 to
43de2d7
Compare
hellohuanlin
previously approved these changes
Aug 17, 2026
Previously, a value assigned to `isGpuDisabled` before the engine ran was silently discarded: `createShell:` checked the current lifecycle state by assigning to the public property immediately before creating the shell, so the caller's value never actually reached `Shell::Create`. We now pass this through where it's safe to do so. The existing GPU state check is necessary: lifecycle notifications only report transitions, so an engine created while the app is already backgrounded won't receive one and needs to check the state explicitly on startup. However, the placement can be updated so we don't overwrite the user-specified state except when it's necessary (e.g. the user specified the GPU is enabled but the app is backgrounded). For apps, we can check `UIApplication.sharedApplication` directly. App extensions have no `sharedApplication` so need to check against the `UIScene`, but that's only reachable via a view that's been mounted in a window view hierarchy. As a result, we also need to check the state when we attach the view controller to see if it's different from the current state. In the case of an app extension where the view controller hasn't been mounted, the safest thing to do is leave the state alone. Enabling while backgrounded would result in the app being terminated. Fixes: flutter#190835 Issue: flutter#112232
cbracken
force-pushed
the
test-gpu-state
branch
from
August 17, 2026 22:42
43de2d7 to
51ff6b1
Compare
hellohuanlin
approved these changes
Aug 17, 2026
This was referenced Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, a value assigned to
isGpuDisabledbefore the engine ran was silently discarded:createShell:checked the current lifecycle state by assigning to the public property immediately before creating the shell, so the caller's value never actually reachedShell::Create. We now pass this through where it's safe to do so.The existing GPU state check is necessary: lifecycle notifications only report transitions, so an engine created while the app is already backgrounded won't receive one and needs to check the state explicitly on startup. However, the placement can be updated so we don't overwrite the user-specified state except when it's necessary (e.g. the user specified the GPU is enabled but the app is backgrounded).
For apps, we can check
UIApplication.sharedApplicationdirectly. App extensions have nosharedApplicationso need to check against theUIScene, but that's only reachable via a view that's been mounted in a window view hierarchy. As a result, we also need to check the state when we attach the view controller to see if it's different from the current state.In the case of an app extension where the view controller hasn't been mounted, the safest thing to do is leave the state alone. Enabling while backgrounded would result in the app being terminated.
Fixes: #190835
Issue: #112232
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.