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

Commit 31d46593 authored by Alex Chau's avatar Alex Chau
Browse files

Only refresh TaskThumbnailViewDeprecated if runningTaskShowScreenshot has changed

- This is a follow-up of ag/28922223, which caused a RECENTS_SCROLLING jank regression
- The regression is probably caused by TaskThumbnailViewDeprecated unnecessarily redrawing, the fix is to only redraw when needed
- Also combined setShouldShowScreenshot and refreshThumbnails into a single method, so we can easily check inside TaskView if a refresh is necessary
- Centralize screenshotTasks logic into RecentsViewUtils, and centralize thumbnailView refreshing inside TaksView.setShouldShowScreenshot

Fix: 362294538
Test: Invoke Omnient or Screenshot hardware button on live tile, verify running task switches to screenshot after overlay closes
Test: Select/Screenshot swithces to screenshot normally
Flag: EXEMPT BUG_FIX
Change-Id: I7c6e73e52ebf18e7c59bb9afea029246b92681d2
parent 380f11e9
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@
package com.android.quickstep.util

import com.android.launcher3.Flags.enableLargeDesktopWindowingTile
import com.android.quickstep.RecentsAnimationController
import com.android.quickstep.views.DesktopTaskView
import com.android.quickstep.views.TaskView
import com.android.quickstep.views.TaskViewType
import com.android.systemui.shared.recents.model.ThumbnailData

/**
 * Helper class for [com.android.quickstep.views.RecentsView]. This util class contains refactored
@@ -68,4 +70,12 @@ class RecentsViewUtils {
            if (taskView?.isLargeTile == true) taskView else null
        }
    }

    fun screenshotTasks(
        taskView: TaskView,
        recentsAnimationController: RecentsAnimationController
    ): Map<Int, ThumbnailData> =
        taskView.taskContainers.associate {
            it.task.key.id to recentsAnimationController.screenshotTask(it.task.key.id)
        }
}
+11 −19
Original line number Diff line number Diff line
@@ -3058,14 +3058,15 @@ public abstract class RecentsView<
    }

    private void setRunningTaskViewShowScreenshot(boolean showScreenshot) {
        setRunningTaskViewShowScreenshot(showScreenshot, /*updatedThumbnails=*/null);
    }

    private void setRunningTaskViewShowScreenshot(boolean showScreenshot,
            @Nullable Map<Integer, ThumbnailData> updatedThumbnails) {
        mRunningTaskShowScreenshot = showScreenshot;
        TaskView runningTaskView = getRunningTaskView();
        if (runningTaskView != null) {
            runningTaskView.setShouldShowScreenshot(mRunningTaskShowScreenshot);
            if (!enableRefactorTaskThumbnail()) {
                runningTaskView.getTaskContainers().forEach(
                        taskContainer -> taskContainer.getThumbnailViewDeprecated().refresh());
            }
            runningTaskView.setShouldShowScreenshot(mRunningTaskShowScreenshot, updatedThumbnails);
        }
        if (enableRefactorTaskThumbnail()) {
            mRecentsViewModel.setRunningTaskShowScreenshot(showScreenshot);
@@ -6154,20 +6155,12 @@ public abstract class RecentsView<
            return;
        }

        Map<Integer, ThumbnailData> updatedThumbnails = mRecentsViewUtils.screenshotTasks(taskView,
                mRecentsAnimationController);
        if (enableRefactorTaskThumbnail()) {
            mHelper.switchToScreenshot(taskView, mRecentsAnimationController, onFinishRunnable);
            mHelper.switchToScreenshot(taskView, updatedThumbnails, onFinishRunnable);
        } else {
            setRunningTaskViewShowScreenshot(true);
            for (TaskContainer container : taskView.getTaskContainers()) {
                ThumbnailData thumbnailData =
                        mRecentsAnimationController.screenshotTask(container.getTask().key.id);
                TaskThumbnailViewDeprecated thumbnailView = container.getThumbnailViewDeprecated();
                if (thumbnailData != null) {
                    thumbnailView.setThumbnail(container.getTask(), thumbnailData);
                } else {
                    thumbnailView.refresh();
                }
            }
            setRunningTaskViewShowScreenshot(true, updatedThumbnails);
            ViewUtils.postFrameDrawn(taskView, onFinishRunnable);
        }
    }
@@ -6186,8 +6179,7 @@ public abstract class RecentsView<
            if (enableRefactorTaskThumbnail()) {
                mHelper.switchToScreenshot(taskView, thumbnailDatas, onFinishRunnable);
            } else {
                taskView.setShouldShowScreenshot(true);
                taskView.refreshThumbnails(thumbnailDatas);
                taskView.setShouldShowScreenshot(true, thumbnailDatas);
                ViewUtils.postFrameDrawn(taskView, onFinishRunnable);
            }
        } else {
+0 −13
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.quickstep.views

import com.android.quickstep.RecentsAnimationController
import com.android.quickstep.ViewUtils
import com.android.quickstep.recents.viewmodel.RecentsViewModel
import com.android.systemui.shared.recents.model.ThumbnailData
@@ -40,18 +39,6 @@ class RecentsViewModelHelper(private val recentsViewModel: RecentsViewModel) {
        viewAttachedScope.cancel("RecentsView detaching from window")
    }

    fun switchToScreenshot(
        taskView: TaskView,
        recentsAnimationController: RecentsAnimationController,
        onFinishRunnable: Runnable,
    ) {
        val updatedThumbnails =
            taskView.taskContainers.associate {
                it.task.key.id to recentsAnimationController.screenshotTask(it.task.key.id)
            }
        switchToScreenshot(taskView, updatedThumbnails, onFinishRunnable)
    }

    fun switchToScreenshot(
        taskView: TaskView,
        updatedThumbnails: Map<Int, ThumbnailData>?,
+8 −2
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ import com.android.launcher3.util.rects.set
import com.android.launcher3.views.ActivityContext
import com.android.quickstep.RecentsModel
import com.android.quickstep.RemoteAnimationTargets
import com.android.quickstep.TaskAnimationManager
import com.android.quickstep.TaskOverlayFactory
import com.android.quickstep.TaskViewUtils
import com.android.quickstep.orientation.RecentsPagedOrientationHandler
@@ -408,6 +407,7 @@ constructor(

    protected var shouldShowScreenshot = false
        get() = !isRunningTask || field
        private set

    /** Enable or disable showing border on hover and focus change */
    @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
@@ -974,7 +974,13 @@ constructor(
        iconView.setText(text)
    }

    open fun refreshThumbnails(thumbnailDatas: Map<Int, ThumbnailData?>?) {
    @JvmOverloads
    open fun setShouldShowScreenshot(
        shouldShowScreenshot: Boolean,
        thumbnailDatas: Map<Int, ThumbnailData?>? = null
    ) {
        if (this.shouldShowScreenshot == shouldShowScreenshot) return
        this.shouldShowScreenshot = shouldShowScreenshot
        if (enableRefactorTaskThumbnail()) {
            return
        }