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

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

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

Merge changes from topics "pointer-icon-refactor-comments", "pointer-icon-refactor-stylus", "pointer-icon-refactor-touch" into main

* changes:
  Address additional comments: Pointer icon refactor for touch/stylus
  Modify getPosition of disabled PointerController
  Pointer icon refactor for stylus (base)
  Pointer icon refactor for touch (base)
parents 0fab2856 b0e28072
Loading
Loading
Loading
Loading
+39 −2
Original line number Diff line number Diff line
@@ -74,6 +74,14 @@ std::shared_ptr<PointerController> PointerController::create(
            controller = std::shared_ptr<PointerController>(
                    new MousePointerController(policy, looper, spriteController, enabled));
            break;
        case ControllerType::TOUCH:
            controller = std::shared_ptr<PointerController>(
                    new TouchPointerController(policy, looper, spriteController, enabled));
            break;
        case ControllerType::STYLUS:
            controller = std::shared_ptr<PointerController>(
                    new StylusPointerController(policy, looper, spriteController, enabled));
            break;
        case ControllerType::LEGACY:
        default:
            controller = std::shared_ptr<PointerController>(
@@ -167,8 +175,7 @@ void PointerController::setPosition(float x, float y) {

FloatPoint PointerController::getPosition() const {
    if (!mEnabled) {
        return FloatPoint{AMOTION_EVENT_INVALID_CURSOR_POSITION,
                          AMOTION_EVENT_INVALID_CURSOR_POSITION};
        return FloatPoint{0, 0};
    }

    const int32_t displayId = mCursorController.getDisplayId();
@@ -397,4 +404,34 @@ MousePointerController::MousePointerController(const sp<PointerControllerPolicyI
    PointerController::setPresentation(Presentation::POINTER);
}

MousePointerController::~MousePointerController() {
    MousePointerController::fade(Transition::IMMEDIATE);
}

// --- TouchPointerController ---

TouchPointerController::TouchPointerController(const sp<PointerControllerPolicyInterface>& policy,
                                               const sp<Looper>& looper,
                                               SpriteController& spriteController, bool enabled)
      : PointerController(policy, looper, spriteController, enabled) {
    PointerController::setPresentation(Presentation::SPOT);
}

TouchPointerController::~TouchPointerController() {
    TouchPointerController::clearSpots();
}

// --- StylusPointerController ---

StylusPointerController::StylusPointerController(const sp<PointerControllerPolicyInterface>& policy,
                                                 const sp<Looper>& looper,
                                                 SpriteController& spriteController, bool enabled)
      : PointerController(policy, looper, spriteController, enabled) {
    PointerController::setPresentation(Presentation::STYLUS_HOVER);
}

StylusPointerController::~StylusPointerController() {
    StylusPointerController::fade(Transition::IMMEDIATE);
}

} // namespace android
+69 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public:

    void updatePointerIcon(PointerIconStyle iconId);
    void setCustomPointerIcon(const SpriteIcon& icon);
    void setInactivityTimeout(InactivityTimeout inactivityTimeout);
    virtual void setInactivityTimeout(InactivityTimeout inactivityTimeout);
    void doInactivityTimeout();
    void reloadPointerResources();
    void onDisplayViewportsUpdated(const std::vector<DisplayViewport>& viewports);
@@ -143,6 +143,74 @@ public:
                           const sp<Looper>& looper, SpriteController& spriteController,
                           bool enabled);

    ~MousePointerController() override;

    void setPresentation(Presentation) override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    void setSpots(const PointerCoords*, const uint32_t*, BitSet32, int32_t) override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    void clearSpots() override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
};

class TouchPointerController : public PointerController {
public:
    /** A version of PointerController that controls touch spots. */
    TouchPointerController(const sp<PointerControllerPolicyInterface>& policy,
                           const sp<Looper>& looper, SpriteController& spriteController,
                           bool enabled);

    ~TouchPointerController() override;

    std::optional<FloatRect> getBounds() const override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    void move(float, float) override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    void setPosition(float, float) override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    FloatPoint getPosition() const override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    int32_t getDisplayId() const override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    void fade(Transition) override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    void unfade(Transition) override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    void setDisplayViewport(const DisplayViewport&) override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    void setPresentation(Presentation) override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    void updatePointerIcon(PointerIconStyle) {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    void setCustomPointerIcon(const SpriteIcon&) {
        LOG_ALWAYS_FATAL("Should not be called");
    }
    // fade() should not be called by inactivity timeout. Do nothing.
    void setInactivityTimeout(InactivityTimeout) override {}
};

class StylusPointerController : public PointerController {
public:
    /** A version of PointerController that controls one stylus pointer. */
    StylusPointerController(const sp<PointerControllerPolicyInterface>& policy,
                            const sp<Looper>& looper, SpriteController& spriteController,
                            bool enabled);

    ~StylusPointerController() override;

    void setPresentation(Presentation) override {
        LOG_ALWAYS_FATAL("Should not be called");
    }
+10 −0
Original line number Diff line number Diff line
@@ -1293,6 +1293,11 @@ void NativeInputManager::setInputDeviceEnabled(uint32_t deviceId, bool enabled)
}

void NativeInputManager::setShowTouches(bool enabled) {
    if (ENABLE_POINTER_CHOREOGRAPHER) {
        mInputManager->getChoreographer().setShowTouchesEnabled(enabled);
        return;
    }

    { // acquire lock
        std::scoped_lock _l(mLock);

@@ -1744,6 +1749,11 @@ FloatPoint NativeInputManager::getMouseCursorPosition() {
}

void NativeInputManager::setStylusPointerIconEnabled(bool enabled) {
    if (ENABLE_POINTER_CHOREOGRAPHER) {
        mInputManager->getChoreographer().setStylusPointerIconEnabled(enabled);
        return;
    }

    { // acquire lock
        std::scoped_lock _l(mLock);