blob: d6c2f66dbb65e1a572d10c2f42fd36a329d2326a [file] [log] [blame]
lumark54284462019-03-05 20:44:27 +08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16package com.android.server.wm;
17
18import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RECENTS_ANIMATIONS;
19
20import android.graphics.GraphicBuffer;
lumark54284462019-03-05 20:44:27 +080021import android.util.Slog;
22import android.view.Surface;
23import android.view.SurfaceControl;
24import android.view.SurfaceSession;
25
26/**
27 * Class used by {@link RecentsAnimationController} to create a surface control with taking
28 * screenshot of task when canceling recents animation.
29 *
Winson Chung7a545ae2019-07-16 14:52:13 -070030 * @see {@link RecentsAnimationController#setCancelOnNextTransitionStart}
lumark54284462019-03-05 20:44:27 +080031 */
32class TaskScreenshotAnimatable implements SurfaceAnimator.Animatable {
33 private static final String TAG = "TaskScreenshotAnim";
34 private Task mTask;
35 private SurfaceControl mSurfaceControl;
36 private int mWidth;
37 private int mHeight;
38
Tracy Zhou8089ffa2019-07-30 17:30:43 -070039 TaskScreenshotAnimatable(Task task,
Peiyong Line3e5efd2019-03-21 20:59:47 +000040 SurfaceControl.ScreenshotGraphicBuffer screenshotBuffer) {
41 GraphicBuffer buffer = screenshotBuffer == null
42 ? null : screenshotBuffer.getGraphicBuffer();
lumark54284462019-03-05 20:44:27 +080043 mTask = task;
44 mWidth = (buffer != null) ? buffer.getWidth() : 1;
45 mHeight = (buffer != null) ? buffer.getHeight() : 1;
46 if (DEBUG_RECENTS_ANIMATIONS) {
47 Slog.d(TAG, "Creating TaskScreenshotAnimatable: task: " + task
48 + "width: " + mWidth + "height: " + mHeight);
49 }
50 mSurfaceControl = new SurfaceControl.Builder(new SurfaceSession())
51 .setName("RecentTaskScreenshotSurface")
52 .setBufferSize(mWidth, mHeight)
53 .build();
54 if (buffer != null) {
55 final Surface surface = new Surface();
56 surface.copyFrom(mSurfaceControl);
Peiyong Linccc06b62019-06-25 17:31:09 -070057 surface.attachAndQueueBufferWithColorSpace(buffer, screenshotBuffer.getColorSpace());
lumark54284462019-03-05 20:44:27 +080058 surface.release();
59 }
60 getPendingTransaction().show(mSurfaceControl);
61 }
62
63 @Override
64 public SurfaceControl.Transaction getPendingTransaction() {
Tiger Huanged6794e2019-05-07 20:07:59 +080065 return mTask.getPendingTransaction();
lumark54284462019-03-05 20:44:27 +080066 }
67
68 @Override
69 public void commitPendingTransaction() {
70 mTask.commitPendingTransaction();
71 }
72
73 @Override
74 public void onAnimationLeashCreated(SurfaceControl.Transaction t, SurfaceControl leash) {
75 t.setLayer(leash, 1);
76 }
77
78 @Override
lumarkf6f34942019-04-29 16:56:50 +080079 public void onAnimationLeashLost(SurfaceControl.Transaction t) {
80 if (mSurfaceControl != null) {
81 t.remove(mSurfaceControl);
82 mSurfaceControl = null;
83 }
lumark54284462019-03-05 20:44:27 +080084 }
85
86 @Override
87 public SurfaceControl.Builder makeAnimationLeash() {
88 return mTask.makeAnimationLeash();
89 }
90
91 @Override
92 public SurfaceControl getAnimationLeashParent() {
93 return mTask.getAnimationLeashParent();
94 }
95
96 @Override
97 public SurfaceControl getSurfaceControl() {
98 return mSurfaceControl;
99 }
100
101 @Override
102 public SurfaceControl getParentSurfaceControl() {
lumarkf6f34942019-04-29 16:56:50 +0800103 return mTask.mSurfaceControl;
lumark54284462019-03-05 20:44:27 +0800104 }
105
106 @Override
107 public int getSurfaceWidth() {
108 return mWidth;
109 }
110
111 @Override
112 public int getSurfaceHeight() {
113 return mHeight;
114 }
115}