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

Commit 2707747e authored by Arpit Singh's avatar Arpit Singh
Browse files

Add density to display viewports

This CL adds display density in DPI to the display viewports. This will
be used by InputManager to scale cursor movement on the display based on
the density value.

Bug: 367662715
Test: presubmit and manual
Flag: com.android.input.flags.scale_cursor_speed_with_dpi
Change-Id: Idfa4ebff81a84cb6f1d73429e2b0b6925173e177
parent bf37af00
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -81,6 +81,9 @@ public final class DisplayViewport {

    public @ViewportType int type;

    // The logical display density which is the basis for density-independent pixels.
    public int densityDpi;

    public void copyFrom(DisplayViewport viewport) {
        valid = viewport.valid;
        isActive = viewport.isActive;
@@ -93,6 +96,7 @@ public final class DisplayViewport {
        uniqueId = viewport.uniqueId;
        physicalPort = viewport.physicalPort;
        type = viewport.type;
        densityDpi = viewport.densityDpi;
    }

    /**
@@ -125,7 +129,8 @@ public final class DisplayViewport {
              && deviceHeight == other.deviceHeight
              && TextUtils.equals(uniqueId, other.uniqueId)
              && Objects.equals(physicalPort, other.physicalPort)
              && type == other.type;
              && type == other.type
              && densityDpi == other.densityDpi;
    }

    @Override
@@ -145,6 +150,7 @@ public final class DisplayViewport {
            result += prime * result + physicalPort.hashCode();
        }
        result += prime * result + type;
        result += prime * result + densityDpi;
        return result;
    }

@@ -158,6 +164,7 @@ public final class DisplayViewport {
                + ", uniqueId='" + uniqueId + "'"
                + ", physicalPort=" + physicalPort
                + ", orientation=" + orientation
                + ", densityDpi=" + densityDpi
                + ", logicalFrame=" + logicalFrame
                + ", physicalFrame=" + physicalFrame
                + ", deviceWidth=" + deviceWidth
+6 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ static struct {
    jfieldID uniqueId;
    jfieldID physicalPort;
    jfieldID type;
    jfieldID densityDpi;
} gDisplayViewportClassInfo;

static struct {
@@ -82,6 +83,8 @@ status_t android_hardware_display_DisplayViewport_toNative(JNIEnv* env, jobject
    viewport->type = static_cast<ViewportType>(env->GetIntField(viewportObj,
                gDisplayViewportClassInfo.type));

    viewport->densityDpi = env->GetIntField(viewportObj, gDisplayViewportClassInfo.densityDpi);

    jobject logicalFrameObj =
            env->GetObjectField(viewportObj, gDisplayViewportClassInfo.logicalFrame);
    viewport->logicalLeft = env->GetIntField(logicalFrameObj, gRectClassInfo.left);
@@ -135,6 +138,9 @@ int register_android_hardware_display_DisplayViewport(JNIEnv* env) {
    gDisplayViewportClassInfo.type = GetFieldIDOrDie(env,
            gDisplayViewportClassInfo.clazz, "type", "I");

    gDisplayViewportClassInfo.densityDpi =
            GetFieldIDOrDie(env, gDisplayViewportClassInfo.clazz, "densityDpi", "I");

    clazz = FindClassOrDie(env, "android/graphics/Rect");
    gRectClassInfo.left = GetFieldIDOrDie(env, clazz, "left", "I");
    gRectClassInfo.top = GetFieldIDOrDie(env, clazz, "top", "I");
+1 −0
Original line number Diff line number Diff line
@@ -3503,6 +3503,7 @@ public final class DisplayManagerService extends SystemService {
        viewport.valid = true;
        viewport.displayId = displayId;
        viewport.isActive = Display.isActiveState(info.state);
        viewport.densityDpi = info.densityDpi;
    }

    private void updateViewportPowerStateLocked(LogicalDisplay display) {