Skip to content

Commit 5963ecd

Browse files
authored
[camera_android_camerax] Force new Surface for each SurfaceRequest (#9360)
> [!IMPORTANT] > flutter/flutter#169899 must be rolled into packages in order for this fix to land. Since timing for `Surface` requests cannot be guaranteed, request a new `Surface` from `SurfaceProducer.getSurface` each time a `Surface` is requested for rendering the camera preview to. Fixes flutter/flutter#155294. Fixes flutter/flutter#169506. ## 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.
1 parent c99425e commit 5963ecd

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

packages/camera/camera_android_camerax/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.6.19
2+
3+
* Ensures that a new surface is provided every time that one is requested to render the camera preview
4+
to fix pausing and resuming the preview.
5+
16
## 0.6.18+3
27

38
* Fixes incorrect camera preview mirroring for front cameras of devices using the Impeller backend.

packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewProxyApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void onSurfaceCleanup() {
121121
// Provide surface.
122122
surfaceProducer.setSize(
123123
request.getResolution().getWidth(), request.getResolution().getHeight());
124-
Surface flutterSurface = surfaceProducer.getSurface();
124+
Surface flutterSurface = surfaceProducer.getForcedNewSurface();
125125
request.provideSurface(
126126
flutterSurface,
127127
Executors.newSingleThreadExecutor(),

packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/PreviewTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ TextureRegistry getTextureRegistry() {
103103
ArgumentCaptor.forClass(TextureRegistry.SurfaceProducer.Callback.class);
104104

105105
when(mockSurfaceRequest.getResolution()).thenReturn(new Size(5, 6));
106-
when(mockSurfaceProducer.getSurface()).thenReturn(mock(Surface.class));
106+
when(mockSurfaceProducer.getForcedNewSurface()).thenReturn(mock(Surface.class));
107107

108108
final Preview.SurfaceProvider previewSurfaceProvider =
109109
api.createSurfaceProvider(mockSurfaceProducer, mockSystemServicesManager);
@@ -155,7 +155,7 @@ TextureRegistry getTextureRegistry() {
155155

156156
when(mockSurfaceRequest.getResolution())
157157
.thenReturn(new Size(resolutionWidth, resolutionHeight));
158-
when(mockSurfaceProducer.getSurface()).thenReturn(mockSurface);
158+
when(mockSurfaceProducer.getForcedNewSurface()).thenReturn(mockSurface);
159159

160160
final ArgumentCaptor<Surface> surfaceCaptor = ArgumentCaptor.forClass(Surface.class);
161161
final ArgumentCaptor<Consumer<SurfaceRequest.Result>> consumerCaptor =

packages/camera/camera_android_camerax/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_android_camerax
22
description: Android implementation of the camera plugin using the CameraX library.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.6.18+3
5+
version: 0.6.19
66

77
environment:
88
sdk: ^3.7.0

0 commit comments

Comments
 (0)