blob: 2c4a511e825b38d19e0de78c38c167776f32d4ec [file] [log] [blame]
Jeff Brown5912f952013-07-01 19:10:31 -07001/*
2 * Copyright (C) 2010 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 _LIBINPUT_INPUT_H
18#define _LIBINPUT_INPUT_H
19
Robert Carr2c358bf2018-08-08 15:58:15 -070020#pragma GCC system_header
21
Jeff Brown5912f952013-07-01 19:10:31 -070022/**
23 * Native input event structures.
24 */
25
26#include <android/input.h>
Michael Wrightd0bd3912014-03-19 12:06:10 -070027#include <utils/BitSet.h>
Jeff Brown5912f952013-07-01 19:10:31 -070028#include <utils/KeyedVector.h>
Jeff Brown5912f952013-07-01 19:10:31 -070029#include <utils/RefBase.h>
Michael Wrightd0bd3912014-03-19 12:06:10 -070030#include <utils/Timers.h>
31#include <utils/Vector.h>
Nick Kralevich834ac202015-10-22 07:09:23 -070032#include <stdint.h>
Jeff Brown5912f952013-07-01 19:10:31 -070033
Jeff Brown5912f952013-07-01 19:10:31 -070034/*
35 * Additional private constants not defined in ndk/ui/input.h.
36 */
37enum {
38 /* Signifies that the key is being predispatched */
39 AKEY_EVENT_FLAG_PREDISPATCH = 0x20000000,
40
41 /* Private control to determine when an app is tracking a key sequence. */
42 AKEY_EVENT_FLAG_START_TRACKING = 0x40000000,
43
44 /* Key event is inconsistent with previously sent key events. */
45 AKEY_EVENT_FLAG_TAINTED = 0x80000000,
46};
47
48enum {
Michael Wrightcdcd8f22016-03-22 16:52:13 -070049
50 /**
51 * This flag indicates that the window that received this motion event is partly
52 * or wholly obscured by another visible window above it. This flag is set to true
53 * even if the event did not directly pass through the obscured area.
54 * A security sensitive application can check this flag to identify situations in which
55 * a malicious application may have covered up part of its content for the purpose
56 * of misleading the user or hijacking touches. An appropriate response might be
57 * to drop the suspect touches or to take additional precautions to confirm the user's
58 * actual intent.
59 */
60 AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2,
61
Prabir Pradhan141a9862018-11-19 14:35:56 -080062 /**
63 * This flag indicates that the event has been generated by a gesture generator. It
64 * provides a hint to the GestureDetector to not apply any touch slop.
65 */
66 AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE = 0x8,
67
Jeff Brown5912f952013-07-01 19:10:31 -070068 /* Motion event is inconsistent with previously sent motion events. */
69 AMOTION_EVENT_FLAG_TAINTED = 0x80000000,
70};
71
72enum {
73 /* Used when a motion event is not associated with any display.
74 * Typically used for non-pointer events. */
75 ADISPLAY_ID_NONE = -1,
76
77 /* The default display id. */
78 ADISPLAY_ID_DEFAULT = 0,
79};
80
81enum {
82 /*
83 * Indicates that an input device has switches.
84 * This input source flag is hidden from the API because switches are only used by the system
85 * and applications have no way to interact with them.
86 */
87 AINPUT_SOURCE_SWITCH = 0x80000000,
88};
89
Michael Wright962a1082013-10-17 17:35:53 -070090enum {
91 /**
92 * Constants for LEDs. Hidden from the API since we don't actually expose a way to interact
93 * with LEDs to developers
94 *
Michael Wright872db4f2014-04-22 15:03:51 -070095 * NOTE: If you add LEDs here, you must also add them to InputEventLabels.h
Michael Wright962a1082013-10-17 17:35:53 -070096 */
97
98 ALED_NUM_LOCK = 0x00,
99 ALED_CAPS_LOCK = 0x01,
100 ALED_SCROLL_LOCK = 0x02,
101 ALED_COMPOSE = 0x03,
102 ALED_KANA = 0x04,
103 ALED_SLEEP = 0x05,
104 ALED_SUSPEND = 0x06,
105 ALED_MUTE = 0x07,
106 ALED_MISC = 0x08,
107 ALED_MAIL = 0x09,
108 ALED_CHARGING = 0x0a,
109 ALED_CONTROLLER_1 = 0x10,
110 ALED_CONTROLLER_2 = 0x11,
111 ALED_CONTROLLER_3 = 0x12,
112 ALED_CONTROLLER_4 = 0x13,
113};
114
Michael Wright9b04f862013-10-18 17:53:50 -0700115/* Maximum number of controller LEDs we support */
116#define MAX_CONTROLLER_LEDS 4
117
Jeff Brown5912f952013-07-01 19:10:31 -0700118/*
119 * SystemUiVisibility constants from View.
120 */
121enum {
122 ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE = 0,
123 ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN = 0x00000001,
124};
125
126/*
127 * Maximum number of pointers supported per motion event.
128 * Smallest number of pointers is 1.
129 * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers
130 * will occasionally emit 11. There is not much harm making this constant bigger.)
131 */
132#define MAX_POINTERS 16
133
134/*
Flanker552a8a52015-09-07 15:28:58 +0800135 * Maximum number of samples supported per motion event.
136 */
137#define MAX_SAMPLES UINT16_MAX
138
139/*
Jeff Brown5912f952013-07-01 19:10:31 -0700140 * Maximum pointer id value supported in a motion event.
141 * Smallest pointer id is 0.
142 * (This is limited by our use of BitSet32 to track pointer assignments.)
143 */
144#define MAX_POINTER_ID 31
145
146/*
147 * Declare a concrete type for the NDK's input event forward declaration.
148 */
149struct AInputEvent {
150 virtual ~AInputEvent() { }
151};
152
153/*
154 * Declare a concrete type for the NDK's input device forward declaration.
155 */
156struct AInputDevice {
157 virtual ~AInputDevice() { }
158};
159
160
161namespace android {
162
Elliott Hughes6071da72015-08-12 15:27:47 -0700163#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700164class Parcel;
165#endif
166
167/*
168 * Flags that flow alongside events in the input dispatch system to help with certain
169 * policy decisions such as waking from device sleep.
170 *
171 * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java.
172 */
173enum {
174 /* These flags originate in RawEvents and are generally set in the key map.
Michael Wright872db4f2014-04-22 15:03:51 -0700175 * NOTE: If you want a flag to be able to set in a keylayout file, then you must add it to
176 * InputEventLabels.h as well. */
Jeff Brown5912f952013-07-01 19:10:31 -0700177
Jeff Brownc9aa6282015-02-11 19:03:28 -0800178 // Indicates that the event should wake the device.
Jeff Brown5912f952013-07-01 19:10:31 -0700179 POLICY_FLAG_WAKE = 0x00000001,
Jeff Brownc9aa6282015-02-11 19:03:28 -0800180
181 // Indicates that the key is virtual, such as a capacitive button, and should
182 // generate haptic feedback. Virtual keys may be suppressed for some time
183 // after a recent touch to prevent accidental activation of virtual keys adjacent
184 // to the touch screen during an edge swipe.
Michael Wright872db4f2014-04-22 15:03:51 -0700185 POLICY_FLAG_VIRTUAL = 0x00000002,
Jeff Brownc9aa6282015-02-11 19:03:28 -0800186
187 // Indicates that the key is the special function modifier.
Michael Wright872db4f2014-04-22 15:03:51 -0700188 POLICY_FLAG_FUNCTION = 0x00000004,
Jeff Brown5912f952013-07-01 19:10:31 -0700189
Jeff Brownc9aa6282015-02-11 19:03:28 -0800190 // Indicates that the key represents a special gesture that has been detected by
191 // the touch firmware or driver. Causes touch events from the same device to be canceled.
192 POLICY_FLAG_GESTURE = 0x00000008,
193
Jeff Brown5912f952013-07-01 19:10:31 -0700194 POLICY_FLAG_RAW_MASK = 0x0000ffff,
195
196 /* These flags are set by the input dispatcher. */
197
198 // Indicates that the input event was injected.
199 POLICY_FLAG_INJECTED = 0x01000000,
200
201 // Indicates that the input event is from a trusted source such as a directly attached
202 // input device or an application with system-wide event injection permission.
203 POLICY_FLAG_TRUSTED = 0x02000000,
204
205 // Indicates that the input event has passed through an input filter.
206 POLICY_FLAG_FILTERED = 0x04000000,
207
208 // Disables automatic key repeating behavior.
209 POLICY_FLAG_DISABLE_KEY_REPEAT = 0x08000000,
210
211 /* These flags are set by the input reader policy as it intercepts each event. */
212
Jeff Browndb19e462014-04-08 19:55:38 -0700213 // Indicates that the device was in an interactive state when the
214 // event was intercepted.
215 POLICY_FLAG_INTERACTIVE = 0x20000000,
Jeff Brown5912f952013-07-01 19:10:31 -0700216
217 // Indicates that the event should be dispatched to applications.
218 // The input event should still be sent to the InputDispatcher so that it can see all
219 // input events received include those that it will not deliver.
220 POLICY_FLAG_PASS_TO_USER = 0x40000000,
221};
222
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800223/**
224 * Classifications of the current gesture, if available.
225 *
226 * The following values must be kept in sync with MotionEvent.java
227 */
228enum class MotionClassification : uint8_t {
229 /**
230 * No classification is available.
231 */
232 NONE = 0,
233 /**
234 * Too early to classify the current gesture. Need more events. Look for changes in the
235 * upcoming motion events.
236 */
237 AMBIGUOUS_GESTURE = 1,
238 /**
239 * The current gesture likely represents a user intentionally exerting force on the touchscreen.
240 */
241 DEEP_PRESS = 2,
242};
243
Jeff Brown5912f952013-07-01 19:10:31 -0700244/*
245 * Pointer coordinate data.
246 */
247struct PointerCoords {
Michael Wright8f6710f2014-06-09 18:56:43 -0700248 enum { MAX_AXES = 30 }; // 30 so that sizeof(PointerCoords) == 128
Jeff Brown5912f952013-07-01 19:10:31 -0700249
250 // Bitfield of axes that are present in this structure.
Fengwei Yin83e0e422014-05-24 05:32:09 +0800251 uint64_t bits __attribute__((aligned(8)));
Jeff Brown5912f952013-07-01 19:10:31 -0700252
253 // Values of axes that are stored in this structure packed in order by axis id
254 // for each axis that is present in the structure according to 'bits'.
255 float values[MAX_AXES];
256
257 inline void clear() {
Michael Wrightd0bd3912014-03-19 12:06:10 -0700258 BitSet64::clear(bits);
259 }
260
261 bool isEmpty() const {
262 return BitSet64::isEmpty(bits);
Jeff Brown5912f952013-07-01 19:10:31 -0700263 }
264
265 float getAxisValue(int32_t axis) const;
266 status_t setAxisValue(int32_t axis, float value);
267
Robert Carre07e1032018-11-26 12:55:53 -0800268 void scale(float globalScale);
269
270 // Scale the pointer coordinates according to a global scale and a
271 // window scale. The global scale will be applied to TOUCH/TOOL_MAJOR/MINOR
272 // axes, however the window scaling will not.
273 void scale(float globalScale, float windowXScale, float windowYScale);
Jeff Browned4d28d2014-02-11 14:28:48 -0800274 void applyOffset(float xOffset, float yOffset);
Jeff Brown5912f952013-07-01 19:10:31 -0700275
276 inline float getX() const {
277 return getAxisValue(AMOTION_EVENT_AXIS_X);
278 }
279
280 inline float getY() const {
281 return getAxisValue(AMOTION_EVENT_AXIS_Y);
282 }
283
Elliott Hughes6071da72015-08-12 15:27:47 -0700284#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700285 status_t readFromParcel(Parcel* parcel);
286 status_t writeToParcel(Parcel* parcel) const;
287#endif
288
289 bool operator==(const PointerCoords& other) const;
290 inline bool operator!=(const PointerCoords& other) const {
291 return !(*this == other);
292 }
293
294 void copyFrom(const PointerCoords& other);
295
296private:
297 void tooManyAxes(int axis);
298};
299
300/*
301 * Pointer property data.
302 */
303struct PointerProperties {
304 // The id of the pointer.
305 int32_t id;
306
307 // The pointer tool type.
308 int32_t toolType;
309
310 inline void clear() {
311 id = -1;
312 toolType = 0;
313 }
314
315 bool operator==(const PointerProperties& other) const;
316 inline bool operator!=(const PointerProperties& other) const {
317 return !(*this == other);
318 }
319
320 void copyFrom(const PointerProperties& other);
321};
322
323/*
324 * Input events.
325 */
326class InputEvent : public AInputEvent {
327public:
328 virtual ~InputEvent() { }
329
330 virtual int32_t getType() const = 0;
331
332 inline int32_t getDeviceId() const { return mDeviceId; }
333
334 inline int32_t getSource() const { return mSource; }
335
336 inline void setSource(int32_t source) { mSource = source; }
337
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100338 inline int32_t getDisplayId() const { return mDisplayId; }
339
340 inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; }
341
342
Jeff Brown5912f952013-07-01 19:10:31 -0700343protected:
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100344 void initialize(int32_t deviceId, int32_t source, int32_t displayId);
Jeff Brown5912f952013-07-01 19:10:31 -0700345 void initialize(const InputEvent& from);
346
347 int32_t mDeviceId;
348 int32_t mSource;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100349 int32_t mDisplayId;
Jeff Brown5912f952013-07-01 19:10:31 -0700350};
351
352/*
353 * Key events.
354 */
355class KeyEvent : public InputEvent {
356public:
357 virtual ~KeyEvent() { }
358
359 virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; }
360
361 inline int32_t getAction() const { return mAction; }
362
363 inline int32_t getFlags() const { return mFlags; }
364
365 inline void setFlags(int32_t flags) { mFlags = flags; }
366
367 inline int32_t getKeyCode() const { return mKeyCode; }
368
369 inline int32_t getScanCode() const { return mScanCode; }
370
371 inline int32_t getMetaState() const { return mMetaState; }
372
373 inline int32_t getRepeatCount() const { return mRepeatCount; }
374
375 inline nsecs_t getDownTime() const { return mDownTime; }
376
377 inline nsecs_t getEventTime() const { return mEventTime; }
378
Michael Wright872db4f2014-04-22 15:03:51 -0700379 static const char* getLabel(int32_t keyCode);
380 static int32_t getKeyCodeFromLabel(const char* label);
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800381
Jeff Brown5912f952013-07-01 19:10:31 -0700382 void initialize(
383 int32_t deviceId,
384 int32_t source,
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100385 int32_t displayId,
Jeff Brown5912f952013-07-01 19:10:31 -0700386 int32_t action,
387 int32_t flags,
388 int32_t keyCode,
389 int32_t scanCode,
390 int32_t metaState,
391 int32_t repeatCount,
392 nsecs_t downTime,
393 nsecs_t eventTime);
394 void initialize(const KeyEvent& from);
395
396protected:
397 int32_t mAction;
398 int32_t mFlags;
399 int32_t mKeyCode;
400 int32_t mScanCode;
401 int32_t mMetaState;
402 int32_t mRepeatCount;
403 nsecs_t mDownTime;
404 nsecs_t mEventTime;
405};
406
407/*
408 * Motion events.
409 */
410class MotionEvent : public InputEvent {
411public:
412 virtual ~MotionEvent() { }
413
414 virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }
415
416 inline int32_t getAction() const { return mAction; }
417
418 inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; }
419
420 inline int32_t getActionIndex() const {
421 return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
422 >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
423 }
424
425 inline void setAction(int32_t action) { mAction = action; }
426
427 inline int32_t getFlags() const { return mFlags; }
428
429 inline void setFlags(int32_t flags) { mFlags = flags; }
430
431 inline int32_t getEdgeFlags() const { return mEdgeFlags; }
432
433 inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; }
434
435 inline int32_t getMetaState() const { return mMetaState; }
436
437 inline void setMetaState(int32_t metaState) { mMetaState = metaState; }
438
439 inline int32_t getButtonState() const { return mButtonState; }
440
Michael Wright6db58792016-09-14 19:53:37 +0100441 inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; }
Michael Wright7b159c92015-05-14 14:48:03 +0100442
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800443 inline MotionClassification getClassification() const { return mClassification; }
444
Michael Wright7b159c92015-05-14 14:48:03 +0100445 inline int32_t getActionButton() const { return mActionButton; }
446
Michael Wright21957b92015-06-17 21:06:54 +0100447 inline void setActionButton(int32_t button) { mActionButton = button; }
448
Jeff Brown5912f952013-07-01 19:10:31 -0700449 inline float getXOffset() const { return mXOffset; }
450
451 inline float getYOffset() const { return mYOffset; }
452
453 inline float getXPrecision() const { return mXPrecision; }
454
455 inline float getYPrecision() const { return mYPrecision; }
456
457 inline nsecs_t getDownTime() const { return mDownTime; }
458
459 inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; }
460
461 inline size_t getPointerCount() const { return mPointerProperties.size(); }
462
463 inline const PointerProperties* getPointerProperties(size_t pointerIndex) const {
464 return &mPointerProperties[pointerIndex];
465 }
466
467 inline int32_t getPointerId(size_t pointerIndex) const {
468 return mPointerProperties[pointerIndex].id;
469 }
470
471 inline int32_t getToolType(size_t pointerIndex) const {
472 return mPointerProperties[pointerIndex].toolType;
473 }
474
475 inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; }
476
477 const PointerCoords* getRawPointerCoords(size_t pointerIndex) const;
478
479 float getRawAxisValue(int32_t axis, size_t pointerIndex) const;
480
481 inline float getRawX(size_t pointerIndex) const {
482 return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
483 }
484
485 inline float getRawY(size_t pointerIndex) const {
486 return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
487 }
488
489 float getAxisValue(int32_t axis, size_t pointerIndex) const;
490
491 inline float getX(size_t pointerIndex) const {
492 return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
493 }
494
495 inline float getY(size_t pointerIndex) const {
496 return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
497 }
498
499 inline float getPressure(size_t pointerIndex) const {
500 return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex);
501 }
502
503 inline float getSize(size_t pointerIndex) const {
504 return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex);
505 }
506
507 inline float getTouchMajor(size_t pointerIndex) const {
508 return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex);
509 }
510
511 inline float getTouchMinor(size_t pointerIndex) const {
512 return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex);
513 }
514
515 inline float getToolMajor(size_t pointerIndex) const {
516 return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex);
517 }
518
519 inline float getToolMinor(size_t pointerIndex) const {
520 return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex);
521 }
522
523 inline float getOrientation(size_t pointerIndex) const {
524 return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex);
525 }
526
527 inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; }
528
529 inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const {
530 return mSampleEventTimes[historicalIndex];
531 }
532
533 const PointerCoords* getHistoricalRawPointerCoords(
534 size_t pointerIndex, size_t historicalIndex) const;
535
536 float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
537 size_t historicalIndex) const;
538
539 inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const {
540 return getHistoricalRawAxisValue(
541 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
542 }
543
544 inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const {
545 return getHistoricalRawAxisValue(
546 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
547 }
548
549 float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const;
550
551 inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const {
552 return getHistoricalAxisValue(
553 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
554 }
555
556 inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const {
557 return getHistoricalAxisValue(
558 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
559 }
560
561 inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const {
562 return getHistoricalAxisValue(
563 AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex);
564 }
565
566 inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const {
567 return getHistoricalAxisValue(
568 AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex);
569 }
570
571 inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const {
572 return getHistoricalAxisValue(
573 AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex);
574 }
575
576 inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const {
577 return getHistoricalAxisValue(
578 AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex);
579 }
580
581 inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const {
582 return getHistoricalAxisValue(
583 AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex);
584 }
585
586 inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const {
587 return getHistoricalAxisValue(
588 AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex);
589 }
590
591 inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const {
592 return getHistoricalAxisValue(
593 AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex);
594 }
595
596 ssize_t findPointerIndex(int32_t pointerId) const;
597
598 void initialize(
599 int32_t deviceId,
600 int32_t source,
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800601 int32_t displayId,
Jeff Brown5912f952013-07-01 19:10:31 -0700602 int32_t action,
Michael Wright7b159c92015-05-14 14:48:03 +0100603 int32_t actionButton,
Jeff Brown5912f952013-07-01 19:10:31 -0700604 int32_t flags,
605 int32_t edgeFlags,
606 int32_t metaState,
607 int32_t buttonState,
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800608 MotionClassification classification,
Jeff Brown5912f952013-07-01 19:10:31 -0700609 float xOffset,
610 float yOffset,
611 float xPrecision,
612 float yPrecision,
613 nsecs_t downTime,
614 nsecs_t eventTime,
615 size_t pointerCount,
616 const PointerProperties* pointerProperties,
617 const PointerCoords* pointerCoords);
618
619 void copyFrom(const MotionEvent* other, bool keepHistory);
620
621 void addSample(
622 nsecs_t eventTime,
623 const PointerCoords* pointerCoords);
624
625 void offsetLocation(float xOffset, float yOffset);
626
Robert Carre07e1032018-11-26 12:55:53 -0800627 void scale(float globalScaleFactor);
Jeff Brown5912f952013-07-01 19:10:31 -0700628
Jeff Brown5a2f68e2013-07-15 17:28:19 -0700629 // Apply 3x3 perspective matrix transformation.
630 // Matrix is in row-major form and compatible with SkMatrix.
631 void transform(const float matrix[9]);
Jeff Brown5912f952013-07-01 19:10:31 -0700632
Elliott Hughes6071da72015-08-12 15:27:47 -0700633#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700634 status_t readFromParcel(Parcel* parcel);
635 status_t writeToParcel(Parcel* parcel) const;
636#endif
637
638 static bool isTouchEvent(int32_t source, int32_t action);
639 inline bool isTouchEvent() const {
640 return isTouchEvent(mSource, mAction);
641 }
642
643 // Low-level accessors.
644 inline const PointerProperties* getPointerProperties() const {
645 return mPointerProperties.array();
646 }
647 inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); }
648 inline const PointerCoords* getSamplePointerCoords() const {
649 return mSamplePointerCoords.array();
650 }
651
Michael Wright872db4f2014-04-22 15:03:51 -0700652 static const char* getLabel(int32_t axis);
653 static int32_t getAxisFromLabel(const char* label);
654
Jeff Brown5912f952013-07-01 19:10:31 -0700655protected:
656 int32_t mAction;
Michael Wright7b159c92015-05-14 14:48:03 +0100657 int32_t mActionButton;
Jeff Brown5912f952013-07-01 19:10:31 -0700658 int32_t mFlags;
659 int32_t mEdgeFlags;
660 int32_t mMetaState;
661 int32_t mButtonState;
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800662 MotionClassification mClassification;
Jeff Brown5912f952013-07-01 19:10:31 -0700663 float mXOffset;
664 float mYOffset;
665 float mXPrecision;
666 float mYPrecision;
667 nsecs_t mDownTime;
668 Vector<PointerProperties> mPointerProperties;
669 Vector<nsecs_t> mSampleEventTimes;
670 Vector<PointerCoords> mSamplePointerCoords;
671};
672
673/*
674 * Input event factory.
675 */
676class InputEventFactoryInterface {
677protected:
678 virtual ~InputEventFactoryInterface() { }
679
680public:
681 InputEventFactoryInterface() { }
682
683 virtual KeyEvent* createKeyEvent() = 0;
684 virtual MotionEvent* createMotionEvent() = 0;
685};
686
687/*
688 * A simple input event factory implementation that uses a single preallocated instance
689 * of each type of input event that are reused for each request.
690 */
691class PreallocatedInputEventFactory : public InputEventFactoryInterface {
692public:
693 PreallocatedInputEventFactory() { }
694 virtual ~PreallocatedInputEventFactory() { }
695
696 virtual KeyEvent* createKeyEvent() { return & mKeyEvent; }
697 virtual MotionEvent* createMotionEvent() { return & mMotionEvent; }
698
699private:
700 KeyEvent mKeyEvent;
701 MotionEvent mMotionEvent;
702};
703
704/*
705 * An input event factory implementation that maintains a pool of input events.
706 */
707class PooledInputEventFactory : public InputEventFactoryInterface {
708public:
Chih-Hung Hsiehf43b02c2018-12-20 15:45:56 -0800709 explicit PooledInputEventFactory(size_t maxPoolSize = 20);
Jeff Brown5912f952013-07-01 19:10:31 -0700710 virtual ~PooledInputEventFactory();
711
712 virtual KeyEvent* createKeyEvent();
713 virtual MotionEvent* createMotionEvent();
714
715 void recycle(InputEvent* event);
716
717private:
718 const size_t mMaxPoolSize;
719
720 Vector<KeyEvent*> mKeyEventPool;
721 Vector<MotionEvent*> mMotionEventPool;
722};
723
724} // namespace android
725
726#endif // _LIBINPUT_INPUT_H