2 * Copyright (C) 2019 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.android.server.wm;
18 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RECENTS_ANIMATIONS;
20 import android.graphics.GraphicBuffer;
21 import android.graphics.Rect;
22 import android.util.Slog;
23 import android.view.Surface;
24 import android.view.SurfaceControl;
25 import android.view.SurfaceSession;
28 * Class used by {@link RecentsAnimationController} to create a surface control with taking
29 * screenshot of task when canceling recents animation.
31 * @see {@link RecentsAnimationController#setCancelOnNextTransitionStart}
33 class TaskScreenshotAnimatable implements SurfaceAnimator.Animatable {
34 private static final String TAG = "TaskScreenshotAnim";
36 private SurfaceControl mSurfaceControl;
40 public static TaskScreenshotAnimatable create(Task task) {
41 return new TaskScreenshotAnimatable(task, getBufferFromTask(task));
44 private static SurfaceControl.ScreenshotGraphicBuffer getBufferFromTask(Task task) {
48 final Rect tmpRect = task.getBounds();
50 return SurfaceControl.captureLayers(
51 task.getSurfaceControl().getHandle(), tmpRect, 1f);
54 private TaskScreenshotAnimatable(Task task,
55 SurfaceControl.ScreenshotGraphicBuffer screenshotBuffer) {
56 GraphicBuffer buffer = screenshotBuffer == null
57 ? null : screenshotBuffer.getGraphicBuffer();
59 mWidth = (buffer != null) ? buffer.getWidth() : 1;
60 mHeight = (buffer != null) ? buffer.getHeight() : 1;
61 if (DEBUG_RECENTS_ANIMATIONS) {
62 Slog.d(TAG, "Creating TaskScreenshotAnimatable: task: " + task
63 + "width: " + mWidth + "height: " + mHeight);
65 mSurfaceControl = new SurfaceControl.Builder(new SurfaceSession())
66 .setName("RecentTaskScreenshotSurface")
67 .setBufferSize(mWidth, mHeight)
70 final Surface surface = new Surface();
71 surface.copyFrom(mSurfaceControl);
72 surface.attachAndQueueBufferWithColorSpace(buffer, screenshotBuffer.getColorSpace());
75 getPendingTransaction().show(mSurfaceControl);
79 public SurfaceControl.Transaction getPendingTransaction() {
80 return mTask.getPendingTransaction();
84 public void commitPendingTransaction() {
85 mTask.commitPendingTransaction();
89 public void onAnimationLeashCreated(SurfaceControl.Transaction t, SurfaceControl leash) {
94 public void onAnimationLeashLost(SurfaceControl.Transaction t) {
95 if (mSurfaceControl != null) {
96 t.remove(mSurfaceControl);
97 mSurfaceControl = null;
102 public SurfaceControl.Builder makeAnimationLeash() {
103 return mTask.makeAnimationLeash();
107 public SurfaceControl getAnimationLeashParent() {
108 return mTask.getAnimationLeashParent();
112 public SurfaceControl getSurfaceControl() {
113 return mSurfaceControl;
117 public SurfaceControl getParentSurfaceControl() {
118 return mTask.mSurfaceControl;
122 public int getSurfaceWidth() {
127 public int getSurfaceHeight() {