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

Commit 5d4bb243 authored by Nergi Rahardi's avatar Nergi Rahardi Committed by Android (Google) Code Review
Browse files

Merge "Refactor DisplayTopologyGraph to be POJO" into main

parents 473e5d58 d6fdca19
Loading
Loading
Loading
Loading
+121 −29
Original line number Diff line number Diff line
@@ -16,45 +16,137 @@

package android.hardware.display;

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

import android.graphics.RectF;

import androidx.annotation.NonNull;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * Graph of the displays in {@link android.hardware.display.DisplayTopology} tree.
 *
 * @hide
 */
public record DisplayTopologyGraph(int primaryDisplayId, DisplayNode[] displayNodes) {
    /**
     * Display in the topology
     */
    public record DisplayNode(
public class DisplayTopologyGraph {

    private final int mPrimaryDisplayId;
    private final DisplayNode[] mDisplayNodes;

    public DisplayTopologyGraph(int primaryDisplayId, DisplayNode[] displayNodes) {
        mPrimaryDisplayId = primaryDisplayId;
        mDisplayNodes = displayNodes;
    }

    public int getPrimaryDisplayId() {
        return mPrimaryDisplayId;
    }

    public @NonNull List<DisplayNode> getDisplayNodes() {
        return Arrays.asList(mDisplayNodes);
    }

    /** Display in the topology */
    public static class DisplayNode {

        private final int mDisplayId;
        private final int mDensity;
        private final RectF mBoundsInGlobalDp;
        private final AdjacentDisplay[] mAdjacentDisplays;

        public DisplayNode(
                int displayId,
                int density,
            RectF boundsInGlobalDp,
            AdjacentDisplay[] adjacentDisplays) {}
                @NonNull RectF boundsInGlobalDp,
                AdjacentDisplay[] adjacentDisplays) {
            mDisplayId = displayId;
            mDensity = density;
            mBoundsInGlobalDp = boundsInGlobalDp;
            mAdjacentDisplays = adjacentDisplays;
        }

        public int getDisplayId() {
            return mDisplayId;
        }

        public int getDensity() {
            return mDensity;
        }

        public @NonNull RectF getBoundsInGlobalDp() {
            return mBoundsInGlobalDp;
        }

        public @NonNull List<AdjacentDisplay> getAdjacentDisplays() {
            return Arrays.asList(mAdjacentDisplays);
        }
    }

    /** Edge to adjacent display */
    public static final class AdjacentDisplay {

    /**
     * Edge to adjacent display
     */
    public record AdjacentDisplay(
        // The logical Id of this adjacent display
            int displayId,
        private final int mDisplayId;

        // Side of the other display which touches this adjacent display.
            @DisplayTopology.TreeNode.Position
            int position,
        @DisplayTopology.TreeNode.Position private final int mPosition;

        // The distance from the top edge of the other 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).
            float offsetDp) {
        private final float mOffsetDp;

        /** Constructor for AdjacentDisplay. */
        public AdjacentDisplay(
                int displayId, @DisplayTopology.TreeNode.Position int position, float offsetDp) {
            mDisplayId = displayId;
            mPosition = position;
            mOffsetDp = offsetDp;
        }

        public int getDisplayId() {
            return mDisplayId;
        }

        @DisplayTopology.TreeNode.Position
        public int getPosition() {
            return mPosition;
        }

        public float getOffsetDp() {
            return mOffsetDp;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            AdjacentDisplay rhs = (AdjacentDisplay) o;
            return this.mDisplayId == rhs.mDisplayId
                    && this.mPosition == rhs.mPosition
                    && this.mOffsetDp == rhs.mOffsetDp;
        }

        @Override
        public int hashCode() {
            return Objects.hash(mDisplayId, mPosition, mOffsetDp);
        }

        @Override
        public String toString() {
            return "AdjacentDisplay{"
                    + "displayId=" + displayId
                    + ", position=" + positionToString(position)
                    + ", offsetDp=" + offsetDp
                    + "displayId="
                    + mDisplayId
                    + ", position="
                    + DisplayTopology.TreeNode.positionToString(mPosition)
                    + ", offsetDp="
                    + mOffsetDp
                    + '}';
        }
    }
+9 −9
Original line number Diff line number Diff line
@@ -166,23 +166,23 @@ int register_android_hardware_display_DisplayTopology(JNIEnv* env) {
    gDisplayTopologyGraphClassInfo.clazz = MakeGlobalRefOrDie(env, graphClazz);

    gDisplayTopologyGraphClassInfo.primaryDisplayId =
            GetFieldIDOrDie(env, gDisplayTopologyGraphClassInfo.clazz, "primaryDisplayId", "I");
            GetFieldIDOrDie(env, gDisplayTopologyGraphClassInfo.clazz, "mPrimaryDisplayId", "I");
    gDisplayTopologyGraphClassInfo.displayNodes =
            GetFieldIDOrDie(env, gDisplayTopologyGraphClassInfo.clazz, "displayNodes",
            GetFieldIDOrDie(env, gDisplayTopologyGraphClassInfo.clazz, "mDisplayNodes",
                            "[Landroid/hardware/display/DisplayTopologyGraph$DisplayNode;");

    jclass displayNodeClazz =
            FindClassOrDie(env, "android/hardware/display/DisplayTopologyGraph$DisplayNode");
    gDisplayTopologyGraphNodeClassInfo.clazz = MakeGlobalRefOrDie(env, displayNodeClazz);
    gDisplayTopologyGraphNodeClassInfo.displayId =
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "displayId", "I");
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "mDisplayId", "I");
    gDisplayTopologyGraphNodeClassInfo.density =
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "density", "I");
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "mDensity", "I");
    gDisplayTopologyGraphNodeClassInfo.boundsInGlobalDp =
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "boundsInGlobalDp",
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "mBoundsInGlobalDp",
                            "Landroid/graphics/RectF;");
    gDisplayTopologyGraphNodeClassInfo.adjacentDisplays =
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "adjacentDisplays",
            GetFieldIDOrDie(env, gDisplayTopologyGraphNodeClassInfo.clazz, "mAdjacentDisplays",
                            "[Landroid/hardware/display/DisplayTopologyGraph$AdjacentDisplay;");

    jclass adjacentDisplayClazz =
@@ -190,13 +190,13 @@ int register_android_hardware_display_DisplayTopology(JNIEnv* env) {
    gDisplayTopologyGraphAdjacentDisplayClassInfo.clazz =
            MakeGlobalRefOrDie(env, adjacentDisplayClazz);
    gDisplayTopologyGraphAdjacentDisplayClassInfo.displayId =
            GetFieldIDOrDie(env, gDisplayTopologyGraphAdjacentDisplayClassInfo.clazz, "displayId",
            GetFieldIDOrDie(env, gDisplayTopologyGraphAdjacentDisplayClassInfo.clazz, "mDisplayId",
                            "I");
    gDisplayTopologyGraphAdjacentDisplayClassInfo.position =
            GetFieldIDOrDie(env, gDisplayTopologyGraphAdjacentDisplayClassInfo.clazz, "position",
            GetFieldIDOrDie(env, gDisplayTopologyGraphAdjacentDisplayClassInfo.clazz, "mPosition",
                            "I");
    gDisplayTopologyGraphAdjacentDisplayClassInfo.offsetDp =
            GetFieldIDOrDie(env, gDisplayTopologyGraphAdjacentDisplayClassInfo.clazz, "offsetDp",
            GetFieldIDOrDie(env, gDisplayTopologyGraphAdjacentDisplayClassInfo.clazz, "mOffsetDp",
                            "F");

    jclass displayBoundsClazz = FindClassOrDie(env, "android/graphics/RectF");
+2 −2
Original line number Diff line number Diff line
@@ -108,8 +108,8 @@ class VisualIndicatorUpdateSchedulerTest : ShellTestCase() {
    private val adjacentDisplay0To3 =
        AdjacentDisplay(displayId0, DisplayTopology.TreeNode.POSITION_LEFT, 0f)

    private val displayNodes: Array<DisplayNode> =
        arrayOf(
    private val displayNodes =
        listOf(
            DisplayNode(
                displayId0,
                TestDisplay.DISPLAY_0.dpi,