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

Commit 33197de2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Let InputReaderContext hold a single PointerController"

parents c74fb6fb c7ef27ee
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -449,10 +449,6 @@ void InputDevice::updateMetaState(int32_t keyCode) {
    for_each_mapper([keyCode](InputMapper& mapper) { mapper.updateMetaState(keyCode); });
}

void InputDevice::fadePointer() {
    for_each_mapper([](InputMapper& mapper) { mapper.fadePointer(); });
}

void InputDevice::bumpGeneration() {
    mGeneration = mContext->bumpGeneration();
}
+45 −3
Original line number Diff line number Diff line
@@ -326,6 +326,10 @@ void InputReader::refreshConfigurationLocked(uint32_t changes) {
              InputReaderConfiguration::changesToString(changes).c_str());
        nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);

        if (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO) {
            updatePointerDisplayLocked();
        }

        if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) {
            mEventHub->requestReopenDevices();
        } else {
@@ -387,10 +391,43 @@ bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, int32_t keyCode, int32
    }
}

sp<PointerControllerInterface> InputReader::getPointerControllerLocked(int32_t deviceId) {
    sp<PointerControllerInterface> controller = mPointerController.promote();
    if (controller == nullptr) {
        controller = mPolicy->obtainPointerController(deviceId);
        mPointerController = controller;
        updatePointerDisplayLocked();
    }
    return controller;
}

void InputReader::updatePointerDisplayLocked() {
    sp<PointerControllerInterface> controller = mPointerController.promote();
    if (controller == nullptr) {
        return;
    }

    std::optional<DisplayViewport> viewport =
            mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId);
    if (!viewport) {
        ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input "
              "mapper. Fall back to default display",
              mConfig.defaultPointerDisplayId);
        viewport = mConfig.getDisplayViewportById(ADISPLAY_ID_DEFAULT);
    }
    if (!viewport) {
        ALOGE("Still can't find a viable viewport to update cursor input mapper. Skip setting it to"
              " PointerController.");
        return;
    }

    controller->setDisplayViewport(*viewport);
}

void InputReader::fadePointerLocked() {
    for (auto& devicePair : mDevices) {
        std::shared_ptr<InputDevice>& device = devicePair.second;
        device->fadePointer();
    sp<PointerControllerInterface> controller = mPointerController.promote();
    if (controller != nullptr) {
        controller->fade(PointerControllerInterface::TRANSITION_GRADUAL);
    }
}

@@ -688,6 +725,11 @@ void InputReader::ContextImpl::fadePointer() {
    mReader->fadePointerLocked();
}

sp<PointerControllerInterface> InputReader::ContextImpl::getPointerController(int32_t deviceId) {
    // lock is already held by the input loop
    return mReader->getPointerControllerLocked(deviceId);
}

void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) {
    // lock is already held by the input loop
    mReader->requestTimeoutAtTimeLocked(when);
+0 −2
Original line number Diff line number Diff line
@@ -88,8 +88,6 @@ public:
    int32_t getMetaState();
    void updateMetaState(int32_t keyCode);

    void fadePointer();

    void bumpGeneration();

    void notifyReset(nsecs_t when);
+6 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "InputReaderContext.h"
#include "InputThread.h"

#include <PointerControllerInterface.h>
#include <utils/Condition.h>
#include <utils/Mutex.h>

@@ -102,6 +103,7 @@ protected:
        virtual void disableVirtualKeysUntil(nsecs_t time) override;
        virtual bool shouldDropVirtualKey(nsecs_t now, int32_t keyCode, int32_t scanCode) override;
        virtual void fadePointer() override;
        virtual sp<PointerControllerInterface> getPointerController(int32_t deviceId) override;
        virtual void requestTimeoutAtTime(nsecs_t when) override;
        virtual int32_t bumpGeneration() override;
        virtual void getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) override;
@@ -159,6 +161,10 @@ private:
    void getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices);
    void dispatchExternalStylusState(const StylusState& state);

    // The PointerController that is shared among all the input devices that need it.
    wp<PointerControllerInterface> mPointerController;
    sp<PointerControllerInterface> getPointerControllerLocked(int32_t deviceId);
    void updatePointerDisplayLocked();
    void fadePointerLocked();

    int32_t mGeneration;
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ class InputDevice;
class InputListenerInterface;
class InputMapper;
class InputReaderPolicyInterface;
class PointerControllerInterface;
struct StylusState;

/* Internal interface used by individual input devices to access global input device state
@@ -45,6 +46,7 @@ public:
    virtual bool shouldDropVirtualKey(nsecs_t now, int32_t keyCode, int32_t scanCode) = 0;

    virtual void fadePointer() = 0;
    virtual sp<PointerControllerInterface> getPointerController(int32_t deviceId) = 0;

    virtual void requestTimeoutAtTime(nsecs_t when) = 0;
    virtual int32_t bumpGeneration() = 0;
Loading