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

Commit 941e4c89 authored by Arpit Singh's avatar Arpit Singh
Browse files

[CD Cursor] Add bounds to DisplayTopologyGraph

This CL adds absolute display bounds to the DisplayTopologyGraph. Theses
will be used in upcoming Cls to allow conversion between local and
global coordinates in InputManager.

Bug: 401220484
Test: presubmit
Test: check output of `dumpsys input`
Flag: com.android.input.flags.use_topology_aware_flag
Change-Id: Ib1a96e57b720d339ff7facbdf3f8343f1069f6e3
parent e4f4ac59
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -809,9 +809,10 @@ public final class DisplayTopology implements Parcelable {
        DisplayTopologyGraph.DisplayNode[] nodes =
                new DisplayTopologyGraph.DisplayNode[infoList.size()];
        for (int i = 0; i < nodes.length; i++) {
            TreeNode treeNode = infoList.get(i).node;
            final NodeDerivedInfo nodeDerivedInfo = infoList.get(i);
            nodes[i] = new DisplayTopologyGraph.DisplayNode(
                    treeNode.mDisplayId, treeNode.mLogicalDensity,
                    nodeDerivedInfo.node.mDisplayId, nodeDerivedInfo.node.mLogicalDensity,
                    nodeDerivedInfo.absoluteBounds(),
                    adjacentDisplays[i].toArray(new DisplayTopologyGraph.AdjacentDisplay[0]));
        }
        return new DisplayTopologyGraph(mPrimaryDisplayId, nodes);
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.hardware.display;

import static android.hardware.display.DisplayTopology.TreeNode.positionToString;

import android.graphics.RectF;

/**
 * Graph of the displays in {@link android.hardware.display.DisplayTopology} tree.
 *
@@ -30,6 +32,7 @@ public record DisplayTopologyGraph(int primaryDisplayId, DisplayNode[] displayNo
    public record DisplayNode(
            int displayId,
            int density,
            RectF boundsInGlobalDp,
            AdjacentDisplay[] adjacentDisplays) {}

    /**
+52 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ static struct {
    jclass clazz;
    jfieldID displayId;
    jfieldID density;
    jfieldID boundsInGlobalDp;
    jfieldID adjacentDisplays;
} gDisplayTopologyGraphNodeClassInfo;

@@ -46,8 +47,30 @@ static struct {
    jfieldID offsetDp;
} gDisplayTopologyGraphAdjacentDisplayClassInfo;

static struct {
    jclass clazz;
    jfieldID left;
    jfieldID top;
    jfieldID right;
    jfieldID bottom;
} gDisplayTopologyGraphDisplayBoundsClassInfo;

// ----------------------------------------------------------------------------

status_t android_hardware_display_DisplayTopologyDisplayBounds_toNative(JNIEnv* env,
                                                                        jobject displayBoundsObj,
                                                                        FloatRect* displayBounds) {
    displayBounds->left =
            env->GetFloatField(displayBoundsObj, gDisplayTopologyGraphDisplayBoundsClassInfo.left);
    displayBounds->top =
            env->GetFloatField(displayBoundsObj, gDisplayTopologyGraphDisplayBoundsClassInfo.top);
    displayBounds->right =
            env->GetFloatField(displayBoundsObj, gDisplayTopologyGraphDisplayBoundsClassInfo.right);
    displayBounds->bottom = env->GetFloatField(displayBoundsObj,
                                               gDisplayTopologyGraphDisplayBoundsClassInfo.bottom);
    return OK;
}

status_t android_hardware_display_DisplayTopologyAdjacentDisplay_toNative(
        JNIEnv* env, jobject adjacentDisplayObj, DisplayTopologyAdjacentDisplay* adjacentDisplay) {
    adjacentDisplay->displayId = ui::LogicalDisplayId{
@@ -66,13 +89,21 @@ status_t android_hardware_display_DisplayTopologyGraphNode_toNative(
        JNIEnv* env, jobject nodeObj,
        std::unordered_map<ui::LogicalDisplayId, std::vector<DisplayTopologyAdjacentDisplay>>&
                graph,
        std::unordered_map<ui::LogicalDisplayId, int>& displaysDensity) {
        std::unordered_map<ui::LogicalDisplayId, int>& displaysDensity,
        std::unordered_map<ui::LogicalDisplayId, FloatRect>& displayBoundsDp) {
    ui::LogicalDisplayId displayId = ui::LogicalDisplayId{
            env->GetIntField(nodeObj, gDisplayTopologyGraphNodeClassInfo.displayId)};

    displaysDensity[displayId] =
            env->GetIntField(nodeObj, gDisplayTopologyGraphNodeClassInfo.density);

    ScopedLocalRef<jobject> displayBounds(env,
                                          env->GetObjectField(nodeObj,
                                                              gDisplayTopologyGraphNodeClassInfo
                                                                      .boundsInGlobalDp));
    android_hardware_display_DisplayTopologyDisplayBounds_toNative(env, displayBounds.get(),
                                                                   &displayBoundsDp[displayId]);

    jobjectArray adjacentDisplaysArray = static_cast<jobjectArray>(
            env->GetObjectField(nodeObj, gDisplayTopologyGraphNodeClassInfo.adjacentDisplays));

@@ -101,6 +132,7 @@ base::Result<const DisplayTopologyGraph> android_hardware_display_DisplayTopolog
    std::unordered_map<ui::LogicalDisplayId, std::vector<DisplayTopologyAdjacentDisplay>>
            topologyGraph;
    std::unordered_map<ui::LogicalDisplayId, int> displaysDensity;
    std::unordered_map<ui::LogicalDisplayId, FloatRect> absoluteDisplayBoundsDp;
    ui::LogicalDisplayId primaryDisplayId = ui::LogicalDisplayId{
            env->GetIntField(topologyObj, gDisplayTopologyGraphClassInfo.primaryDisplayId)};

@@ -117,11 +149,14 @@ base::Result<const DisplayTopologyGraph> android_hardware_display_DisplayTopolog

            android_hardware_display_DisplayTopologyGraphNode_toNative(env, nodeObj.get(),
                                                                       /*byRef*/ topologyGraph,
                                                                       /*byRef*/ displaysDensity);
                                                                       /*byRef*/ displaysDensity,
                                                                       /*byRef*/
                                                                       absoluteDisplayBoundsDp);
        }
    }
    return DisplayTopologyGraph::create(primaryDisplayId, std::move(topologyGraph),
                                        std::move(displaysDensity));
                                        std::move(displaysDensity),
                                        std::move(absoluteDisplayBoundsDp));
}

// ----------------------------------------------------------------------------
@@ -143,6 +178,9 @@ int register_android_hardware_display_DisplayTopology(JNIEnv* env) {
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "displayId", "I");
    gDisplayTopologyGraphNodeClassInfo.density =
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "density", "I");
    gDisplayTopologyGraphNodeClassInfo.boundsInGlobalDp =
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "boundsInGlobalDp",
                            "Landroid/graphics/RectF;");
    gDisplayTopologyGraphNodeClassInfo.adjacentDisplays =
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "adjacentDisplays",
                            "[Landroid/hardware/display/DisplayTopologyGraph$AdjacentDisplay;");
@@ -160,6 +198,17 @@ int register_android_hardware_display_DisplayTopology(JNIEnv* env) {
    gDisplayTopologyGraphAdjacentDisplayClassInfo.offsetDp =
            GetFieldIDOrDie(env, gDisplayTopologyGraphAdjacentDisplayClassInfo.clazz, "offsetDp",
                            "F");

    jclass displayBoundsClazz = FindClassOrDie(env, "android/graphics/RectF");
    gDisplayTopologyGraphDisplayBoundsClassInfo.clazz = MakeGlobalRefOrDie(env, displayBoundsClazz);
    gDisplayTopologyGraphDisplayBoundsClassInfo.left =
            GetFieldIDOrDie(env, gDisplayTopologyGraphDisplayBoundsClassInfo.clazz, "left", "F");
    gDisplayTopologyGraphDisplayBoundsClassInfo.top =
            GetFieldIDOrDie(env, gDisplayTopologyGraphDisplayBoundsClassInfo.clazz, "top", "F");
    gDisplayTopologyGraphDisplayBoundsClassInfo.right =
            GetFieldIDOrDie(env, gDisplayTopologyGraphDisplayBoundsClassInfo.clazz, "right", "F");
    gDisplayTopologyGraphDisplayBoundsClassInfo.bottom =
            GetFieldIDOrDie(env, gDisplayTopologyGraphDisplayBoundsClassInfo.clazz, "bottom", "F");
    return 0;
}

+13 −2
Original line number Diff line number Diff line
@@ -113,10 +113,21 @@ class VisualIndicatorUpdateSchedulerTest : ShellTestCase() {
            DisplayNode(
                displayId0,
                TestDisplay.DISPLAY_0.dpi,
                TestDisplay.DISPLAY_0.bounds,
                arrayOf(adjacentDisplay1To0, adjacentDisplay3To0),
            ),
            DisplayNode(displayId1, TestDisplay.DISPLAY_1.dpi, arrayOf(adjacentDisplay0To1)),
            DisplayNode(displayId3, TestDisplay.DISPLAY_3.dpi, arrayOf(adjacentDisplay0To3)),
            DisplayNode(
                displayId1,
                TestDisplay.DISPLAY_1.dpi,
                TestDisplay.DISPLAY_1.bounds,
                arrayOf(adjacentDisplay0To1),
            ),
            DisplayNode(
                displayId3,
                TestDisplay.DISPLAY_3.dpi,
                TestDisplay.DISPLAY_3.bounds,
                arrayOf(adjacentDisplay0To3),
            ),
        )

    @Before