Add a boolean that exposes rotation/crop metadata capability. (flutter/engine#55434)

Closes https://github.com/flutter/flutter/issues/144407.
Closes https://github.com/flutter/flutter/issues/155633.
This commit is contained in:
Matan Lurey
2024-09-25 12:27:08 -07:00
committed by GitHub
parent 5016ac77af
commit f425edfbf7
5 changed files with 60 additions and 0 deletions

View File

@@ -765,6 +765,11 @@ public class FlutterRenderer implements TextureRegistry {
this.callback = callback;
}
@Override
public boolean handlesCropAndRotation() {
return false;
}
@Override
public long id() {
return id;

View File

@@ -60,6 +60,11 @@ final class SurfaceTextureSurfaceProducer
// Intentionally blank: SurfaceTextures don't get platform notifications or cleanup.
}
@Override
public boolean handlesCropAndRotation() {
return true;
}
@Override
@NonNull
public SurfaceTexture getSurfaceTexture() {

View File

@@ -171,6 +171,28 @@ public interface TextureRegistry {
/** This method is not officially part of the public API surface and will be deprecated. */
void scheduleFrame();
/**
* Returns whether the current rendering path handles crop and rotation metadata.
*
* <p>On most newer Android devices (API 29+), a {@link android.media.ImageReader} backend is
* used, which has more features, works in new graphic backends directly (such as Impeller's
* Vulkan backend), and is the Android recommended solution. However, crop and rotation metadata
* are <strong>not</strong> handled automatically, and require plugin authors to make
* appropriate changes ({@see https://github.com/flutter/flutter/issues/144407}).
*
* <pre>{@code
* void example(SurfaceProducer producer) {
* bool supported = producer.handlesCropAndRotation();
* if (!supported) {
* // Manually rotate/crop, either in the Android plugin or in the Dart framework layer.
* }
* }
* }</pre>
*
* @return {@code true} if crop and rotation is handled automatically, {@code false} otherwise.
*/
boolean handlesCropAndRotation();
}
/** A registry entry for a managed SurfaceTexture. */

View File

@@ -7,8 +7,10 @@ package io.flutter.embedding.engine.renderer;
import static android.content.ComponentCallbacks2.TRIM_MEMORY_COMPLETE;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -735,6 +737,27 @@ public class FlutterRendererTest {
}
}
@Test
public void SurfaceTextureSurfaceProducerDoesNotCropOrRotate() {
try {
FlutterRenderer.debugForceSurfaceProducerGlTextures = true;
FlutterRenderer flutterRenderer = engineRule.getFlutterEngine().getRenderer();
TextureRegistry.SurfaceProducer producer = flutterRenderer.createSurfaceProducer();
assertTrue(producer.handlesCropAndRotation());
} finally {
FlutterRenderer.debugForceSurfaceProducerGlTextures = false;
}
}
@Test
public void ImageReaderSurfaceProducerDoesNotCropOrRotate() {
FlutterRenderer flutterRenderer = engineRule.getFlutterEngine().getRenderer();
TextureRegistry.SurfaceProducer producer = flutterRenderer.createSurfaceProducer();
assertFalse(producer.handlesCropAndRotation());
}
@Test
public void ImageReaderSurfaceProducerIsDestroyedOnTrimMemory() {
FlutterRenderer flutterRenderer = engineRule.getFlutterEngine().getRenderer();

View File

@@ -1651,6 +1651,11 @@ public class PlatformViewsControllerTest {
return null;
}
@Override
public boolean handlesCropAndRotation() {
return false;
}
public void scheduleFrame() {}
};
}