-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[camera_android_camerax] Fix camera preview rotation for landscape oriented devices #9097
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a few comments
packages/camera/camera_android_camerax/lib/src/image_reader_rotated_preview.dart
Outdated
Show resolved
Hide resolved
packages/camera/camera_android_camerax/lib/src/rotated_preview_delegate.dart
Outdated
Show resolved
Hide resolved
|
||
/// Returns the clockwise quarter turns applied by the CameraPreview widget | ||
/// based on [orientation], the current device orientation (see | ||
/// camera/camera/lib/src/camera_preview.dart). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly concerned that the rotation in this plugin depending on the rotation of the app-facing package. This comment doesn't block this PR, but in a future implementation of the entire camera
package structure, each platform should probably handle its own rotations and the app facing shouldn't make any assumptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. It does seem like Android is the only platform currently where rotation needs to be handled beyond the app-facing CameraPreview
widget as of today, but nonetheless, I agree that organizationally, it should be handled within each platform implementation as a result.
Co-authored-by: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com>
Co-authored-by: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com>
…tated_preview.dart Co-authored-by: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com>
…_delegate.dart Co-authored-by: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com>
@reidbaker do you want to take a look before merging? |
yes looking now |
…ndscape oriented devices (flutter/packages#9097)
flutter/packages@ab44c26...7814fab 2025-05-08 40433176+KevynSM@users.noreply.github.com [go_router] Fix requestFocus propagation to Navigator (flutter/packages#9177) 2025-05-08 65381000+raju8000@users.noreply.github.com [go_router_builder] Fixes an deprecated warning for using withNullability (flutter/packages#9158) 2025-05-08 engine-flutter-autoroll@skia.org Roll Flutter from b0f5c8c to 02d8c1a (19 revisions) (flutter/packages#9230) 2025-05-08 43054281+camsim99@users.noreply.github.com [camera_android_camerax] Fix camera preview rotation for landscape oriented devices (flutter/packages#9097) 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-flutter-autoroll Please CC flutter-ecosystem@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
…iented devices (flutter#9097) Fixes the incorrect camera preview rotation on landscape-oriented devices (like some tablets). Really, this PR generalizes the fix added in flutter#8629 for correcting the camera preview rotation by correcting the camera preview rotation according to the rotation from the natural device orientation instead of assuming the device is naturally oriented in portrait up. There are technically two different fixes in this PR; here's the breakdown for clarity: 1. For devices using the `SurfaceTexture` Impeller backend: Rotate the camera preview according to the current default display rotation (the rotation away from the natural device orientation) and ignore rotation added in `CameraPreview` widget completely (as it assumes the natural device orientation to be portrait up). 2. For devices using the `ImageReader` Impeller backend: Rotate the camera preview according to https://developer.android.com/media/camera/camera2/camera-preview#orientation_calculation, where `deviceOrientationDegrees` comes from [a call](https://developer.android.com/reference/android/view/Display?_gl=1*lysjx*_up*MQ..*_ga*NjY3Nzk0Mzg2LjE3NDU5NjY3ODc.*_ga_6HH9YJMN9M*MTc0NTk2Njc4Ni4xLjAuMTc0NTk2Njc4Ni4wLjAuMjEwMTI3NTg1Mg..#getRotation()) to get the current default display rotation (the rotation away from the natural device orientation) instead of assuming it to be the rotation degrees from portrait up. Also, fixes a potential regression that @bparrishMines discovered in the `DeviceOrientationManager`. The changes there essentially ensure that it resets its state every time it is "re-started" to listen into changes into device orientation changes. Fixes flutter/flutter#164493 *Seems to work on all physical devices I test, but not emulators (tried Pixel Tablet API 28, 35). I think that is an emulator bug? Otherwise tested on a new Pixel Tablet (API 34), Pixel Tablet C (API 12), Pixel 3A (phone, API 32). ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Fixes the incorrect camera preview rotation on landscape-oriented devices (like some tablets). Really, this PR generalizes the fix added in #8629 for correcting the camera preview rotation by correcting the camera preview rotation according to the rotation from the natural device orientation instead of assuming the device is naturally oriented in portrait up.
There are technically two different fixes in this PR; here's the breakdown for clarity:
SurfaceTexture
Impeller backend: Rotate the camera preview according to the current default display rotation (the rotation away from the natural device orientation) and ignore rotation added inCameraPreview
widget completely (as it assumes the natural device orientation to be portrait up).ImageReader
Impeller backend: Rotate the camera preview according to https://developer.android.com/media/camera/camera2/camera-preview#orientation_calculation, wheredeviceOrientationDegrees
comes from a call to get the current default display rotation (the rotation away from the natural device orientation) instead of assuming it to be the rotation degrees from portrait up.Also, fixes a potential regression that @bparrishMines discovered in the
DeviceOrientationManager
. The changes there essentially ensure that it resets its state every time it is "re-started" to listen into changes into device orientation changes.Fixes flutter/flutter#164493.*
*Seems to work on all physical devices I test, but not emulators (tried Pixel Tablet API 28, 35). I think that is an emulator bug? Otherwise tested on a new Pixel Tablet (API 34), Pixel Tablet C (API 12), Pixel 3A (phone, API 32).
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3