Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5af71f2 authored by Pannag Sanketi's avatar Pannag Sanketi
Browse files

Fixing the weird preview size w/ effects on camera

The aspect ratio sent from the camera app to the SurfaceTextureTarget
filter  does not really matter now since the camera app handles
the re-sizing. Hence, the SurfaceTextureTarget filter needs to be render
in "stretch" mode all the time even though the aspect ratio sent to the
filter might indicate otherwise. The filter still needs the correct
frame size for things other than determining aspect ratio.

Fix b/6430124

Change-Id: Ie7fa5cd2adf2a8d41e6e005418f6c6fd738ed85d
parent 2411c336
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -376,8 +376,6 @@ public class MediaEncoderFilter extends Filter {

    @Override
    public void process(FilterContext context) {
        if (mLogVerbose) Log.v(TAG, "Starting frame processing");

        GLEnvironment glEnv = context.getGLEnvironment();
        // Get input frame
        Frame input = pullInput("videoframe");
+15 −3
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ public class SurfaceTextureTarget extends Filter {
    }

    public void updateRenderMode() {
        if (mLogVerbose) Log.v(TAG, "updateRenderMode. Thread: " + Thread.currentThread());
        if (mRenderModeString != null) {
            if (mRenderModeString.equals("stretch")) {
                mRenderMode = RENDERMODE_STRETCH;
@@ -139,6 +140,7 @@ public class SurfaceTextureTarget extends Filter {

    @Override
    public void prepare(FilterContext context) {
        if (mLogVerbose) Log.v(TAG, "Prepare. Thread: " + Thread.currentThread());
        // Create identity shader to render, and make sure to render upside-down, as textures
        // are stored internally bottom-to-top.
        mProgram = ShaderProgram.createIdentity(context);
@@ -214,8 +216,10 @@ public class SurfaceTextureTarget extends Filter {
        float currentAspectRatio =
          (float)input.getFormat().getWidth() / input.getFormat().getHeight();
        if (currentAspectRatio != mAspectRatio) {
            if (mLogVerbose) Log.v(TAG, "New aspect ratio: " + currentAspectRatio +
                ", previously: " + mAspectRatio);
            if (mLogVerbose) {
                Log.v(TAG, "Process. New aspect ratio: " + currentAspectRatio +
                    ", previously: " + mAspectRatio + ". Thread: " + Thread.currentThread());
            }
            mAspectRatio = currentAspectRatio;
            updateTargetRect();
        }
@@ -249,6 +253,7 @@ public class SurfaceTextureTarget extends Filter {

    @Override
    public void fieldPortValueUpdated(String name, FilterContext context) {
        if (mLogVerbose) Log.v(TAG, "FPVU. Thread: " + Thread.currentThread());
        updateRenderMode();
    }

@@ -260,16 +265,22 @@ public class SurfaceTextureTarget extends Filter {
    }

    private void updateTargetRect() {
        if (mLogVerbose) Log.v(TAG, "updateTargetRect. Thread: " + Thread.currentThread());
        if (mScreenWidth > 0 && mScreenHeight > 0 && mProgram != null) {
            float screenAspectRatio = (float)mScreenWidth / mScreenHeight;
            float relativeAspectRatio = screenAspectRatio / mAspectRatio;
            if (mLogVerbose) {
                Log.v(TAG, "UTR. screen w = " + (float)mScreenWidth + " x screen h = " +
                    (float)mScreenHeight + " Screen AR: " + screenAspectRatio +
                    ", frame AR: "  + mAspectRatio + ", relative AR: " + relativeAspectRatio);
            }

            if (relativeAspectRatio == 1.0f && mRenderMode != RENDERMODE_CUSTOMIZE) {
                mProgram.setTargetRect(0, 0, 1, 1);
                mProgram.setClearsOutput(false);
            } else {
                switch (mRenderMode) {
                    case RENDERMODE_STRETCH:
                        mProgram.setTargetRect(0, 0, 1, 1);
                        mTargetQuad.p0.set(0f, 0.0f);
                        mTargetQuad.p1.set(1f, 0.0f);
                        mTargetQuad.p2.set(0f, 1.0f);
@@ -313,6 +324,7 @@ public class SurfaceTextureTarget extends Filter {
                        ((ShaderProgram) mProgram).setSourceRegion(mSourceQuad);
                        break;
                }
                if (mLogVerbose) Log.v(TAG,  "UTR. quad: " + mTargetQuad);
                ((ShaderProgram) mProgram).setTargetRegion(mTargetQuad);
            }
        }