Skip to content

Commit

Permalink
[camerax] Correct assumption about preview being correctly rotated by…
Browse files Browse the repository at this point in the history
… default on API 29 (#7714)

Changes assumption about camera preview being automatically corrected by CameraX on API <= 29 to API < 29 based on the fact that an `ImageReader` backs devices running API 29+, on which the camera preview will not automatically be corrected by CameraX. 

Related to flutter/flutter#154241.
  • Loading branch information
camsim99 authored Oct 1, 2024
1 parent 33fa73a commit ebcc4f0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.6.9

* Corrects assumption about automatic preview correction happening on API >= 29 to API > 29,
based on the fact that the `ImageReader` Impeller backend is not used for the most part on
devices running API 29+.

## 0.6.8+3

* Removes dependency on org.jetbrains.kotlin:kotlin-bom.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ public String getTempFilePath(@NonNull String prefix, @NonNull String suffix) {
}

/**
* Returns whether or not a {@code SurfaceTexture} backs the {@code Surface} provided to CameraX
* to build the camera preview. If it is backed by a {@code Surface}, then the transformation
* needed to correctly rotate the preview has already been applied.
* Returns whether or not Impeller uses an {@code ImageReader} backend to provide a {@code
* Surface} to CameraX to build the preview. If it is backed by an {@code ImageReader}, then
* CameraX will not automatically apply the transformation needed to correct the preview.
*
* <p>This is determined by the engine, who uses {@code SurfaceTexture}s on Android SDKs 29 and
* below.
* <p>This is determined by the engine, which approximately uses {@code SurfaceTexture}s on
* Android SDKs below 29.
*/
@Override
@NonNull
public Boolean isPreviewPreTransformed() {
return Build.VERSION.SDK_INT <= 29;
return Build.VERSION.SDK_INT < 29;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,16 @@ public void isPreviewPreTransformed_returnsTrueWhenRunningBelowSdk29() {
}

@Test
@Config(sdk = 29)
public void isPreviewPreTransformed_returnsTrueWhenRunningSdk29() {
@Config(sdk = 28)
public void isPreviewPreTransformed_returnsTrueWhenRunningSdk28() {
final SystemServicesHostApiImpl systemServicesHostApi =
new SystemServicesHostApiImpl(mockBinaryMessenger, mockInstanceManager, mockContext);
assertTrue(systemServicesHostApi.isPreviewPreTransformed());
}

@Test
@Config(sdk = 30)
public void isPreviewPreTransformed_returnsFalseWhenRunningAboveSdk29() {
@Config(sdk = 29)
public void isPreviewPreTransformed_returnsFalseWhenRunningAboveSdk28() {
final SystemServicesHostApiImpl systemServicesHostApi =
new SystemServicesHostApiImpl(mockBinaryMessenger, mockInstanceManager, mockContext);
assertFalse(systemServicesHostApi.isPreviewPreTransformed());
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android_camerax/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_android_camerax
description: Android implementation of the camera plugin using the CameraX library.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.6.8+3
version: 0.6.9

environment:
sdk: ^3.5.0
Expand Down

0 comments on commit ebcc4f0

Please sign in to comment.