Merge "Improve SurfaceView postion snapping" into nyc-dev am: 987609f

am: 942bd9d

* commit '942bd9dcfa33992f3b1c3a89c54fdfeef45260b7':
  Improve SurfaceView postion snapping

Change-Id: Ifbd2a6dd4c70aa8a64bac8cd5142d79c8928d6f8
This commit is contained in:
Chris Craik
2016-04-26 20:31:32 +00:00
committed by android-build-merger
2 changed files with 28 additions and 15 deletions

View File

@@ -562,6 +562,16 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
bounds.top -= info.windowInsetTop; bounds.top -= info.windowInsetTop;
bounds.bottom -= 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( auto functor = std::bind(
std::mem_fn(&SurfaceViewPositionUpdater::doUpdatePosition), this, std::mem_fn(&SurfaceViewPositionUpdater::doUpdatePosition), this,
(jlong) info.canvasContext.getFrameNumber(), (jlong) info.canvasContext.getFrameNumber(),

View File

@@ -20,33 +20,36 @@ import android.animation.ObjectAnimator;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback; import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View;
import android.view.animation.LinearInterpolator; import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout; import android.widget.FrameLayout;
public class MovingSurfaceViewActivity extends Activity implements Callback { public class MovingSurfaceViewActivity extends Activity implements Callback {
static final String TAG = "MovingSurfaceView";
SurfaceView mSurfaceView; SurfaceView mSurfaceView;
ObjectAnimator mAnimator; ObjectAnimator mAnimator;
class MySurfaceView extends SurfaceView { class MySurfaceView extends SurfaceView {
boolean mSlowToggled; boolean mSlow;
boolean mScaled;
int mToggle = 0;
public MySurfaceView(Context context) { public MySurfaceView(Context context) {
super(context); super(context);
setOnClickListener(new OnClickListener() { setOnClickListener(v -> {
@Override mToggle = (mToggle + 1) % 4;
public void onClick(View v) { mSlow = (mToggle & 0x2) != 0;
mSlowToggled = !mSlowToggled; mScaled = (mToggle & 0x1) != 0;
Log.d(TAG, "SLOW MODE: " + mSlowToggled);
invalidate(); mSurfaceView.setScaleX(mScaled ? 1.6f : 1f);
} mSurfaceView.setScaleY(mScaled ? 0.8f : 1f);
setTitle("Slow=" + mSlow + ", scaled=" + mScaled);
invalidate();
}); });
setWillNotDraw(false); setWillNotDraw(false);
} }
@@ -54,7 +57,7 @@ public class MovingSurfaceViewActivity extends Activity implements Callback {
@Override @Override
public void draw(Canvas canvas) { public void draw(Canvas canvas) {
super.draw(canvas); super.draw(canvas);
if (mSlowToggled) { if (mSlow) {
try { try {
Thread.sleep(16); Thread.sleep(16);
} catch (InterruptedException e) {} } catch (InterruptedException e) {}
@@ -63,7 +66,7 @@ public class MovingSurfaceViewActivity extends Activity implements Callback {
public void setMyTranslationY(float ty) { public void setMyTranslationY(float ty) {
setTranslationY(ty); setTranslationY(ty);
if (mSlowToggled) { if (mSlow) {
invalidate(); invalidate();
} }
} }
@@ -86,7 +89,7 @@ public class MovingSurfaceViewActivity extends Activity implements Callback {
int size = (int) (200 * density); int size = (int) (200 * density);
content.addView(mSurfaceView, new FrameLayout.LayoutParams( content.addView(mSurfaceView, new FrameLayout.LayoutParams(
size, size, Gravity.CENTER)); size, size, Gravity.CENTER_HORIZONTAL | Gravity.TOP));
mAnimator = ObjectAnimator.ofFloat(mSurfaceView, "myTranslationY", mAnimator = ObjectAnimator.ofFloat(mSurfaceView, "myTranslationY",
0, size); 0, size);
mAnimator.setRepeatMode(ObjectAnimator.REVERSE); mAnimator.setRepeatMode(ObjectAnimator.REVERSE);
@@ -103,7 +106,7 @@ public class MovingSurfaceViewActivity extends Activity implements Callback {
@Override @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Canvas canvas = holder.lockCanvas(); Canvas canvas = holder.lockCanvas();
canvas.drawARGB(0xFF, 0x00, 0xFF, 0x00); canvas.drawColor(Color.WHITE);
holder.unlockCanvasAndPost(canvas); holder.unlockCanvasAndPost(canvas);
} }