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

Commit 8cda8e91 authored by Alan Viverette's avatar Alan Viverette
Browse files

Avoid drawable invalidation during draw()

Prevents infinite invalidation loop when reusing a drawable asset within
a single draw() call. Also reduces unnecessary extra invalidations due to
drawable setters (ex. setBounds()) being called during draw().

Bug: 26329675
Change-Id: I31b3c99e8efd4193415cc562a84c8939a2f56c2d
parent f43f627f
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -3586,6 +3586,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    private int[] mDrawableState = null;
    /** Whether draw() is currently being called. */
    private boolean mInDraw = false;
    ViewOutlineProvider mOutlineProvider = ViewOutlineProvider.BACKGROUND;
    /**
@@ -16460,6 +16463,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    @CallSuper
    public void draw(Canvas canvas) {
        mInDraw = true;
        final int privateFlags = mPrivateFlags;
        final boolean dirtyOpaque = (privateFlags & PFLAG_DIRTY_MASK) == PFLAG_DIRTY_OPAQUE &&
                (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState);
@@ -16504,6 +16509,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            onDrawForeground(canvas);
            // we're done...
            mInDraw = false;
            return;
        }
@@ -16651,6 +16657,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        // Step 6, draw decorations (foreground, scrollbars)
        onDrawForeground(canvas);
        mInDraw = false;
    }
    /**
@@ -17095,7 +17103,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    @Override
    public void invalidateDrawable(@NonNull Drawable drawable) {
        if (verifyDrawable(drawable)) {
        // Don't invalidate if a drawable changes during drawing.
        if (verifyDrawable(drawable) && !mInDraw) {
            final Rect dirty = drawable.getDirtyBounds();
            final int scrollX = mScrollX;
            final int scrollY = mScrollY;