Skip to content

Commit

Permalink
Add Impeller migration step for camera plugin authors (#11008)
Browse files Browse the repository at this point in the history
_Description of what this PR is changing or adding, and why:_ 
Adds a note to the Impeller Android plugins migration to clarify that
plugin authors that create a camera preview may additionally need to
correct the rotation of the preview due to rotation information of
produced `Surface`s being lost.

_Issues fixed by this PR (if any):_ 
N/A

_PRs or commits this PR depends on (if any):_ 
Should land after flutter/packages#6856 as this
is mentioned as an example.

cc @navaronbracke

## Presubmit checklist

- [x] This PR is marked as draft with an explanation if not meant to
land until a future stable release.
- [x] This PR doesn’t contain automatically generated corrections
(Grammarly or similar).
- [x] This PR follows the [Google Developer Documentation Style
Guidelines](https://developers.google.com/style) — for example, it
doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person).
- [x] This PR uses [semantic line
breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks)
of 80 characters or fewer.

---------

Co-authored-by: Parker Lougheed <[email protected]>
Co-authored-by: Shams Zakhour (ignore Sfshaza) <[email protected]>
  • Loading branch information
3 people authored Aug 20, 2024
1 parent 900f21b commit a99e785
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/content/release/breaking-changes/android-surface-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,36 @@ surfaceProducer.setCallback(
A full example of using this new API can be found in [PR 6989][] for the
`video_player_android` plugin.

## Note on camera previews

If your plugin implements a camera preview, your migration might also require
fixing the rotation of that preview. This is because `Surface`s produced by the
`SurfaceProducer` might not contain the transformation information that Android
libraries need to correctly rotate the preview automatically.

In order to correct the rotation, you need to rotate the preview with
respect to the camera sensor orientation and the device orientation according
to the equation:

```plaintext
rotation = (sensorOrientationDegrees - deviceOrientationDegrees * sign + 360) % 360
```

where `deviceOrientationDegrees` is counterclockwise degrees and `sign` is 1 for
front-facing cameras and -1 for back-facing cameras.

To calculate this rotation,
- Retrieve the sensor orientation degrees by retrieving the value of
[`CameraCharacteristics.SENSOR_ORIENTATION`][].
- Retrieve the device orientation degrees in one of the ways that the
[Android orientation calculation documentation][] details.

To apply this rotation, you can use a [`RotatedBox`][] widget.

For more information on this calculation, check out the
[Android orientation calculation documentation][]. For a full example of making
this fix, check out [this `camera_android_camerax` PR][].

## Timeline

Landed in version: 3.22
Expand Down Expand Up @@ -116,7 +146,11 @@ Relevant PRs:
[`createSurfaceProducer`]: {{site.api}}/javadoc/io/flutter/view/TextureRegistry.html#createSurfaceProducer()
[`createSurfaceTexture`]: {{site.api}}/javadoc/io/flutter/view/TextureRegistry.html#createSurfaceTexture()
[`getSurface()`]: {{site.api}}/javadoc/io/flutter/view/TextureRegistry.SurfaceProducer.html#getSurface()
[`setCallback`]: https://main-api.flutter.dev/javadoc/io/flutter/view/TextureRegistry.SurfaceProducer.html#setCallback(io.flutter.view.TextureRegistry.SurfaceProducer.Callback)
[`setCallback`]: {{site.api}}/javadoc/io/flutter/view/TextureRegistry.SurfaceProducer.html#setCallback(io.flutter.view.TextureRegistry.SurfaceProducer.Callback)
[`CameraCharacteristics.SENSOR_ORIENTATION`]: {{site.android-dev}}/reference/android/hardware/camera2/CameraCharacteristics#SENSOR_ORIENTATION
[`RotatedBox`]: {{site.api}}/flutter/widgets/RotatedBox-class.html
[Android orientation calculation documentation]: {{site.android-dev}}/media/camera/camera2/camera-preview#orientation_calculation
[this`camera_android_camerax` PR]: {{site.repo.flutter}}/packages/pull/7044
[Issue 139702]: {{site.repo.flutter}}/issues/139702
[Issue 145930]: {{site.repo.flutter}}/issues/145930
[PR 51061]: {{site.repo.engine}}/pull/51061
Expand Down

0 comments on commit a99e785

Please sign in to comment.