blob: 3128d18a052969567f6a82287e0313b41be6bb7b [file] [log] [blame]
Harry Cutts79cc9fa2022-10-28 15:32:39 +00001/*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
Harry Cutts4fb941a2022-12-14 19:14:04 +000019#include <list>
Harry Cutts1f48a442022-11-15 17:38:36 +000020#include <memory>
Harry Cutts47db1c72022-12-13 19:20:47 +000021#include <vector>
Harry Cutts1f48a442022-11-15 17:38:36 +000022
Harry Cutts74235542022-11-24 15:52:53 +000023#include <PointerControllerInterface.h>
Harry Cuttsbb24e272023-03-21 10:49:47 +000024#include <utils/Timers.h>
Harry Cutts74235542022-11-24 15:52:53 +000025
Harry Cuttsbb24e272023-03-21 10:49:47 +000026#include "CapturedTouchpadEventConverter.h"
Harry Cutts79cc9fa2022-10-28 15:32:39 +000027#include "EventHub.h"
28#include "InputDevice.h"
29#include "InputMapper.h"
Harry Cuttsedf6ce72023-01-04 12:15:53 +000030#include "InputReaderBase.h"
Harry Cutts79cc9fa2022-10-28 15:32:39 +000031#include "NotifyArgs.h"
Harry Cuttsbb24e272023-03-21 10:49:47 +000032#include "accumulator/MultiTouchMotionAccumulator.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000033#include "gestures/GestureConverter.h"
Harry Cutts47db1c72022-12-13 19:20:47 +000034#include "gestures/HardwareStateConverter.h"
Harry Cutts1b217912023-01-03 17:13:19 +000035#include "gestures/PropertyProvider.h"
Harry Cutts1f48a442022-11-15 17:38:36 +000036
37#include "include/gestures.h"
Harry Cutts79cc9fa2022-10-28 15:32:39 +000038
39namespace android {
40
41class TouchpadInputMapper : public InputMapper {
42public:
Arpit Singh8e6fb252023-04-06 11:49:17 +000043 explicit TouchpadInputMapper(InputDeviceContext& deviceContext,
44 const InputReaderConfiguration& readerConfig);
Harry Cutts74235542022-11-24 15:52:53 +000045 ~TouchpadInputMapper();
Harry Cutts79cc9fa2022-10-28 15:32:39 +000046
Harry Cutts1f48a442022-11-15 17:38:36 +000047 uint32_t getSources() const override;
Harry Cuttsd02ea102023-03-17 18:21:30 +000048 void populateDeviceInfo(InputDeviceInfo& deviceInfo) override;
Harry Cuttsea73eaa2023-01-16 17:55:46 +000049 void dump(std::string& dump) override;
50
Arpit Singh4be4eef2023-03-28 14:26:01 +000051 [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when,
Arpit Singhed6c3de2023-04-05 19:24:37 +000052 const InputReaderConfiguration& config,
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000053 ConfigurationChanges changes) override;
Harry Cutts1f48a442022-11-15 17:38:36 +000054 [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override;
55 [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override;
56
Harry Cutts74235542022-11-24 15:52:53 +000057 void consumeGesture(const Gesture* gesture);
58
Harry Cutts1f48a442022-11-15 17:38:36 +000059private:
Harry Cuttsbb24e272023-03-21 10:49:47 +000060 void resetGestureInterpreter(nsecs_t when);
Harry Cutts47db1c72022-12-13 19:20:47 +000061 [[nodiscard]] std::list<NotifyArgs> sendHardwareState(nsecs_t when, nsecs_t readTime,
62 SelfContainedHardwareState schs);
Harry Cutts74235542022-11-24 15:52:53 +000063 [[nodiscard]] std::list<NotifyArgs> processGestures(nsecs_t when, nsecs_t readTime);
Harry Cutts1f48a442022-11-15 17:38:36 +000064
65 std::unique_ptr<gestures::GestureInterpreter, void (*)(gestures::GestureInterpreter*)>
66 mGestureInterpreter;
Harry Cutts74235542022-11-24 15:52:53 +000067 std::shared_ptr<PointerControllerInterface> mPointerController;
Harry Cutts1f48a442022-11-15 17:38:36 +000068
Harry Cutts1b217912023-01-03 17:13:19 +000069 PropertyProvider mPropertyProvider;
70
Harry Cuttsbb24e272023-03-21 10:49:47 +000071 // The MultiTouchMotionAccumulator is shared between the HardwareStateConverter and
72 // CapturedTouchpadEventConverter, so that if the touchpad is captured or released while touches
73 // are down, the relevant converter can still benefit from the current axis values stored in the
74 // accumulator.
75 MultiTouchMotionAccumulator mMotionAccumulator;
76
Harry Cutts47db1c72022-12-13 19:20:47 +000077 HardwareStateConverter mStateConverter;
Harry Cutts4fb941a2022-12-14 19:14:04 +000078 GestureConverter mGestureConverter;
Harry Cuttsbb24e272023-03-21 10:49:47 +000079 CapturedTouchpadEventConverter mCapturedEventConverter;
Harry Cutts74235542022-11-24 15:52:53 +000080
Harry Cuttsbb24e272023-03-21 10:49:47 +000081 bool mPointerCaptured = false;
Harry Cutts74235542022-11-24 15:52:53 +000082 bool mProcessing = false;
Harry Cuttsbb24e272023-03-21 10:49:47 +000083 bool mResettingInterpreter = false;
Harry Cutts74235542022-11-24 15:52:53 +000084 std::vector<Gesture> mGesturesToProcess;
Harry Cutts79cc9fa2022-10-28 15:32:39 +000085};
86
87} // namespace android