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

Commit 6ee5b419 authored by Eric Jeong's avatar Eric Jeong Committed by Android (Google) Code Review
Browse files

Merge "Assign display groups to individual physical displays"

parents 86e58512 eb21cf10
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -411,6 +411,11 @@ public abstract class DisplayManagerInternal {
    @Nullable
    public abstract HostUsiVersion getHostUsiVersion(int displayId);

    /**
     * Get all available DisplayGroupIds.
     */
    public abstract IntArray getDisplayGroupIds();

    /**
     * Describes the requested power state of the display.
     *
+1 −0
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ class DeviceStateToLayoutMap {
                            DisplayAddress.fromPhysicalDisplayId(d.getAddress().longValue()),
                            d.isDefaultDisplay(),
                            d.isEnabled(),
                            d.getDisplayGroup(),
                            mIdProducer,
                            d.getBrightnessThrottlingMapId(),
                            leadDisplayId);
+17 −0
Original line number Diff line number Diff line
@@ -4239,6 +4239,23 @@ public final class DisplayManagerService extends SystemService {
                        .getHostUsiVersion();
            }
        }

        @Override
        public IntArray getDisplayGroupIds() {
            Set<Integer> visitedIds = new ArraySet<>();
            IntArray displayGroupIds = new IntArray();
            synchronized (mSyncRoot) {
                mLogicalDisplayMapper.forEachLocked(logicalDisplay -> {
                    int groupId = mLogicalDisplayMapper.getDisplayGroupIdFromDisplayIdLocked(
                            logicalDisplay.getDisplayIdLocked());
                    if (!visitedIds.contains(groupId)) {
                        visitedIds.add(groupId);
                        displayGroupIds.add(groupId);
                    }
                });
            }
            return displayGroupIds;
        }
    }

    class DesiredDisplayModeSpecsObserver
+33 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.Nullable;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.display.DisplayManagerInternal;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.SparseArray;
import android.view.Display;
@@ -136,6 +137,11 @@ final class LogicalDisplay {
    private final Rect mTempLayerStackRect = new Rect();
    private final Rect mTempDisplayRect = new Rect();

    /**
     * Name of a display group to which the display is assigned.
     */
    private String mDisplayGroupName;

    /**
     * The UID mappings for refresh rate override
     */
@@ -869,6 +875,32 @@ final class LogicalDisplay {
        return mLeadDisplayId;
    }

    /**
     * Sets the name of display group to which the display is assigned.
     */
    public void setDisplayGroupNameLocked(String displayGroupName) {
        mDisplayGroupName = displayGroupName;
    }

    /**
     * Gets the name of display group to which the display is assigned.
     */
    public String getDisplayGroupNameLocked() {
        return mDisplayGroupName;
    }

    /**
     * Returns whether a display group other than the default display group needs to be assigned.
     *
     * <p>If display group name is empty or {@code Display.FLAG_OWN_DISPLAY_GROUP} is set, the
     * display is assigned to the default display group.
     */
    public boolean needsOwnDisplayGroupLocked() {
        DisplayInfo info = getDisplayInfoLocked();
        return (info.flags & Display.FLAG_OWN_DISPLAY_GROUP) != 0
                || !TextUtils.isEmpty(mDisplayGroupName);
    }

    public void dumpLocked(PrintWriter pw) {
        pw.println("mDisplayId=" + mDisplayId);
        pw.println("mIsEnabled=" + mIsEnabled);
@@ -887,6 +919,7 @@ final class LogicalDisplay {
        pw.println("mRequestedMinimalPostProcessing=" + mRequestedMinimalPostProcessing);
        pw.println("mFrameRateOverrides=" + Arrays.toString(mFrameRateOverrides));
        pw.println("mPendingFrameRateOverrideUids=" + mPendingFrameRateOverrideUids);
        pw.println("mDisplayGroupName=" + mDisplayGroupName);
        pw.println("mBrightnessThrottlingDataId=" + mBrightnessThrottlingDataId);
        pw.println("mLeadDisplayId=" + mLeadDisplayId);
    }
+24 −9
Original line number Diff line number Diff line
@@ -133,6 +133,11 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
     */
    private final SparseIntArray mDeviceDisplayGroupIds = new SparseIntArray();

    /**
     * Map of display group ids indexed by display group name.
     */
    private final ArrayMap<String, Integer> mDisplayGroupIdsByName = new ArrayMap<>();

    private final DisplayDeviceRepository mDisplayDeviceRepo;
    private final DeviceStateToLayoutMap mDeviceStateToLayoutMap;
    private final Listener mListener;
@@ -640,7 +645,8 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                        & DisplayDeviceInfo.FLAG_ALLOWED_TO_BE_DEFAULT_DISPLAY) != 0
                        && !nextDeviceInfo.address.equals(deviceInfo.address)) {
                    layout.createDisplayLocked(nextDeviceInfo.address,
                            /* isDefault= */ true, /* isEnabled= */ true, mIdProducer,
                            /* isDefault= */ true, /* isEnabled= */ true,
                            Layout.DEFAULT_DISPLAY_GROUP_NAME, mIdProducer,
                            /* brightnessThrottlingMapId= */ null, DEFAULT_DISPLAY);
                    applyLayoutLocked();
                    return;
@@ -843,8 +849,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
        final DisplayGroup oldGroup = getDisplayGroupLocked(groupId);

        // Get the new display group if a change is needed
        final DisplayInfo info = display.getDisplayInfoLocked();
        final boolean needsOwnDisplayGroup = (info.flags & Display.FLAG_OWN_DISPLAY_GROUP) != 0;
        final boolean needsOwnDisplayGroup = display.needsOwnDisplayGroupLocked();
        final boolean hasOwnDisplayGroup = groupId != Display.DEFAULT_DISPLAY_GROUP;
        final boolean needsDeviceDisplayGroup =
                !needsOwnDisplayGroup && linkedDeviceUniqueId != null;
@@ -854,8 +859,9 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                || hasOwnDisplayGroup != needsOwnDisplayGroup
                || hasDeviceDisplayGroup != needsDeviceDisplayGroup) {
            groupId =
                    assignDisplayGroupIdLocked(
                            needsOwnDisplayGroup, needsDeviceDisplayGroup, linkedDeviceUniqueId);
                    assignDisplayGroupIdLocked(needsOwnDisplayGroup,
                            display.getDisplayGroupNameLocked(), needsDeviceDisplayGroup,
                            linkedDeviceUniqueId);
        }

        // Create a new group if needed
@@ -1000,6 +1006,8 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                    displayLayout.getBrightnessThrottlingMapId() == null
                            ? DisplayDeviceConfig.DEFAULT_BRIGHTNESS_THROTTLING_DATA_ID
                            : displayLayout.getBrightnessThrottlingMapId());

            newDisplay.setDisplayGroupNameLocked(displayLayout.getDisplayGroupName());
        }
    }

@@ -1053,8 +1061,8 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
        }
    }

    private int assignDisplayGroupIdLocked(
            boolean isOwnDisplayGroup, boolean isDeviceDisplayGroup, Integer linkedDeviceUniqueId) {
    private int assignDisplayGroupIdLocked(boolean isOwnDisplayGroup, String displayGroupName,
            boolean isDeviceDisplayGroup, Integer linkedDeviceUniqueId) {
        if (isDeviceDisplayGroup && linkedDeviceUniqueId != null) {
            int deviceDisplayGroupId = mDeviceDisplayGroupIds.get(linkedDeviceUniqueId);
            // A value of 0 indicates that no device display group was found.
@@ -1064,7 +1072,13 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
            }
            return deviceDisplayGroupId;
        }
        return isOwnDisplayGroup ? mNextNonDefaultGroupId++ : Display.DEFAULT_DISPLAY_GROUP;
        if (!isOwnDisplayGroup) return Display.DEFAULT_DISPLAY_GROUP;
        Integer displayGroupId = mDisplayGroupIdsByName.get(displayGroupName);
        if (displayGroupId == null) {
            displayGroupId = Integer.valueOf(mNextNonDefaultGroupId++);
            mDisplayGroupIdsByName.put(displayGroupName, displayGroupId);
        }
        return displayGroupId;
    }

    private void initializeDefaultDisplayDeviceLocked(DisplayDevice device) {
@@ -1079,7 +1093,8 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
        }
        final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
        layout.createDisplayLocked(info.address, /* isDefault= */ true, /* isEnabled= */ true,
                mIdProducer, /* brightnessThrottlingMapId= */ null, NO_LEAD_DISPLAY);
                Layout.DEFAULT_DISPLAY_GROUP_NAME, mIdProducer,
                /* brightnessThrottlingMapId= */ null, NO_LEAD_DISPLAY);
    }

    private int assignLayerStackLocked(int displayId) {
Loading