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

Commit d4f9cc21 authored by Arpit Singh's avatar Arpit Singh
Browse files

Scale cursor moves with display density

This CL updates the CursorInputMapper to scale the cursor moves with the
display density. Scaling is not applied when the pointer capture is
enabled or scaling is explicitly disabled.

This CL also adds connected display dev option override for
connected_displays_associated_display_cursor_bugfix flag.

Bug: 367662715
Bug: 407953907
Test: atest CursorInputMapperUnitTest
Flag: com.android.input.flags.scale_cursor_speed_with_dpi
Change-Id: Ie27d32d8b84174055f32463d3097e6136f51a1d7
parent 92e0a7e6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -133,10 +133,14 @@ enum {
     * resource qualifier.
     */
    ACONFIGURATION_DENSITY_XXXHIGH = 640,
    // If adding additional special density values, also update ACONFIGURATION_MAX_SUPPORTED_DENSITY
    // in CursorInputMapper.
    // LINT.IfChange
    /** Density: any density. */
    ACONFIGURATION_DENSITY_ANY = 0xfffe,
    /** Density: no density specified. */
    ACONFIGURATION_DENSITY_NONE = 0xffff,
    // LINT.ThenChange(/services/inputflinger/reader/mapper/CursorInputMapper.cpp)

    /** Keyboard: not specified. */
    ACONFIGURATION_KEYBOARD_ANY  = 0x0000,
+8 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <android-base/stringprintf.h>
#include <android/configuration.h>
#include <ftl/enum.h>
#include <ftl/string.h>
#include <input/Input.h>
@@ -64,6 +65,7 @@ struct DisplayViewport {
    // Not all viewports will have this specified.
    std::optional<uint8_t> physicalPort;
    ViewportType type;
    int32_t densityDpi;

    DisplayViewport()
          : displayId(ui::LogicalDisplayId::INVALID),
@@ -81,7 +83,8 @@ struct DisplayViewport {
            isActive(false),
            uniqueId(),
            physicalPort(std::nullopt),
            type(ViewportType::INTERNAL) {}
            type(ViewportType::INTERNAL),
            densityDpi(ACONFIGURATION_DENSITY_NONE) {}

    bool operator==(const DisplayViewport& other) const {
        return displayId == other.displayId && orientation == other.orientation &&
@@ -121,6 +124,7 @@ struct DisplayViewport {

    std::string toString() const {
        return StringPrintf("Viewport %s: displayId=%s, uniqueId=%s, port=%s, orientation=%d, "
                            "densityDpi=%d "
                            "logicalFrame=[%d, %d, %d, %d], "
                            "physicalFrame=[%d, %d, %d, %d], "
                            "deviceSize=[%d, %d], "
@@ -128,9 +132,9 @@ struct DisplayViewport {
                            ftl::enum_string(type).c_str(), displayId.toString().c_str(),
                            uniqueId.c_str(),
                            physicalPort ? ftl::to_string(*physicalPort).c_str() : "<none>",
                            static_cast<int>(orientation), logicalLeft, logicalTop, logicalRight,
                            logicalBottom, physicalLeft, physicalTop, physicalRight, physicalBottom,
                            deviceWidth, deviceHeight, isActive);
                            static_cast<int>(orientation), densityDpi, logicalLeft, logicalTop,
                            logicalRight, logicalBottom, physicalLeft, physicalTop, physicalRight,
                            physicalBottom, deviceWidth, deviceHeight, isActive);
    }
};

+9 −0
Original line number Diff line number Diff line
@@ -42,8 +42,17 @@ public:

    /**
     * Check if both connectedDisplaysCursor and associatedDisplayCursorBugfix is enabled.
     * This setting can be overridden with the dev option similar to the
     * connectedDisplaysCursorEnabled flag.
     */
    static bool connectedDisplaysCursorAndAssociatedDisplayCursorBugfixEnabled();

    /**
     * Check if display density based cursor scaling is enabled.
     * This setting can be overridden with the dev option similar to the
     * connectedDisplaysCursorEnabled flag.
     */
    static bool scaleCursorSpeedWithDisplayDensity();
};

} // namespace android
+23 −3
Original line number Diff line number Diff line
@@ -25,9 +25,13 @@

namespace android {

bool InputFlags::connectedDisplaysCursorEnabled() {
namespace {

// Returns the cached dev option value if available.
// This check is only required for connected-displays related features.
std::optional<bool> getConnectedDisplaysDevOptionValue() {
    if (!com::android::window::flags::enable_desktop_mode_through_dev_option()) {
        return com::android::input::flags::connected_displays_cursor();
        return std::nullopt;
    }
    static std::optional<bool> cachedDevOption;
    if (!cachedDevOption.has_value()) {
@@ -37,15 +41,31 @@ bool InputFlags::connectedDisplaysCursorEnabled() {
                property_get(sysprop_name, value, nullptr) > 0 ? std::atoi(value) : 0;
        cachedDevOption = devOptionEnabled == 1;
    }
    if (cachedDevOption.value_or(false)) {
    return cachedDevOption;
}

} // namespace

bool InputFlags::connectedDisplaysCursorEnabled() {
    if (getConnectedDisplaysDevOptionValue().value_or(false)) {
        return true;
    }
    return com::android::input::flags::connected_displays_cursor();
}

bool InputFlags::connectedDisplaysCursorAndAssociatedDisplayCursorBugfixEnabled() {
    if (getConnectedDisplaysDevOptionValue().value_or(false)) {
        return true;
    }
    return connectedDisplaysCursorEnabled() &&
            com::android::input::flags::connected_displays_associated_display_cursor_bugfix();
}

bool InputFlags::scaleCursorSpeedWithDisplayDensity() {
    if (getConnectedDisplaysDevOptionValue().value_or(false)) {
        return true;
    }
    return com::android::input::flags::scale_cursor_speed_with_dpi();
}

} // namespace android
 No newline at end of file
+32 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <com_android_input_flags.h>
#include <ftl/enum.h>
#include <input/AccelerationCurve.h>
#include <input/InputFlags.h>

#include "CursorButtonAccumulator.h"
#include "CursorScrollAccumulator.h"
@@ -35,6 +36,24 @@

namespace android {

namespace {

/** Max density value supported by input. */
const int32_t ACONFIGURATION_MAX_SUPPORTED_DENSITY = ACONFIGURATION_DENSITY_ANY;

// Density values in range (0, ACONFIGURATION_MAX_SUPPORTED_DENSITY] are supported for cursor
// moves scaling. Other density values e.g. ACONFIGURATION_DENSITY_DEFAULT,
// ACONFIGURATION_DENSITY_NONE etc. are ignored.
inline bool isDensityValueSupportedForScaling(int32_t density) {
    if (density > 0 && density <= ACONFIGURATION_MAX_SUPPORTED_DENSITY) {
        return true;
    }
    ALOGE("Unexpected display density value %d, cursor move scaling will be disabled.", density);
    return false;
}

} // namespace

// The default velocity control parameters that has no effect.
static const VelocityControlParameters FLAT_VELOCITY_CONTROL_PARAMS{};

@@ -129,6 +148,7 @@ void CursorInputMapper::dump(std::string& dump) {
    dump += StringPrintf(INDENT3 "DisplayId: %s\n",
                         toString(mDisplayId, streamableToString).c_str());
    dump += StringPrintf(INDENT3 "Orientation: %s\n", ftl::enum_string(mOrientation).c_str());
    dump += StringPrintf(INDENT3 "ViewportDensityDpi: %d\n", mViewportDensityDpi);
    dump += StringPrintf(INDENT3 "ButtonState: 0x%08x\n", mButtonState);
    dump += StringPrintf(INDENT3 "Down: %s\n", toString(isPointerDown(mButtonState)));
    dump += StringPrintf(INDENT3 "DownTime: %" PRId64 "\n", mDownTime);
@@ -496,6 +516,15 @@ void CursorInputMapper::configureOnChangePointerSpeed(const InputReaderConfigura
    bool disableAllScaling = config.displaysWithMouseScalingDisabled.count(
                                     mDisplayId.value_or(ui::LogicalDisplayId::INVALID)) != 0;

    if (InputFlags::scaleCursorSpeedWithDisplayDensity() &&
        mParameters.mode == Parameters::Mode::POINTER && !disableAllScaling) {
        // TODO(b/408170793): We use ACONFIGURATION_DENSITY_XHIGH as baseline for scale due to
        // legacy reasons, this need to be tuned with further UX testing.
        mXScale = mYScale = isDensityValueSupportedForScaling(mViewportDensityDpi)
                ? static_cast<float>(mViewportDensityDpi) /
                        static_cast<float>(ACONFIGURATION_DENSITY_XHIGH)
                : 1.0;
    }
    mPointerVelocityControl.setAccelerationEnabled(!disableAllScaling);

    mPointerVelocityControl.setCurve(
@@ -538,6 +567,9 @@ void CursorInputMapper::configureOnChangeDisplayInfo(const InputReaderConfigurat
                        static_cast<float>(resolvedViewport->logicalBottom - 1)}
            : FloatRect{0, 0, 0, 0};

    mViewportDensityDpi =
            resolvedViewport ? resolvedViewport->densityDpi : ACONFIGURATION_DENSITY_MEDIUM;

    bumpGeneration();
}

Loading