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

Commit 342a7e6a authored by sergeyv's avatar sergeyv
Browse files

Clean up setLayerType and setLayerPaint

bug:21755299
Change-Id: I8f0953ccfc3d743abdecc8ec228ed3e1b6718c3c
parent e60d72f4
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import android.annotation.Nullable;
import android.graphics.Bitmap;
import android.graphics.Matrix;
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.
     * @see View#setLayerPaint(android.graphics.Paint)
     */
    public void setLayerPaint(Paint paint) {
        nSetLayerPaint(mFinalizer.get(), paint.getNativeInstance());
    public void setLayerPaint(@Nullable Paint paint) {
        nSetLayerPaint(mFinalizer.get(), paint != null ? paint.getNativeInstance() : 0);
        mRenderer.pushLayerUpdate(this);
    }

+1 −1
Original line number Diff line number Diff line
@@ -259,7 +259,7 @@ public class RenderNode {
        return nSetLayerType(mNativeRenderNode, layerType);
    }

    public boolean setLayerPaint(Paint paint) {
    public boolean setLayerPaint(@Nullable Paint paint) {
        return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.getNativeInstance() : 0);
    }

+9 −16
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -133,7 +134,6 @@ public class TextureView extends View {
     */
    public TextureView(Context context) {
        super(context);
        init();
    }

    /**
@@ -144,7 +144,6 @@ public class TextureView extends View {
     */
    public TextureView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    /**
@@ -158,7 +157,6 @@ public class TextureView extends View {
     */
    public TextureView(Context context, AttributeSet attrs, int 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) {
        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
     * 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_HARDWARE}
     * @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}
     */
    @Override
    public void setLayerType(int layerType, Paint paint) {
        if (paint != mLayerPaint) {
            mLayerPaint = paint == null ? new Paint() : paint;
            invalidate();
        }
    public void setLayerType(int layerType, @Nullable Paint paint) {
        setLayerPaint(paint);
    }

    @Override
    public void setLayerPaint(Paint paint) {
        setLayerType(/* ignored */ 0, paint);
    public void setLayerPaint(@Nullable Paint paint) {
        if (paint != mLayerPaint) {
            mLayerPaint = paint;
            invalidate();
        }
    }

    /**
+7 −8
Original line number Diff line number Diff line
@@ -15626,7 +15626,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     *
     * @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) {
            throw new IllegalArgumentException("Layer type can only be one of: LAYER_TYPE_NONE, "
                    + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE");
@@ -15645,8 +15645,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
        mLayerType = layerType;
        final boolean layerDisabled = (mLayerType == LAYER_TYPE_NONE);
        mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint);
        mLayerPaint = mLayerType == LAYER_TYPE_NONE ? null : paint;
        mRenderNode.setLayerPaint(mLayerPaint);
        // 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)
     */
    public void setLayerPaint(Paint paint) {
    public void setLayerPaint(@Nullable Paint paint) {
        int layerType = getLayerType();
        if (layerType != LAYER_TYPE_NONE) {
            mLayerPaint = paint == null ? new Paint() : paint;
            mLayerPaint = paint;
            if (layerType == LAYER_TYPE_HARDWARE) {
                if (mRenderNode.setLayerPaint(mLayerPaint)) {
                if (mRenderNode.setLayerPaint(paint)) {
                    invalidateViewProperty(false, false);
                }
            } else {
@@ -16855,7 +16854,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint);
            } else {
                // 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));
                canvas.drawBitmap(cache, 0.0f, 0.0f, mLayerPaint);
                mLayerPaint.setAlpha(layerPaintAlpha);