Remove GlTransformOptions
Remove GlTransformOptions. It's no longer being used. When GL pipeline is enabled, the preview output is always transformed.
Bug: 241910577
Test: manual test and ./gradlew bOS
Change-Id: I14f72bf6cd551379077116c3d6600ea92194ab86
diff --git a/camera/camera-core/src/androidTest/java/androidx/camera/core/processing/DefaultSurfaceProcessorTest.kt b/camera/camera-core/src/androidTest/java/androidx/camera/core/processing/DefaultSurfaceProcessorTest.kt
index 3f88ffa..884de88 100644
--- a/camera/camera-core/src/androidTest/java/androidx/camera/core/processing/DefaultSurfaceProcessorTest.kt
+++ b/camera/camera-core/src/androidTest/java/androidx/camera/core/processing/DefaultSurfaceProcessorTest.kt
@@ -22,7 +22,6 @@
import android.util.Size
import android.view.Surface
import androidx.camera.core.CameraEffect
-import androidx.camera.core.SurfaceOutput.GlTransformOptions.USE_SURFACE_TEXTURE_TRANSFORM
import androidx.camera.core.SurfaceRequest
import androidx.camera.core.impl.DeferrableSurface
import androidx.camera.core.impl.ImageFormatConstants
@@ -315,7 +314,6 @@
CameraEffect.PREVIEW,
ImageFormatConstants.INTERNAL_DEFINED_IMAGE_FORMAT_PRIVATE,
Size(WIDTH, HEIGHT),
- USE_SURFACE_TEXTURE_TRANSFORM,
Size(WIDTH, HEIGHT),
Rect(0, 0, WIDTH, HEIGHT),
/*rotationDegrees=*/0,
diff --git a/camera/camera-core/src/main/java/androidx/camera/core/Preview.java b/camera/camera-core/src/main/java/androidx/camera/core/Preview.java
index c7a93db..f266b2d 100644
--- a/camera/camera-core/src/main/java/androidx/camera/core/Preview.java
+++ b/camera/camera-core/src/main/java/androidx/camera/core/Preview.java
@@ -16,7 +16,6 @@
package androidx.camera.core;
-import static androidx.camera.core.SurfaceOutput.GlTransformOptions.APPLY_CROP_ROTATE_AND_MIRRORING;
import static androidx.camera.core.impl.ImageInputConfig.OPTION_INPUT_FORMAT;
import static androidx.camera.core.impl.ImageOutputConfig.OPTION_APP_TARGET_ROTATION;
import static androidx.camera.core.impl.ImageOutputConfig.OPTION_RESOLUTION_SELECTOR;
@@ -315,8 +314,7 @@
clearPipeline();
// Create nodes and edges.
- mNode = new SurfaceProcessorNode(
- camera, APPLY_CROP_ROTATE_AND_MIRRORING, mSurfaceProcessor);
+ mNode = new SurfaceProcessorNode(camera, mSurfaceProcessor);
SettableSurface cameraSurface = new SettableSurface(
CameraEffect.PREVIEW,
resolution,
diff --git a/camera/camera-core/src/main/java/androidx/camera/core/SurfaceOutput.java b/camera/camera-core/src/main/java/androidx/camera/core/SurfaceOutput.java
index 6bf27c5..1ee0da0 100644
--- a/camera/camera-core/src/main/java/androidx/camera/core/SurfaceOutput.java
+++ b/camera/camera-core/src/main/java/androidx/camera/core/SurfaceOutput.java
@@ -177,16 +177,4 @@
return new AutoValue_SurfaceOutput_Event(code, surfaceOutput);
}
}
-
- /** OpenGL transformation options for SurfaceOutput. */
- enum GlTransformOptions {
- /** Apply only the value of {@link SurfaceTexture#getTransformMatrix(float[])}. */
- USE_SURFACE_TEXTURE_TRANSFORM,
-
- /**
- * Discard the value of {@link SurfaceTexture#getTransformMatrix(float[])} and calculate
- * the transform based on crop rect, rotation degrees and mirroring.
- */
- APPLY_CROP_ROTATE_AND_MIRRORING,
- }
}
diff --git a/camera/camera-core/src/main/java/androidx/camera/core/processing/SettableSurface.java b/camera/camera-core/src/main/java/androidx/camera/core/processing/SettableSurface.java
index 64bd82e..8584670 100644
--- a/camera/camera-core/src/main/java/androidx/camera/core/processing/SettableSurface.java
+++ b/camera/camera-core/src/main/java/androidx/camera/core/processing/SettableSurface.java
@@ -37,7 +37,6 @@
import androidx.annotation.RequiresApi;
import androidx.camera.core.CameraEffect;
import androidx.camera.core.SurfaceOutput;
-import androidx.camera.core.SurfaceOutput.GlTransformOptions;
import androidx.camera.core.SurfaceProcessor;
import androidx.camera.core.SurfaceRequest;
import androidx.camera.core.SurfaceRequest.TransformationInfo;
@@ -254,7 +253,6 @@
* <p>Do not provide the {@link SurfaceOutput} to external target if the
* {@link ListenableFuture} fails.
*
- * @param glTransformOptions OpenGL transformation options for SurfaceOutput
* @param resolution resolution of input image buffer
* @param cropRect crop rect of input image buffer
* @param rotationDegrees expected rotation to the input image buffer
@@ -262,8 +260,7 @@
*/
@MainThread
@NonNull
- public ListenableFuture<SurfaceOutput> createSurfaceOutputFuture(
- @NonNull GlTransformOptions glTransformOptions, @NonNull Size resolution,
+ public ListenableFuture<SurfaceOutput> createSurfaceOutputFuture(@NonNull Size resolution,
@NonNull Rect cropRect, int rotationDegrees, boolean mirroring) {
checkMainThread();
Preconditions.checkState(!mHasConsumer, "Consumer can only be linked once.");
@@ -276,9 +273,9 @@
} catch (SurfaceClosedException e) {
return Futures.immediateFailedFuture(e);
}
- SurfaceOutputImpl surfaceOutputImpl = new SurfaceOutputImpl(
- surface, getTargets(), getFormat(), getSize(), glTransformOptions,
- resolution, cropRect, rotationDegrees, mirroring);
+ SurfaceOutputImpl surfaceOutputImpl = new SurfaceOutputImpl(surface,
+ getTargets(), getFormat(), getSize(), resolution, cropRect,
+ rotationDegrees, mirroring);
surfaceOutputImpl.getCloseFuture().addListener(this::decrementUseCount,
directExecutor());
mConsumerToNotify = surfaceOutputImpl;
diff --git a/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceOutputImpl.java b/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceOutputImpl.java
index 6a2894a..04956c5 100644
--- a/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceOutputImpl.java
+++ b/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceOutputImpl.java
@@ -16,7 +16,6 @@
package androidx.camera.core.processing;
-import static androidx.camera.core.SurfaceOutput.GlTransformOptions.APPLY_CROP_ROTATE_AND_MIRRORING;
import static androidx.camera.core.impl.utils.MatrixExt.preRotate;
import static androidx.camera.core.impl.utils.TransformUtils.getRectToRect;
import static androidx.camera.core.impl.utils.TransformUtils.rotateSize;
@@ -64,7 +63,6 @@
private final int mFormat;
@NonNull
private final Size mSize;
- private final GlTransformOptions mGlTransformOptions;
private final Size mInputSize;
private final Rect mInputCropRect;
private final int mRotationDegrees;
@@ -93,8 +91,6 @@
int targets,
int format,
@NonNull Size size,
- // TODO(b/241910577): remove this flag when PreviewView handles cropped stream.
- @NonNull GlTransformOptions glTransformOptions,
@NonNull Size inputSize,
@NonNull Rect inputCropRect,
int rotationDegree,
@@ -103,20 +99,11 @@
mTargets = targets;
mFormat = format;
mSize = size;
- mGlTransformOptions = glTransformOptions;
mInputSize = inputSize;
mInputCropRect = new Rect(inputCropRect);
mMirroring = mirroring;
-
- if (mGlTransformOptions == APPLY_CROP_ROTATE_AND_MIRRORING) {
- mRotationDegrees = rotationDegree;
- calculateGlTransform();
- } else {
- // TODO(b/241910577): remove this assignment when the PreviewView handles cropped
- // stream.
- mRotationDegrees = 0;
- }
-
+ mRotationDegrees = rotationDegree;
+ calculateGlTransform();
mCloseFuture = CallbackToFutureAdapter.getFuture(
completer -> {
mCloseFutureCompleter = completer;
@@ -248,16 +235,7 @@
@AnyThread
@Override
public void updateTransformMatrix(@NonNull float[] output, @NonNull float[] input) {
- switch (mGlTransformOptions) {
- case USE_SURFACE_TEXTURE_TRANSFORM:
- System.arraycopy(input, 0, output, 0, 16);
- break;
- case APPLY_CROP_ROTATE_AND_MIRRORING:
- System.arraycopy(mGlTransform, 0, output, 0, 16);
- break;
- default:
- throw new AssertionError("Unknown GlTransformOptions: " + mGlTransformOptions);
- }
+ System.arraycopy(input, 0, output, 0, 16);
}
/**
diff --git a/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceProcessorNode.java b/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceProcessorNode.java
index 6007535..347a8ca 100644
--- a/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceProcessorNode.java
+++ b/camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceProcessorNode.java
@@ -36,7 +36,6 @@
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.camera.core.SurfaceOutput;
-import androidx.camera.core.SurfaceOutput.GlTransformOptions;
import androidx.camera.core.SurfaceProcessor;
import androidx.camera.core.SurfaceRequest;
import androidx.camera.core.impl.CameraInternal;
@@ -60,7 +59,6 @@
@SuppressWarnings("UnusedVariable")
public class SurfaceProcessorNode implements Node<SurfaceEdge, SurfaceEdge> {
- private final GlTransformOptions mGlTransformOptions;
@NonNull
final SurfaceProcessorInternal mSurfaceProcessor;
@NonNull
@@ -74,15 +72,12 @@
/**
* Constructs the {@link SurfaceProcessorNode}.
*
- * @param cameraInternal the associated camera instance.
- * @param glTransformOptions the OpenGL transformation options.
- * @param surfaceProcessor the interface to wrap around.
+ * @param cameraInternal the associated camera instance.
+ * @param surfaceProcessor the interface to wrap around.
*/
public SurfaceProcessorNode(@NonNull CameraInternal cameraInternal,
- @NonNull GlTransformOptions glTransformOptions,
@NonNull SurfaceProcessorInternal surfaceProcessor) {
mCameraInternal = cameraInternal;
- mGlTransformOptions = glTransformOptions;
mSurfaceProcessor = surfaceProcessor;
}
@@ -112,63 +107,43 @@
final Runnable onSurfaceInvalidated = inputSurface::invalidate;
SettableSurface outputSurface;
- switch (mGlTransformOptions) {
- case APPLY_CROP_ROTATE_AND_MIRRORING:
- Size resolution = inputSurface.getSize();
- Rect cropRect = inputSurface.getCropRect();
- int rotationDegrees = inputSurface.getRotationDegrees();
- boolean mirroring = inputSurface.getMirroring();
+ Size resolution = inputSurface.getSize();
+ Rect cropRect = inputSurface.getCropRect();
+ int rotationDegrees = inputSurface.getRotationDegrees();
+ boolean mirroring = inputSurface.getMirroring();
- // Calculate rotated resolution and cropRect
- Size rotatedCroppedSize = is90or270(rotationDegrees)
- ? new Size(/*width=*/cropRect.height(), /*height=*/cropRect.width())
- : rectToSize(cropRect);
+ // Calculate rotated resolution and cropRect
+ Size rotatedCroppedSize = is90or270(rotationDegrees)
+ ? new Size(/*width=*/cropRect.height(), /*height=*/cropRect.width())
+ : rectToSize(cropRect);
- // Calculate sensorToBufferTransform
- android.graphics.Matrix sensorToBufferTransform =
- new android.graphics.Matrix(inputSurface.getSensorToBufferTransform());
- android.graphics.Matrix imageTransform = getRectToRect(sizeToRectF(resolution),
- new RectF(cropRect), rotationDegrees, mirroring);
- sensorToBufferTransform.postConcat(imageTransform);
+ // Calculate sensorToBufferTransform
+ android.graphics.Matrix sensorToBufferTransform =
+ new android.graphics.Matrix(inputSurface.getSensorToBufferTransform());
+ android.graphics.Matrix imageTransform = getRectToRect(sizeToRectF(resolution),
+ new RectF(cropRect), rotationDegrees, mirroring);
+ sensorToBufferTransform.postConcat(imageTransform);
- outputSurface = new SettableSurface(
- inputSurface.getTargets(),
- rotatedCroppedSize,
- inputSurface.getFormat(),
- sensorToBufferTransform,
- // The Surface transform cannot be carried over during buffer copy.
- /*hasEmbeddedTransform=*/false,
- sizeToRect(rotatedCroppedSize),
- /*rotationDegrees=*/0,
- /*mirroring=*/false,
- onSurfaceInvalidated);
- break;
- case USE_SURFACE_TEXTURE_TRANSFORM:
- // No transform output as placeholder.
- outputSurface = new SettableSurface(
- inputSurface.getTargets(),
- inputSurface.getSize(),
- inputSurface.getFormat(),
- inputSurface.getSensorToBufferTransform(),
- // The Surface transform cannot be carried over during buffer copy.
- /*hasEmbeddedTransform=*/false,
- inputSurface.getCropRect(),
- inputSurface.getRotationDegrees(),
- inputSurface.getMirroring(),
- onSurfaceInvalidated);
- break;
- default:
- throw new AssertionError("Unknown GlTransformOptions: " + mGlTransformOptions);
- }
+ outputSurface = new SettableSurface(
+ inputSurface.getTargets(),
+ rotatedCroppedSize,
+ inputSurface.getFormat(),
+ sensorToBufferTransform,
+ // The Surface transform cannot be carried over during buffer copy.
+ /*hasEmbeddedTransform=*/false,
+ sizeToRect(rotatedCroppedSize),
+ /*rotationDegrees=*/0,
+ /*mirroring=*/false,
+ onSurfaceInvalidated);
+
return outputSurface;
}
private void sendSurfacesToProcessorWhenReady(@NonNull SettableSurface input,
@NonNull SettableSurface output) {
SurfaceRequest surfaceRequest = input.createSurfaceRequest(mCameraInternal);
- Futures.addCallback(output.createSurfaceOutputFuture(mGlTransformOptions,
- input.getSize(), input.getCropRect(), input.getRotationDegrees(),
- input.getMirroring()),
+ Futures.addCallback(output.createSurfaceOutputFuture(input.getSize(), input.getCropRect(),
+ input.getRotationDegrees(), input.getMirroring()),
new FutureCallback<SurfaceOutput>() {
@Override
public void onSuccess(@Nullable SurfaceOutput surfaceOutput) {
diff --git a/camera/camera-core/src/test/java/androidx/camera/core/processing/SettableSurfaceTest.kt b/camera/camera-core/src/test/java/androidx/camera/core/processing/SettableSurfaceTest.kt
index d2dca35..93b374f 100644
--- a/camera/camera-core/src/test/java/androidx/camera/core/processing/SettableSurfaceTest.kt
+++ b/camera/camera-core/src/test/java/androidx/camera/core/processing/SettableSurfaceTest.kt
@@ -26,7 +26,6 @@
import android.view.Surface
import androidx.camera.core.CameraEffect
import androidx.camera.core.SurfaceOutput
-import androidx.camera.core.SurfaceOutput.GlTransformOptions.USE_SURFACE_TEXTURE_TRANSFORM
import androidx.camera.core.SurfaceRequest
import androidx.camera.core.SurfaceRequest.Result.RESULT_REQUEST_CANCELLED
import androidx.camera.core.SurfaceRequest.TransformationInfo
@@ -310,7 +309,6 @@
private fun createSurfaceOutputFuture(settableSurface: SettableSurface) =
settableSurface.createSurfaceOutputFuture(
- USE_SURFACE_TEXTURE_TRANSFORM,
INPUT_SIZE,
sizeToRect(INPUT_SIZE),
/*rotationDegrees=*/0,
diff --git a/camera/camera-core/src/test/java/androidx/camera/core/processing/SurfaceOutputImplTest.kt b/camera/camera-core/src/test/java/androidx/camera/core/processing/SurfaceOutputImplTest.kt
index 621eb1d..6f44748 100644
--- a/camera/camera-core/src/test/java/androidx/camera/core/processing/SurfaceOutputImplTest.kt
+++ b/camera/camera-core/src/test/java/androidx/camera/core/processing/SurfaceOutputImplTest.kt
@@ -23,8 +23,6 @@
import android.util.Size
import android.view.Surface
import androidx.camera.core.CameraEffect
-import androidx.camera.core.SurfaceOutput.GlTransformOptions
-import androidx.camera.core.SurfaceOutput.GlTransformOptions.USE_SURFACE_TEXTURE_TRANSFORM
import androidx.camera.core.impl.utils.TransformUtils.sizeToRect
import androidx.camera.core.impl.utils.executor.CameraXExecutors.mainThreadExecutor
import com.google.common.truth.Truth.assertThat
@@ -119,29 +117,11 @@
assertThat(hasRequestedClose).isFalse()
}
- @Test
- fun updateMatrix_useSurfaceTextureTransform_sameResult() {
- // Arrange.
- val surfaceOut =
- createFakeSurfaceOutputImpl(glTransformOptions = USE_SURFACE_TEXTURE_TRANSFORM)
-
- // Act.
- val input = floatArrayOf(1f, 1f, 1f, 1f, 2f, 2f, 2f, 2f, 3f, 3f, 3f, 3f, 4f, 4f, 4f, 4f)
- val result = FloatArray(16)
- surfaceOut.updateTransformMatrix(result, input)
-
- // Assert.
- assertThat(result).isEqualTo(input)
- }
-
- private fun createFakeSurfaceOutputImpl(
- glTransformOptions: GlTransformOptions = USE_SURFACE_TEXTURE_TRANSFORM
- ) = SurfaceOutputImpl(
+ private fun createFakeSurfaceOutputImpl() = SurfaceOutputImpl(
fakeSurface,
TARGET,
FORMAT,
OUTPUT_SIZE,
- glTransformOptions,
INPUT_SIZE,
sizeToRect(INPUT_SIZE),
/*rotationDegrees=*/0,
diff --git a/camera/camera-core/src/test/java/androidx/camera/core/processing/SurfaceProcessorNodeTest.kt b/camera/camera-core/src/test/java/androidx/camera/core/processing/SurfaceProcessorNodeTest.kt
index 3027ece..43fac3e 100644
--- a/camera/camera-core/src/test/java/androidx/camera/core/processing/SurfaceProcessorNodeTest.kt
+++ b/camera/camera-core/src/test/java/androidx/camera/core/processing/SurfaceProcessorNodeTest.kt
@@ -24,9 +24,6 @@
import android.util.Size
import android.view.Surface
import androidx.camera.core.CameraEffect.PREVIEW
-import androidx.camera.core.SurfaceOutput.GlTransformOptions
-import androidx.camera.core.SurfaceOutput.GlTransformOptions.APPLY_CROP_ROTATE_AND_MIRRORING
-import androidx.camera.core.SurfaceOutput.GlTransformOptions.USE_SURFACE_TEXTURE_TRANSFORM
import androidx.camera.core.SurfaceRequest
import androidx.camera.core.SurfaceRequest.TransformationInfo
import androidx.camera.core.impl.utils.TransformUtils.is90or270
@@ -94,33 +91,11 @@
}
@Test
- fun transformInput_useSurfaceTextureTransform_outputHasTheSameProperty() {
- // Arrange.
- createSurfaceProcessorNode()
- createInputEdge()
- val inputSurface = inputEdge.surfaces[0]
-
- // Act.
- val outputEdge = node.transform(inputEdge)
-
- // Assert: without transformation, the output has the same property as the input.
- assertThat(outputEdge.surfaces).hasSize(1)
- val outputSurface = outputEdge.surfaces[0]
- assertThat(outputSurface.size).isEqualTo(inputSurface.size)
- assertThat(outputSurface.format).isEqualTo(inputSurface.format)
- assertThat(outputSurface.targets).isEqualTo(inputSurface.targets)
- assertThat(outputSurface.cropRect).isEqualTo(inputSurface.cropRect)
- assertThat(outputSurface.rotationDegrees).isEqualTo(inputSurface.rotationDegrees)
- assertThat(outputSurface.mirroring).isEqualTo(inputSurface.mirroring)
- assertThat(outputSurface.hasEmbeddedTransform()).isFalse()
- }
-
- @Test
fun transformInput_applyCropRotateAndMirroring_outputIsCroppedAndRotated() {
val cropRect = Rect(200, 100, 600, 400)
for (rotationDegrees in arrayOf(0, 90, 180, 270)) {
// Arrange.
- createSurfaceProcessorNode(APPLY_CROP_ROTATE_AND_MIRRORING)
+ createSurfaceProcessorNode()
createInputEdge(
size = rectToSize(cropRect),
cropRect = cropRect,
@@ -153,7 +128,7 @@
fun transformInput_applyCropRotateAndMirroring_outputHasNoMirroring() {
for (mirroring in arrayOf(false, true)) {
// Arrange.
- createSurfaceProcessorNode(APPLY_CROP_ROTATE_AND_MIRRORING)
+ createSurfaceProcessorNode()
createInputEdge(mirroring = mirroring)
// Act.
@@ -173,7 +148,7 @@
@Test
fun transformInput_applyCropRotateAndMirroring_initialTransformInfoIsPropagated() {
// Arrange.
- createSurfaceProcessorNode(APPLY_CROP_ROTATE_AND_MIRRORING)
+ createSurfaceProcessorNode()
createInputEdge(rotationDegrees = 90, cropRect = Rect(0, 0, 600, 400))
// Act.
@@ -192,7 +167,7 @@
@Test
fun setRotationToInput_applyCropRotateAndMirroring_rotationIsPropagated() {
// Arrange.
- createSurfaceProcessorNode(APPLY_CROP_ROTATE_AND_MIRRORING)
+ createSurfaceProcessorNode()
createInputEdge(rotationDegrees = 90)
val inputSurface = inputEdge.surfaces[0]
val outputEdge = node.transform(inputEdge)
@@ -269,12 +244,9 @@
inputEdge = SurfaceEdge.create(listOf(surface))
}
- private fun createSurfaceProcessorNode(
- glTransformOptions: GlTransformOptions = USE_SURFACE_TEXTURE_TRANSFORM
- ) {
+ private fun createSurfaceProcessorNode() {
node = SurfaceProcessorNode(
FakeCamera(),
- glTransformOptions,
surfaceProcessorInternal
)
}
diff --git a/camera/camera-video/src/main/java/androidx/camera/video/VideoCapture.java b/camera/camera-video/src/main/java/androidx/camera/video/VideoCapture.java
index 9234617..5f8641f 100644
--- a/camera/camera-video/src/main/java/androidx/camera/video/VideoCapture.java
+++ b/camera/camera-video/src/main/java/androidx/camera/video/VideoCapture.java
@@ -17,7 +17,6 @@
package androidx.camera.video;
import static androidx.camera.core.CameraEffect.VIDEO_CAPTURE;
-import static androidx.camera.core.SurfaceOutput.GlTransformOptions.APPLY_CROP_ROTATE_AND_MIRRORING;
import static androidx.camera.core.impl.ImageOutputConfig.OPTION_DEFAULT_RESOLUTION;
import static androidx.camera.core.impl.ImageOutputConfig.OPTION_MAX_RESOLUTION;
import static androidx.camera.core.impl.ImageOutputConfig.OPTION_RESOLUTION_SELECTOR;
@@ -735,7 +734,6 @@
if (mSurfaceProcessor != null || ENABLE_SURFACE_PROCESSING_BY_QUIRK || isCropNeeded) {
Logger.d(TAG, "Surface processing is enabled.");
return new SurfaceProcessorNode(requireNonNull(getCamera()),
- APPLY_CROP_ROTATE_AND_MIRRORING,
mSurfaceProcessor != null ? mSurfaceProcessor : new DefaultSurfaceProcessor());
}
return null;