From cd6e9816a596471b9f0e7cb71fba5ec04703efd2 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Wed, 28 Apr 2021 17:59:27 -0700 Subject: [PATCH] Unify round corner radius in PipSurfaceTransactionHelper(s) Per discussion, will keep the two classes in Launcher and WMShell as for now and re-address the unification in next release. In this change - deprecate config_pipEnableRoundCorner since it's now behind a system property and waiting to be turned on - pass the corner radius value from WMShell to Launcher Video: http://recall/-/aaaaaabFQoRHlzixHdtY/dmUy8qBEMxHShFcFKB3cT3 Bug: 171721389 Test: make sure autoEnterPip has round corner support, see video Change-Id: If978ee6c3b0307a7423fe51b996f535d7009e74c --- .../WindowManager/Shell/res/values/config.xml | 3 --- .../wm/shell/pip/IPipAnimationListener.aidl | 8 +++++++ .../pip/PipSurfaceTransactionHelper.java | 23 +++++-------------- .../wm/shell/pip/phone/PipController.java | 22 ++++++++++++++---- .../wm/shell/pip/phone/PipMenuView.java | 5 ++-- .../shell/pip/PipAnimationControllerTest.java | 2 +- .../pip/PipSurfaceTransactionHelper.java | 8 ++++--- .../systemui/wmshell/WMShellBaseModule.java | 4 ++-- 8 files changed, 42 insertions(+), 33 deletions(-) diff --git a/libs/WindowManager/Shell/res/values/config.xml b/libs/WindowManager/Shell/res/values/config.xml index e8757b5d96f45..becf42d728da4 100644 --- a/libs/WindowManager/Shell/res/values/config.xml +++ b/libs/WindowManager/Shell/res/values/config.xml @@ -33,9 +33,6 @@ false - - false - 250 diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/IPipAnimationListener.aidl b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/IPipAnimationListener.aidl index 2569b780c1bb1..b4c745fc48925 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/IPipAnimationListener.aidl +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/IPipAnimationListener.aidl @@ -24,4 +24,12 @@ oneway interface IPipAnimationListener { * Notifies the listener that the Pip animation is started. */ void onPipAnimationStarted(); + + /** + * Notifies the listener about PiP round corner radius changes. + * Listener can expect an immediate callback the first time they attach. + * + * @param cornerRadius the pixel value of the corner radius, zero means it's disabled. + */ + void onPipCornerRadiusChanged(int cornerRadius); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSurfaceTransactionHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSurfaceTransactionHelper.java index 2b795390adda1..319d57a633209 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSurfaceTransactionHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSurfaceTransactionHelper.java @@ -17,7 +17,6 @@ package com.android.wm.shell.pip; import android.content.Context; -import android.content.res.Resources; import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.RectF; @@ -30,10 +29,6 @@ import com.android.wm.shell.R; * Abstracts the common operations on {@link SurfaceControl.Transaction} for PiP transition. */ public class PipSurfaceTransactionHelper { - - private final boolean mEnableCornerRadius; - private int mCornerRadius; - /** for {@link #scale(SurfaceControl.Transaction, SurfaceControl, Rect, Rect)} operation */ private final Matrix mTmpTransform = new Matrix(); private final float[] mTmpFloat9 = new float[9]; @@ -41,11 +36,7 @@ public class PipSurfaceTransactionHelper { private final RectF mTmpDestinationRectF = new RectF(); private final Rect mTmpDestinationRect = new Rect(); - public PipSurfaceTransactionHelper(Context context) { - final Resources res = context.getResources(); - mEnableCornerRadius = res.getBoolean(R.bool.config_pipEnableRoundCorner) - || SystemProperties.getBoolean("debug.sf.enable_hole_punch_pip", false); - } + private int mCornerRadius; /** * Called when display size or font size of settings changed @@ -53,10 +44,10 @@ public class PipSurfaceTransactionHelper { * @param context the current context */ public void onDensityOrFontScaleChanged(Context context) { - if (mEnableCornerRadius) { - final Resources res = context.getResources(); - mCornerRadius = res.getDimensionPixelSize(R.dimen.pip_corner_radius); - } + final boolean enableCornerRadius = + SystemProperties.getBoolean("debug.sf.enable_hole_punch_pip", false); + mCornerRadius = enableCornerRadius + ? context.getResources().getDimensionPixelSize(R.dimen.pip_corner_radius) : 0; } /** @@ -194,9 +185,7 @@ public class PipSurfaceTransactionHelper { */ public PipSurfaceTransactionHelper round(SurfaceControl.Transaction tx, SurfaceControl leash, boolean applyCornerRadius) { - if (mEnableCornerRadius) { - tx.setCornerRadius(leash, applyCornerRadius ? mCornerRadius : 0); - } + tx.setCornerRadius(leash, applyCornerRadius ? mCornerRadius : 0); return this; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java index b881fea3ac791..e0e8469207d85 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java @@ -36,6 +36,7 @@ import android.content.res.Configuration; import android.graphics.Rect; import android.os.IBinder; import android.os.RemoteException; +import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; import android.util.Log; @@ -50,6 +51,7 @@ import androidx.annotation.BinderThread; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.android.wm.shell.R; import com.android.wm.shell.WindowManagerShellWrapper; import com.android.wm.shell.common.DisplayChangeController; import com.android.wm.shell.common.DisplayController; @@ -428,6 +430,7 @@ public class PipController implements PipTransitionController.PipTransitionCallb private void onDensityOrFontScaleChanged() { mPipTaskOrganizer.onDensityOrFontScaleChanged(mContext); + onPipCornerRadiusChanged(); } private void onOverlayChanged() { @@ -487,10 +490,6 @@ public class PipController implements PipTransitionController.PipTransitionCallb mTouchHandler.getMotionHelper().expandLeavePip(false /* skipAnimation */); } - private PipTouchHandler getPipTouchHandler() { - return mTouchHandler; - } - /** * Hides the PIP menu. */ @@ -530,6 +529,21 @@ public class PipController implements PipTransitionController.PipTransitionCallb private void setPinnedStackAnimationListener(IPipAnimationListener callback) { mPinnedStackAnimationRecentsCallback = callback; + onPipCornerRadiusChanged(); + } + + private void onPipCornerRadiusChanged() { + if (mPinnedStackAnimationRecentsCallback != null) { + final boolean enableCornerRadius = + SystemProperties.getBoolean("debug.sf.enable_hole_punch_pip", false); + final int cornerRadius = enableCornerRadius + ? mContext.getResources().getDimensionPixelSize(R.dimen.pip_corner_radius) : 0; + try { + mPinnedStackAnimationRecentsCallback.onPipCornerRadiusChanged(cornerRadius); + } catch (RemoteException e) { + Log.e(TAG, "Failed to call onPipCornerRadiusChanged", e); + } + } } private Rect startSwipePipToHome(ComponentName componentName, ActivityInfo activityInfo, diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java index a57e8cdd09286..8c2254f973d31 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuView.java @@ -131,9 +131,8 @@ public class PipMenuView extends FrameLayout { mAccessibilityManager = context.getSystemService(AccessibilityManager.class); inflate(context, R.layout.pip_menu, this); - final boolean enableCornerRadius = mContext.getResources() - .getBoolean(R.bool.config_pipEnableRoundCorner) - || SystemProperties.getBoolean("debug.sf.enable_hole_punch_pip", false); + final boolean enableCornerRadius = + SystemProperties.getBoolean("debug.sf.enable_hole_punch_pip", false); mBackgroundDrawable = enableCornerRadius ? mContext.getDrawable(R.drawable.pip_menu_background) : new ColorDrawable(Color.BLACK); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipAnimationControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipAnimationControllerTest.java index 882d382861309..8ef1df606b432 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipAnimationControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipAnimationControllerTest.java @@ -68,7 +68,7 @@ public class PipAnimationControllerTest extends ShellTestCase { @Before public void setUp() throws Exception { mPipAnimationController = new PipAnimationController( - new PipSurfaceTransactionHelper(mContext)); + new PipSurfaceTransactionHelper()); mLeash = new SurfaceControl.Builder() .setContainerLayer() .setName("FakeLeash") 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 index 7cd7c9ed7de5c..0346158f044a2 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/pip/PipSurfaceTransactionHelper.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/pip/PipSurfaceTransactionHelper.java @@ -32,15 +32,17 @@ import android.window.PictureInPictureSurfaceTransaction; * source of truth on enabling/disabling and the actual value of corner radius. */ public class PipSurfaceTransactionHelper { - /** corner radius is currently disabled. */ - private final float mCornerRadius = 0f; - + private final int mCornerRadius; private final Matrix mTmpTransform = new Matrix(); private final float[] mTmpFloat9 = new float[9]; private final RectF mTmpSourceRectF = new RectF(); private final RectF mTmpDestinationRectF = new RectF(); private final Rect mTmpDestinationRect = new Rect(); + public PipSurfaceTransactionHelper(int cornerRadius) { + mCornerRadius = cornerRadius; + } + public PictureInPictureSurfaceTransaction scale( SurfaceControl.Transaction tx, SurfaceControl leash, Rect sourceBounds, Rect destinationBounds) { diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java index 26b68afed4949..6c306743e4cef 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java @@ -280,8 +280,8 @@ public abstract class WMShellBaseModule { @WMSingleton @Provides - static PipSurfaceTransactionHelper providePipSurfaceTransactionHelper(Context context) { - return new PipSurfaceTransactionHelper(context); + static PipSurfaceTransactionHelper providePipSurfaceTransactionHelper() { + return new PipSurfaceTransactionHelper(); } @WMSingleton