OSDN Git Service

Merge "docs: Add documentation for equals() method" into qt-dev am: 732a127636
[android-x86/frameworks-base.git] / services / core / java / com / android / server / wm / TaskScreenshotAnimatable.java
1 /*
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  */
16 package com.android.server.wm;
17
18 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RECENTS_ANIMATIONS;
19
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;
26
27 /**
28  * Class used by {@link RecentsAnimationController} to create a surface control with taking
29  * screenshot of task when canceling recents animation.
30  *
31  * @see {@link RecentsAnimationController#setCancelOnNextTransitionStart}
32  */
33 class TaskScreenshotAnimatable implements SurfaceAnimator.Animatable {
34     private static final String TAG = "TaskScreenshotAnim";
35     private Task mTask;
36     private SurfaceControl mSurfaceControl;
37     private int mWidth;
38     private int mHeight;
39
40     public static TaskScreenshotAnimatable create(Task task) {
41         return new TaskScreenshotAnimatable(task, getBufferFromTask(task));
42     }
43
44     private static SurfaceControl.ScreenshotGraphicBuffer getBufferFromTask(Task task) {
45         if (task == null) {
46             return null;
47         }
48         final Rect tmpRect = task.getBounds();
49         tmpRect.offset(0, 0);
50         return SurfaceControl.captureLayers(
51                 task.getSurfaceControl().getHandle(), tmpRect, 1f);
52     }
53
54     private TaskScreenshotAnimatable(Task task,
55             SurfaceControl.ScreenshotGraphicBuffer screenshotBuffer) {
56         GraphicBuffer buffer = screenshotBuffer == null
57                 ? null : screenshotBuffer.getGraphicBuffer();
58         mTask = task;
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);
64         }
65         mSurfaceControl = new SurfaceControl.Builder(new SurfaceSession())
66                 .setName("RecentTaskScreenshotSurface")
67                 .setBufferSize(mWidth, mHeight)
68                 .build();
69         if (buffer != null) {
70             final Surface surface = new Surface();
71             surface.copyFrom(mSurfaceControl);
72             surface.attachAndQueueBufferWithColorSpace(buffer, screenshotBuffer.getColorSpace());
73             surface.release();
74         }
75         getPendingTransaction().show(mSurfaceControl);
76     }
77
78     @Override
79     public SurfaceControl.Transaction getPendingTransaction() {
80         return mTask.getPendingTransaction();
81     }
82
83     @Override
84     public void commitPendingTransaction() {
85         mTask.commitPendingTransaction();
86     }
87
88     @Override
89     public void onAnimationLeashCreated(SurfaceControl.Transaction t, SurfaceControl leash) {
90         t.setLayer(leash, 1);
91     }
92
93     @Override
94     public void onAnimationLeashLost(SurfaceControl.Transaction t) {
95         if (mSurfaceControl != null) {
96             t.remove(mSurfaceControl);
97             mSurfaceControl = null;
98         }
99     }
100
101     @Override
102     public SurfaceControl.Builder makeAnimationLeash() {
103         return mTask.makeAnimationLeash();
104     }
105
106     @Override
107     public SurfaceControl getAnimationLeashParent() {
108         return mTask.getAnimationLeashParent();
109     }
110
111     @Override
112     public SurfaceControl getSurfaceControl() {
113         return mSurfaceControl;
114     }
115
116     @Override
117     public SurfaceControl getParentSurfaceControl() {
118         return mTask.mSurfaceControl;
119     }
120
121     @Override
122     public int getSurfaceWidth() {
123         return mWidth;
124     }
125
126     @Override
127     public int getSurfaceHeight() {
128         return mHeight;
129     }
130 }