Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f80c6a3f authored by chaviw's avatar chaviw
Browse files

Apply show or hide transaction for InputSurface immediately

Currently, the show or hide is added to a transaction when the
updateInputWindows runnable is executed asynchronously. This could cause
a delay when the input surface is sent to SurfaceFlinger, causing issues
with input that occurs after the input surface is expected to have been
created.

This change applies the show and hide transaction immediately so when
the performDrag returns to the client the surface has already been
added. Since the input surface is not tied to the windows, applying it
doesn't need to be in sync with applying the other transactions.

Bug: 122965081
Test: atest DragDropTest
Change-Id: I90d67116b8e4f15eed4f98a8fa593861164ea0c5
parent f85bf680
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -73,17 +73,6 @@ class DragDropController {
        return mDragState != null && !mDragState.isClosing();
    }

    void showInputSurface(SurfaceControl.Transaction t, int displayId) {
        mDragState.showInputSurface(t, displayId);
    }

    void hideInputSurface(SurfaceControl.Transaction t, int displayId) {
        if (mDragState != null) {
            // TODO: Are we guaranteed to get here?
            mDragState.hideInputSurface(t, displayId);
        }
    }

    void registerCallback(IDragDropCallback callback) {
        Preconditions.checkNotNull(callback);
        mCallback.set(callback);
+18 −22
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ class DragState {
    // A surface used to catch input events for the drag-and-drop operation.
    SurfaceControl mInputSurface;

    private final SurfaceControl.Transaction mTransaction = new SurfaceControl.Transaction();
    private final SurfaceControl.Transaction mTransaction;

    private final Rect mTmpClipRect = new Rect();

@@ -140,31 +140,24 @@ class DragState {
        mFlags = flags;
        mLocalWin = localWin;
        mNotifiedWindows = new ArrayList<WindowState>();

        mTransaction = service.mTransactionFactory.make();
    }

    boolean isClosing() {
        return mIsClosing;
    }

    void hideInputSurface(SurfaceControl.Transaction t, int displayId) {
        if (displayId != mDisplayContent.getDisplayId()) {
            return;
        }

    private void hideInputSurface() {
        if (mInputSurface != null) {
            t.hide(mInputSurface);
            mTransaction.hide(mInputSurface).apply();
        }
    }

    void showInputSurface(SurfaceControl.Transaction t, int displayId) {
        if (displayId != mDisplayContent.getDisplayId()) {
            return;
        }

    private void showInputSurface() {
        if (mInputSurface == null) {
            mInputSurface = mService.makeSurfaceBuilder(mService.mRoot.getDisplayContent(displayId)
                    .getSession()).setContainerLayer()
            mInputSurface = mService.makeSurfaceBuilder(
                    mService.mRoot.getDisplayContent(mDisplayContent.getDisplayId()).getSession())
                    .setContainerLayer()
                    .setName("Drag and Drop Input Consumer").build();
        }
        final InputWindowHandle h = getInputWindowHandle();
@@ -174,14 +167,16 @@ class DragState {
            return;
        }

        t.show(mInputSurface);
        t.setInputWindowInfo(mInputSurface, h);
        t.setLayer(mInputSurface, Integer.MAX_VALUE);
        mTransaction.show(mInputSurface);
        mTransaction.setInputWindowInfo(mInputSurface, h);
        mTransaction.setLayer(mInputSurface, Integer.MAX_VALUE);

        mTmpClipRect.set(0, 0, mDisplaySize.x, mDisplaySize.y);
        t.setWindowCrop(mInputSurface, mTmpClipRect);
        t.transferTouchFocus(mTransferTouchFromToken, h.token);
        mTransaction.setWindowCrop(mInputSurface, mTmpClipRect);
        mTransaction.transferTouchFocus(mTransferTouchFromToken, h.token);
        mTransferTouchFromToken = null;

        mTransaction.apply();
    }

    /**
@@ -199,9 +194,10 @@ class DragState {
            mDragDropController.sendHandlerMessage(
                    MSG_TEAR_DOWN_DRAG_AND_DROP_INPUT, mInputInterceptor);
            mInputInterceptor = null;
            mDisplayContent.getInputMonitor().updateInputWindowsLw(true /*force*/);
        }

        hideInputSurface();

        // Send drag end broadcast if drag start has been sent.
        if (mDragInProgress) {
            final int myPid = Process.myPid();
@@ -352,7 +348,7 @@ class DragState {
            Slog.e(TAG_WM, "Duplicate register of drag input channel");
        } else {
            mInputInterceptor = new InputInterceptor(display);
            mDisplayContent.getInputMonitor().updateInputWindowsLw(true /*force*/);
            showInputSurface();
        }
    }

+0 −10
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLP
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;

import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
@@ -129,15 +128,6 @@ final class InputMonitor {

                // If there's a drag in flight, provide a pseudo-window to catch drag input
                final boolean inDrag = mService.mDragDropController.dragDropActiveLocked();
                if (inDrag) {
                    if (DEBUG_DRAG) {
                        Log.d(TAG_WM, "Inserting drag window");
                    }
                    mService.mDragDropController.showInputSurface(mInputTransaction, mDisplayId);
                } else {
                    mService.mDragDropController.hideInputSurface(mInputTransaction, mDisplayId);
                }

                final boolean inPositioning =
                        mService.mTaskPositioningController.isPositioningLocked();
                if (inPositioning) {