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

Commit 6849af96 authored by Piotr Wilczyński's avatar Piotr Wilczyński
Browse files

Topology tree representation

Bug: 364905636
Test: adb shell dumpsys display
Flag: com.android.server.display.feature.flags.display_topology
Change-Id: I76a2db80969e97cfc6b9ee3b75b4a22b3422f87d
parent 8419ae39
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -570,6 +570,10 @@ public final class DisplayManagerService extends SystemService {
    private final DisplayNotificationManager mDisplayNotificationManager;
    private final ExternalDisplayStatsService mExternalDisplayStatsService;

    // Manages the relative placement of extended displays
    @Nullable
    private final DisplayTopologyCoordinator mDisplayTopologyCoordinator;

    /**
     * Applications use {@link android.view.Display#getRefreshRate} and
     * {@link android.view.Display.Mode#getRefreshRate} to know what is the display refresh rate.
@@ -643,6 +647,11 @@ public final class DisplayManagerService extends SystemService {
        mDisplayNotificationManager = new DisplayNotificationManager(mFlags, mContext,
                mExternalDisplayStatsService);
        mExternalDisplayPolicy = new ExternalDisplayPolicy(new ExternalDisplayPolicyInjector());
        if (mFlags.isDisplayTopologyEnabled()) {
            mDisplayTopologyCoordinator = new DisplayTopologyCoordinator();
        } else {
            mDisplayTopologyCoordinator = null;
        }
    }

    public void setupSchedulerPolicies() {
@@ -3429,9 +3438,13 @@ public final class DisplayManagerService extends SystemService {
            mSmallAreaDetectionController.dump(pw);
        }

        if (mDisplayTopologyCoordinator != null) {
            pw.println();
        mFlags.dump(pw);
            mDisplayTopologyCoordinator.dump(pw);
        }

        pw.println();
        mFlags.dump(pw);
    }

    private static float[] getFloatArray(TypedArray array) {
+104 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.display;

import android.annotation.Nullable;
import android.util.IndentingPrintWriter;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * This class manages the relative placement (topology) of extended displays. It is responsible for
 * updating and persisting the topology.
 */
class DisplayTopologyCoordinator {

    /**
     * The topology tree
     */
    @Nullable
    private TopologyTreeNode mRoot;

    /**
     * The logical display ID of the primary display that will show certain UI elements.
     * This is not necessarily the same as the default display.
     */
    private int mPrimaryDisplayId;

    /**
     * Print the object's state and debug information into the given stream.
     * @param pw The stream to dump information to.
     */
    public void dump(PrintWriter pw) {
        pw.println("DisplayTopologyCoordinator:");
        pw.println("--------------------");
        IndentingPrintWriter ipw = new IndentingPrintWriter(pw);
        ipw.increaseIndent();

        ipw.println("mPrimaryDisplayId: " + mPrimaryDisplayId);

        ipw.println("Topology tree:");
        if (mRoot != null) {
            ipw.increaseIndent();
            mRoot.dump(ipw);
            ipw.decreaseIndent();
        }
    }

    private static class TopologyTreeNode {

        /**
         * The logical display ID
         */
        private int mDisplayId;

        private final List<TopologyTreeNode> mChildren = new ArrayList<>();

        /**
         * The position of this display relative to its parent.
         */
        private Position mPosition;

        /**
         * The distance from the top edge of the parent display to the top edge of this display (in
         * case of POSITION_LEFT or POSITION_RIGHT) or from the left edge of the parent display
         * to the left edge of this display (in case of POSITION_TOP or POSITION_BOTTOM). The unit
         * used is density-independent pixels (dp).
         */
        private double mOffset;

        /**
         * Print the object's state and debug information into the given stream.
         * @param ipw The stream to dump information to.
         */
        void dump(IndentingPrintWriter ipw) {
            ipw.println("Display {id=" + mDisplayId + ", position=" + mPosition
                    + ", offset=" + mOffset + "}");
            ipw.increaseIndent();
            for (TopologyTreeNode child : mChildren) {
                child.dump(ipw);
            }
            ipw.decreaseIndent();
        }

        private enum Position {
            POSITION_LEFT, POSITION_TOP, POSITION_RIGHT, POSITION_BOTTOM
        }
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -69,6 +69,10 @@ public class DisplayManagerFlags {
            Flags.FLAG_ENABLE_MODE_LIMIT_FOR_EXTERNAL_DISPLAY,
            Flags::enableModeLimitForExternalDisplay);

    private final FlagState mDisplayTopology = new FlagState(
            Flags.FLAG_DISPLAY_TOPOLOGY,
            Flags::displayTopology);

    private final FlagState mConnectedDisplayErrorHandlingFlagState = new FlagState(
            Flags.FLAG_ENABLE_CONNECTED_DISPLAY_ERROR_HANDLING,
            Flags::enableConnectedDisplayErrorHandling);
@@ -261,6 +265,10 @@ public class DisplayManagerFlags {
        return mExternalDisplayLimitModeState.isEnabled();
    }

    public boolean isDisplayTopologyEnabled() {
        return mDisplayTopology.isEnabled();
    }

    /**
     * @return Whether displays refresh rate synchronization is enabled.
     */
@@ -428,6 +436,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mConnectedDisplayManagementFlagState);
        pw.println(" " + mDisplayOffloadFlagState);
        pw.println(" " + mExternalDisplayLimitModeState);
        pw.println(" " + mDisplayTopology);
        pw.println(" " + mHdrClamperFlagState);
        pw.println(" " + mNbmControllerFlagState);
        pw.println(" " + mPowerThrottlingClamperFlagState);
+8 −0
Original line number Diff line number Diff line
@@ -91,6 +91,14 @@ flag {
    is_fixed_read_only: true
}

flag {
    name: "display_topology"
    namespace: "display_manager"
    description: "Display topology for moving cursors and windows between extended displays"
    bug: "278199220"
    is_fixed_read_only: true
}

flag {
    name: "enable_displays_refresh_rates_synchronization"
    namespace: "display_manager"