diff options
| -rw-r--r-- | libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java index e7a1395f541c..5e1b6becfa45 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java @@ -31,6 +31,8 @@ import android.os.RemoteException; import android.util.Size; import android.view.MotionEvent; import android.view.SurfaceControl; +import android.view.View; +import android.view.ViewRootImpl; import android.view.WindowManagerGlobal; import com.android.internal.protolog.common.ProtoLog; @@ -131,6 +133,8 @@ public class PhonePipMenuController implements PipMenuController { private PipMenuView mPipMenuView; + private SurfaceControl mLeash; + private ActionListener mMediaActionListener = new ActionListener() { @Override public void onMediaActionsChanged(List<RemoteAction> mediaActions) { @@ -166,6 +170,7 @@ public class PhonePipMenuController implements PipMenuController { */ @Override public void attach(SurfaceControl leash) { + mLeash = leash; attachPipMenuView(); } @@ -176,6 +181,7 @@ public class PhonePipMenuController implements PipMenuController { public void detach() { hideMenu(); detachPipMenuView(); + mLeash = null; } void attachPipMenuView() { @@ -185,6 +191,36 @@ public class PhonePipMenuController implements PipMenuController { } mPipMenuView = new PipMenuView(mContext, this, mMainExecutor, mMainHandler, mSplitScreenController, mPipUiEventLogger); + mPipMenuView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { + @Override + public void onViewAttachedToWindow(View v) { + v.getViewRootImpl().addSurfaceChangedCallback( + new ViewRootImpl.SurfaceChangedCallback() { + @Override + public void surfaceCreated(SurfaceControl.Transaction t) { + final SurfaceControl sc = getSurfaceControl(); + if (sc != null) { + t.reparent(sc, mLeash); + // make menu on top of the surface + t.setLayer(sc, Integer.MAX_VALUE); + } + } + + @Override + public void surfaceReplaced(SurfaceControl.Transaction t) { + } + + @Override + public void surfaceDestroyed() { + } + }); + } + + @Override + public void onViewDetachedFromWindow(View v) { + } + }); + mSystemWindows.addView(mPipMenuView, getPipMenuLayoutParams(mContext, MENU_WINDOW_TITLE, 0 /* width */, 0 /* height */), 0, SHELL_ROOT_LAYER_PIP); @@ -321,30 +357,10 @@ public class PhonePipMenuController implements PipMenuController { return; } - // If there is no pip leash supplied, that means the PiP leash is already finalized - // resizing and the PiP menu is also resized. We then want to do a scale from the current - // new menu bounds. + // TODO(b/286307861) transaction should be applied outside of PiP menu controller if (pipLeash != null && t != null) { - mPipMenuView.getBoundsOnScreen(mTmpSourceBounds); - } else { - mTmpSourceBounds.set(0, 0, destinationBounds.width(), destinationBounds.height()); + t.apply(); } - - mTmpSourceRectF.set(mTmpSourceBounds); - mTmpDestinationRectF.set(destinationBounds); - mMoveTransform.setRectToRect(mTmpSourceRectF, mTmpDestinationRectF, Matrix.ScaleToFit.FILL); - final SurfaceControl surfaceControl = getSurfaceControl(); - if (surfaceControl == null) { - return; - } - final SurfaceControl.Transaction menuTx = - mSurfaceControlTransactionFactory.getTransaction(); - menuTx.setMatrix(surfaceControl, mMoveTransform, mTmpTransform); - if (pipLeash != null && t != null) { - // Merge the two transactions, vsyncId has been set on menuTx. - menuTx.merge(t); - } - menuTx.apply(); } /** @@ -362,18 +378,10 @@ public class PhonePipMenuController implements PipMenuController { return; } - final SurfaceControl surfaceControl = getSurfaceControl(); - if (surfaceControl == null) { - return; - } - final SurfaceControl.Transaction menuTx = - mSurfaceControlTransactionFactory.getTransaction(); - menuTx.setCrop(surfaceControl, destinationBounds); + // TODO(b/286307861) transaction should be applied outside of PiP menu controller if (pipLeash != null && t != null) { - // Merge the two transactions, vsyncId has been set on menuTx. - menuTx.merge(t); + t.apply(); } - menuTx.apply(); } private boolean checkPipMenuState() { |