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

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

Simplify RenderNode refresh/build/update process

A View's RenderNode is created lazily, but the instance never changes
afterward.

Change-Id: I0b05769cd49aa55061d3fb8c2ea55a04e8391e48
parent 08c96b55
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -269,8 +269,8 @@ public class RenderNode {
    }

    /**
     * Returns whether the display list is currently usable. If this returns false,
     * the display list should be re-recorded prior to replaying it.
     * Returns whether the RenderNode's display list content is currently usable.
     * If this returns false, the display list should be re-recorded prior to replaying it.
     *
     * @return boolean true if the display list is able to be replayed, false otherwise.
     */
+30 −30
Original line number Diff line number Diff line
@@ -3551,10 +3551,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    private Bitmap mUnscaledDrawingCache;
    /**
     * Display list used for the View content.
     * RenderNode holding View properties, potentially holding a DisplayList of View content.
     * <p>
     * When non-null and valid, this is expected to contain an up-to-date copy
     * of the View content. It is cleared on temporary detach and reset on
     * of the View content. Its DisplayList content is cleared on temporary detach and reset on
     * cleanup.
     */
    RenderNode mDisplayList;
@@ -9733,6 +9733,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
    }
    void ensureRenderNode() {
        if (mDisplayList == null) {
            mDisplayList = RenderNode.create(getClass().getName());
        }
    }
    /**
     * Recomputes the transform matrix if necessary.
     */
@@ -13703,10 +13709,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            mHardwareLayer.setLayerPaint(mLayerPaint);
            RenderNode displayList = mHardwareLayer.startRecording();
            if (getDisplayList(displayList, true) != displayList) {
                throw new IllegalStateException("getDisplayList() didn't return"
                        + " the input displaylist for a hardware layer!");
            }
            getDisplayList(displayList, true);
            mHardwareLayer.endRecording(mLocalDirtyRect);
            mLocalDirtyRect.setEmpty();
        }
@@ -13847,29 +13850,34 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * Otherwise, the same display list will be returned (after having been rendered into
     * along the way, depending on the invalidation state of the view).
     *
     * @param displayList The previous version of this displayList, could be null.
     * @param renderNode The previous version of this displayList, could be null.
     * @param isLayer Whether the requester of the display list is a layer. If so,
     * the view will avoid creating a layer inside the resulting display list.
     * @return A new or reused DisplayList object.
     */
    private RenderNode getDisplayList(RenderNode displayList, boolean isLayer) {
    private void getDisplayList(@NonNull RenderNode renderNode, boolean isLayer) {
        final HardwareRenderer renderer = getHardwareRenderer();
        if (renderNode == null) {
            throw new IllegalArgumentException("RenderNode must not be null");
        }
        if (renderer == null || !canHaveDisplayList()) {
            return null;
            // can't populate RenderNode, don't try
            return;
        }
        if (((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 ||
                displayList == null || !displayList.isValid() ||
                (!isLayer && mRecreateDisplayList))) {
        if ((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0
                || !renderNode.isValid()
                || (!isLayer && mRecreateDisplayList)) {
            // Don't need to recreate the display list, just need to tell our
            // children to restore/recreate theirs
            if (displayList != null && displayList.isValid() &&
                    !isLayer && !mRecreateDisplayList) {
            if (renderNode.isValid()
                    && !isLayer
                    && !mRecreateDisplayList) {
                mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID;
                mPrivateFlags &= ~PFLAG_DIRTY_MASK;
                dispatchGetDisplayList();
                return displayList;
                return; // no work needed
            }
            if (!isLayer) {
@@ -13877,20 +13885,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                // we copy in child display lists into ours in drawChild()
                mRecreateDisplayList = true;
            }
            if (displayList == null) {
                displayList = RenderNode.create(getClass().getName());
                // If we're creating a new display list, make sure our parent gets invalidated
                // since they will need to recreate their display list to account for this
                // new child display list.
                invalidateParentCaches();
            }
            boolean caching = false;
            int width = mRight - mLeft;
            int height = mBottom - mTop;
            int layerType = getLayerType();
            final HardwareCanvas canvas = displayList.start(width, height);
            final HardwareCanvas canvas = renderNode.start(width, height);
            try {
                if (!isLayer && layerType != LAYER_TYPE_NONE) {
@@ -13933,12 +13934,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                    }
                }
            } finally {
                displayList.end(renderer, canvas);
                displayList.setCaching(caching);
                renderNode.end(renderer, canvas);
                renderNode.setCaching(caching);
                if (isLayer) {
                    displayList.setLeftTopRightBottom(0, 0, width, height);
                    renderNode.setLeftTopRightBottom(0, 0, width, height);
                } else {
                    setDisplayListProperties(displayList);
                    setDisplayListProperties(renderNode);
                }
                if (renderer != getHardwareRenderer()) {
@@ -13953,8 +13954,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID;
            mPrivateFlags &= ~PFLAG_DIRTY_MASK;
        }
        return displayList;
    }
    /**
@@ -13966,7 +13965,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * @hide
     */
    public RenderNode getDisplayList() {
        mDisplayList = getDisplayList(mDisplayList, false);
        ensureRenderNode();
        getDisplayList(mDisplayList, false);
        return mDisplayList;
    }
+0 −1
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.SystemClock;
import android.util.AttributeSet;