Skip to content
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

[camerax] Correct assumption about preview being correctly rotated by default on API 29 #7714

Merged
merged 8 commits into from
Oct 1, 2024
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 hte preview. If it is backed by an {@code ImageReader}, then CameraX will not
reidbaker marked this conversation as resolved.
Show resolved Hide resolved
* 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 determine by the engine, who approximately uses {@code SurfaceTexture}s on Android SDKs
reidbaker marked this conversation as resolved.
Show resolved Hide resolved
* 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,15 +146,15 @@ public void isPreviewPreTransformed_returnsTrueWhenRunningBelowSdk29() {
}

@Test
@Config(sdk = 29)
@Config(sdk = 28)
public void isPreviewPreTransformed_returnsTrueWhenRunningSdk29() {
camsim99 marked this conversation as resolved.
Show resolved Hide resolved
reidbaker marked this conversation as resolved.
Show resolved Hide resolved
final SystemServicesHostApiImpl systemServicesHostApi =
new SystemServicesHostApiImpl(mockBinaryMessenger, mockInstanceManager, mockContext);
assertTrue(systemServicesHostApi.isPreviewPreTransformed());
}

@Test
@Config(sdk = 30)
@Config(sdk = 29)
public void isPreviewPreTransformed_returnsFalseWhenRunningAboveSdk29() {
final SystemServicesHostApiImpl systemServicesHostApi =
new SystemServicesHostApiImpl(mockBinaryMessenger, mockInstanceManager, mockContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,10 @@ class AndroidCameraCameraX extends CameraPlatform {
naturalDeviceOrientationDegrees * signForCameraDirection +
360) %
360;
print('sensorOrientaiton: $sensorOrientation');
camsim99 marked this conversation as resolved.
Show resolved Hide resolved
print('naturalDeviceOrientationDegrees $naturalDeviceOrientationDegrees');
print('signForCameraDirection: $signForCameraDirection');
print('rotation $rotation');
int quarterTurnsToCorrectPreview = rotation ~/ 90;

if (naturalOrientation == DeviceOrientation.landscapeLeft ||
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