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

Commit 87b7e43b authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Clear snapshot buffer preemptively if unused" into tm-dev

parents bee318e3 91800b7e
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -54,7 +54,13 @@ public interface TaskStackListenerCallback {

    default void onTaskDescriptionChanged(RunningTaskInfo taskInfo) { }

    default void onTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) { }
    /**
     * @return whether the snapshot is consumed and the lifecycle of the snapshot extends beyond
     *         the lifecycle of this callback.
     */
    default boolean onTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) {
        return false;
    }

    default void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { }

+8 −2
Original line number Diff line number Diff line
@@ -275,9 +275,15 @@ public class TaskStackListenerImpl extends TaskStackListener implements Handler.
                }
                case ON_TASK_SNAPSHOT_CHANGED: {
                    Trace.beginSection("onTaskSnapshotChanged");
                    final TaskSnapshot snapshot = (TaskSnapshot) msg.obj;
                    boolean snapshotConsumed = false;
                    for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) {
                        mTaskStackListeners.get(i).onTaskSnapshotChanged(msg.arg1,
                                (TaskSnapshot) msg.obj);
                        boolean consumed = mTaskStackListeners.get(i).onTaskSnapshotChanged(
                                msg.arg1, snapshot);
                        snapshotConsumed |= consumed;
                    }
                    if (!snapshotConsumed && snapshot.getHardwareBuffer() != null) {
                        snapshot.getHardwareBuffer().close();
                    }
                    Trace.endSection();
                    break;
+3 −0
Original line number Diff line number Diff line
@@ -389,6 +389,9 @@ public class TaskSnapshotWindow {
        reportDrawn();

        // In case window manager leaks us, make sure we don't retain the snapshot.
        if (mSnapshot.getHardwareBuffer() != null) {
            mSnapshot.getHardwareBuffer().close();
        }
        mSnapshot = null;
        mSurfaceControl.release();
    }
+6 −0
Original line number Diff line number Diff line
@@ -65,6 +65,12 @@ public class ThumbnailData {
        snapshotId = 0;
    }

    public void recycleBitmap() {
        if (thumbnail != null) {
            thumbnail.recycle();
        }
    }

    private static Bitmap makeThumbnail(TaskSnapshot snapshot) {
        Bitmap thumbnail = null;
        try (final HardwareBuffer buffer = snapshot.getHardwareBuffer()) {
+8 −1
Original line number Diff line number Diff line
@@ -33,7 +33,14 @@ public interface TaskStackChangeListener {

    // Main thread callbacks
    default void onTaskStackChanged() { }
    default void onTaskSnapshotChanged(int taskId, ThumbnailData snapshot) { }

    /**
     * @return whether the snapshot is consumed and the lifecycle of the snapshot extends beyond
     *         the lifecycle of this callback.
     */
    default boolean onTaskSnapshotChanged(int taskId, ThumbnailData snapshot) {
        return false;
    }
    default void onActivityPinned(String packageName, int userId, int taskId, int stackId) { }
    default void onActivityUnpinned() { }
    default void onActivityRestartAttempt(RunningTaskInfo task, boolean homeTaskVisible,
Loading