From 4b3b3e1e5c5a1c89ea6a264b49257f2867bd325d Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 26 Oct 2020 11:08:48 -0700 Subject: [PATCH] Adding compat calls for building with UB Bug: 143965596 Test: Build and verify on ub branch that pip animation still works Change-Id: I1da328e74403c3d834b41bc12f4c2fcf1f1c3afb --- .../pip/PipSurfaceTransactionHelper.java | 74 +++++++++++++++++++ .../shared/system/TaskInfoCompat.java | 19 +++++ 2 files changed, 93 insertions(+) create mode 100644 packages/SystemUI/shared/src/com/android/systemui/shared/pip/PipSurfaceTransactionHelper.java diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/pip/PipSurfaceTransactionHelper.java b/packages/SystemUI/shared/src/com/android/systemui/shared/pip/PipSurfaceTransactionHelper.java new file mode 100644 index 0000000000000..22ffd2819c486 --- /dev/null +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/pip/PipSurfaceTransactionHelper.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.shared.pip; + +import android.graphics.Matrix; +import android.graphics.Rect; +import android.graphics.RectF; +import android.view.SurfaceControl; + +/** + * TODO(b/171721389): unify this class with + * {@link com.android.wm.shell.pip.PipSurfaceTransactionHelper}, for instance, there should be one + * source of truth on enabling/disabling and the actual value of corner radius. + */ +public class PipSurfaceTransactionHelper { + private final Matrix mTmpTransform = new Matrix(); + private final float[] mTmpFloat9 = new float[9]; + private final RectF mTmpSourceRectF = new RectF(); + private final Rect mTmpDestinationRect = new Rect(); + + public void scaleAndCrop(SurfaceControl.Transaction tx, SurfaceControl leash, + Rect sourceBounds, Rect destinationBounds, Rect insets) { + mTmpSourceRectF.set(sourceBounds); + mTmpDestinationRect.set(sourceBounds); + mTmpDestinationRect.inset(insets); + // Scale by the shortest edge and offset such that the top/left of the scaled inset + // source rect aligns with the top/left of the destination bounds + final float scale = sourceBounds.width() <= sourceBounds.height() + ? (float) destinationBounds.width() / sourceBounds.width() + : (float) destinationBounds.height() / sourceBounds.height(); + final float left = destinationBounds.left - insets.left * scale; + final float top = destinationBounds.top - insets.top * scale; + mTmpTransform.setScale(scale, scale); + tx.setMatrix(leash, mTmpTransform, mTmpFloat9) + .setWindowCrop(leash, mTmpDestinationRect) + .setPosition(leash, left, top); + } + + public void reset(SurfaceControl.Transaction tx, SurfaceControl leash, Rect destinationBounds) { + resetScale(tx, leash, destinationBounds); + resetCornerRadius(tx, leash); + crop(tx, leash, destinationBounds); + } + + public void resetScale(SurfaceControl.Transaction tx, SurfaceControl leash, + Rect destinationBounds) { + tx.setMatrix(leash, Matrix.IDENTITY_MATRIX, mTmpFloat9) + .setPosition(leash, destinationBounds.left, destinationBounds.top); + } + + public void resetCornerRadius(SurfaceControl.Transaction tx, SurfaceControl leash) { + tx.setCornerRadius(leash, 0); + } + + public void crop(SurfaceControl.Transaction tx, SurfaceControl leash, + Rect destinationBounds) { + tx.setWindowCrop(leash, destinationBounds.width(), destinationBounds.height()) + .setPosition(leash, destinationBounds.left, destinationBounds.top); + } +} diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/TaskInfoCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/TaskInfoCompat.java index 326c2aa371756..7b9ebc0d4656f 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/TaskInfoCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/TaskInfoCompat.java @@ -17,8 +17,11 @@ package com.android.systemui.shared.system; import android.app.ActivityManager; +import android.app.PictureInPictureParams; import android.app.TaskInfo; import android.content.ComponentName; +import android.content.pm.ActivityInfo; +import android.graphics.Rect; public class TaskInfoCompat { @@ -34,6 +37,10 @@ public class TaskInfoCompat { return info.configuration.windowConfiguration.getWindowingMode(); } + public static Rect getWindowConfigurationBounds(TaskInfo info) { + return info.configuration.windowConfiguration.getBounds(); + } + public static boolean supportsSplitScreenMultiWindow(TaskInfo info) { return info.supportsSplitScreenMultiWindow; } @@ -45,4 +52,16 @@ public class TaskInfoCompat { public static ActivityManager.TaskDescription getTaskDescription(TaskInfo info) { return info.taskDescription; } + + public static ActivityInfo getTopActivityInfo(TaskInfo info) { + return info.topActivityInfo; + } + + public static boolean isAutoEnterPipEnabled(PictureInPictureParams params) { + return params.isAutoEnterEnabled(); + } + + public static Rect getPipSourceRectHint(PictureInPictureParams params) { + return params.getSourceRectHint(); + } }