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

Commit fc48b072 authored by Winson's avatar Winson
Browse files

Caching the display rect to reduce binder calls.

- Only update the display rect and orientation on configuration change.

Bug: 28122871
Change-Id: I2e87e7643902d5f45ac4a311109f5e1870f48d3b
parent 6c83c7aa
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -588,6 +588,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
     */
    private void updateHeaderBarLayout(TaskStack stack, Rect windowRectOverride) {
        SystemServicesProxy ssp = Recents.getSystemServices();
        Rect displayRect = ssp.getDisplayRect();
        Rect systemInsets = new Rect();
        ssp.getStableInsets(systemInsets);
        Rect windowRect = windowRectOverride != null
@@ -608,10 +609,10 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        // Rebind the header bar and draw it for the transition
        stackLayout.setSystemInsets(systemInsets);
        if (stack != null) {
            stackLayout.getTaskStackBounds(windowRect, systemInsets.top, systemInsets.right,
                    mTaskStackBounds);
            stackLayout.getTaskStackBounds(displayRect, windowRect, systemInsets.top,
                    systemInsets.right, mTaskStackBounds);
            stackLayout.reset();
            stackLayout.initialize(windowRect, mTaskStackBounds,
            stackLayout.initialize(displayRect, windowRect, mTaskStackBounds,
                    TaskStackLayoutAlgorithm.StackState.getStackStateForStack(stack));
            mDummyStackView.setTasks(stack, false /* allowNotifyStackChanges */);

+5 −3
Original line number Diff line number Diff line
@@ -481,8 +481,9 @@ public class TaskStack {
         * Returns the task stack bounds with the given {@param width} and
         * {@param height}.
         */
        public Rect getDockedTaskStackBounds(int width, int height, int dividerSize, Rect insets,
                TaskStackLayoutAlgorithm layoutAlgorithm, Resources res, Rect windowRectOut) {
        public Rect getDockedTaskStackBounds(Rect displayRect, int width, int height,
                int dividerSize, Rect insets, TaskStackLayoutAlgorithm layoutAlgorithm,
                Resources res, Rect windowRectOut) {
            // Calculate the inverse docked task bounds
            boolean isHorizontalDivision =
                    res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
@@ -499,7 +500,8 @@ public class TaskStack {
            int top = dockArea.bottom < 1f
                    ? 0
                    : insets.top;
            layoutAlgorithm.getTaskStackBounds(windowRectOut, top, insets.right, taskStackBounds);
            layoutAlgorithm.getTaskStackBounds(displayRect, windowRectOut, top, insets.right,
                    taskStackBounds);
            return taskStackBounds;
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -404,7 +404,7 @@ public class RecentsTransitionHelper {
        transform.rect.round(taskRect);
        if (stackView.getStack().getStackFrontMostTask(false /* includeFreeformTasks */) !=
                taskView.getTask()) {
            taskRect.bottom = 2 * Recents.getSystemServices().getDisplayRect().height();
            taskRect.bottom = taskRect.top + stackView.getMeasuredHeight();
        }
        return new AppTransitionAnimationSpec(taskView.getTask().key.id, b, taskRect);
    }
+3 −6
Original line number Diff line number Diff line
@@ -432,10 +432,9 @@ public class TaskStackLayoutAlgorithm {
     * Computes the stack and task rects.  The given task stack bounds already has the top/right
     * insets and left/right padding already applied.
     */
    public void initialize(Rect windowRect, Rect taskStackBounds, StackState state) {
        SystemServicesProxy ssp = Recents.getSystemServices();
    public void initialize(Rect displayRect, Rect windowRect, Rect taskStackBounds,
            StackState state) {
        Rect lastStackRect = new Rect(mStackRect);
        Rect displayRect = ssp.getDisplayRect();

        int topMargin = getScaleForExtent(windowRect, displayRect, mBaseTopMargin, mMinMargin, HEIGHT);
        int bottomMargin = getScaleForExtent(windowRect, displayRect, mBaseBottomMargin, mMinMargin,
@@ -999,14 +998,12 @@ public class TaskStackLayoutAlgorithm {
     * top and right system insets (but not the bottom inset) and left/right paddings, but _not_
     * the top/bottom padding or insets.
     */
    public void getTaskStackBounds(Rect windowRect, int topInset, int rightInset,
    public void getTaskStackBounds(Rect displayRect, Rect windowRect, int topInset, int rightInset,
            Rect taskStackBounds) {
        taskStackBounds.set(windowRect.left, windowRect.top + topInset,
                windowRect.right - rightInset, windowRect.bottom);

        // Ensure that the new width is at most the smaller display edge size
        SystemServicesProxy ssp = Recents.getSystemServices();
        Rect displayRect = ssp.getDisplayRect();
        int sideMargin = getScaleForExtent(windowRect, displayRect, mBaseSideMargin, mMinMargin,
                WIDTH);
        int targetStackWidth = taskStackBounds.width() - 2 * sideMargin;
+44 −30
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.animation.ValueAnimator;
import android.annotation.IntDef;
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Rect;
@@ -126,48 +127,48 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    /** Update only the layout to the initial state. */
    private static final int INITIAL_STATE_UPDATE_LAYOUT_ONLY = 2;

    LayoutInflater mInflater;
    TaskStack mStack = new TaskStack();
    private LayoutInflater mInflater;
    private TaskStack mStack = new TaskStack();
    @ViewDebug.ExportedProperty(deepExport=true, prefix="layout_")
    TaskStackLayoutAlgorithm mLayoutAlgorithm;
    // The stable layout algorithm is only used to calculate the task rect with the stable bounds
    TaskStackLayoutAlgorithm mStableLayoutAlgorithm;
    private TaskStackLayoutAlgorithm mStableLayoutAlgorithm;
    @ViewDebug.ExportedProperty(deepExport=true, prefix="scroller_")
    TaskStackViewScroller mStackScroller;
    private TaskStackViewScroller mStackScroller;
    @ViewDebug.ExportedProperty(deepExport=true, prefix="touch_")
    TaskStackViewTouchHandler mTouchHandler;
    TaskStackAnimationHelper mAnimationHelper;
    GradientDrawable mFreeformWorkspaceBackground;
    ObjectAnimator mFreeformWorkspaceBackgroundAnimator;
    ViewPool<TaskView, Task> mViewPool;
    private TaskStackViewTouchHandler mTouchHandler;
    private TaskStackAnimationHelper mAnimationHelper;
    private GradientDrawable mFreeformWorkspaceBackground;
    private ObjectAnimator mFreeformWorkspaceBackgroundAnimator;
    private ViewPool<TaskView, Task> mViewPool;

    ArrayList<TaskView> mTaskViews = new ArrayList<>();
    ArrayList<TaskViewTransform> mCurrentTaskTransforms = new ArrayList<>();
    ArraySet<Task.TaskKey> mIgnoreTasks = new ArraySet<>();
    AnimationProps mDeferredTaskViewLayoutAnimation = null;
    private ArrayList<TaskView> mTaskViews = new ArrayList<>();
    private ArrayList<TaskViewTransform> mCurrentTaskTransforms = new ArrayList<>();
    private ArraySet<Task.TaskKey> mIgnoreTasks = new ArraySet<>();
    private AnimationProps mDeferredTaskViewLayoutAnimation = null;

    @ViewDebug.ExportedProperty(deepExport=true, prefix="doze_")
    DozeTrigger mUIDozeTrigger;
    private DozeTrigger mUIDozeTrigger;
    @ViewDebug.ExportedProperty(deepExport=true, prefix="focused_task_")
    Task mFocusedTask;
    private Task mFocusedTask;

    int mTaskCornerRadiusPx;
    private int mTaskCornerRadiusPx;
    private int mDividerSize;
    private int mStartTimerIndicatorDuration;

    @ViewDebug.ExportedProperty(category="recents")
    boolean mTaskViewsClipDirty = true;
    private boolean mTaskViewsClipDirty = true;
    @ViewDebug.ExportedProperty(category="recents")
    boolean mAwaitingFirstLayout = true;
    private boolean mAwaitingFirstLayout = true;
    @ViewDebug.ExportedProperty(category="recents")
    @InitialStateAction
    int mInitialState = INITIAL_STATE_UPDATE_ALL;
    private int mInitialState = INITIAL_STATE_UPDATE_ALL;
    @ViewDebug.ExportedProperty(category="recents")
    boolean mInMeasureLayout = false;
    private boolean mInMeasureLayout = false;
    @ViewDebug.ExportedProperty(category="recents")
    boolean mEnterAnimationComplete = false;
    private boolean mEnterAnimationComplete = false;
    @ViewDebug.ExportedProperty(category="recents")
    boolean mTouchExplorationEnabled;
    private boolean mTouchExplorationEnabled;
    @ViewDebug.ExportedProperty(category="recents")
    boolean mScreenPinningEnabled;

@@ -183,12 +184,17 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    // The current window bounds are dynamic and may change as the user drags and drops
    @ViewDebug.ExportedProperty(category="recents")
    private Rect mWindowRect = new Rect();
    // The current display bounds
    @ViewDebug.ExportedProperty(category="recents")
    private Rect mDisplayRect = new Rect();
    // The current display orientation
    @ViewDebug.ExportedProperty(category="recents")
    private int mDisplayOrientation = Configuration.ORIENTATION_UNDEFINED;

    private Rect mTmpRect = new Rect();
    private ArrayMap<Task.TaskKey, TaskView> mTmpTaskViewMap = new ArrayMap<>();
    private List<TaskView> mTmpTaskViews = new ArrayList<>();
    private TaskViewTransform mTmpTransform = new TaskViewTransform();
    private ArrayList<TaskViewTransform> mTmpTaskTransforms = new ArrayList<>();
    private int[] mTmpIntPair = new int[2];
    private boolean mResetToInitialStateWhenResized;
    private int mLastWidth;
@@ -248,6 +254,8 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        mTaskCornerRadiusPx = res.getDimensionPixelSize(
                R.dimen.recents_task_view_rounded_corners_radius);
        mDividerSize = ssp.getDockedDividerSize(context);
        mDisplayOrientation = Utilities.getAppConfiguration(mContext).orientation;
        mDisplayRect = ssp.getDisplayRect();

        int taskBarDismissDozeDelaySeconds = getResources().getInteger(
                R.integer.recents_task_bar_dismiss_delay_seconds);
@@ -1150,7 +1158,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        // Update the stable stack bounds, but only update the current stack bounds if the stable
        // bounds have changed.  This is because we may get spurious measures while dragging where
        // our current stack bounds reflect the target drop region.
        mLayoutAlgorithm.getTaskStackBounds(new Rect(0, 0, width, height),
        mLayoutAlgorithm.getTaskStackBounds(mDisplayRect, new Rect(0, 0, width, height),
                mLayoutAlgorithm.mSystemInsets.top, mLayoutAlgorithm.mSystemInsets.right, mTmpRect);
        if (!mTmpRect.equals(mStableStackBounds)) {
            mStableStackBounds.set(mTmpRect);
@@ -1160,9 +1168,9 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        }

        // Compute the rects in the stack algorithm
        mStableLayoutAlgorithm.initialize(mStableWindowRect, mStableStackBounds,
        mStableLayoutAlgorithm.initialize(mDisplayRect, mStableWindowRect, mStableStackBounds,
                TaskStackLayoutAlgorithm.StackState.getStackStateForStack(mStack));
        mLayoutAlgorithm.initialize(mWindowRect, mStackBounds,
        mLayoutAlgorithm.initialize(mDisplayRect, mWindowRect, mStackBounds,
                TaskStackLayoutAlgorithm.StackState.getStackStateForStack(mStack));
        updateLayoutAlgorithm(false /* boundScroll */);

@@ -1538,7 +1546,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal

    private void bindTaskView(TaskView tv, Task task) {
        // Rebind the task and request that this task's data be filled into the TaskView
        tv.onTaskBound(task);
        tv.onTaskBound(task, mTouchExplorationEnabled, mDisplayOrientation, mDisplayRect);

        // Load the task data
        Recents.getTaskLoader().loadTaskData(task);
@@ -1802,11 +1810,11 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
            int height = getMeasuredHeight();
            height -= systemInsets.bottom;
            systemInsets.bottom = 0;
            mStackBounds.set(dockState.getDockedTaskStackBounds(getMeasuredWidth(),
            mStackBounds.set(dockState.getDockedTaskStackBounds(mDisplayRect, getMeasuredWidth(),
                    height, mDividerSize, systemInsets,
                    mLayoutAlgorithm, getResources(), mWindowRect));
            mLayoutAlgorithm.setSystemInsets(systemInsets);
            mLayoutAlgorithm.initialize(mWindowRect, mStackBounds,
            mLayoutAlgorithm.initialize(mDisplayRect, mWindowRect, mStackBounds,
                    TaskStackLayoutAlgorithm.StackState.getStackStateForStack(mStack));
            updateLayoutAlgorithm(true /* boundScroll */);
            ignoreTaskOverrides = true;
@@ -1817,7 +1825,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
            mStackBounds.set(mStableStackBounds);
            removeIgnoreTask(event.task);
            mLayoutAlgorithm.setSystemInsets(mStableLayoutAlgorithm.mSystemInsets);
            mLayoutAlgorithm.initialize(mWindowRect, mStackBounds,
            mLayoutAlgorithm.initialize(mDisplayRect, mWindowRect, mStackBounds,
                    TaskStackLayoutAlgorithm.StackState.getStackStateForStack(mStack));
            updateLayoutAlgorithm(true /* boundScroll */);
            addIgnoreTask(event.task);
@@ -1960,6 +1968,10 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    }

    public final void onBusEvent(ConfigurationChangedEvent event) {
        if (event.fromDeviceOrientationChange) {
            mDisplayOrientation = Utilities.getAppConfiguration(mContext).orientation;
            mDisplayRect = Recents.getSystemServices().getDisplayRect();
        }
        reloadOnConfigurationChange();

        // Notify the task views of the configuration change so they can reload their resources
@@ -2072,6 +2084,8 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        writer.print(" stackBounds="); writer.print(Utilities.dumpRect(mStackBounds));
        writer.print(" stableWindow="); writer.print(Utilities.dumpRect(mStableWindowRect));
        writer.print(" window="); writer.print(Utilities.dumpRect(mWindowRect));
        writer.print(" display="); writer.print(Utilities.dumpRect(mDisplayRect));
        writer.print(" orientation="); writer.print(mDisplayOrientation);
        writer.print(" [0x"); writer.print(id); writer.print("]");
        writer.println();

Loading