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

Commit 987609f5 authored by Chris Craik's avatar Chris Craik Committed by Android (Google) Code Review
Browse files

Merge "Improve SurfaceView postion snapping" into nyc-dev

parents 6e3a90d9 0e974e74
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -562,6 +562,16 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
            bounds.top -= info.windowInsetTop;
            bounds.bottom -= info.windowInsetTop;

            if (CC_LIKELY(transform.isPureTranslate())) {
                // snap/round the computed bounds, so they match the rounding behavior
                // of the clear done in SurfaceView#draw().
                bounds.snapToPixelBoundaries();
            } else {
                // Conservatively round out so the punched hole (in the ZOrderOnTop = true case)
                // doesn't extend beyond the other window
                bounds.roundOut();
            }

            auto functor = std::bind(
                std::mem_fn(&SurfaceViewPositionUpdater::doUpdatePosition), this,
                (jlong) info.canvasContext.getFrameNumber(),
+18 −15
Original line number Diff line number Diff line
@@ -20,33 +20,36 @@ import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout;

public class MovingSurfaceViewActivity extends Activity implements Callback {
    static final String TAG = "MovingSurfaceView";
    SurfaceView mSurfaceView;
    ObjectAnimator mAnimator;

    class MySurfaceView extends SurfaceView {
        boolean mSlowToggled;
        boolean mSlow;
        boolean mScaled;
        int mToggle = 0;

        public MySurfaceView(Context context) {
            super(context);
            setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    mSlowToggled = !mSlowToggled;
                    Log.d(TAG, "SLOW MODE: " + mSlowToggled);
            setOnClickListener(v -> {
                mToggle = (mToggle + 1) % 4;
                mSlow = (mToggle & 0x2) != 0;
                mScaled = (mToggle & 0x1) != 0;

                mSurfaceView.setScaleX(mScaled ? 1.6f : 1f);
                mSurfaceView.setScaleY(mScaled ? 0.8f : 1f);

                setTitle("Slow=" + mSlow + ", scaled=" + mScaled);
                invalidate();
                }
            });
            setWillNotDraw(false);
        }
@@ -54,7 +57,7 @@ public class MovingSurfaceViewActivity extends Activity implements Callback {
        @Override
        public void draw(Canvas canvas) {
            super.draw(canvas);
            if (mSlowToggled) {
            if (mSlow) {
                try {
                    Thread.sleep(16);
                } catch (InterruptedException e) {}
@@ -63,7 +66,7 @@ public class MovingSurfaceViewActivity extends Activity implements Callback {

        public void setMyTranslationY(float ty) {
            setTranslationY(ty);
            if (mSlowToggled) {
            if (mSlow) {
                invalidate();
            }
        }
@@ -86,7 +89,7 @@ public class MovingSurfaceViewActivity extends Activity implements Callback {
        int size = (int) (200 * density);

        content.addView(mSurfaceView, new FrameLayout.LayoutParams(
                size, size, Gravity.CENTER));
                size, size, Gravity.CENTER_HORIZONTAL | Gravity.TOP));
        mAnimator = ObjectAnimator.ofFloat(mSurfaceView, "myTranslationY",
                0, size);
        mAnimator.setRepeatMode(ObjectAnimator.REVERSE);
@@ -103,7 +106,7 @@ public class MovingSurfaceViewActivity extends Activity implements Callback {
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        Canvas canvas = holder.lockCanvas();
        canvas.drawARGB(0xFF, 0x00, 0xFF, 0x00);
        canvas.drawColor(Color.WHITE);
        holder.unlockCanvasAndPost(canvas);
    }