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

Commit ee0ff18c authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Optimize onAttachedTo/onDetachedFromWindow"

parents bebd1a09 fbb93fa2
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import android.graphics.Matrix;
 * @hide 
 */
public abstract class DisplayList {
    private boolean mDirty;

    /**
     * Flag used when calling
     * {@link HardwareCanvas#drawDisplayList(DisplayList, android.graphics.Rect, int)} 
@@ -95,6 +97,28 @@ public abstract class DisplayList {
     */
    public abstract void clear();

    /**
     * Sets the dirty flag. When a display list is dirty, both
     * {@link #invalidate()} and {@link #clear()} should be invoked whenever
     * possible.
     *
     * @param dirty True to mark the display list dirty, false otherwise
     *
     * @see #isDirty()
     */
    public void setDirty(boolean dirty) {
        mDirty = dirty;
    }

    /**
     * Indicates whether the display list is dirty.
     *
     * @see #setDirty(boolean)
     */
    public boolean isDirty() {
        return mDirty;
    }

    /**
     * Returns whether the display list is currently usable. If this returns false,
     * the display list should be re-recorded prior to replaying it.
+3 −2
Original line number Diff line number Diff line
@@ -11562,8 +11562,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            imm.focusIn(this);
        }
        if (mAttachInfo != null && mDisplayList != null) {
            mAttachInfo.mViewRootImpl.dequeueDisplayList(mDisplayList);
        if (mDisplayList != null) {
            mDisplayList.setDirty(false);
        }
    }
@@ -11843,6 +11843,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        if (mAttachInfo != null) {
            if (mDisplayList != null) {
                mDisplayList.setDirty(true);
                mAttachInfo.mViewRootImpl.enqueueDisplayList(mDisplayList);
            }
            mAttachInfo.mViewRootImpl.cancelInvalidate(this);
+15 −28
Original line number Diff line number Diff line
@@ -297,7 +297,7 @@ public final class ViewRootImpl implements ViewParent,
    private long mFpsPrevTime = -1;
    private int mFpsNumFrames;

    private final ArrayList<DisplayList> mDisplayLists = new ArrayList<DisplayList>(24);
    private final ArrayList<DisplayList> mDisplayLists = new ArrayList<DisplayList>();
    
    /**
     * see {@link #playSoundEffect(int)}
@@ -2128,7 +2128,7 @@ public final class ViewRootImpl implements ViewParent,

    private void draw(boolean fullRedrawNeeded) {
        Surface surface = mSurface;
        if (surface == null || !surface.isValid()) {
        if (!surface.isValid()) {
            return;
        }

@@ -2209,6 +2209,8 @@ public final class ViewRootImpl implements ViewParent,
                    appScale + ", width=" + mWidth + ", height=" + mHeight);
        }

        invalidateDisplayLists();

        attachInfo.mTreeObserver.dispatchOnDraw();

        if (!dirty.isEmpty() || mIsAnimating) {
@@ -2419,8 +2421,11 @@ public final class ViewRootImpl implements ViewParent,

        for (int i = 0; i < count; i++) {
            final DisplayList displayList = displayLists.get(i);
            if (displayList.isDirty()) {
                displayList.invalidate();
                displayList.clear();
                displayList.setDirty(false);
            }
        }

        displayLists.clear();
@@ -2794,11 +2799,10 @@ public final class ViewRootImpl implements ViewParent,
    private final static int MSG_UPDATE_CONFIGURATION = 18;
    private final static int MSG_PROCESS_INPUT_EVENTS = 19;
    private final static int MSG_DISPATCH_SCREEN_STATE = 20;
    private final static int MSG_INVALIDATE_DISPLAY_LIST = 21;
    private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 22;
    private final static int MSG_DISPATCH_DONE_ANIMATING = 23;
    private final static int MSG_INVALIDATE_WORLD = 24;
    private final static int MSG_WINDOW_MOVED = 25;
    private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 21;
    private final static int MSG_DISPATCH_DONE_ANIMATING = 22;
    private final static int MSG_INVALIDATE_WORLD = 23;
    private final static int MSG_WINDOW_MOVED = 24;

    final class ViewRootHandler extends Handler {
        @Override
@@ -2844,8 +2848,6 @@ public final class ViewRootImpl implements ViewParent,
                    return "MSG_PROCESS_INPUT_EVENTS";
                case MSG_DISPATCH_SCREEN_STATE:
                    return "MSG_DISPATCH_SCREEN_STATE";
                case MSG_INVALIDATE_DISPLAY_LIST:
                    return "MSG_INVALIDATE_DISPLAY_LIST";
                case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST:
                    return "MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST";
                case MSG_DISPATCH_DONE_ANIMATING:
@@ -3066,9 +3068,6 @@ public final class ViewRootImpl implements ViewParent,
                    handleScreenStateChange(msg.arg1 == 1);
                }
            } break;
            case MSG_INVALIDATE_DISPLAY_LIST: {
                invalidateDisplayLists();
            } break;
            case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: {
                setAccessibilityFocus(null, null);
            } break;
@@ -4153,6 +4152,7 @@ public final class ViewRootImpl implements ViewParent,
            }

            if (mAdded && !mFirst) {
                invalidateDisplayLists();
                destroyHardwareRenderer();

                if (mView != null) {
@@ -4572,19 +4572,6 @@ public final class ViewRootImpl implements ViewParent,

    public void enqueueDisplayList(DisplayList displayList) {
        mDisplayLists.add(displayList);

        mHandler.removeMessages(MSG_INVALIDATE_DISPLAY_LIST);
        Message msg = mHandler.obtainMessage(MSG_INVALIDATE_DISPLAY_LIST);
        mHandler.sendMessage(msg);
    }

    public void dequeueDisplayList(DisplayList displayList) {
        if (mDisplayLists.remove(displayList)) {
            displayList.invalidate();
            if (mDisplayLists.size() == 0) {
                mHandler.removeMessages(MSG_INVALIDATE_DISPLAY_LIST);
            }
        }
    }

    public void cancelInvalidate(View view) {