Merge "Adding compat calls for building with UB"
This commit is contained in:
committed by
Android (Google) Code Review
commit
b55bd9217a
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user