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

Commit d9829999 authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge changes from topics "pointer-icon-refactor-setPointerIcon",...

Merge changes from topics "pointer-icon-refactor-setPointerIcon", "setPointerIcon-hitTest" into main

* changes:
  InputDispatcher: Add hit test method isPointerInWindow
  Address comments: Add setPointerIcon for PointerChoreographer
  Add setPointerIcon for PointerChoreographer
parents e74cd0ae 64f21d2f
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
@@ -445,6 +445,59 @@ void PointerChoreographer::setStylusPointerIconEnabled(bool enabled) {
    updatePointerControllersLocked();
}

bool PointerChoreographer::setPointerIcon(
        std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, int32_t displayId,
        DeviceId deviceId) {
    std::scoped_lock _l(mLock);
    if (deviceId < 0) {
        LOG(WARNING) << "Invalid device id " << deviceId << ". Cannot set pointer icon.";
        return false;
    }
    const InputDeviceInfo* info = findInputDeviceLocked(deviceId);
    if (!info) {
        LOG(WARNING) << "No input device info found for id " << deviceId
                     << ". Cannot set pointer icon.";
        return false;
    }
    const uint32_t sources = info->getSources();
    const auto stylusPointerIt = mStylusPointersByDevice.find(deviceId);

    if (isFromSource(sources, AINPUT_SOURCE_STYLUS) &&
        stylusPointerIt != mStylusPointersByDevice.end()) {
        if (std::holds_alternative<std::unique_ptr<SpriteIcon>>(icon)) {
            if (std::get<std::unique_ptr<SpriteIcon>>(icon) == nullptr) {
                LOG(FATAL) << "SpriteIcon should not be null";
            }
            stylusPointerIt->second->setCustomPointerIcon(
                    *std::get<std::unique_ptr<SpriteIcon>>(icon));
        } else {
            stylusPointerIt->second->updatePointerIcon(std::get<PointerIconStyle>(icon));
        }
    } else if (isFromSource(sources, AINPUT_SOURCE_MOUSE)) {
        if (const auto mousePointerIt = mMousePointersByDisplay.find(displayId);
            mousePointerIt != mMousePointersByDisplay.end()) {
            if (std::holds_alternative<std::unique_ptr<SpriteIcon>>(icon)) {
                if (std::get<std::unique_ptr<SpriteIcon>>(icon) == nullptr) {
                    LOG(FATAL) << "SpriteIcon should not be null";
                }
                mousePointerIt->second->setCustomPointerIcon(
                        *std::get<std::unique_ptr<SpriteIcon>>(icon));
            } else {
                mousePointerIt->second->updatePointerIcon(std::get<PointerIconStyle>(icon));
            }
        } else {
            LOG(WARNING) << "No mouse pointer controller found for display " << displayId
                         << ", device " << deviceId << ".";
            return false;
        }
    } else {
        LOG(WARNING) << "Cannot set pointer icon for display " << displayId << ", device "
                     << deviceId << ".";
        return false;
    }
    return true;
}

PointerChoreographer::ControllerConstructor PointerChoreographer::getMouseControllerConstructor(
        int32_t displayId) {
    std::function<std::shared_ptr<PointerControllerInterface>()> ctor =
+12 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@

namespace android {

struct SpriteIcon;

/**
 * A helper class that wraps a factory method that acts as a constructor for the type returned
 * by the factory method.
@@ -58,6 +60,14 @@ public:
    virtual FloatPoint getMouseCursorPosition(int32_t displayId) = 0;
    virtual void setShowTouchesEnabled(bool enabled) = 0;
    virtual void setStylusPointerIconEnabled(bool enabled) = 0;
    /**
     * Set the icon that is shown for the given pointer. The request may fail in some cases, such
     * as if the device or display was removed, or if the cursor was moved to a different display.
     * Returns true if the icon was changed successfully, false otherwise.
     */
    virtual bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon,
                                int32_t displayId, DeviceId deviceId) = 0;

    /**
     * This method may be called on any thread (usually by the input manager on a binder thread).
     */
@@ -77,6 +87,8 @@ public:
    FloatPoint getMouseCursorPosition(int32_t displayId) override;
    void setShowTouchesEnabled(bool enabled) override;
    void setStylusPointerIconEnabled(bool enabled) override;
    bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon,
                        int32_t displayId, DeviceId deviceId) override;

    void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
    void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override;
+17 −0
Original line number Diff line number Diff line
@@ -6924,4 +6924,21 @@ void InputDispatcher::setKeyRepeatConfiguration(std::chrono::nanoseconds timeout
    mConfig.keyRepeatDelay = delay.count();
}

bool InputDispatcher::isPointerInWindow(const sp<android::IBinder>& token, int32_t displayId,
                                        DeviceId deviceId, int32_t pointerId) {
    std::scoped_lock _l(mLock);
    auto touchStateIt = mTouchStatesByDisplay.find(displayId);
    if (touchStateIt == mTouchStatesByDisplay.end()) {
        return false;
    }
    for (const TouchedWindow& window : touchStateIt->second.windows) {
        if (window.windowHandle->getToken() == token &&
            (window.hasTouchingPointer(deviceId, pointerId) ||
             window.hasHoveringPointer(deviceId, pointerId))) {
            return true;
        }
    }
    return false;
}

} // namespace android::inputdispatcher
+3 −0
Original line number Diff line number Diff line
@@ -148,6 +148,9 @@ public:
    void setKeyRepeatConfiguration(std::chrono::nanoseconds timeout,
                                   std::chrono::nanoseconds delay) override;

    bool isPointerInWindow(const sp<IBinder>& token, int32_t displayId, DeviceId deviceId,
                           int32_t pointerId) override;

private:
    enum class DropReason {
        NOT_DROPPED,
+6 −0
Original line number Diff line number Diff line
@@ -223,6 +223,12 @@ public:
     */
    virtual void setKeyRepeatConfiguration(std::chrono::nanoseconds timeout,
                                           std::chrono::nanoseconds delay) = 0;

    /*
     * Determine if a pointer from a device is being dispatched to the given window.
     */
    virtual bool isPointerInWindow(const sp<IBinder>& token, int32_t displayId, DeviceId deviceId,
                                   int32_t pointerId) = 0;
};

} // namespace android
Loading