Commit 70cffd8c by hschlueter Committed by Ian Baker

Split configureOutputSize into setInputSize and getOutputSize.

This makes it easier (smaller CL diff) to merge output size
configuration and initialize() in a follow-up.

PiperOrigin-RevId: 438543247
parent d8e5e2de
...@@ -89,6 +89,7 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor { ...@@ -89,6 +89,7 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor {
private final Context context; private final Context context;
private final Matrix transformationMatrix; private final Matrix transformationMatrix;
private @MonotonicNonNull Size size;
private @MonotonicNonNull GlProgram glProgram; private @MonotonicNonNull GlProgram glProgram;
/** /**
...@@ -105,8 +106,13 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor { ...@@ -105,8 +106,13 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor {
} }
@Override @Override
public Size configureOutputSize(int inputWidth, int inputHeight) { public void setInputSize(int inputWidth, int inputHeight) {
return new Size(inputWidth, inputHeight); size = new Size(inputWidth, inputHeight);
}
@Override
public Size getOutputSize() {
return checkStateNotNull(size);
} }
@Override @Override
......
...@@ -51,6 +51,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -51,6 +51,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private final Context context; private final Context context;
private final boolean enableExperimentalHdrEditing; private final boolean enableExperimentalHdrEditing;
private @MonotonicNonNull Size size;
private @MonotonicNonNull GlProgram glProgram; private @MonotonicNonNull GlProgram glProgram;
public ExternalCopyFrameProcessor(Context context, boolean enableExperimentalHdrEditing) { public ExternalCopyFrameProcessor(Context context, boolean enableExperimentalHdrEditing) {
...@@ -59,8 +60,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -59,8 +60,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
@Override @Override
public Size configureOutputSize(int inputWidth, int inputHeight) { public void setInputSize(int inputWidth, int inputHeight) {
return new Size(inputWidth, inputHeight); size = new Size(inputWidth, inputHeight);
}
@Override
public Size getOutputSize() {
return checkStateNotNull(size);
} }
@Override @Override
......
...@@ -28,7 +28,6 @@ import android.opengl.EGLDisplay; ...@@ -28,7 +28,6 @@ import android.opengl.EGLDisplay;
import android.opengl.EGLExt; import android.opengl.EGLExt;
import android.opengl.EGLSurface; import android.opengl.EGLSurface;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.util.Pair;
import android.util.Size; import android.util.Size;
import android.view.Surface; import android.view.Surface;
import android.view.SurfaceView; import android.view.SurfaceView;
...@@ -79,6 +78,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -79,6 +78,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private volatile boolean releaseRequested; private volatile boolean releaseRequested;
private boolean inputStreamEnded; private boolean inputStreamEnded;
private final Size inputSize;
/** Wraps the {@link #inputSurfaceTexture}. */ /** Wraps the {@link #inputSurfaceTexture}. */
private @MonotonicNonNull Surface inputSurface; private @MonotonicNonNull Surface inputSurface;
/** Associated with an OpenGL external texture. */ /** Associated with an OpenGL external texture. */
...@@ -100,11 +100,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -100,11 +100,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* <p>The {@link ExternalCopyFrameProcessor} writes to the first framebuffer. * <p>The {@link ExternalCopyFrameProcessor} writes to the first framebuffer.
*/ */
private final int[] framebuffers; private final int[] framebuffers;
/** The input {@link Size} of each of the {@code frameProcessors}. */
private final ImmutableList<Size> inputSizes;
private int outputWidth; private Size outputSize;
private int outputHeight;
/** /**
* Wraps the output {@link Surface} that is populated with the output of the final {@link * Wraps the output {@link Surface} that is populated with the output of the final {@link
* GlFrameProcessor} for each frame. * GlFrameProcessor} for each frame.
...@@ -154,30 +151,27 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -154,30 +151,27 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
singleThreadExecutorService = Util.newSingleThreadExecutor(THREAD_NAME); singleThreadExecutorService = Util.newSingleThreadExecutor(THREAD_NAME);
futures = new ConcurrentLinkedQueue<>(); futures = new ConcurrentLinkedQueue<>();
pendingFrameCount = new AtomicInteger(); pendingFrameCount = new AtomicInteger();
inputSize = new Size(inputWidth, inputHeight);
textureTransformMatrix = new float[16]; textureTransformMatrix = new float[16];
externalCopyFrameProcessor = externalCopyFrameProcessor =
new ExternalCopyFrameProcessor(context, enableExperimentalHdrEditing); new ExternalCopyFrameProcessor(context, enableExperimentalHdrEditing);
framebuffers = new int[frameProcessors.size()]; framebuffers = new int[frameProcessors.size()];
Pair<ImmutableList<Size>, Size> sizes = configureFrameProcessorSizes(inputSize, frameProcessors);
configureFrameProcessorSizes(inputWidth, inputHeight, frameProcessors); outputSize = frameProcessors.isEmpty() ? inputSize : getLast(frameProcessors).getOutputSize();
inputSizes = sizes.first;
outputWidth = sizes.second.getWidth();
outputHeight = sizes.second.getHeight();
debugPreviewWidth = C.LENGTH_UNSET; debugPreviewWidth = C.LENGTH_UNSET;
debugPreviewHeight = C.LENGTH_UNSET; debugPreviewHeight = C.LENGTH_UNSET;
} }
/** Returns the output {@link Size}. */ /** Returns the output {@link Size}. */
public Size getOutputSize() { public Size getOutputSize() {
return new Size(outputWidth, outputHeight); return outputSize;
} }
/** /**
* Configures the {@code FrameProcessorChain} to process frames to the specified output targets. * Configures the {@code FrameProcessorChain} to process frames to the specified output targets.
* *
* <p>This method may only be called once and may override the {@linkplain * <p>This method may only be called once and may override the {@linkplain
* GlFrameProcessor#configureOutputSize(int, int) output size} of the final {@link * GlFrameProcessor#setInputSize(int, int) output size} of the final {@link GlFrameProcessor}.
* GlFrameProcessor}.
* *
* @param outputSurface The output {@link Surface}. * @param outputSurface The output {@link Surface}.
* @param outputWidth The output width, in pixels. * @param outputWidth The output width, in pixels.
...@@ -196,8 +190,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -196,8 +190,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
checkState(inputSurface == null, "The FrameProcessorChain has already been configured."); checkState(inputSurface == null, "The FrameProcessorChain has already been configured.");
// TODO(b/218488308): Don't override output size for encoder fallback. Instead allow the final // TODO(b/218488308): Don't override output size for encoder fallback. Instead allow the final
// GlFrameProcessor to be re-configured or append another GlFrameProcessor. // GlFrameProcessor to be re-configured or append another GlFrameProcessor.
this.outputWidth = outputWidth; outputSize = new Size(outputWidth, outputHeight);
this.outputHeight = outputHeight;
if (debugSurfaceView != null) { if (debugSurfaceView != null) {
debugPreviewWidth = debugSurfaceView.getWidth(); debugPreviewWidth = debugSurfaceView.getWidth();
...@@ -387,15 +380,16 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -387,15 +380,16 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
inputExternalTexId = GlUtil.createExternalTexture(); inputExternalTexId = GlUtil.createExternalTexture();
Size inputSize = inputSizes.get(0); externalCopyFrameProcessor.setInputSize(inputSize.getWidth(), inputSize.getHeight());
externalCopyFrameProcessor.configureOutputSize(inputSize.getWidth(), inputSize.getHeight());
externalCopyFrameProcessor.initialize(inputExternalTexId); externalCopyFrameProcessor.initialize(inputExternalTexId);
Size intermediateSize = inputSize;
for (int i = 0; i < frameProcessors.size(); i++) { for (int i = 0; i < frameProcessors.size(); i++) {
inputSize = inputSizes.get(i); int inputTexId =
int inputTexId = GlUtil.createTexture(inputSize.getWidth(), inputSize.getHeight()); GlUtil.createTexture(intermediateSize.getWidth(), intermediateSize.getHeight());
framebuffers[i] = GlUtil.createFboForTexture(inputTexId); framebuffers[i] = GlUtil.createFboForTexture(inputTexId);
frameProcessors.get(i).initialize(inputTexId); frameProcessors.get(i).initialize(inputTexId);
intermediateSize = frameProcessors.get(i).getOutputSize();
} }
// Return something because only Callables not Runnables can throw checked exceptions. // Return something because only Callables not Runnables can throw checked exceptions.
return null; return null;
...@@ -414,15 +408,16 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -414,15 +408,16 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
checkStateNotNull(eglDisplay); checkStateNotNull(eglDisplay);
if (frameProcessors.isEmpty()) { if (frameProcessors.isEmpty()) {
GlUtil.focusEglSurface(eglDisplay, eglContext, eglSurface, outputWidth, outputHeight); GlUtil.focusEglSurface(
eglDisplay, eglContext, eglSurface, outputSize.getWidth(), outputSize.getHeight());
} else { } else {
GlUtil.focusFramebuffer( GlUtil.focusFramebuffer(
eglDisplay, eglDisplay,
eglContext, eglContext,
eglSurface, eglSurface,
framebuffers[0], framebuffers[0],
inputSizes.get(0).getWidth(), inputSize.getWidth(),
inputSizes.get(0).getHeight()); inputSize.getHeight());
} }
inputSurfaceTexture.updateTexImage(); inputSurfaceTexture.updateTexImage();
inputSurfaceTexture.getTransformMatrix(textureTransformMatrix); inputSurfaceTexture.getTransformMatrix(textureTransformMatrix);
...@@ -433,19 +428,20 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -433,19 +428,20 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
externalCopyFrameProcessor.updateProgramAndDraw(presentationTimeUs); externalCopyFrameProcessor.updateProgramAndDraw(presentationTimeUs);
for (int i = 0; i < frameProcessors.size() - 1; i++) { for (int i = 0; i < frameProcessors.size() - 1; i++) {
Size outputSize = inputSizes.get(i + 1); Size intermediateSize = frameProcessors.get(i).getOutputSize();
GlUtil.focusFramebuffer( GlUtil.focusFramebuffer(
eglDisplay, eglDisplay,
eglContext, eglContext,
eglSurface, eglSurface,
framebuffers[i + 1], framebuffers[i + 1],
outputSize.getWidth(), intermediateSize.getWidth(),
outputSize.getHeight()); intermediateSize.getHeight());
clearOutputFrame(); clearOutputFrame();
frameProcessors.get(i).updateProgramAndDraw(presentationTimeUs); frameProcessors.get(i).updateProgramAndDraw(presentationTimeUs);
} }
if (!frameProcessors.isEmpty()) { if (!frameProcessors.isEmpty()) {
GlUtil.focusEglSurface(eglDisplay, eglContext, eglSurface, outputWidth, outputHeight); GlUtil.focusEglSurface(
eglDisplay, eglContext, eglSurface, outputSize.getWidth(), outputSize.getHeight());
clearOutputFrame(); clearOutputFrame();
getLast(frameProcessors).updateProgramAndDraw(presentationTimeUs); getLast(frameProcessors).updateProgramAndDraw(presentationTimeUs);
} }
...@@ -474,26 +470,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -474,26 +470,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
/** /**
* Configures the input and output {@linkplain Size sizes} of a list of {@link GlFrameProcessor * Configures the input and output {@linkplain Size sizes} of a list of {@link GlFrameProcessor
* GlFrameProcessors}. * GlFrameProcessors}.
*
* @param inputWidth The width of frames passed to the first {@link GlFrameProcessor}, in pixels.
* @param inputHeight The height of frames passed to the first {@link GlFrameProcessor}, in
* pixels.
* @param frameProcessors The {@link GlFrameProcessor GlFrameProcessors}.
* @return The input {@link Size} of each {@link GlFrameProcessor} and the output {@link Size} of
* the final {@link GlFrameProcessor}.
*/ */
private static Pair<ImmutableList<Size>, Size> configureFrameProcessorSizes( private static void configureFrameProcessorSizes(
int inputWidth, int inputHeight, List<GlFrameProcessor> frameProcessors) { Size inputSize, List<GlFrameProcessor> frameProcessors) {
Size size = new Size(inputWidth, inputHeight);
if (frameProcessors.isEmpty()) {
return Pair.create(ImmutableList.of(size), size);
}
ImmutableList.Builder<Size> inputSizes = new ImmutableList.Builder<>();
for (int i = 0; i < frameProcessors.size(); i++) { for (int i = 0; i < frameProcessors.size(); i++) {
inputSizes.add(size); frameProcessors.get(i).setInputSize(inputSize.getWidth(), inputSize.getHeight());
size = frameProcessors.get(i).configureOutputSize(size.getWidth(), size.getHeight()); inputSize = frameProcessors.get(i).getOutputSize();
} }
return Pair.create(inputSizes.build(), size);
} }
} }
...@@ -26,7 +26,7 @@ import java.io.IOException; ...@@ -26,7 +26,7 @@ import java.io.IOException;
* *
* <ol> * <ol>
* <li>The constructor, for implementation-specific arguments. * <li>The constructor, for implementation-specific arguments.
* <li>{@link #configureOutputSize(int, int)}, to configure based on input dimensions. * <li>{@link #setInputSize(int, int)}, to configure based on input dimensions.
* <li>{@link #initialize(int)}, to set up graphics initialization. * <li>{@link #initialize(int)}, to set up graphics initialization.
* <li>{@link #updateProgramAndDraw(long)}, to process one frame. * <li>{@link #updateProgramAndDraw(long)}, to process one frame.
* <li>{@link #release()}, upon conclusion of processing. * <li>{@link #release()}, upon conclusion of processing.
...@@ -39,12 +39,23 @@ public interface GlFrameProcessor { ...@@ -39,12 +39,23 @@ public interface GlFrameProcessor {
// configureOutputSize to a simple getter. // configureOutputSize to a simple getter.
/** /**
* Sets the input size of frames processed through {@link #updateProgramAndDraw(long)}.
*
* <p>This method must be called before {@link #initialize(int)} and does not use OpenGL, as
* calling this method without a current OpenGL context is allowed.
*
* <p>After setting the input size, the output size can be obtained using {@link
* #getOutputSize()}.
*/
void setInputSize(int inputWidth, int inputHeight);
/**
* Returns the output {@link Size} of frames processed through {@link * Returns the output {@link Size} of frames processed through {@link
* #updateProgramAndDraw(long)}. * #updateProgramAndDraw(long)}.
* *
* <p>This method must be called before {@link #initialize(int)} and does not use OpenGL. * <p>Must call {@link #setInputSize(int, int)} before calling this method.
*/ */
Size configureOutputSize(int inputWidth, int inputHeight); Size getOutputSize();
/** /**
* Does any initialization necessary such as loading and compiling a GLSL shader programs. * Does any initialization necessary such as loading and compiling a GLSL shader programs.
......
...@@ -84,6 +84,7 @@ public final class PresentationFrameProcessor implements GlFrameProcessor { ...@@ -84,6 +84,7 @@ public final class PresentationFrameProcessor implements GlFrameProcessor {
private int inputWidth; private int inputWidth;
private int inputHeight; private int inputHeight;
private int outputRotationDegrees; private int outputRotationDegrees;
private @MonotonicNonNull Size outputSize;
private @MonotonicNonNull Matrix transformationMatrix; private @MonotonicNonNull Matrix transformationMatrix;
/** /**
...@@ -106,7 +107,7 @@ public final class PresentationFrameProcessor implements GlFrameProcessor { ...@@ -106,7 +107,7 @@ public final class PresentationFrameProcessor implements GlFrameProcessor {
* *
* <p>Return values may be {@code 0} or {@code 90} degrees. * <p>Return values may be {@code 0} or {@code 90} degrees.
* *
* <p>This method can only be called after {@link #configureOutputSize(int, int)}. * <p>This method can only be called after {@link #setInputSize(int, int)}.
*/ */
public int getOutputRotationDegrees() { public int getOutputRotationDegrees() {
checkState(outputRotationDegrees != C.LENGTH_UNSET); checkState(outputRotationDegrees != C.LENGTH_UNSET);
...@@ -114,7 +115,7 @@ public final class PresentationFrameProcessor implements GlFrameProcessor { ...@@ -114,7 +115,7 @@ public final class PresentationFrameProcessor implements GlFrameProcessor {
} }
@Override @Override
public Size configureOutputSize(int inputWidth, int inputHeight) { public void setInputSize(int inputWidth, int inputHeight) {
this.inputWidth = inputWidth; this.inputWidth = inputWidth;
this.inputHeight = inputHeight; this.inputHeight = inputHeight;
transformationMatrix = new Matrix(); transformationMatrix = new Matrix();
...@@ -136,18 +137,23 @@ public final class PresentationFrameProcessor implements GlFrameProcessor { ...@@ -136,18 +137,23 @@ public final class PresentationFrameProcessor implements GlFrameProcessor {
// TODO(b/201293185): After fragment shader transformations are implemented, put // TODO(b/201293185): After fragment shader transformations are implemented, put
// postRotate in a later GlFrameProcessor. // postRotate in a later GlFrameProcessor.
transformationMatrix.postRotate(outputRotationDegrees); transformationMatrix.postRotate(outputRotationDegrees);
return new Size(displayHeight, displayWidth); outputSize = new Size(displayHeight, displayWidth);
} else { } else {
outputRotationDegrees = 0; outputRotationDegrees = 0;
return new Size(displayWidth, displayHeight); outputSize = new Size(displayWidth, displayHeight);
} }
} }
@Override @Override
public Size getOutputSize() {
return checkStateNotNull(outputSize);
}
@Override
public void initialize(int inputTexId) throws IOException { public void initialize(int inputTexId) throws IOException {
checkStateNotNull(transformationMatrix); checkStateNotNull(transformationMatrix);
advancedFrameProcessor = new AdvancedFrameProcessor(context, transformationMatrix); advancedFrameProcessor = new AdvancedFrameProcessor(context, transformationMatrix);
advancedFrameProcessor.configureOutputSize(inputWidth, inputHeight); advancedFrameProcessor.setInputSize(inputWidth, inputHeight);
advancedFrameProcessor.initialize(inputTexId); advancedFrameProcessor.initialize(inputTexId);
} }
......
...@@ -102,6 +102,7 @@ public final class ScaleToFitFrameProcessor implements GlFrameProcessor { ...@@ -102,6 +102,7 @@ public final class ScaleToFitFrameProcessor implements GlFrameProcessor {
private @MonotonicNonNull AdvancedFrameProcessor advancedFrameProcessor; private @MonotonicNonNull AdvancedFrameProcessor advancedFrameProcessor;
private int inputWidth; private int inputWidth;
private int inputHeight; private int inputHeight;
private @MonotonicNonNull Size outputSize;
private @MonotonicNonNull Matrix adjustedTransformationMatrix; private @MonotonicNonNull Matrix adjustedTransformationMatrix;
/** /**
...@@ -125,13 +126,14 @@ public final class ScaleToFitFrameProcessor implements GlFrameProcessor { ...@@ -125,13 +126,14 @@ public final class ScaleToFitFrameProcessor implements GlFrameProcessor {
} }
@Override @Override
public Size configureOutputSize(int inputWidth, int inputHeight) { public void setInputSize(int inputWidth, int inputHeight) {
this.inputWidth = inputWidth; this.inputWidth = inputWidth;
this.inputHeight = inputHeight; this.inputHeight = inputHeight;
adjustedTransformationMatrix = new Matrix(transformationMatrix); adjustedTransformationMatrix = new Matrix(transformationMatrix);
if (transformationMatrix.isIdentity()) { if (transformationMatrix.isIdentity()) {
return new Size(inputWidth, inputHeight); outputSize = new Size(inputWidth, inputHeight);
return;
} }
float inputAspectRatio = (float) inputWidth / inputHeight; float inputAspectRatio = (float) inputWidth / inputHeight;
...@@ -161,17 +163,19 @@ public final class ScaleToFitFrameProcessor implements GlFrameProcessor { ...@@ -161,17 +163,19 @@ public final class ScaleToFitFrameProcessor implements GlFrameProcessor {
float xScale = (xMax - xMin) / ndcWidthAndHeight; float xScale = (xMax - xMin) / ndcWidthAndHeight;
float yScale = (yMax - yMin) / ndcWidthAndHeight; float yScale = (yMax - yMin) / ndcWidthAndHeight;
adjustedTransformationMatrix.postScale(1f / xScale, 1f / yScale); adjustedTransformationMatrix.postScale(1f / xScale, 1f / yScale);
outputSize = new Size(Math.round(inputWidth * xScale), Math.round(inputHeight * yScale));
}
int outputWidth = Math.round(inputWidth * xScale); @Override
int outputHeight = Math.round(inputHeight * yScale); public Size getOutputSize() {
return new Size(outputWidth, outputHeight); return checkStateNotNull(outputSize);
} }
@Override @Override
public void initialize(int inputTexId) throws IOException { public void initialize(int inputTexId) throws IOException {
checkStateNotNull(adjustedTransformationMatrix); checkStateNotNull(adjustedTransformationMatrix);
advancedFrameProcessor = new AdvancedFrameProcessor(context, adjustedTransformationMatrix); advancedFrameProcessor = new AdvancedFrameProcessor(context, adjustedTransformationMatrix);
advancedFrameProcessor.configureOutputSize(inputWidth, inputHeight); advancedFrameProcessor.setInputSize(inputWidth, inputHeight);
advancedFrameProcessor.initialize(inputTexId); advancedFrameProcessor.initialize(inputTexId);
} }
......
...@@ -27,27 +27,28 @@ import org.junit.runner.RunWith; ...@@ -27,27 +27,28 @@ import org.junit.runner.RunWith;
/** /**
* Unit tests for {@link AdvancedFrameProcessor}. * Unit tests for {@link AdvancedFrameProcessor}.
* *
* <p>See {@link AdvancedFrameProcessorPixelTest} for pixel tests testing {@link * <p>See {@code AdvancedFrameProcessorPixelTest} for pixel tests testing {@link
* AdvancedFrameProcessor} given a transformation matrix. * AdvancedFrameProcessor} given a transformation matrix.
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class AdvancedFrameProcessorTest { public final class AdvancedFrameProcessorTest {
@Test @Test
public void getOutputDimensions_withIdentityMatrix_leavesDimensionsUnchanged() { public void getOutputSize_withIdentityMatrix_leavesSizeUnchanged() {
Matrix identityMatrix = new Matrix(); Matrix identityMatrix = new Matrix();
int inputWidth = 200; int inputWidth = 200;
int inputHeight = 150; int inputHeight = 150;
AdvancedFrameProcessor advancedFrameProcessor = AdvancedFrameProcessor advancedFrameProcessor =
new AdvancedFrameProcessor(getApplicationContext(), identityMatrix); new AdvancedFrameProcessor(getApplicationContext(), identityMatrix);
Size outputSize = advancedFrameProcessor.configureOutputSize(inputWidth, inputHeight); advancedFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = advancedFrameProcessor.getOutputSize();
assertThat(outputSize.getWidth()).isEqualTo(inputWidth); assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
} }
@Test @Test
public void getOutputDimensions_withTransformationMatrix_leavesDimensionsUnchanged() { public void getOutputSize_withTransformationMatrix_leavesSizeUnchanged() {
Matrix transformationMatrix = new Matrix(); Matrix transformationMatrix = new Matrix();
transformationMatrix.postRotate(/* degrees= */ 90); transformationMatrix.postRotate(/* degrees= */ 90);
transformationMatrix.postScale(/* sx= */ .5f, /* sy= */ 1.2f); transformationMatrix.postScale(/* sx= */ .5f, /* sy= */ 1.2f);
...@@ -56,7 +57,8 @@ public final class AdvancedFrameProcessorTest { ...@@ -56,7 +57,8 @@ public final class AdvancedFrameProcessorTest {
AdvancedFrameProcessor advancedFrameProcessor = AdvancedFrameProcessor advancedFrameProcessor =
new AdvancedFrameProcessor(getApplicationContext(), transformationMatrix); new AdvancedFrameProcessor(getApplicationContext(), transformationMatrix);
Size outputSize = advancedFrameProcessor.configureOutputSize(inputWidth, inputHeight); advancedFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = advancedFrameProcessor.getOutputSize();
assertThat(outputSize.getWidth()).isEqualTo(inputWidth); assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
......
...@@ -139,7 +139,10 @@ public final class FrameProcessorChainTest { ...@@ -139,7 +139,10 @@ public final class FrameProcessorChainTest {
} }
@Override @Override
public Size configureOutputSize(int inputWidth, int inputHeight) { public void setInputSize(int inputWidth, int inputHeight) {}
@Override
public Size getOutputSize() {
return outputSize; return outputSize;
} }
......
...@@ -33,13 +33,14 @@ import org.junit.runner.RunWith; ...@@ -33,13 +33,14 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class PresentationFrameProcessorTest { public final class PresentationFrameProcessorTest {
@Test @Test
public void configureOutputSize_noEditsLandscape_leavesFramesUnchanged() { public void getOutputSize_noEditsLandscape_leavesFramesUnchanged() {
int inputWidth = 200; int inputWidth = 200;
int inputHeight = 150; int inputHeight = 150;
PresentationFrameProcessor presentationFrameProcessor = PresentationFrameProcessor presentationFrameProcessor =
new PresentationFrameProcessor.Builder(getApplicationContext()).build(); new PresentationFrameProcessor.Builder(getApplicationContext()).build();
Size outputSize = presentationFrameProcessor.configureOutputSize(inputWidth, inputHeight); presentationFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = presentationFrameProcessor.getOutputSize();
assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(0); assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(0);
assertThat(outputSize.getWidth()).isEqualTo(inputWidth); assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
...@@ -47,13 +48,14 @@ public final class PresentationFrameProcessorTest { ...@@ -47,13 +48,14 @@ public final class PresentationFrameProcessorTest {
} }
@Test @Test
public void configureOutputSize_noEditsSquare_leavesFramesUnchanged() { public void getOutputSize_noEditsSquare_leavesFramesUnchanged() {
int inputWidth = 150; int inputWidth = 150;
int inputHeight = 150; int inputHeight = 150;
PresentationFrameProcessor presentationFrameProcessor = PresentationFrameProcessor presentationFrameProcessor =
new PresentationFrameProcessor.Builder(getApplicationContext()).build(); new PresentationFrameProcessor.Builder(getApplicationContext()).build();
Size outputSize = presentationFrameProcessor.configureOutputSize(inputWidth, inputHeight); presentationFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = presentationFrameProcessor.getOutputSize();
assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(0); assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(0);
assertThat(outputSize.getWidth()).isEqualTo(inputWidth); assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
...@@ -61,13 +63,14 @@ public final class PresentationFrameProcessorTest { ...@@ -61,13 +63,14 @@ public final class PresentationFrameProcessorTest {
} }
@Test @Test
public void configureOutputSize_noEditsPortrait_flipsOrientation() { public void getOutputSize_noEditsPortrait_flipsOrientation() {
int inputWidth = 150; int inputWidth = 150;
int inputHeight = 200; int inputHeight = 200;
PresentationFrameProcessor presentationFrameProcessor = PresentationFrameProcessor presentationFrameProcessor =
new PresentationFrameProcessor.Builder(getApplicationContext()).build(); new PresentationFrameProcessor.Builder(getApplicationContext()).build();
Size outputSize = presentationFrameProcessor.configureOutputSize(inputWidth, inputHeight); presentationFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = presentationFrameProcessor.getOutputSize();
assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(90); assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(90);
assertThat(outputSize.getWidth()).isEqualTo(inputHeight); assertThat(outputSize.getWidth()).isEqualTo(inputHeight);
...@@ -75,7 +78,7 @@ public final class PresentationFrameProcessorTest { ...@@ -75,7 +78,7 @@ public final class PresentationFrameProcessorTest {
} }
@Test @Test
public void configureOutputSize_setResolution_changesDimensions() { public void getOutputSize_setResolution_changesDimensions() {
int inputWidth = 200; int inputWidth = 200;
int inputHeight = 150; int inputHeight = 150;
int requestedHeight = 300; int requestedHeight = 300;
...@@ -84,7 +87,8 @@ public final class PresentationFrameProcessorTest { ...@@ -84,7 +87,8 @@ public final class PresentationFrameProcessorTest {
.setResolution(requestedHeight) .setResolution(requestedHeight)
.build(); .build();
Size outputSize = presentationFrameProcessor.configureOutputSize(inputWidth, inputHeight); presentationFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = presentationFrameProcessor.getOutputSize();
assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(0); assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(0);
assertThat(outputSize.getWidth()).isEqualTo(requestedHeight * inputWidth / inputHeight); assertThat(outputSize.getWidth()).isEqualTo(requestedHeight * inputWidth / inputHeight);
...@@ -96,7 +100,7 @@ public final class PresentationFrameProcessorTest { ...@@ -96,7 +100,7 @@ public final class PresentationFrameProcessorTest {
PresentationFrameProcessor presentationFrameProcessor = PresentationFrameProcessor presentationFrameProcessor =
new PresentationFrameProcessor.Builder(getApplicationContext()).build(); new PresentationFrameProcessor.Builder(getApplicationContext()).build();
// configureOutputSize not called before initialize. // configureOutputSize not called before getOutputRotationDegrees.
assertThrows(IllegalStateException.class, presentationFrameProcessor::getOutputRotationDegrees); assertThrows(IllegalStateException.class, presentationFrameProcessor::getOutputRotationDegrees);
} }
} }
...@@ -34,13 +34,14 @@ import org.junit.runner.RunWith; ...@@ -34,13 +34,14 @@ import org.junit.runner.RunWith;
public final class ScaleToFitFrameProcessorTest { public final class ScaleToFitFrameProcessorTest {
@Test @Test
public void configureOutputSize_noEdits_leavesFramesUnchanged() { public void getOutputSize_noEdits_leavesFramesUnchanged() {
int inputWidth = 200; int inputWidth = 200;
int inputHeight = 150; int inputHeight = 150;
ScaleToFitFrameProcessor scaleToFitFrameProcessor = ScaleToFitFrameProcessor scaleToFitFrameProcessor =
new ScaleToFitFrameProcessor.Builder(getApplicationContext()).build(); new ScaleToFitFrameProcessor.Builder(getApplicationContext()).build();
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight); scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
assertThat(outputSize.getWidth()).isEqualTo(inputWidth); assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
...@@ -58,7 +59,7 @@ public final class ScaleToFitFrameProcessorTest { ...@@ -58,7 +59,7 @@ public final class ScaleToFitFrameProcessorTest {
} }
@Test @Test
public void configureOutputSize_scaleNarrow_decreasesWidth() { public void getOutputSize_scaleNarrow_decreasesWidth() {
int inputWidth = 200; int inputWidth = 200;
int inputHeight = 150; int inputHeight = 150;
ScaleToFitFrameProcessor scaleToFitFrameProcessor = ScaleToFitFrameProcessor scaleToFitFrameProcessor =
...@@ -66,14 +67,15 @@ public final class ScaleToFitFrameProcessorTest { ...@@ -66,14 +67,15 @@ public final class ScaleToFitFrameProcessorTest {
.setScale(/* scaleX= */ .5f, /* scaleY= */ 1f) .setScale(/* scaleX= */ .5f, /* scaleY= */ 1f)
.build(); .build();
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight); scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
assertThat(outputSize.getWidth()).isEqualTo(Math.round(inputWidth * .5f)); assertThat(outputSize.getWidth()).isEqualTo(Math.round(inputWidth * .5f));
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
} }
@Test @Test
public void configureOutputSize_scaleWide_increasesWidth() { public void getOutputSize_scaleWide_increasesWidth() {
int inputWidth = 200; int inputWidth = 200;
int inputHeight = 150; int inputHeight = 150;
ScaleToFitFrameProcessor scaleToFitFrameProcessor = ScaleToFitFrameProcessor scaleToFitFrameProcessor =
...@@ -81,14 +83,15 @@ public final class ScaleToFitFrameProcessorTest { ...@@ -81,14 +83,15 @@ public final class ScaleToFitFrameProcessorTest {
.setScale(/* scaleX= */ 2f, /* scaleY= */ 1f) .setScale(/* scaleX= */ 2f, /* scaleY= */ 1f)
.build(); .build();
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight); scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
assertThat(outputSize.getWidth()).isEqualTo(inputWidth * 2); assertThat(outputSize.getWidth()).isEqualTo(inputWidth * 2);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight); assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
} }
@Test @Test
public void configureOutputDimensions_scaleTall_increasesHeight() { public void getOutputSize_scaleTall_increasesHeight() {
int inputWidth = 200; int inputWidth = 200;
int inputHeight = 150; int inputHeight = 150;
ScaleToFitFrameProcessor scaleToFitFrameProcessor = ScaleToFitFrameProcessor scaleToFitFrameProcessor =
...@@ -96,14 +99,15 @@ public final class ScaleToFitFrameProcessorTest { ...@@ -96,14 +99,15 @@ public final class ScaleToFitFrameProcessorTest {
.setScale(/* scaleX= */ 1f, /* scaleY= */ 2f) .setScale(/* scaleX= */ 1f, /* scaleY= */ 2f)
.build(); .build();
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight); scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
assertThat(outputSize.getWidth()).isEqualTo(inputWidth); assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
assertThat(outputSize.getHeight()).isEqualTo(inputHeight * 2); assertThat(outputSize.getHeight()).isEqualTo(inputHeight * 2);
} }
@Test @Test
public void configureOutputSize_rotate90_swapsDimensions() { public void getOutputSize_rotate90_swapsDimensions() {
int inputWidth = 200; int inputWidth = 200;
int inputHeight = 150; int inputHeight = 150;
ScaleToFitFrameProcessor scaleToFitFrameProcessor = ScaleToFitFrameProcessor scaleToFitFrameProcessor =
...@@ -111,14 +115,15 @@ public final class ScaleToFitFrameProcessorTest { ...@@ -111,14 +115,15 @@ public final class ScaleToFitFrameProcessorTest {
.setRotationDegrees(90) .setRotationDegrees(90)
.build(); .build();
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight); scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
assertThat(outputSize.getWidth()).isEqualTo(inputHeight); assertThat(outputSize.getWidth()).isEqualTo(inputHeight);
assertThat(outputSize.getHeight()).isEqualTo(inputWidth); assertThat(outputSize.getHeight()).isEqualTo(inputWidth);
} }
@Test @Test
public void configureOutputSize_rotate45_changesDimensions() { public void getOutputSize_rotate45_changesDimensions() {
int inputWidth = 200; int inputWidth = 200;
int inputHeight = 150; int inputHeight = 150;
ScaleToFitFrameProcessor scaleToFitFrameProcessor = ScaleToFitFrameProcessor scaleToFitFrameProcessor =
...@@ -127,7 +132,8 @@ public final class ScaleToFitFrameProcessorTest { ...@@ -127,7 +132,8 @@ public final class ScaleToFitFrameProcessorTest {
.build(); .build();
long expectedOutputWidthHeight = 247; long expectedOutputWidthHeight = 247;
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight); scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
assertThat(outputSize.getWidth()).isEqualTo(expectedOutputWidthHeight); assertThat(outputSize.getWidth()).isEqualTo(expectedOutputWidthHeight);
assertThat(outputSize.getHeight()).isEqualTo(expectedOutputWidthHeight); assertThat(outputSize.getHeight()).isEqualTo(expectedOutputWidthHeight);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment