Inject Choreographer of the shell main thread

Also use the injected Choreographer for drag resizing.

Bug: 239973193
Test: Drag resizing still works.
Change-Id: Ia58f2de285a4f18d8a84098142bc793803cd4aec
This commit is contained in:
Garfield Tan
2022-07-22 14:00:29 -07:00
parent 2699850a80
commit b813936017
5 changed files with 41 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Trace;
import android.view.Choreographer;
import androidx.annotation.Nullable;
@@ -143,6 +144,25 @@ public abstract class WMShellConcurrencyModule {
return sysuiMainExecutor;
}
/**
* Provide a Shell main-thread {@link Choreographer} with the app vsync.
*
* @param executor the executor of the shell main thread
*/
@WMSingleton
@Provides
@ShellMainThread
public static Choreographer provideShellMainChoreographer(
@ShellMainThread ShellExecutor executor) {
try {
final Choreographer[] choreographer = new Choreographer[1];
executor.executeBlocking(() -> choreographer[0] = Choreographer.getInstance());
return choreographer[0];
} catch (InterruptedException e) {
throw new RuntimeException("Failed to obtain main Choreographer.", e);
}
}
/**
* Provide a Shell animation-thread Executor.
*/

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.pm.LauncherApps;
import android.os.Handler;
import android.os.UserManager;
import android.view.Choreographer;
import android.view.WindowManager;
import com.android.internal.jank.InteractionJankMonitor;
@@ -173,12 +174,14 @@ public abstract class WMShellModule {
static WindowDecorViewModel<?> provideWindowDecorViewModel(
Context context,
@ShellMainThread Handler mainHandler,
@ShellMainThread Choreographer mainChoreographer,
ShellTaskOrganizer taskOrganizer,
DisplayController displayController,
SyncTransactionQueue syncQueue) {
return new CaptionWindowDecorViewModel(
context,
mainHandler,
mainChoreographer,
taskOrganizer,
displayController,
syncQueue);

View File

@@ -25,6 +25,7 @@ import android.app.ActivityManager.RunningTaskInfo;
import android.app.ActivityTaskManager;
import android.content.Context;
import android.os.Handler;
import android.view.Choreographer;
import android.view.MotionEvent;
import android.view.SurfaceControl;
import android.view.View;
@@ -45,17 +46,20 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel<Caption
private final ShellTaskOrganizer mTaskOrganizer;
private final Context mContext;
private final Handler mMainHandler;
private final Choreographer mMainChoreographer;
private final DisplayController mDisplayController;
private final SyncTransactionQueue mSyncQueue;
public CaptionWindowDecorViewModel(
Context context,
Handler mainHandler,
Choreographer mainChoreographer,
ShellTaskOrganizer taskOrganizer,
DisplayController displayController,
SyncTransactionQueue syncQueue) {
mContext = context;
mMainHandler = mainHandler;
mMainChoreographer = mainChoreographer;
mActivityTaskManager = mContext.getSystemService(ActivityTaskManager.class);
mTaskOrganizer = taskOrganizer;
mDisplayController = displayController;
@@ -72,6 +76,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel<Caption
taskInfo,
taskSurface,
mMainHandler,
mMainChoreographer,
mSyncQueue);
TaskPositioner taskPositioner = new TaskPositioner(mTaskOrganizer, windowDecoration);
CaptionTouchEventListener touchEventListener =

View File

@@ -25,6 +25,7 @@ import android.graphics.Rect;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.VectorDrawable;
import android.os.Handler;
import android.view.Choreographer;
import android.view.SurfaceControl;
import android.view.View;
import android.window.WindowContainerTransaction;
@@ -59,6 +60,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
RESIZE_HANDLE_IN_DIP, RESIZE_HANDLE_IN_DIP, RESIZE_HANDLE_IN_DIP, RESIZE_HANDLE_IN_DIP);
private final Handler mHandler;
private final Choreographer mChoreographer;
private final SyncTransactionQueue mSyncQueue;
private View.OnClickListener mOnCaptionButtonClickListener;
@@ -77,10 +79,12 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
ActivityManager.RunningTaskInfo taskInfo,
SurfaceControl taskSurface,
Handler handler,
Choreographer choreographer,
SyncTransactionQueue syncQueue) {
super(context, displayController, taskOrganizer, taskInfo, taskSurface);
mHandler = handler;
mChoreographer = choreographer;
mSyncQueue = syncQueue;
}
@@ -138,6 +142,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
mDragResizeListener = new DragResizeInputListener(
mContext,
mHandler,
mChoreographer,
mDisplay.getDisplayId(),
mDecorationContainerSurface,
mDragResizeCallback);

View File

@@ -49,6 +49,7 @@ class DragResizeInputListener implements AutoCloseable {
private final IWindowSession mWindowSession = WindowManagerGlobal.getWindowSession();
private final Handler mHandler;
private final Choreographer mChoreographer;
private final InputManager mInputManager;
private final int mDisplayId;
@@ -68,11 +69,13 @@ class DragResizeInputListener implements AutoCloseable {
DragResizeInputListener(
Context context,
Handler handler,
Choreographer choreographer,
int displayId,
SurfaceControl decorationSurface,
DragResizeCallback callback) {
mInputManager = context.getSystemService(InputManager.class);
mHandler = handler;
mChoreographer = choreographer;
mDisplayId = displayId;
mDecorationSurface = decorationSurface;
// Use a fake window as the backing surface is a container layer and we don't want to create
@@ -97,7 +100,8 @@ class DragResizeInputListener implements AutoCloseable {
e.rethrowFromSystemServer();
}
mInputEventReceiver = new TaskResizeInputEventReceiver(mInputChannel, mHandler);
mInputEventReceiver = new TaskResizeInputEventReceiver(
mInputChannel, mHandler, mChoreographer);
mCallback = callback;
}
@@ -171,13 +175,10 @@ class DragResizeInputListener implements AutoCloseable {
private final Runnable mConsumeBatchEventRunnable;
private boolean mConsumeBatchEventScheduled;
private TaskResizeInputEventReceiver(InputChannel inputChannel, Handler handler) {
private TaskResizeInputEventReceiver(
InputChannel inputChannel, Handler handler, Choreographer choreographer) {
super(inputChannel, handler.getLooper());
final Choreographer[] choreographer = new Choreographer[1];
handler.runWithScissors(
() -> choreographer[0] = Choreographer.getInstance(), 0);
mChoreographer = choreographer[0];
mChoreographer = choreographer;
mConsumeBatchEventRunnable = () -> {
mConsumeBatchEventScheduled = false;