lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 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; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 21 | import android.util.Slog; |
| 22 | import android.view.Surface; |
| 23 | import android.view.SurfaceControl; |
| 24 | import 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 Chung | 7a545ae | 2019-07-16 14:52:13 -0700 | [diff] [blame] | 30 | * @see {@link RecentsAnimationController#setCancelOnNextTransitionStart} |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 31 | */ |
| 32 | class 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 Zhou | 8089ffa | 2019-07-30 17:30:43 -0700 | [diff] [blame^] | 39 | TaskScreenshotAnimatable(Task task, |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 40 | SurfaceControl.ScreenshotGraphicBuffer screenshotBuffer) { |
| 41 | GraphicBuffer buffer = screenshotBuffer == null |
| 42 | ? null : screenshotBuffer.getGraphicBuffer(); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 43 | 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 Lin | ccc06b6 | 2019-06-25 17:31:09 -0700 | [diff] [blame] | 57 | surface.attachAndQueueBufferWithColorSpace(buffer, screenshotBuffer.getColorSpace()); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 58 | surface.release(); |
| 59 | } |
| 60 | getPendingTransaction().show(mSurfaceControl); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public SurfaceControl.Transaction getPendingTransaction() { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 65 | return mTask.getPendingTransaction(); |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 66 | } |
| 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 |
lumark | f6f3494 | 2019-04-29 16:56:50 +0800 | [diff] [blame] | 79 | public void onAnimationLeashLost(SurfaceControl.Transaction t) { |
| 80 | if (mSurfaceControl != null) { |
| 81 | t.remove(mSurfaceControl); |
| 82 | mSurfaceControl = null; |
| 83 | } |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 84 | } |
| 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() { |
lumark | f6f3494 | 2019-04-29 16:56:50 +0800 | [diff] [blame] | 103 | return mTask.mSurfaceControl; |
lumark | 5428446 | 2019-03-05 20:44:27 +0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public int getSurfaceWidth() { |
| 108 | return mWidth; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public int getSurfaceHeight() { |
| 113 | return mHeight; |
| 114 | } |
| 115 | } |