Merge "Clean up setLayerType and setLayerPaint" into nyc-dev

am: 4ce5653

* commit '4ce5653555b3140f1e6190c7cfa44ce416ce3693':
  Clean up setLayerType and setLayerPaint
This commit is contained in:
sergeyv
2016-03-25 01:49:03 +00:00
committed by android-build-merger
4 changed files with 20 additions and 27 deletions

View File

@@ -16,6 +16,7 @@
package android.view; package android.view;
import android.annotation.Nullable;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
@@ -51,8 +52,8 @@ final class HardwareLayer {
* @param paint The paint used when the layer is drawn into the destination canvas. * @param paint The paint used when the layer is drawn into the destination canvas.
* @see View#setLayerPaint(android.graphics.Paint) * @see View#setLayerPaint(android.graphics.Paint)
*/ */
public void setLayerPaint(Paint paint) { public void setLayerPaint(@Nullable Paint paint) {
nSetLayerPaint(mFinalizer.get(), paint.getNativeInstance()); nSetLayerPaint(mFinalizer.get(), paint != null ? paint.getNativeInstance() : 0);
mRenderer.pushLayerUpdate(this); mRenderer.pushLayerUpdate(this);
} }

View File

@@ -259,7 +259,7 @@ public class RenderNode {
return nSetLayerType(mNativeRenderNode, layerType); return nSetLayerType(mNativeRenderNode, layerType);
} }
public boolean setLayerPaint(Paint paint) { public boolean setLayerPaint(@Nullable Paint paint) {
return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.getNativeInstance() : 0); return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.getNativeInstance() : 0);
} }

View File

@@ -16,6 +16,7 @@
package android.view; package android.view;
import android.annotation.Nullable;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
@@ -133,7 +134,6 @@ public class TextureView extends View {
*/ */
public TextureView(Context context) { public TextureView(Context context) {
super(context); super(context);
init();
} }
/** /**
@@ -144,7 +144,6 @@ public class TextureView extends View {
*/ */
public TextureView(Context context, AttributeSet attrs) { public TextureView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
init();
} }
/** /**
@@ -158,7 +157,6 @@ public class TextureView extends View {
*/ */
public TextureView(Context context, AttributeSet attrs, int defStyleAttr) { public TextureView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
init();
} }
/** /**
@@ -176,11 +174,6 @@ public class TextureView extends View {
*/ */
public TextureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public TextureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
mLayerPaint = new Paint();
} }
/** /**
@@ -260,7 +253,7 @@ public class TextureView extends View {
* method will however be taken into account when rendering the content of * method will however be taken into account when rendering the content of
* this TextureView. * this TextureView.
* *
* @param layerType The ype of layer to use with this view, must be one of * @param layerType The type of layer to use with this view, must be one of
* {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or
* {@link #LAYER_TYPE_HARDWARE} * {@link #LAYER_TYPE_HARDWARE}
* @param paint The paint used to compose the layer. This argument is optional * @param paint The paint used to compose the layer. This argument is optional
@@ -268,16 +261,16 @@ public class TextureView extends View {
* {@link #LAYER_TYPE_NONE} * {@link #LAYER_TYPE_NONE}
*/ */
@Override @Override
public void setLayerType(int layerType, Paint paint) { public void setLayerType(int layerType, @Nullable Paint paint) {
if (paint != mLayerPaint) { setLayerPaint(paint);
mLayerPaint = paint == null ? new Paint() : paint;
invalidate();
}
} }
@Override @Override
public void setLayerPaint(Paint paint) { public void setLayerPaint(@Nullable Paint paint) {
setLayerType(/* ignored */ 0, paint); if (paint != mLayerPaint) {
mLayerPaint = paint;
invalidate();
}
} }
/** /**

View File

@@ -11741,7 +11741,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
} }
} }
/** /**
* Utility method to retrieve the inverse of the current mMatrix property. * Utility method to retrieve the inverse of the current mMatrix property.
* We cache the matrix to avoid recalculating it when transform properties * We cache the matrix to avoid recalculating it when transform properties
* have not changed. * have not changed.
@@ -15626,7 +15626,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* *
* @attr ref android.R.styleable#View_layerType * @attr ref android.R.styleable#View_layerType
*/ */
public void setLayerType(int layerType, Paint paint) { public void setLayerType(int layerType, @Nullable Paint paint) {
if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) {
throw new IllegalArgumentException("Layer type can only be one of: LAYER_TYPE_NONE, " throw new IllegalArgumentException("Layer type can only be one of: LAYER_TYPE_NONE, "
+ "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE");
@@ -15645,8 +15645,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
} }
mLayerType = layerType; mLayerType = layerType;
final boolean layerDisabled = (mLayerType == LAYER_TYPE_NONE); mLayerPaint = mLayerType == LAYER_TYPE_NONE ? null : paint;
mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint);
mRenderNode.setLayerPaint(mLayerPaint); mRenderNode.setLayerPaint(mLayerPaint);
// draw() behaves differently if we are on a layer, so we need to // draw() behaves differently if we are on a layer, so we need to
@@ -15680,12 +15679,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* *
* @see #setLayerType(int, android.graphics.Paint) * @see #setLayerType(int, android.graphics.Paint)
*/ */
public void setLayerPaint(Paint paint) { public void setLayerPaint(@Nullable Paint paint) {
int layerType = getLayerType(); int layerType = getLayerType();
if (layerType != LAYER_TYPE_NONE) { if (layerType != LAYER_TYPE_NONE) {
mLayerPaint = paint == null ? new Paint() : paint; mLayerPaint = paint;
if (layerType == LAYER_TYPE_HARDWARE) { if (layerType == LAYER_TYPE_HARDWARE) {
if (mRenderNode.setLayerPaint(mLayerPaint)) { if (mRenderNode.setLayerPaint(paint)) {
invalidateViewProperty(false, false); invalidateViewProperty(false, false);
} }
} else { } else {
@@ -16855,7 +16854,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint);
} else { } else {
// use layer paint to draw the bitmap, merging the two alphas, but also restore // use layer paint to draw the bitmap, merging the two alphas, but also restore
int layerPaintAlpha = mLayerPaint.getAlpha(); int layerPaintAlpha = mLayerPaint != null ? mLayerPaint.getAlpha() : 255;
mLayerPaint.setAlpha((int) (alpha * layerPaintAlpha)); mLayerPaint.setAlpha((int) (alpha * layerPaintAlpha));
canvas.drawBitmap(cache, 0.0f, 0.0f, mLayerPaint); canvas.drawBitmap(cache, 0.0f, 0.0f, mLayerPaint);
mLayerPaint.setAlpha(layerPaintAlpha); mLayerPaint.setAlpha(layerPaintAlpha);