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

Commit a753f4c6 authored by Chris Craik's avatar Chris Craik
Browse files

Move ClipBounds to native

bug:15698973

Also simplifies RenderNode LTRB properties

Change-Id: I09263a697b71d325a46b57cd5250a2b165f251c8
parent 543650bb
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.Pools.SynchronizedPool;

/**
@@ -41,7 +42,6 @@ class GLES20RecordingCanvas extends GLES20Canvas {

    static GLES20RecordingCanvas obtain(@NonNull RenderNode node) {
        if (node == null) throw new IllegalArgumentException("node cannot be null");

        GLES20RecordingCanvas canvas = sPool.acquire();
        if (canvas == null) {
            canvas = new GLES20RecordingCanvas();
@@ -58,4 +58,9 @@ class GLES20RecordingCanvas extends GLES20Canvas {
    long finishRecording() {
        return nFinishRecording(mRenderer);
    }

    @Override
    public boolean isRecordingFor(Object o) {
        return o == mNode;
    }
}
+17 −55
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@
package android.view;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Matrix;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Rect;

/**
 * <p>A display list records a series of graphics related operations and can replay
@@ -294,13 +296,6 @@ public class RenderNode {
    // RenderProperty Setters
    ///////////////////////////////////////////////////////////////////////////

    /**
     * Set the caching property on the display list, which indicates whether the display list
     * holds a layer. Layer display lists should avoid creating an alpha layer, since alpha is
     * handled in the drawLayer operation directly (and more efficiently).
     *
     * @param caching true if the display list represents a hardware layer, false otherwise.
     */
    public boolean setLayerType(int layerType) {
        return nSetLayerType(mNativeRenderNode, layerType);
    }
@@ -309,6 +304,14 @@ public class RenderNode {
        return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.mNativePaint : 0);
    }

    public boolean setClipBounds(@Nullable Rect rect) {
        if (rect == null) {
            return nSetClipBoundsEmpty(mNativeRenderNode);
        } else {
            return nSetClipBounds(mNativeRenderNode, rect.left, rect.top, rect.right, rect.bottom);
        }
    }

    /**
     * Set whether the Render node should clip itself to its bounds. This property is controlled by
     * the view's parent.
@@ -702,84 +705,44 @@ public class RenderNode {
     * @param left The left position, in pixels, of the display list
     *
     * @see View#setLeft(int)
     * @see #getLeft()
     */
    public boolean setLeft(int left) {
        return nSetLeft(mNativeRenderNode, left);
    }

    /**
     * Returns the left position for the display list in pixels.
     *
     * @see #setLeft(int)
     */
    public float getLeft() {
        return nGetLeft(mNativeRenderNode);
    }

    /**
     * Sets the top position for the display list.
     *
     * @param top The top position, in pixels, of the display list
     *
     * @see View#setTop(int)
     * @see #getTop()
     */
    public boolean setTop(int top) {
        return nSetTop(mNativeRenderNode, top);
    }

    /**
     * Returns the top position for the display list in pixels.
     *
     * @see #setTop(int)
     */
    public float getTop() {
        return nGetTop(mNativeRenderNode);
    }

    /**
     * Sets the right position for the display list.
     *
     * @param right The right position, in pixels, of the display list
     *
     * @see View#setRight(int)
     * @see #getRight()
     */
    public boolean setRight(int right) {
        return nSetRight(mNativeRenderNode, right);
    }

    /**
     * Returns the right position for the display list in pixels.
     *
     * @see #setRight(int)
     */
    public float getRight() {
        return nGetRight(mNativeRenderNode);
    }

    /**
     * Sets the bottom position for the display list.
     *
     * @param bottom The bottom position, in pixels, of the display list
     *
     * @see View#setBottom(int)
     * @see #getBottom()
     */
    public boolean setBottom(int bottom) {
        return nSetBottom(mNativeRenderNode, bottom);
    }

    /**
     * Returns the bottom position for the display list in pixels.
     *
     * @see #setBottom(int)
     */
    public float getBottom() {
        return nGetBottom(mNativeRenderNode);
    }

    /**
     * Sets the left and top positions for the display list
     *
@@ -805,7 +768,7 @@ public class RenderNode {
     *
     * @see View#offsetLeftAndRight(int)
     */
    public boolean offsetLeftAndRight(float offset) {
    public boolean offsetLeftAndRight(int offset) {
        return nOffsetLeftAndRight(mNativeRenderNode, offset);
    }

@@ -817,7 +780,7 @@ public class RenderNode {
     *
     * @see View#offsetTopAndBottom(int)
     */
    public boolean offsetTopAndBottom(float offset) {
    public boolean offsetTopAndBottom(int offset) {
        return nOffsetTopAndBottom(mNativeRenderNode, offset);
    }

@@ -860,8 +823,8 @@ public class RenderNode {

    // Properties

    private static native boolean nOffsetTopAndBottom(long renderNode, float offset);
    private static native boolean nOffsetLeftAndRight(long renderNode, float offset);
    private static native boolean nOffsetTopAndBottom(long renderNode, int offset);
    private static native boolean nOffsetLeftAndRight(long renderNode, int offset);
    private static native boolean nSetLeftTopRightBottom(long renderNode, int left, int top,
            int right, int bottom);
    private static native boolean nSetBottom(long renderNode, int bottom);
@@ -874,6 +837,9 @@ public class RenderNode {
    private static native boolean nSetLayerType(long renderNode, int layerType);
    private static native boolean nSetLayerPaint(long renderNode, long paint);
    private static native boolean nSetClipToBounds(long renderNode, boolean clipToBounds);
    private static native boolean nSetClipBounds(long renderNode, int left, int top,
            int right, int bottom);
    private static native boolean nSetClipBoundsEmpty(long renderNode);
    private static native boolean nSetProjectBackwards(long renderNode, boolean shouldProject);
    private static native boolean nSetProjectionReceiver(long renderNode, boolean shouldRecieve);
    private static native boolean nSetOutlineRoundRect(long renderNode, int left, int top,
@@ -902,10 +868,6 @@ public class RenderNode {
    private static native boolean nHasOverlappingRendering(long renderNode);
    private static native boolean nGetClipToOutline(long renderNode);
    private static native float nGetAlpha(long renderNode);
    private static native float nGetLeft(long renderNode);
    private static native float nGetTop(long renderNode);
    private static native float nGetRight(long renderNode);
    private static native float nGetBottom(long renderNode);
    private static native float nGetCameraDistance(long renderNode);
    private static native float nGetScaleX(long renderNode);
    private static native float nGetScaleY(long renderNode);
+20 −26
Original line number Diff line number Diff line
@@ -723,11 +723,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    private static boolean sIgnoreMeasureCache = false;
    /**
     * Ignore the clipBounds of this view for the children.
     */
    static boolean sIgnoreClipBoundsForChildren = false;
    /**
     * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when
     * calling setFlags.
@@ -3558,9 +3553,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            // of whether a layout was requested on that View.
            sIgnoreMeasureCache = targetSdkVersion < KITKAT;
            // Older apps may need this to ignore the clip bounds
            sIgnoreClipBoundsForChildren = targetSdkVersion < L;
            sCompatibilityDone = true;
        }
    }
@@ -14309,6 +14301,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                mClipBounds = null;
            }
        }
        mRenderNode.setClipBounds(mClipBounds);
    }
    /**
@@ -14430,7 +14423,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * to be called from anywhere else other than ViewGroup.drawChild().
     */
    boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
        boolean useDisplayListProperties = mAttachInfo != null && mAttachInfo.mHardwareAccelerated;
        boolean usingRenderNodeProperties = mAttachInfo != null && mAttachInfo.mHardwareAccelerated;
        boolean more = false;
        final boolean childHasIdentityMatrix = hasIdentityMatrix();
        final int flags = parent.mGroupFlags;
@@ -14471,7 +14464,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                mRenderNode.setAnimationMatrix(null);
                mPrivateFlags3 &= ~PFLAG3_VIEW_IS_ANIMATING_TRANSFORM;
            }
            if (!useDisplayListProperties &&
            if (!usingRenderNodeProperties &&
                    (flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) {
                final Transformation t = parent.getChildTransformation();
                final boolean hasTransform = parent.getChildStaticTransformation(this, t);
@@ -14519,7 +14512,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            } else {
                switch (layerType) {
                    case LAYER_TYPE_SOFTWARE:
                        if (useDisplayListProperties) {
                        if (usingRenderNodeProperties) {
                            hasDisplayList = canHaveDisplayList();
                        } else {
                            buildDrawingCache(true);
@@ -14527,7 +14520,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                        }
                        break;
                    case LAYER_TYPE_HARDWARE:
                        if (useDisplayListProperties) {
                        if (usingRenderNodeProperties) {
                            hasDisplayList = canHaveDisplayList();
                        }
                        break;
@@ -14539,8 +14532,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                }
            }
        }
        useDisplayListProperties &= hasDisplayList;
        if (useDisplayListProperties) {
        usingRenderNodeProperties &= hasDisplayList;
        if (usingRenderNodeProperties) {
            renderNode = getDisplayList();
            if (!renderNode.isValid()) {
                // Uncommon, but possible. If a view is removed from the hierarchy during the call
@@ -14548,7 +14541,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                // try to use it again.
                renderNode = null;
                hasDisplayList = false;
                useDisplayListProperties = false;
                usingRenderNodeProperties = false;
            }
        }
@@ -14565,17 +14558,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                layerType != LAYER_TYPE_HARDWARE;
        int restoreTo = -1;
        if (!useDisplayListProperties || transformToApply != null) {
        if (!usingRenderNodeProperties || transformToApply != null) {
            restoreTo = canvas.save();
        }
        if (offsetForScroll) {
            canvas.translate(mLeft - sx, mTop - sy);
        } else {
            if (!useDisplayListProperties) {
            if (!usingRenderNodeProperties) {
                canvas.translate(mLeft, mTop);
            }
            if (scalingRequired) {
                if (useDisplayListProperties) {
                if (usingRenderNodeProperties) {
                    // TODO: Might not need this if we put everything inside the DL
                    restoreTo = canvas.save();
                }
@@ -14585,7 +14578,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            }
        }
        float alpha = useDisplayListProperties ? 1 : (getAlpha() * getTransitionAlpha());
        float alpha = usingRenderNodeProperties ? 1 : (getAlpha() * getTransitionAlpha());
        if (transformToApply != null || alpha < 1 ||  !hasIdentityMatrix() ||
                (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) {
            if (transformToApply != null || !childHasIdentityMatrix) {
@@ -14599,7 +14592,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                if (transformToApply != null) {
                    if (concatMatrix) {
                        if (useDisplayListProperties) {
                        if (usingRenderNodeProperties) {
                            renderNode.setAnimationMatrix(transformToApply.getMatrix());
                        } else {
                            // Undo the scroll translation, apply the transformation matrix,
@@ -14618,7 +14611,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                    }
                }
                if (!childHasIdentityMatrix && !useDisplayListProperties) {
                if (!childHasIdentityMatrix && !usingRenderNodeProperties) {
                    canvas.translate(-transX, -transY);
                    canvas.concat(getMatrix());
                    canvas.translate(transX, transY);
@@ -14642,7 +14635,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                                layerType != LAYER_TYPE_NONE) {
                            layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG;
                        }
                        if (useDisplayListProperties) {
                        if (usingRenderNodeProperties) {
                            renderNode.setAlpha(alpha * getAlpha() * getTransitionAlpha());
                        } else  if (layerType == LAYER_TYPE_NONE) {
                            final int scrollX = hasDisplayList ? 0 : sx;
@@ -14662,7 +14655,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
        if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) == ViewGroup.FLAG_CLIP_CHILDREN &&
                !useDisplayListProperties && cache == null) {
                !usingRenderNodeProperties && cache == null) {
            if (offsetForScroll) {
                canvas.clipRect(sx, sy, sx + (mRight - mLeft), sy + (mBottom - mTop));
            } else {
@@ -14674,7 +14667,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            }
        }
        if (!useDisplayListProperties && hasDisplayList) {
        if (!usingRenderNodeProperties && hasDisplayList) {
            renderNode = getDisplayList();
            if (!renderNode.isValid()) {
                // Uncommon, but possible. If a view is removed from the hierarchy during the call
@@ -14687,7 +14680,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        if (hasNoCache) {
            boolean layerRendered = false;
            if (layerType == LAYER_TYPE_HARDWARE && !useDisplayListProperties) {
            if (layerType == LAYER_TYPE_HARDWARE && !usingRenderNodeProperties) {
                final HardwareLayer layer = getHardwareLayer();
                if (layer != null && layer.isValid()) {
                    mLayerPaint.setAlpha((int) (alpha * 255));
@@ -14774,7 +14767,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * @param canvas The Canvas to which the View is rendered.
     */
    public void draw(Canvas canvas) {
        if (mClipBounds != null) {
        boolean usingRenderNodeProperties = canvas.isRecordingFor(mRenderNode);
        if (mClipBounds != null && !usingRenderNodeProperties) {
            canvas.clipRect(mClipBounds);
        }
        final int privateFlags = mPrivateFlags;
+3 −2
Original line number Diff line number Diff line
@@ -3015,6 +3015,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     */
    @Override
    protected void dispatchDraw(Canvas canvas) {
        boolean usingRenderNodeProperties = canvas.isRecordingFor(mRenderNode);
        final int childrenCount = mChildrenCount;
        final View[] children = mChildren;
        int flags = mGroupFlags;
@@ -3059,7 +3060,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

        int clipSaveCount = 0;
        final boolean clipToPadding = (flags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK;
        boolean hasClipBounds = mClipBounds != null && !sIgnoreClipBoundsForChildren;
        boolean hasClipBounds = mClipBounds != null && !usingRenderNodeProperties;
        boolean clippingNeeded = clipToPadding || hasClipBounds;

        if (clippingNeeded) {
@@ -3087,7 +3088,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

        // Only use the preordered list if not HW accelerated, since the HW pipeline will do the
        // draw reordering internally
        final ArrayList<View> preorderedList = canvas.isHardwareAccelerated()
        final ArrayList<View> preorderedList = usingRenderNodeProperties
                ? null : buildOrderedChildList();
        final boolean customOrder = preorderedList == null
                && isChildrenDrawingOrderEnabled();
+17 −32
Original line number Diff line number Diff line
@@ -117,6 +117,17 @@ static jboolean android_view_RenderNode_setClipToBounds(JNIEnv* env,
    return SET_AND_DIRTY(setClipToBounds, clipToBounds, RenderNode::GENERIC);
}

static jboolean android_view_RenderNode_setClipBounds(JNIEnv* env,
        jobject clazz, jlong renderNodePtr, jint left, jint top, jint right, jint bottom) {
    android::uirenderer::Rect clipBounds(left, top, right, bottom);
    return SET_AND_DIRTY(setClipBounds, clipBounds, RenderNode::GENERIC);
}

static jboolean android_view_RenderNode_setClipBoundsEmpty(JNIEnv* env,
        jobject clazz, jlong renderNodePtr) {
    return SET_AND_DIRTY(setClipBoundsEmpty,, RenderNode::GENERIC);
}

static jboolean android_view_RenderNode_setProjectBackwards(JNIEnv* env,
        jobject clazz, jlong renderNodePtr, jboolean shouldProject) {
    return SET_AND_DIRTY(setProjectBackwards, shouldProject, RenderNode::GENERIC);
@@ -282,12 +293,12 @@ static jboolean android_view_RenderNode_setLeftTopRightBottom(JNIEnv* env,
}

static jboolean android_view_RenderNode_offsetLeftAndRight(JNIEnv* env,
        jobject clazz, jlong renderNodePtr, float offset) {
        jobject clazz, jlong renderNodePtr, jint offset) {
    return SET_AND_DIRTY(offsetLeftRight, offset, RenderNode::X);
}

static jboolean android_view_RenderNode_offsetTopAndBottom(JNIEnv* env,
        jobject clazz, jlong renderNodePtr, float offset) {
        jobject clazz, jlong renderNodePtr, jint offset) {
    return SET_AND_DIRTY(offsetTopBottom, offset, RenderNode::Y);
}

@@ -313,30 +324,6 @@ static jfloat android_view_RenderNode_getAlpha(JNIEnv* env,
    return renderNode->stagingProperties().getAlpha();
}

static jfloat android_view_RenderNode_getLeft(JNIEnv* env,
        jobject clazz, jlong renderNodePtr) {
    RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
    return renderNode->stagingProperties().getLeft();
}

static jfloat android_view_RenderNode_getTop(JNIEnv* env,
        jobject clazz, jlong renderNodePtr) {
    RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
    return renderNode->stagingProperties().getTop();
}

static jfloat android_view_RenderNode_getRight(JNIEnv* env,
        jobject clazz, jlong renderNodePtr) {
    RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
    return renderNode->stagingProperties().getRight();
}

static jfloat android_view_RenderNode_getBottom(JNIEnv* env,
        jobject clazz, jlong renderNodePtr) {
    RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
    return renderNode->stagingProperties().getBottom();
}

static jfloat android_view_RenderNode_getCameraDistance(JNIEnv* env,
        jobject clazz, jlong renderNodePtr) {
    RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
@@ -488,6 +475,8 @@ static JNINativeMethod gMethods[] = {
    { "nSetStaticMatrix",      "(JJ)Z",  (void*) android_view_RenderNode_setStaticMatrix },
    { "nSetAnimationMatrix",   "(JJ)Z",  (void*) android_view_RenderNode_setAnimationMatrix },
    { "nSetClipToBounds",      "(JZ)Z",  (void*) android_view_RenderNode_setClipToBounds },
    { "nSetClipBounds",        "(JIIII)Z", (void*) android_view_RenderNode_setClipBounds },
    { "nSetClipBoundsEmpty",   "(J)Z",   (void*) android_view_RenderNode_setClipBoundsEmpty },
    { "nSetProjectBackwards",  "(JZ)Z",  (void*) android_view_RenderNode_setProjectBackwards },
    { "nSetProjectionReceiver","(JZ)Z",  (void*) android_view_RenderNode_setProjectionReceiver },

@@ -518,16 +507,12 @@ static JNINativeMethod gMethods[] = {
    { "nSetRight",             "(JI)Z",  (void*) android_view_RenderNode_setRight },
    { "nSetBottom",            "(JI)Z",  (void*) android_view_RenderNode_setBottom },
    { "nSetLeftTopRightBottom","(JIIII)Z", (void*) android_view_RenderNode_setLeftTopRightBottom },
    { "nOffsetLeftAndRight",   "(JF)Z",  (void*) android_view_RenderNode_offsetLeftAndRight },
    { "nOffsetTopAndBottom",   "(JF)Z",  (void*) android_view_RenderNode_offsetTopAndBottom },
    { "nOffsetLeftAndRight",   "(JI)Z",  (void*) android_view_RenderNode_offsetLeftAndRight },
    { "nOffsetTopAndBottom",   "(JI)Z",  (void*) android_view_RenderNode_offsetTopAndBottom },

    { "nHasOverlappingRendering", "(J)Z",  (void*) android_view_RenderNode_hasOverlappingRendering },
    { "nGetClipToOutline",        "(J)Z",  (void*) android_view_RenderNode_getClipToOutline },
    { "nGetAlpha",                "(J)F",  (void*) android_view_RenderNode_getAlpha },
    { "nGetLeft",                 "(J)F",  (void*) android_view_RenderNode_getLeft },
    { "nGetTop",                  "(J)F",  (void*) android_view_RenderNode_getTop },
    { "nGetRight",                "(J)F",  (void*) android_view_RenderNode_getRight },
    { "nGetBottom",               "(J)F",  (void*) android_view_RenderNode_getBottom },
    { "nGetCameraDistance",       "(J)F",  (void*) android_view_RenderNode_getCameraDistance },
    { "nGetScaleX",               "(J)F",  (void*) android_view_RenderNode_getScaleX },
    { "nGetScaleY",               "(J)F",  (void*) android_view_RenderNode_getScaleY },
Loading