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

Commit 6851e005 authored by Paulsu Su's avatar Paulsu Su
Browse files

uibench: cancel animations when paused.

This prevents the activity from continuing request next app vsync after it has been paused.

Bug: 358345639
Test: ab/L90600030005773761 + local build and run
Flag: TEST_ONLY
Change-Id: Ie2446172e40a155f244d1271420310502d3b1d45
parent f9d7fada
Loading
Loading
Loading
Loading
+23 −8
Original line number Diff line number Diff line
@@ -74,6 +74,9 @@ public class BitmapUploadActivity extends AppCompatActivity {
        }
    }

    private ObjectAnimator mColorValueAnimator;
    private ObjectAnimator mYAnimator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -81,16 +84,28 @@ public class BitmapUploadActivity extends AppCompatActivity {

        // animate color to force bitmap uploads
        UploadView uploadView = findViewById(R.id.upload_view);
        ObjectAnimator colorValueAnimator = ObjectAnimator.ofInt(uploadView, "colorValue", 0, 255);
        colorValueAnimator.setRepeatMode(ValueAnimator.REVERSE);
        colorValueAnimator.setRepeatCount(ValueAnimator.INFINITE);
        colorValueAnimator.start();
        mColorValueAnimator = ObjectAnimator.ofInt(uploadView, "colorValue", 0, 255);
        mColorValueAnimator.setRepeatMode(ValueAnimator.REVERSE);
        mColorValueAnimator.setRepeatCount(ValueAnimator.INFINITE);
        mColorValueAnimator.start();

        // animate scene root to guarantee there's a minimum amount of GPU rendering work
        View uploadRoot = findViewById(R.id.upload_root);
        ObjectAnimator yAnimator = ObjectAnimator.ofFloat(uploadRoot, "translationY", 0, 100);
        yAnimator.setRepeatMode(ValueAnimator.REVERSE);
        yAnimator.setRepeatCount(ValueAnimator.INFINITE);
        yAnimator.start();
        mYAnimator = ObjectAnimator.ofFloat(uploadRoot, "translationY", 0, 100);
        mYAnimator.setRepeatMode(ValueAnimator.REVERSE);
        mYAnimator.setRepeatCount(ValueAnimator.INFINITE);
        mYAnimator.start();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mColorValueAnimator != null) {
            mColorValueAnimator.cancel();
        }

        if (mYAnimator != null) {
            mYAnimator.cancel();
        }
    }
}
+16 −5
Original line number Diff line number Diff line
@@ -66,18 +66,29 @@ public class FullscreenOverdrawActivity extends AppCompatActivity {
            return PixelFormat.OPAQUE;
        }
    }

    private ObjectAnimator mObjectAnimator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        OverdrawDrawable overdraw = new OverdrawDrawable();
        getWindow().setBackgroundDrawable(overdraw);

        setContentView(new View(this));

        ObjectAnimator objectAnimator = ObjectAnimator.ofInt(overdraw, "colorValue", 0, 255);
        objectAnimator.setRepeatMode(ValueAnimator.REVERSE);
        objectAnimator.setRepeatCount(ValueAnimator.INFINITE);
        objectAnimator.start();
        mObjectAnimator = ObjectAnimator.ofInt(overdraw, "colorValue", 0, 255);
        mObjectAnimator.setRepeatMode(ValueAnimator.REVERSE);
        mObjectAnimator.setRepeatCount(ValueAnimator.INFINITE);

        mObjectAnimator.start();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mObjectAnimator != null) {
            mObjectAnimator.cancel();
        }
    }
}
+14 −6
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.test.uibench.opengl.ImageFlipRenderThread;
public class GlTextureViewActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener {
    private ImageFlipRenderThread mRenderThread;
    private TextureView mTextureView;
    private ObjectAnimator mAnimator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -54,17 +55,17 @@ public class GlTextureViewActivity extends AppCompatActivity implements TextureV
        int distance = Math.max(mTextureView.getWidth(), mTextureView.getHeight());
        mTextureView.setCameraDistance(distance * metrics.density);

        ObjectAnimator animator = ObjectAnimator.ofFloat(mTextureView, "rotationY", 0.0f, 360.0f);
        animator.setRepeatMode(ObjectAnimator.REVERSE);
        animator.setRepeatCount(ObjectAnimator.INFINITE);
        animator.setDuration(4000);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        mAnimator = ObjectAnimator.ofFloat(mTextureView, "rotationY", 0.0f, 360.0f);
        mAnimator.setRepeatMode(ObjectAnimator.REVERSE);
        mAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        mAnimator.setDuration(4000);
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mTextureView.invalidate();
            }
        });
        animator.start();
        mAnimator.start();
    }

    @Override
@@ -86,4 +87,11 @@ public class GlTextureViewActivity extends AppCompatActivity implements TextureV
    public void onSurfaceTextureUpdated(SurfaceTexture surface) {
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mAnimator != null) {
            mAnimator.cancel();
        }
    }
}
 No newline at end of file
+13 −4
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public class InvalidateActivity extends AppCompatActivity {
    }

    private ColorView[][] mColorViews;
    private ObjectAnimator mAnimator;

    @SuppressWarnings("unused")
    public void setColorValue(int colorValue) {
@@ -80,9 +81,17 @@ public class InvalidateActivity extends AppCompatActivity {
            }
        }

        ObjectAnimator animator = ObjectAnimator.ofInt(this, "colorValue", 0, 255);
        animator.setRepeatMode(ValueAnimator.REVERSE);
        animator.setRepeatCount(ValueAnimator.INFINITE);
        animator.start();
        mAnimator = ObjectAnimator.ofInt(this, "colorValue", 0, 255);
        mAnimator.setRepeatMode(ValueAnimator.REVERSE);
        mAnimator.setRepeatCount(ValueAnimator.INFINITE);
        mAnimator.start();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mAnimator != null) {
            mAnimator.cancel();
        }
    }
}
+13 −4
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public class InvalidateTreeActivity extends AppCompatActivity {
    private final ArrayList<LinearLayout> mLayouts = new ArrayList<>();

    private int mColorToggle = 0;
    private ObjectAnimator mAnimator;

    private void createQuadTree(LinearLayout parent, int remainingDepth) {
        mLayouts.add(parent);
@@ -71,9 +72,17 @@ public class InvalidateTreeActivity extends AppCompatActivity {
        createQuadTree(root, 8);
        setContentView(root);

        ObjectAnimator animator = ObjectAnimator.ofInt(this, "ignoredValue", 0, 1000);
        animator.setRepeatMode(ValueAnimator.REVERSE);
        animator.setRepeatCount(ValueAnimator.INFINITE);
        animator.start();
        mAnimator = ObjectAnimator.ofInt(this, "ignoredValue", 0, 1000);
        mAnimator.setRepeatMode(ValueAnimator.REVERSE);
        mAnimator.setRepeatCount(ValueAnimator.INFINITE);
        mAnimator.start();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mAnimator != null) {
            mAnimator.cancel();
        }
    }
}