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

Commit ae606b44 authored by Robert Carr's avatar Robert Carr
Browse files

Eliminate usage of global transaction for display configuration.

For seamless rotation to work in the brave new world we need the setting
of the display projection to occur in the same transaction as the
reconfiguration of the stack SurfaceControl. To understand this simply see
that the inverse rotation for seamless rotation happens at the
WindowStateAnimator level so if the stack bounds weren't updated to the new
rotation we would clip. This means: We need to use the pending transaction.
We also need to port the rotation animation to use the pending transaction
as it needs to perform transactions at the same time as setting the display
projection. A pleasant consequence is we can eliminate some "inTransaction"
code-paths that always seemed to be a bit of a wart.

Bug: 72038766
Test: Manual. go/wm-smoke.
Change-Id: I949fbe8150d452c1ef5c13e704ddf87269f824f3
parent a9e73469
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.util.IntArray;
import android.util.SparseArray;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.SurfaceControl;

/**
 * Display manager local system service interface.
@@ -115,7 +116,7 @@ public abstract class DisplayManagerInternal {
     * Called by the window manager to perform traversals while holding a
     * surface flinger transaction.
     */
    public abstract void performTraversalInTransactionFromWindowManager();
    public abstract void performTraversal(SurfaceControl.Transaction t);

    /**
     * Tells the display manager about properties of the display that depend on the windows on it.
+9 −9
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ abstract class DisplayDevice {
    private Rect mCurrentDisplayRect;

    // The display device owns its surface, but it should only set it
    // within a transaction from performTraversalInTransactionLocked.
    // within a transaction from performTraversalLocked.
    private Surface mCurrentSurface;

    // DEBUG STATE: Last device info which was written to the log, or null if none.
@@ -122,7 +122,7 @@ abstract class DisplayDevice {
    /**
     * Gives the display device a chance to update its properties while in a transaction.
     */
    public void performTraversalInTransactionLocked() {
    public void performTraversalLocked(SurfaceControl.Transaction t) {
    }

    /**
@@ -140,7 +140,7 @@ abstract class DisplayDevice {
    /**
     * Sets the mode, if supported.
     */
    public void requestDisplayModesInTransactionLocked(int colorMode, int modeId) {
    public void requestDisplayModesLocked(int colorMode, int modeId) {
    }

    public void onOverlayChangedLocked() {
@@ -149,10 +149,10 @@ abstract class DisplayDevice {
    /**
     * Sets the display layer stack while in a transaction.
     */
    public final void setLayerStackInTransactionLocked(int layerStack) {
    public final void setLayerStackLocked(SurfaceControl.Transaction t, int layerStack) {
        if (mCurrentLayerStack != layerStack) {
            mCurrentLayerStack = layerStack;
            SurfaceControl.setDisplayLayerStack(mDisplayToken, layerStack);
            t.setDisplayLayerStack(mDisplayToken, layerStack);
        }
    }

@@ -166,7 +166,7 @@ abstract class DisplayDevice {
     *            mapped to. displayRect is specified post-orientation, that is
     *            it uses the orientation seen by the end-user
     */
    public final void setProjectionInTransactionLocked(int orientation,
    public final void setProjectionLocked(SurfaceControl.Transaction t, int orientation,
            Rect layerStackRect, Rect displayRect) {
        if (mCurrentOrientation != orientation
                || mCurrentLayerStackRect == null
@@ -185,7 +185,7 @@ abstract class DisplayDevice {
            }
            mCurrentDisplayRect.set(displayRect);

            SurfaceControl.setDisplayProjection(mDisplayToken,
            t.setDisplayProjection(mDisplayToken,
                    orientation, layerStackRect, displayRect);
        }
    }
@@ -193,10 +193,10 @@ abstract class DisplayDevice {
    /**
     * Sets the display surface while in a transaction.
     */
    public final void setSurfaceInTransactionLocked(Surface surface) {
    public final void setSurfaceLocked(SurfaceControl.Transaction t, Surface surface) {
        if (mCurrentSurface != surface) {
            mCurrentSurface = surface;
            SurfaceControl.setDisplaySurface(mDisplayToken, surface);
            t.setDisplaySurface(mDisplayToken, surface);
        }
    }

+11 −10
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import android.util.SparseArray;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.Surface;
import android.view.SurfaceControl;

import com.android.internal.util.Preconditions;
import com.android.server.AnimationThread;
@@ -457,14 +458,14 @@ public final class DisplayManagerService extends SystemService {
    }

    @VisibleForTesting
    void performTraversalInTransactionFromWindowManagerInternal() {
    void performTraversalInternal(SurfaceControl.Transaction t) {
        synchronized (mSyncRoot) {
            if (!mPendingTraversal) {
                return;
            }
            mPendingTraversal = false;

            performTraversalInTransactionLocked();
            performTraversalLocked(t);
        }

        // List is self-synchronized copy-on-write.
@@ -1056,7 +1057,7 @@ public final class DisplayManagerService extends SystemService {
        return changed;
    }

    private void performTraversalInTransactionLocked() {
    private void performTraversalLocked(SurfaceControl.Transaction t) {
        // Clear all viewports before configuring displays so that we can keep
        // track of which ones we have configured.
        clearViewportsLocked();
@@ -1065,8 +1066,8 @@ public final class DisplayManagerService extends SystemService {
        final int count = mDisplayDevices.size();
        for (int i = 0; i < count; i++) {
            DisplayDevice device = mDisplayDevices.get(i);
            configureDisplayInTransactionLocked(device);
            device.performTraversalInTransactionLocked();
            configureDisplayLocked(t, device);
            device.performTraversalLocked(t);
        }

        // Tell the input system about these new viewports.
@@ -1150,7 +1151,7 @@ public final class DisplayManagerService extends SystemService {
        mVirtualTouchViewports.clear();
    }

    private void configureDisplayInTransactionLocked(DisplayDevice device) {
    private void configureDisplayLocked(SurfaceControl.Transaction t, DisplayDevice device) {
        final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
        final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0;

@@ -1175,7 +1176,7 @@ public final class DisplayManagerService extends SystemService {
                    + device.getDisplayDeviceInfoLocked());
            return;
        }
        display.configureDisplayInTransactionLocked(device, info.state == Display.STATE_OFF);
        display.configureDisplayLocked(t, device, info.state == Display.STATE_OFF);

        // Update the viewports if needed.
        if (!mDefaultViewport.valid
@@ -1233,7 +1234,7 @@ public final class DisplayManagerService extends SystemService {
        mHandler.sendMessage(msg);
    }

    // Requests that performTraversalsInTransactionFromWindowManager be called at a
    // Requests that performTraversals be called at a
    // later time to apply changes to surfaces and displays.
    private void scheduleTraversalLocked(boolean inTraversal) {
        if (!mPendingTraversal && mWindowManagerInternal != null) {
@@ -2031,8 +2032,8 @@ public final class DisplayManagerService extends SystemService {
        }

        @Override
        public void performTraversalInTransactionFromWindowManager() {
            performTraversalInTransactionFromWindowManagerInternal();
        public void performTraversal(SurfaceControl.Transaction t) {
            performTraversalInternal(t);
        }

        @Override
+5 −6
Original line number Diff line number Diff line
@@ -584,10 +584,9 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        }

        @Override
        public void requestDisplayModesInTransactionLocked(
                int colorMode, int modeId) {
            if (requestModeInTransactionLocked(modeId) ||
                    requestColorModeInTransactionLocked(colorMode)) {
        public void requestDisplayModesLocked(int colorMode, int modeId) {
            if (requestModeLocked(modeId) ||
                    requestColorModeLocked(colorMode)) {
                updateDeviceInfoLocked();
            }
        }
@@ -597,7 +596,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            updateDeviceInfoLocked();
        }

        public boolean requestModeInTransactionLocked(int modeId) {
        public boolean requestModeLocked(int modeId) {
            if (modeId == 0) {
                modeId = mDefaultModeId;
            } else if (mSupportedModes.indexOfKey(modeId) < 0) {
@@ -623,7 +622,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            return true;
        }

        public boolean requestColorModeInTransactionLocked(int colorMode) {
        public boolean requestColorModeLocked(int colorMode) {
            if (mActiveColorMode == colorMode) {
                return false;
            }
+7 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.hardware.display.DisplayManagerInternal;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.Surface;
import android.view.SurfaceControl;

import java.io.PrintWriter;
import java.util.Arrays;
@@ -304,17 +305,18 @@ final class LogicalDisplay {
     * @param device The display device to modify.
     * @param isBlanked True if the device is being blanked.
     */
    public void configureDisplayInTransactionLocked(DisplayDevice device,
    public void configureDisplayLocked(SurfaceControl.Transaction t,
            DisplayDevice device,
            boolean isBlanked) {
        // Set the layer stack.
        device.setLayerStackInTransactionLocked(isBlanked ? BLANK_LAYER_STACK : mLayerStack);
        device.setLayerStackLocked(t, isBlanked ? BLANK_LAYER_STACK : mLayerStack);

        // Set the color mode and mode.
        if (device == mPrimaryDisplayDevice) {
            device.requestDisplayModesInTransactionLocked(
            device.requestDisplayModesLocked(
                    mRequestedColorMode, mRequestedModeId);
        } else {
            device.requestDisplayModesInTransactionLocked(0, 0);  // Revert to default.
            device.requestDisplayModesLocked(0, 0);  // Revert to default.
        }

        // Only grab the display info now as it may have been changed based on the requests above.
@@ -377,7 +379,7 @@ final class LogicalDisplay {
        mTempDisplayRect.right += mDisplayOffsetX;
        mTempDisplayRect.top += mDisplayOffsetY;
        mTempDisplayRect.bottom += mDisplayOffsetY;
        device.setProjectionInTransactionLocked(orientation, mTempLayerStackRect, mTempDisplayRect);
        device.setProjectionLocked(t, orientation, mTempLayerStackRect, mTempDisplayRect);
    }

    /**
Loading