diff options
| author | 2020-02-21 02:49:02 +0000 | |
|---|---|---|
| committer | 2020-02-21 02:49:02 +0000 | |
| commit | 33197de22df072b4331fdc2ceaba8ae64ef4ccea (patch) | |
| tree | f7ad44745403acd026081cd030c71376b1f0dc7e /services | |
| parent | c74fb6fb4369656985732776d443317adefa7325 (diff) | |
| parent | c7ef27eeccb801ed6d82b62a1d743f246f66eec9 (diff) | |
Merge "Let InputReaderContext hold a single PointerController"
Diffstat (limited to 'services')
12 files changed, 83 insertions, 61 deletions
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index d0eee64b0c..f2afc818ff 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -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(); } diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp index cbfa702015..6ab5902bb7 100644 --- a/services/inputflinger/reader/InputReader.cpp +++ b/services/inputflinger/reader/InputReader.cpp @@ -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); diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h index aaa0d268b3..71313fc86f 100644 --- a/services/inputflinger/reader/include/InputDevice.h +++ b/services/inputflinger/reader/include/InputDevice.h @@ -88,8 +88,6 @@ public: int32_t getMetaState(); void updateMetaState(int32_t keyCode); - void fadePointer(); - void bumpGeneration(); void notifyReset(nsecs_t when); diff --git a/services/inputflinger/reader/include/InputReader.h b/services/inputflinger/reader/include/InputReader.h index 31d82f1abe..ca1a081e48 100644 --- a/services/inputflinger/reader/include/InputReader.h +++ b/services/inputflinger/reader/include/InputReader.h @@ -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; diff --git a/services/inputflinger/reader/include/InputReaderContext.h b/services/inputflinger/reader/include/InputReaderContext.h index e14fbbec3d..d5527cf926 100644 --- a/services/inputflinger/reader/include/InputReaderContext.h +++ b/services/inputflinger/reader/include/InputReaderContext.h @@ -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; diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp index 520a4a4f52..c4162bc510 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp @@ -132,7 +132,7 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration* mYPrecision = 1.0f; mXScale = 1.0f; mYScale = 1.0f; - mPointerController = getPolicy()->obtainPointerController(getDeviceId()); + mPointerController = getContext()->getPointerController(getDeviceId()); break; case Parameters::MODE_NAVIGATION: mSource = AINPUT_SOURCE_TRACKBALL; @@ -189,34 +189,10 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration* } } - // Update the PointerController if viewports changed. - if (mParameters.mode == Parameters::MODE_POINTER) { - updatePointerControllerDisplayViewport(*config); - } bumpGeneration(); } } -void CursorInputMapper::updatePointerControllerDisplayViewport( - const InputReaderConfiguration& config) { - std::optional<DisplayViewport> viewport = - config.getDisplayViewportById(config.defaultPointerDisplayId); - if (!viewport) { - ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input " - "mapper. Fall back to default display", - config.defaultPointerDisplayId); - viewport = config.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; - } - - mPointerController->setDisplayViewport(*viewport); -} - void CursorInputMapper::configureParameters() { mParameters.mode = Parameters::MODE_POINTER; String8 cursorModeString; @@ -481,12 +457,6 @@ int32_t CursorInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCod } } -void CursorInputMapper::fadePointer() { - if (mPointerController != nullptr) { - mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL); - } -} - std::optional<int32_t> CursorInputMapper::getAssociatedDisplayId() { if (mParameters.hasAssociatedDisplay) { if (mParameters.mode == Parameters::MODE_POINTER) { diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.h b/services/inputflinger/reader/mapper/CursorInputMapper.h index 94ab30674d..f65ac3934a 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.h +++ b/services/inputflinger/reader/mapper/CursorInputMapper.h @@ -66,8 +66,6 @@ public: virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override; - virtual void fadePointer() override; - virtual std::optional<int32_t> getAssociatedDisplayId() override; private: @@ -117,7 +115,6 @@ private: void dumpParameters(std::string& dump); void sync(nsecs_t when); - void updatePointerControllerDisplayViewport(const InputReaderConfiguration& config); }; } // namespace android diff --git a/services/inputflinger/reader/mapper/InputMapper.cpp b/services/inputflinger/reader/mapper/InputMapper.cpp index c5f99c9b63..a8fe39aa10 100644 --- a/services/inputflinger/reader/mapper/InputMapper.cpp +++ b/services/inputflinger/reader/mapper/InputMapper.cpp @@ -71,8 +71,6 @@ void InputMapper::updateMetaState(int32_t keyCode) {} void InputMapper::updateExternalStylusState(const StylusState& state) {} -void InputMapper::fadePointer() {} - status_t InputMapper::getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo) { return getDeviceContext().getAbsoluteAxisInfo(axis, axisInfo); } diff --git a/services/inputflinger/reader/mapper/InputMapper.h b/services/inputflinger/reader/mapper/InputMapper.h index 09888bfe20..949c7ea34e 100644 --- a/services/inputflinger/reader/mapper/InputMapper.h +++ b/services/inputflinger/reader/mapper/InputMapper.h @@ -71,7 +71,6 @@ public: virtual void updateExternalStylusState(const StylusState& state); - virtual void fadePointer(); virtual std::optional<int32_t> getAssociatedDisplayId() { return std::nullopt; } protected: diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index b3a6df8f15..7543374ebd 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -756,16 +756,11 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { mOrientedRanges.clear(); } - // Create or update pointer controller if needed. + // Create pointer controller if needed. if (mDeviceMode == DEVICE_MODE_POINTER || (mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) { - if (mPointerController == nullptr || viewportChanged) { - mPointerController = getPolicy()->obtainPointerController(getDeviceId()); - // Set the DisplayViewport for the PointerController to the default pointer display - // that is recommended by the configuration before using it. - std::optional<DisplayViewport> defaultViewport = - mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId); - mPointerController->setDisplayViewport(defaultViewport.value_or(mViewport)); + if (mPointerController == nullptr) { + mPointerController = getContext()->getPointerController(getDeviceId()); } } else { mPointerController.clear(); @@ -3624,12 +3619,6 @@ bool TouchInputMapper::updateMovedPointers(const PointerProperties* inProperties return changed; } -void TouchInputMapper::fadePointer() { - if (mPointerController != nullptr) { - mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL); - } -} - void TouchInputMapper::cancelTouch(nsecs_t when) { abortPointerUsage(when, 0 /*policyFlags*/); abortTouches(when, 0 /* policyFlags*/); diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h index 3a61206481..e21a33abed 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchInputMapper.h @@ -148,7 +148,6 @@ public: virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) override; - virtual void fadePointer() override; virtual void cancelTouch(nsecs_t when) override; virtual void timeoutExpired(nsecs_t when) override; virtual void updateExternalStylusState(const StylusState& state) override; diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index af11256892..4da9d93890 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -847,6 +847,7 @@ class FakeInputReaderContext : public InputReaderContext { bool mUpdateGlobalMetaStateWasCalled; int32_t mGeneration; uint32_t mNextSequenceNum; + wp<PointerControllerInterface> mPointerController; public: FakeInputReaderContext(std::shared_ptr<EventHubInterface> eventHub, @@ -874,6 +875,18 @@ public: return mGeneration; } + void updatePointerDisplay() { + sp<PointerControllerInterface> controller = mPointerController.promote(); + if (controller != nullptr) { + InputReaderConfiguration config; + mPolicy->getReaderConfiguration(&config); + auto viewport = config.getDisplayViewportById(config.defaultPointerDisplayId); + if (viewport) { + controller->setDisplayViewport(*viewport); + } + } + } + private: virtual void updateGlobalMetaState() { mUpdateGlobalMetaStateWasCalled = true; @@ -900,6 +913,16 @@ private: virtual bool shouldDropVirtualKey(nsecs_t, int32_t, int32_t) { return false; } + virtual sp<PointerControllerInterface> getPointerController(int32_t deviceId) { + sp<PointerControllerInterface> controller = mPointerController.promote(); + if (controller == nullptr) { + controller = mPolicy->obtainPointerController(deviceId); + mPointerController = controller; + updatePointerDisplay(); + } + return controller; + } + virtual void fadePointer() { } @@ -2095,6 +2118,9 @@ protected: } void configureDevice(uint32_t changes) { + if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { + mFakeContext->updatePointerDisplay(); + } mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), changes); } |