Skip to content

iOS: Don't discard GPU state set before an engine runs - #191055

Merged
cbracken merged 2 commits into
flutter:masterfrom
cbracken:test-gpu-state
Aug 18, 2026
Merged

cbracken merged 2 commits into
flutter:masterfrom
cbracken:test-gpu-state

Conversation

@cbracken

@cbracken cbracken commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

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: #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-assist bot 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.

@cbracken
cbracken requested a review from a team as a code owner August 13, 2026 09:10
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 13, 2026
@github-actions github-actions Bot added platform-ios iOS applications specifically engine flutter/engine related. See also e: labels. team-ios Owned by iOS platform team labels Aug 13, 2026

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

Copy link
Copy Markdown
Contributor

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 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 cbracken changed the title iOS: Stop discarding the GPU state set before an engine runs iOS: Don't discard the GPU state set before an engine runs Aug 13, 2026
@cbracken cbracken changed the title iOS: Don't discard the GPU state set before an engine runs iOS: Don't discard GPU state set before an engine runs Aug 13, 2026
@cbracken
cbracken force-pushed the test-gpu-state branch 2 times, most recently from 0e2d1f4 to 43de2d7 Compare August 14, 2026 23:40
hellohuanlin
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS: isGpuDisabled set before engine start is silently clobbered by createShell

2 participants