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

Commit d15ebf25 authored by Chet Haase's avatar Chet Haase
Browse files

Enable changing properties of layer paint

Previously, to draw a layered view with a changed Paint object for the
drawLayer operation, you'd have to invalidate the parent view, to get the
native DisplayList to pick up the new Paint properties. This change adds
API and functionality so that the developer can call setLayerPaint(), which
does the proper invalidation (lightweight, doesn't cause redrawing the view).

Issue #6923810 Make it easy to efficiently animate a layer's Paint

Change-Id: I7fea79788d50f6d9c86dd5e5b2a4490cb95142bb
parent 4db5d23d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25027,6 +25027,7 @@ package android.view {
    method public void setId(int);
    method public void setImportantForAccessibility(int);
    method public void setKeepScreenOn(boolean);
    method public void setLayerPaint(android.graphics.Paint);
    method public void setLayerType(int, android.graphics.Paint);
    method public void setLayoutDirection(int);
    method public void setLayoutParams(android.view.ViewGroup.LayoutParams);
+4 −7
Original line number Diff line number Diff line
@@ -152,6 +152,8 @@ class GLES20Canvas extends HardwareCanvas {
    static native int nCreateLayer(int width, int height, boolean isOpaque, int[] layerInfo);
    static native void nResizeLayer(int layerId, int width, int height, int[] layerInfo);
    static native void nSetOpaqueLayer(int layerId, boolean isOpaque);
    static native void nSetLayerPaint(int layerId, int nativePaint);
    static native void nSetLayerColorFilter(int layerId, int nativeColorFilter);
    static native void nUpdateTextureLayer(int layerId, int width, int height, boolean opaque,
            SurfaceTexture surface);
    static native void nSetTextureLayerTransform(int layerId, int matrix);
@@ -394,13 +396,8 @@ class GLES20Canvas extends HardwareCanvas {
    
    void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint) {
        final GLES20Layer glLayer = (GLES20Layer) layer;
        int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE;
        try {
        final int nativePaint = paint == null ? 0 : paint.mNativePaint;
        nDrawLayer(mRenderer, glLayer.getLayer(), x, y, nativePaint);
        } finally {
            if (modifier != MODIFIER_NONE) nResetModifiers(mRenderer, modifier);
        }
    }

    private static native void nDrawLayer(int renderer, int layer, float x, float y, int paint);
+10 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
package android.view;

import android.graphics.Bitmap;
import android.graphics.Paint;

/**
 * An OpenGL ES 2.0 implementation of {@link HardwareLayer}.
@@ -42,6 +43,15 @@ abstract class GLES20Layer extends HardwareLayer {
        return mLayer;
    }

    @Override
    void setLayerPaint(Paint paint) {
        if (paint != null) {
            GLES20Canvas.nSetLayerPaint(mLayer, paint.mNativePaint);
            GLES20Canvas.nSetLayerColorFilter(mLayer, paint.getColorFilter() != null ?
                    paint.getColorFilter().nativeColorFilter : 0);
        }
    }

    @Override
    boolean copyInto(Bitmap bitmap) {
        return GLES20Canvas.nCopyLayer(mLayer, bitmap.mNativeBitmap);
+9 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.view;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;

/**
@@ -61,6 +62,14 @@ abstract class HardwareLayer {
        mOpaque = isOpaque;
    }

    /**
     * Update the paint used when drawing this layer.
     *
     * @param paint The paint used when the layer is drawn into the destination canvas.
     * @see View#setLayerPaint(android.graphics.Paint)
     */
    void setLayerPaint(Paint paint) {}

    /**
     * Returns the minimum width of the layer.
     * 
+1 −0
Original line number Diff line number Diff line
@@ -367,6 +367,7 @@ public class TextureView extends View {
            if (mListener != null && !mUpdateSurface) {
                mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight());
            }
            mLayer.setLayerPaint(mLayerPaint);
        }

        if (mUpdateSurface) {
Loading