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

Commit 0567cea9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "dw-jank" into main

* changes:
  Delay creation of ResizeVeil until it needs to be shown
  Add INPUT_FEATURE_NO_INPUT_CHANNEL feature to app handle
  Add traces for Desktop Windowing decorations
parents 7648d1dd 8cc072a3
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -200,7 +200,6 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
        mRelayoutParams.mShadowRadiusId = shadowRadiusID;
        mRelayoutParams.mApplyStartTransactionOnDraw = applyStartTransactionOnDraw;
        mRelayoutParams.mSetTaskPositionAndCrop = setTaskCropAndPosition;
        mRelayoutParams.mAllowCaptionInputFallthrough = false;

        relayout(mRelayoutParams, startT, finishT, wct, oldRootView, mResult);
        // After this line, mTaskInfo is up-to-date and should be used instead of taskInfo
+0 −1
Original line number Diff line number Diff line
@@ -1037,7 +1037,6 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                        mSyncQueue,
                        mRootTaskDisplayAreaOrganizer);
        mWindowDecorByTaskId.put(taskInfo.taskId, windowDecoration);
        windowDecoration.createResizeVeil();

        final DragPositioningCallback dragPositioningCallback;
        if (!DesktopModeStatus.isVeiledResizeEnabled()) {
+32 −6
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Trace;
import android.util.Log;
import android.util.Size;
import android.view.Choreographer;
@@ -51,6 +52,7 @@ import android.view.MotionEvent;
import android.view.SurfaceControl;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.window.WindowContainerTransaction;

@@ -158,7 +160,9 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        mSyncQueue = syncQueue;
        mRootTaskDisplayAreaOrganizer = rootTaskDisplayAreaOrganizer;

        Trace.beginSection("DesktopModeWindowDecoration#loadAppInfo");
        loadAppInfo();
        Trace.endSection();
    }

    void setCaptionListeners(
@@ -204,6 +208,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    void relayout(ActivityManager.RunningTaskInfo taskInfo,
            SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT,
            boolean applyStartTransactionOnDraw, boolean shouldSetTaskPositionAndCrop) {
        Trace.beginSection("DesktopModeWindowDecoration#relayout");
        if (isHandleMenuActive()) {
            mHandleMenu.relayout(startT);
        }
@@ -215,16 +220,22 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        final SurfaceControl oldDecorationSurface = mDecorationContainerSurface;
        final WindowContainerTransaction wct = new WindowContainerTransaction();

        Trace.beginSection("DesktopModeWindowDecoration#relayout-inner");
        relayout(mRelayoutParams, startT, finishT, wct, oldRootView, mResult);
        Trace.endSection();
        // After this line, mTaskInfo is up-to-date and should be used instead of taskInfo

        Trace.beginSection("DesktopModeWindowDecoration#relayout-applyWCT");
        mTaskOrganizer.applyTransaction(wct);
        Trace.endSection();

        if (mResult.mRootView == null) {
            // This means something blocks the window decor from showing, e.g. the task is hidden.
            // Nothing is set up in this case including the decoration surface.
            Trace.endSection(); // DesktopModeWindowDecoration#relayout
            return;
        }

        if (oldRootView != mResult.mRootView) {
            if (mRelayoutParams.mLayoutResId == R.layout.desktop_mode_focused_window_decor) {
                mWindowDecorViewHolder = new DesktopModeFocusedWindowDecorationViewHolder(
@@ -252,7 +263,9 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                throw new IllegalArgumentException("Unexpected layout resource id");
            }
        }
        Trace.beginSection("DesktopModeWindowDecoration#relayout-binding");
        mWindowDecorViewHolder.bindData(mTaskInfo);
        Trace.endSection();

        if (!mTaskInfo.isFocused) {
            closeHandleMenu();
@@ -268,11 +281,13 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                updateExclusionRegion();
            }
            closeDragResizeListener();
            Trace.endSection(); // DesktopModeWindowDecoration#relayout
            return;
        }

        if (oldDecorationSurface != mDecorationContainerSurface || mDragResizeListener == null) {
            closeDragResizeListener();
            Trace.beginSection("DesktopModeWindowDecoration#relayout-DragResizeInputListener");
            mDragResizeListener = new DragResizeInputListener(
                    mContext,
                    mHandler,
@@ -283,6 +298,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                    mSurfaceControlBuilderSupplier,
                    mSurfaceControlTransactionSupplier,
                    mDisplayController);
            Trace.endSection();
        }

        final int touchSlop = ViewConfiguration.get(mResult.mRootView.getContext())
@@ -307,6 +323,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                mMaximizeMenu.positionMenu(calculateMaximizeMenuPosition(), startT);
            }
        }
        Trace.endSection(); // DesktopModeWindowDecoration#relayout
    }

    @VisibleForTesting
@@ -324,11 +341,12 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        relayoutParams.mCaptionWidthId = getCaptionWidthId(relayoutParams.mLayoutResId);

        if (captionLayoutId == R.layout.desktop_mode_app_controls_window_decor) {
            // If the app is requesting to customize the caption bar, allow input to fall through
            // to the windows below so that the app can respond to input events on their custom
            // content.
            relayoutParams.mAllowCaptionInputFallthrough =
                    TaskInfoKt.isTransparentCaptionBarAppearance(taskInfo);
            if (TaskInfoKt.isTransparentCaptionBarAppearance(taskInfo)) {
                // If the app is requesting to customize the caption bar, allow input to fall
                // through to the windows below so that the app can respond to input events on
                // their custom content.
                relayoutParams.mInputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_SPY;
            }
            // Report occluding elements as bounding rects to the insets system so that apps can
            // draw in the empty space in the center:
            //   First, the "app chip" section of the caption bar (+ some extra margins).
@@ -343,6 +361,11 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            controlsElement.mWidthResId = R.dimen.desktop_mode_customizable_caption_margin_end;
            controlsElement.mAlignment = RelayoutParams.OccludingCaptionElement.Alignment.END;
            relayoutParams.mOccludingCaptionElements.add(controlsElement);
        } else if (captionLayoutId == R.layout.desktop_mode_focused_window_decor) {
            // The focused decor (fullscreen/split) does not need to handle input because input in
            // the App Handle is handled by the InputMonitor in DesktopModeWindowDecorViewModel.
            relayoutParams.mInputFeatures
                    |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
        }
        if (DesktopModeStatus.useWindowShadow(/* isFocusedWindow= */ taskInfo.isFocused)) {
            relayoutParams.mShadowRadiusId = taskInfo.isFocused
@@ -464,7 +487,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
     * Create the resize veil for this task. Note the veil's visibility is View.GONE by default
     * until a resize event calls showResizeVeil below.
     */
    void createResizeVeil() {
    private void createResizeVeilIfNeeded() {
        if (mResizeVeil != null) return;
        mResizeVeil = new ResizeVeil(mContext, mDisplayController, mAppIconBitmap, mTaskInfo,
                mTaskSurface, mSurfaceControlTransactionSupplier);
    }
@@ -473,6 +497,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
     * Show the resize veil.
     */
    public void showResizeVeil(Rect taskBounds) {
        createResizeVeilIfNeeded();
        mResizeVeil.showVeil(mTaskSurface, taskBounds);
    }

@@ -480,6 +505,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
     * Show the resize veil.
     */
    public void showResizeVeil(SurfaceControl.Transaction tx, Rect taskBounds) {
        createResizeVeilIfNeeded();
        mResizeVeil.showVeil(tx, mTaskSurface, taskBounds, false /* fadeIn */);
    }

+3 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Trace;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.SurfaceControl;
@@ -135,6 +136,7 @@ public class ResizeVeil {
            // Display may not be available yet, skip this until then.
            return;
        }
        Trace.beginSection("ResizeVeil#setupResizeVeil");
        mVeilSurface = mSurfaceControlBuilderFactory
                .create("Resize veil of Task=" + mTaskInfo.taskId)
                .setContainerLayer()
@@ -179,6 +181,7 @@ public class ResizeVeil {

        mViewHost = mSurfaceControlViewHostFactory.create(mContext, mDisplay, wwm, "ResizeVeil");
        mViewHost.setView(root, lp);
        Trace.endSection();
    }

    private boolean obtainDisplayOrRegisterListener() {
+12 −9
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Binder;
import android.os.Trace;
import android.view.Display;
import android.view.InsetsSource;
import android.view.InsetsState;
@@ -311,7 +312,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
                boundingRects = null;
            } else {
                // The customizable region can at most be equal to the caption bar.
                if (params.mAllowCaptionInputFallthrough) {
                if (params.hasInputFeatureSpy()) {
                    outResult.mCustomizableCaptionRegion.set(mCaptionInsetsRect);
                }
                boundingRects = new Rect[numOfElements];
@@ -324,7 +325,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
                            calculateBoundingRect(element, elementWidthPx, mCaptionInsetsRect);
                    // Subtract the regions used by the caption elements, the rest is
                    // customizable.
                    if (params.mAllowCaptionInputFallthrough) {
                    if (params.hasInputFeatureSpy()) {
                        outResult.mCustomizableCaptionRegion.op(boundingRects[i],
                                Region.Op.DIFFERENCE);
                    }
@@ -378,6 +379,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
            startT.unsetColor(mTaskSurface);
        }

        Trace.beginSection("CaptionViewHostLayout");
        if (mCaptionWindowManager == null) {
            // Put caption under a container surface because ViewRootImpl sets the destination frame
            // of windowless window layers and BLASTBufferQueue#update() doesn't support offset.
@@ -394,11 +396,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
                        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSPARENT);
        lp.setTitle("Caption of Task=" + mTaskInfo.taskId);
        lp.setTrustedOverlay();
        if (params.mAllowCaptionInputFallthrough) {
            lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_SPY;
        } else {
            lp.inputFeatures &= ~WindowManager.LayoutParams.INPUT_FEATURE_SPY;
        }
        lp.inputFeatures = params.mInputFeatures;
        if (mViewHost == null) {
            mViewHost = mSurfaceControlViewHostFactory.create(mDecorWindowContext, mDisplay,
                    mCaptionWindowManager);
@@ -412,6 +410,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
            }
            mViewHost.relayout(lp);
        }
        Trace.endSection(); // CaptionViewHostLayout
    }

    private Rect calculateBoundingRect(@NonNull OccludingCaptionElement element,
@@ -605,7 +604,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
        int mCaptionHeightId;
        int mCaptionWidthId;
        final List<OccludingCaptionElement> mOccludingCaptionElements = new ArrayList<>();
        boolean mAllowCaptionInputFallthrough;
        int mInputFeatures;

        int mShadowRadiusId;
        int mCornerRadius;
@@ -620,7 +619,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
            mCaptionHeightId = Resources.ID_NULL;
            mCaptionWidthId = Resources.ID_NULL;
            mOccludingCaptionElements.clear();
            mAllowCaptionInputFallthrough = false;
            mInputFeatures = 0;

            mShadowRadiusId = Resources.ID_NULL;
            mCornerRadius = 0;
@@ -630,6 +629,10 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
            mWindowDecorConfig = null;
        }

        boolean hasInputFeatureSpy() {
            return (mInputFeatures & WindowManager.LayoutParams.INPUT_FEATURE_SPY) != 0;
        }

        /**
         * Describes elements within the caption bar that could occlude app content, and should be
         * sent as bounding rectangles to the insets system.
Loading