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

[WIP] feat: Android Impeller support #1283

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

navaronbracke
Copy link
Collaborator

This PR adds support for Impeller on Android.

Supercedes #1277 (retargets those changes onto the new develop branch)

TODO:

  • replace SurfaceTexture with SurfaceProducer
  • suppress deprecation for the to-be-deprecated onSurfaceDestroyed (I need to add the annotation)
  • add rotation correction, inspired by the change in camera_android_camerax

Fixes #867

@navaronbracke navaronbracke changed the title [WIP] Android Impeller support [WIP] feat: Android Impeller support Jan 9, 2025
@@ -16,8 +16,8 @@ screenshots:
path: example/screenshots/overlay.png

environment:
sdk: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"
sdk: ">=3.6.0 <4.0.0"
Copy link
Collaborator Author

@navaronbracke navaronbracke Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SurfaceProducer API has seen some changes over a long period of time, due to the lengthy release cadence of the framework itself.

The SurfaceProducer API was available, but non-functional in Flutter 3.22, with the migration doc for plugin authors listing Flutter 3.24 as the minimum required version for the migration. However, in Flutter 3.27 both Impeller on Android has been turned on by default, and there was a name change for one of the two callbacks in the SurfaceProducer usage. (onSurfaceCreated -> onSurfaceAvailable)

In Flutter 3.28 there will be another name change (onSurfaceDestroyed -> onSurfaceCleanup), but since the current stable is only version 3.27, I added a TODO for that change

// See: https://developer.android.com/reference/androidx/camera/core/SurfaceRequest.Result

// Always attempt a release.
surface.release()
Copy link
Collaborator Author

@navaronbracke navaronbracke Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that adding this line fixes any occurrences of A resource failed to call close that we sometimes get.
Previously, we never did anything with the result callback, thus also not releasing the surface.

// Only need to release, do nothing.
}
SurfaceRequest.Result.RESULT_INVALID_SURFACE -> {
// The surface was invalid, so it is not clear how to recover from this.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that adding this line fixes any occurrences of A resource failed to call close that we sometimes get.
Previously, we never did anything with the result callback, thus also not releasing the surface.


// Preview
val surfaceProvider = Preview.SurfaceProvider { request ->
if (isStopped()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer have this check, I'm not sure if we should put it back or not.


val texture = textureEntry!!.surfaceTexture()
texture.setDefaultBufferSize(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is replaced by the surfaceProducer.setSize(request.resolution.width, request.resolution.height) on line 199.

@navaronbracke
Copy link
Collaborator Author

@juliansteenbakker I moved over the changes from the old PR into this one.

One thing that I don't know for sure is if we should provide Impeller support on Android in Flutter 3.24 or 3.27.
The current stable is version 3.27, but I think there were fixes for things in this API, between those two stable releases.
See also #1283 (comment)

@@ -53,6 +53,67 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {

int? _textureId;

/// Rotate the given [child] to account for the device orientation.
Widget _buildCameraViewWithDeviceOrientation(Widget child) {
final Map<DeviceOrientation, int> degreesForDeviceOrientation =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is still a work in progress, as we need to retrieve some arguments (camera direction, sensor orientation, natural device orientation) and observe the device orientation changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Impeller on Android
1 participant