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

Commit dbc7ca0b authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

Fix view outline for shadows in LayoutLib.

Set the bounds on the drawable before getting the view outline for
shadow. Also, reuse the temp outline object in AttachInfo rather than
allocating a new one each time.

Change-Id: I69793d38d60c5b9f9050569f2b22fbc7b90620bf
parent 0c2d0deb
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -15778,11 +15778,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            return;
        }
        if (mBackgroundSizeChanged) {
            background.setBounds(0, 0,  mRight - mLeft, mBottom - mTop);
            mBackgroundSizeChanged = false;
            rebuildOutline();
        }
        setBackgroundBounds();
        // Attempt to use a display list if requested.
        if (canvas.isHardwareAccelerated() && mAttachInfo != null
@@ -15808,6 +15804,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
    }
    /**
     * Sets the correct background bounds and rebuilds the outline, if needed.
     * <p/>
     * This is called by LayoutLib.
     */
    void setBackgroundBounds() {
        if (mBackgroundSizeChanged && mBackground != null) {
            mBackground.setBounds(0, 0,  mRight - mLeft, mBottom - mTop);
            mBackgroundSizeChanged = false;
            rebuildOutline();
        }
    }
    private void setBackgroundRenderNodeProperties(RenderNode renderNode) {
        renderNode.setTranslationX(mScrollX);
        renderNode.setTranslationY(mScrollY);
+5 −2
Original line number Diff line number Diff line
@@ -220,7 +220,8 @@ public final class Canvas_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_restore(long nativeCanvas) {
    /*package*/ static void native_restore(long nativeCanvas, boolean throwOnUnderflow) {
        // FIXME: implement throwOnUnderflow.
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
@@ -231,7 +232,9 @@ public final class Canvas_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_restoreToCount(long nativeCanvas, int saveCount) {
    /*package*/ static void native_restoreToCount(long nativeCanvas, int saveCount,
            boolean throwOnUnderflow) {
        // FIXME: implement throwOnUnderflow.
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
+4 −8
Original line number Diff line number Diff line
@@ -46,16 +46,12 @@ public class ViewGroup_Delegate {
    /*package*/ static boolean drawChild(ViewGroup thisVG, Canvas canvas, View child,
            long drawingTime) {
        if (child.getZ() > thisVG.getZ()) {
            // The background's bounds are set lazily. Make sure they are set correctly so that
            // the outline obtained is correct.
            child.setBackgroundBounds();
            ViewOutlineProvider outlineProvider = child.getOutlineProvider();
            Outline outline = new Outline();
            Outline outline = child.mAttachInfo.mTmpOutline;
            outlineProvider.getOutline(child, outline);
            if (outline.mPath == null && outline.mRect == null) {
                // Sometimes, the bounds of the background drawable are not set until View.draw()
                // is called. So, we set the bounds manually and try to get the outline again.
                child.getBackground().setBounds(0, 0, child.mRight - child.mLeft,
                        child.mBottom - child.mTop);
                outlineProvider.getOutline(child, outline);
            }
            if (outline.mPath != null || (outline.mRect != null && !outline.mRect.isEmpty())) {
                int restoreTo = transformCanvas(thisVG, canvas, child);
                drawShadow(thisVG, canvas, child, outline);