diff options
author | 2020-12-30 16:58:01 +0800 | |
---|---|---|
committer | 2021-03-08 21:40:13 +0800 | |
commit | 7632c3391394a47cface411997ce03d126d1e4da (patch) | |
tree | f4c4ab55383c089cb766c95442dfd958a5c78fb3 /libs/input/Input.cpp | |
parent | 335c73a433ab3e7e158204d09a6f1f5f6a2ff1dc (diff) |
Move drag event to InputDispatcher (1/n)
This CL adds the ability to send a DRAG event through the
InputChannel, and adds the appropriate processing logic to
InputPublisher and InputConsumer.
Bug: 158242495
Test: atest libinput_tests InputPublisherAndConsumerTest
Change-Id: I7aead341a9851facf654024c476bd6d7eaae4590
Diffstat (limited to 'libs/input/Input.cpp')
-rw-r--r-- | libs/input/Input.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 0a00d68556..5600eb3f5e 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -92,6 +92,9 @@ const char* inputEventTypeToString(int32_t type) { case AINPUT_EVENT_TYPE_CAPTURE: { return "CAPTURE"; } + case AINPUT_EVENT_TYPE_DRAG: { + return "DRAG"; + } } return "UNKNOWN"; } @@ -770,6 +773,23 @@ void CaptureEvent::initialize(const CaptureEvent& from) { mPointerCaptureEnabled = from.mPointerCaptureEnabled; } +// --- DragEvent --- + +void DragEvent::initialize(int32_t id, float x, float y, bool isExiting) { + InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, + ADISPLAY_ID_NONE, INVALID_HMAC); + mIsExiting = isExiting; + mX = x; + mY = y; +} + +void DragEvent::initialize(const DragEvent& from) { + InputEvent::initialize(from); + mIsExiting = from.mIsExiting; + mX = from.mX; + mY = from.mY; +} + // --- PooledInputEventFactory --- PooledInputEventFactory::PooledInputEventFactory(size_t maxPoolSize) : @@ -815,6 +835,15 @@ CaptureEvent* PooledInputEventFactory::createCaptureEvent() { return event; } +DragEvent* PooledInputEventFactory::createDragEvent() { + if (mDragEventPool.empty()) { + return new DragEvent(); + } + DragEvent* event = mDragEventPool.front().release(); + mDragEventPool.pop(); + return event; +} + void PooledInputEventFactory::recycle(InputEvent* event) { switch (event->getType()) { case AINPUT_EVENT_TYPE_KEY: @@ -842,6 +871,12 @@ void PooledInputEventFactory::recycle(InputEvent* event) { return; } break; + case AINPUT_EVENT_TYPE_DRAG: + if (mDragEventPool.size() < mMaxPoolSize) { + mDragEventPool.push(std::unique_ptr<DragEvent>(static_cast<DragEvent*>(event))); + return; + } + break; } delete event; } |