blob: e7d935082aada2197716b5206f3dcd90dfc551af [file] [log] [blame]
Prabir Pradhanbaa5c822019-08-30 15:27:05 -07001/*
2 * Copyright (C) 2019 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#ifndef _UI_INPUTREADER_MULTI_TOUCH_INPUT_MAPPER_H
18#define _UI_INPUTREADER_MULTI_TOUCH_INPUT_MAPPER_H
19
20#include "TouchInputMapper.h"
21
22namespace android {
23
24/* Keeps track of the state of multi-touch protocol. */
25class MultiTouchMotionAccumulator {
26public:
27 class Slot {
28 public:
29 inline bool isInUse() const { return mInUse; }
30 inline int32_t getX() const { return mAbsMTPositionX; }
31 inline int32_t getY() const { return mAbsMTPositionY; }
32 inline int32_t getTouchMajor() const { return mAbsMTTouchMajor; }
33 inline int32_t getTouchMinor() const {
34 return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor;
35 }
36 inline int32_t getToolMajor() const { return mAbsMTWidthMajor; }
37 inline int32_t getToolMinor() const {
38 return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor;
39 }
40 inline int32_t getOrientation() const { return mAbsMTOrientation; }
41 inline int32_t getTrackingId() const { return mAbsMTTrackingId; }
42 inline int32_t getPressure() const { return mAbsMTPressure; }
43 inline int32_t getDistance() const { return mAbsMTDistance; }
44 inline int32_t getToolType() const;
45
46 private:
47 friend class MultiTouchMotionAccumulator;
48
49 bool mInUse;
50 bool mHaveAbsMTTouchMinor;
51 bool mHaveAbsMTWidthMinor;
52 bool mHaveAbsMTToolType;
53
54 int32_t mAbsMTPositionX;
55 int32_t mAbsMTPositionY;
56 int32_t mAbsMTTouchMajor;
57 int32_t mAbsMTTouchMinor;
58 int32_t mAbsMTWidthMajor;
59 int32_t mAbsMTWidthMinor;
60 int32_t mAbsMTOrientation;
61 int32_t mAbsMTTrackingId;
62 int32_t mAbsMTPressure;
63 int32_t mAbsMTDistance;
64 int32_t mAbsMTToolType;
65
66 Slot();
67 void clear();
68 };
69
70 MultiTouchMotionAccumulator();
71 ~MultiTouchMotionAccumulator();
72
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080073 void configure(InputDeviceContext& deviceContext, size_t slotCount, bool usingSlotsProtocol);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070074 void process(const RawEvent* rawEvent);
75 void finishSync();
76 bool hasStylus() const;
77
78 inline size_t getSlotCount() const { return mSlotCount; }
79 inline const Slot* getSlot(size_t index) const { return &mSlots[index]; }
80
81private:
82 int32_t mCurrentSlot;
83 Slot* mSlots;
84 size_t mSlotCount;
85 bool mUsingSlotsProtocol;
86 bool mHaveStylus;
87
Prabir Pradhan6c7fd132022-09-27 19:32:43 +000088 void resetSlots();
Arthur Hung9ad18942021-06-19 02:04:46 +000089 void warnIfNotInUse(const RawEvent& event, const Slot& slot);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070090};
91
92class MultiTouchInputMapper : public TouchInputMapper {
93public:
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080094 explicit MultiTouchInputMapper(InputDeviceContext& deviceContext);
Michael Wright227c5542020-07-02 18:30:52 +010095 ~MultiTouchInputMapper() override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070096
Michael Wright227c5542020-07-02 18:30:52 +010097 void reset(nsecs_t when) override;
98 void process(const RawEvent* rawEvent) override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070099
100protected:
Michael Wright227c5542020-07-02 18:30:52 +0100101 void syncTouch(nsecs_t when, RawState* outState) override;
102 void configureRawPointerAxes() override;
103 bool hasStylus() const override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700104
105private:
Prabir Pradhanf4d65b12022-02-10 07:15:38 -0800106 // simulate_stylus_with_touch is a debug mode that converts all finger pointers reported by this
107 // mapper's touchscreen into stylus pointers, and adds SOURCE_STYLUS to the input device.
108 // It is used to simulate stylus events for debugging and testing on a device that does not
109 // support styluses. It can be enabled using
110 // "adb shell setprop persist.debug.input.simulate_stylus_with_touch true",
111 // and requires a reboot to take effect.
112 inline bool shouldSimulateStylusWithTouch() const;
113
arthurhungcc7f9802020-04-30 17:55:40 +0800114 // If the slot is in use, return the bit id. Return std::nullopt otherwise.
115 std::optional<int32_t> getActiveBitId(const MultiTouchMotionAccumulator::Slot& inSlot);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700116 MultiTouchMotionAccumulator mMultiTouchMotionAccumulator;
117
118 // Specifies the pointer id bits that are in use, and their associated tracking id.
119 BitSet32 mPointerIdBits;
120 int32_t mPointerTrackingIdMap[MAX_POINTER_ID + 1];
121};
122
123} // namespace android
124
125#endif // _UI_INPUTREADER_MULTI_TOUCH_INPUT_MAPPER_H