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

Commit f03bad79 authored by Maryam Dehaini's avatar Maryam Dehaini
Browse files

Add shadow to view in sync with the handle menu appearing

When we add the shadow right after running
SurfaceControlViewHost#setView, the shadow become visible on the screen
before the view which causes a flashing affect. This change uses a
SyncSurfaceGroup to sync set view and the application of our
transaction.

Bug: 276356641
Test: Manual Testing
Change-Id: Iecbcb0e9f7736bddfd3054f8e91c69bce41e3e78
parent 86e2b60c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -303,6 +303,7 @@ public class SurfaceControlViewHost {
    /** @hide */
    public SurfaceControlViewHost(@NonNull Context c, @NonNull Display d,
            @NonNull WindowlessWindowManager wwm, @NonNull String callsite) {
        mSurfaceControl = wwm.mRootSurface;
        mWm = wwm;
        mViewRoot = new ViewRootImpl(c, d, mWm, new WindowlessWindowLayout());
        mCloseGuard.openWithCallSite("release", callsite);
+13 −13
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.window.SurfaceSyncGroup;
import android.window.WindowContainerTransaction;

import com.android.launcher3.icons.IconProvider;
@@ -311,51 +312,50 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
     * Create and display handle menu window
     */
    void createHandleMenu() {
        final SurfaceSyncGroup ssg = new SurfaceSyncGroup(TAG);
        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        updateHandleMenuPillPositions();

        createAppInfoPill(t);
        createAppInfoPill(t, ssg);

        // Only show windowing buttons in proto2. Proto1 uses a system-level mode only.
        final boolean shouldShowWindowingPill = DesktopModeStatus.isProto2Enabled();
        if (shouldShowWindowingPill) {
            createWindowingPill(t);
            createWindowingPill(t, ssg);
        }

        createMoreActionsPill(t);
        createMoreActionsPill(t, ssg);

        mSyncQueue.runInSync(transaction -> {
            transaction.merge(t);
            t.close();
        });
        ssg.addTransaction(t);
        ssg.markSyncReady();
        setupHandleMenu(shouldShowWindowingPill);
    }

    private void createAppInfoPill(SurfaceControl.Transaction t) {
    private void createAppInfoPill(SurfaceControl.Transaction t, SurfaceSyncGroup ssg) {
        final int x = (int) mHandleMenuAppInfoPillPosition.x;
        final int y = (int) mHandleMenuAppInfoPillPosition.y;
        mHandleMenuAppInfoPill = addWindow(
                R.layout.desktop_mode_window_decor_handle_menu_app_info_pill,
                "Menu's app info pill",
                t, x, y, mMenuWidth, mAppInfoPillHeight, mShadowRadius, mCornerRadius);
                t, ssg, x, y, mMenuWidth, mAppInfoPillHeight, mShadowRadius, mCornerRadius);
    }

    private void createWindowingPill(SurfaceControl.Transaction t) {
    private void createWindowingPill(SurfaceControl.Transaction t, SurfaceSyncGroup ssg) {
        final int x = (int) mHandleMenuWindowingPillPosition.x;
        final int y = (int) mHandleMenuWindowingPillPosition.y;
        mHandleMenuWindowingPill = addWindow(
                R.layout.desktop_mode_window_decor_handle_menu_windowing_pill,
                "Menu's windowing pill",
                t, x, y, mMenuWidth, mWindowingPillHeight, mShadowRadius, mCornerRadius);
                t, ssg, x, y, mMenuWidth, mWindowingPillHeight, mShadowRadius, mCornerRadius);
    }

    private void createMoreActionsPill(SurfaceControl.Transaction t) {
    private void createMoreActionsPill(SurfaceControl.Transaction t, SurfaceSyncGroup ssg) {
        final int x = (int) mHandleMenuMoreActionsPillPosition.x;
        final int y = (int) mHandleMenuMoreActionsPillPosition.y;
        mHandleMenuMoreActionsPill = addWindow(
                R.layout.desktop_mode_window_decor_handle_menu_more_actions_pill,
                "Menu's more actions pill",
                t, x, y, mMenuWidth, mMoreActionsPillHeight, mShadowRadius, mCornerRadius);
                t, ssg, x, y, mMenuWidth, mMoreActionsPillHeight, mShadowRadius, mCornerRadius);
    }

    private void setupHandleMenu(boolean windowingPillShown) {
+14 −11
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.view.ViewRootImpl;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.WindowlessWindowManager;
import android.window.SurfaceSyncGroup;
import android.window.TaskConstants;
import android.window.WindowContainerTransaction;

@@ -382,6 +383,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
    /**
     * Create a window associated with this WindowDecoration.
     * Note that subclass must dispose of this when the task is hidden/closed.
     *
     * @param layoutId     layout to make the window from
     * @param t            the transaction to apply
     * @param xPos         x position of new window
@@ -393,7 +395,8 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
     * @return the {@link AdditionalWindow} that was added.
     */
    AdditionalWindow addWindow(int layoutId, String namePrefix, SurfaceControl.Transaction t,
            int xPos, int yPos, int width, int height, int shadowRadius, int cornerRadius) {
            SurfaceSyncGroup ssg, int xPos, int yPos, int width, int height, int shadowRadius,
            int cornerRadius) {
        final SurfaceControl.Builder builder = mSurfaceControlBuilderSupplier.get();
        SurfaceControl windowSurfaceControl = builder
                .setName(namePrefix + " of Task=" + mTaskInfo.taskId)
@@ -417,7 +420,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
                windowSurfaceControl, null /* hostInputToken */);
        SurfaceControlViewHost viewHost = mSurfaceControlViewHostFactory
                .create(mDecorWindowContext, mDisplay, windowManager);
        viewHost.setView(v, lp);
        ssg.add(viewHost.getSurfacePackage(), () -> viewHost.setView(v, lp));
        return new AdditionalWindow(windowSurfaceControl, viewHost,
                mSurfaceControlTransactionSupplier);
    }
+4 −1
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.view.View;
import android.view.ViewRootImpl;
import android.view.WindowInsets;
import android.view.WindowManager.LayoutParams;
import android.window.SurfaceSyncGroup;
import android.window.TaskConstants;
import android.window.WindowContainerTransaction;

@@ -100,6 +101,8 @@ public class WindowDecorationTests extends ShellTestCase {
    private TestView mMockView;
    @Mock
    private WindowContainerTransaction mMockWindowContainerTransaction;
    @Mock
    private SurfaceSyncGroup mMockSurfaceSyncGroup;

    private final List<SurfaceControl.Transaction> mMockSurfaceControlTransactions =
            new ArrayList<>();
@@ -553,7 +556,7 @@ public class WindowDecorationTests extends ShellTestCase {
            String name = "Test Window";
            WindowDecoration.AdditionalWindow additionalWindow =
                    addWindow(R.layout.desktop_mode_window_decor_handle_menu_app_info_pill, name,
                            mMockSurfaceControlAddWindowT, x, y,
                            mMockSurfaceControlAddWindowT, mMockSurfaceSyncGroup, x, y,
                            width, height, shadowRadius, cornerRadius);
            return additionalWindow;
        }