blob: ee22bc63716983febf8f71e16617535ea2f80f1f [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
223/*
224 * Pointer coordinate data.
225 */
226struct PointerCoords {
Michael Wright8f6710f2014-06-09 18:56:43 -0700227 enum { MAX_AXES = 30 }; // 30 so that sizeof(PointerCoords) == 128
Jeff Brown5912f952013-07-01 19:10:31 -0700228
229 // Bitfield of axes that are present in this structure.
Fengwei Yin83e0e422014-05-24 05:32:09 +0800230 uint64_t bits __attribute__((aligned(8)));
Jeff Brown5912f952013-07-01 19:10:31 -0700231
232 // Values of axes that are stored in this structure packed in order by axis id
233 // for each axis that is present in the structure according to 'bits'.
234 float values[MAX_AXES];
235
236 inline void clear() {
Michael Wrightd0bd3912014-03-19 12:06:10 -0700237 BitSet64::clear(bits);
238 }
239
240 bool isEmpty() const {
241 return BitSet64::isEmpty(bits);
Jeff Brown5912f952013-07-01 19:10:31 -0700242 }
243
244 float getAxisValue(int32_t axis) const;
245 status_t setAxisValue(int32_t axis, float value);
246
Robert Carre07e1032018-11-26 12:55:53 -0800247 void scale(float globalScale);
248
249 // Scale the pointer coordinates according to a global scale and a
250 // window scale. The global scale will be applied to TOUCH/TOOL_MAJOR/MINOR
251 // axes, however the window scaling will not.
252 void scale(float globalScale, float windowXScale, float windowYScale);
Jeff Browned4d28d2014-02-11 14:28:48 -0800253 void applyOffset(float xOffset, float yOffset);
Jeff Brown5912f952013-07-01 19:10:31 -0700254
255 inline float getX() const {
256 return getAxisValue(AMOTION_EVENT_AXIS_X);
257 }
258
259 inline float getY() const {
260 return getAxisValue(AMOTION_EVENT_AXIS_Y);
261 }
262
Elliott Hughes6071da72015-08-12 15:27:47 -0700263#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700264 status_t readFromParcel(Parcel* parcel);
265 status_t writeToParcel(Parcel* parcel) const;
266#endif
267
268 bool operator==(const PointerCoords& other) const;
269 inline bool operator!=(const PointerCoords& other) const {
270 return !(*this == other);
271 }
272
273 void copyFrom(const PointerCoords& other);
274
275private:
276 void tooManyAxes(int axis);
277};
278
279/*
280 * Pointer property data.
281 */
282struct PointerProperties {
283 // The id of the pointer.
284 int32_t id;
285
286 // The pointer tool type.
287 int32_t toolType;
288
289 inline void clear() {
290 id = -1;
291 toolType = 0;
292 }
293
294 bool operator==(const PointerProperties& other) const;
295 inline bool operator!=(const PointerProperties& other) const {
296 return !(*this == other);
297 }
298
299 void copyFrom(const PointerProperties& other);
300};
301
302/*
303 * Input events.
304 */
305class InputEvent : public AInputEvent {
306public:
307 virtual ~InputEvent() { }
308
309 virtual int32_t getType() const = 0;
310
311 inline int32_t getDeviceId() const { return mDeviceId; }
312
313 inline int32_t getSource() const { return mSource; }
314
315 inline void setSource(int32_t source) { mSource = source; }
316
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100317 inline int32_t getDisplayId() const { return mDisplayId; }
318
319 inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; }
320
321
Jeff Brown5912f952013-07-01 19:10:31 -0700322protected:
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100323 void initialize(int32_t deviceId, int32_t source, int32_t displayId);
Jeff Brown5912f952013-07-01 19:10:31 -0700324 void initialize(const InputEvent& from);
325
326 int32_t mDeviceId;
327 int32_t mSource;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100328 int32_t mDisplayId;
Jeff Brown5912f952013-07-01 19:10:31 -0700329};
330
331/*
332 * Key events.
333 */
334class KeyEvent : public InputEvent {
335public:
336 virtual ~KeyEvent() { }
337
338 virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; }
339
340 inline int32_t getAction() const { return mAction; }
341
342 inline int32_t getFlags() const { return mFlags; }
343
344 inline void setFlags(int32_t flags) { mFlags = flags; }
345
346 inline int32_t getKeyCode() const { return mKeyCode; }
347
348 inline int32_t getScanCode() const { return mScanCode; }
349
350 inline int32_t getMetaState() const { return mMetaState; }
351
352 inline int32_t getRepeatCount() const { return mRepeatCount; }
353
354 inline nsecs_t getDownTime() const { return mDownTime; }
355
356 inline nsecs_t getEventTime() const { return mEventTime; }
357
Michael Wright872db4f2014-04-22 15:03:51 -0700358 static const char* getLabel(int32_t keyCode);
359 static int32_t getKeyCodeFromLabel(const char* label);
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800360
Jeff Brown5912f952013-07-01 19:10:31 -0700361 void initialize(
362 int32_t deviceId,
363 int32_t source,
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100364 int32_t displayId,
Jeff Brown5912f952013-07-01 19:10:31 -0700365 int32_t action,
366 int32_t flags,
367 int32_t keyCode,
368 int32_t scanCode,
369 int32_t metaState,
370 int32_t repeatCount,
371 nsecs_t downTime,
372 nsecs_t eventTime);
373 void initialize(const KeyEvent& from);
374
375protected:
376 int32_t mAction;
377 int32_t mFlags;
378 int32_t mKeyCode;
379 int32_t mScanCode;
380 int32_t mMetaState;
381 int32_t mRepeatCount;
382 nsecs_t mDownTime;
383 nsecs_t mEventTime;
384};
385
386/*
387 * Motion events.
388 */
389class MotionEvent : public InputEvent {
390public:
391 virtual ~MotionEvent() { }
392
393 virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }
394
395 inline int32_t getAction() const { return mAction; }
396
397 inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; }
398
399 inline int32_t getActionIndex() const {
400 return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
401 >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
402 }
403
404 inline void setAction(int32_t action) { mAction = action; }
405
406 inline int32_t getFlags() const { return mFlags; }
407
408 inline void setFlags(int32_t flags) { mFlags = flags; }
409
410 inline int32_t getEdgeFlags() const { return mEdgeFlags; }
411
412 inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; }
413
414 inline int32_t getMetaState() const { return mMetaState; }
415
416 inline void setMetaState(int32_t metaState) { mMetaState = metaState; }
417
418 inline int32_t getButtonState() const { return mButtonState; }
419
Michael Wright6db58792016-09-14 19:53:37 +0100420 inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; }
Michael Wright7b159c92015-05-14 14:48:03 +0100421
422 inline int32_t getActionButton() const { return mActionButton; }
423
Michael Wright21957b92015-06-17 21:06:54 +0100424 inline void setActionButton(int32_t button) { mActionButton = button; }
425
Jeff Brown5912f952013-07-01 19:10:31 -0700426 inline float getXOffset() const { return mXOffset; }
427
428 inline float getYOffset() const { return mYOffset; }
429
430 inline float getXPrecision() const { return mXPrecision; }
431
432 inline float getYPrecision() const { return mYPrecision; }
433
434 inline nsecs_t getDownTime() const { return mDownTime; }
435
436 inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; }
437
438 inline size_t getPointerCount() const { return mPointerProperties.size(); }
439
440 inline const PointerProperties* getPointerProperties(size_t pointerIndex) const {
441 return &mPointerProperties[pointerIndex];
442 }
443
444 inline int32_t getPointerId(size_t pointerIndex) const {
445 return mPointerProperties[pointerIndex].id;
446 }
447
448 inline int32_t getToolType(size_t pointerIndex) const {
449 return mPointerProperties[pointerIndex].toolType;
450 }
451
452 inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; }
453
454 const PointerCoords* getRawPointerCoords(size_t pointerIndex) const;
455
456 float getRawAxisValue(int32_t axis, size_t pointerIndex) const;
457
458 inline float getRawX(size_t pointerIndex) const {
459 return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
460 }
461
462 inline float getRawY(size_t pointerIndex) const {
463 return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
464 }
465
466 float getAxisValue(int32_t axis, size_t pointerIndex) const;
467
468 inline float getX(size_t pointerIndex) const {
469 return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
470 }
471
472 inline float getY(size_t pointerIndex) const {
473 return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
474 }
475
476 inline float getPressure(size_t pointerIndex) const {
477 return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex);
478 }
479
480 inline float getSize(size_t pointerIndex) const {
481 return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex);
482 }
483
484 inline float getTouchMajor(size_t pointerIndex) const {
485 return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex);
486 }
487
488 inline float getTouchMinor(size_t pointerIndex) const {
489 return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex);
490 }
491
492 inline float getToolMajor(size_t pointerIndex) const {
493 return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex);
494 }
495
496 inline float getToolMinor(size_t pointerIndex) const {
497 return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex);
498 }
499
500 inline float getOrientation(size_t pointerIndex) const {
501 return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex);
502 }
503
504 inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; }
505
506 inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const {
507 return mSampleEventTimes[historicalIndex];
508 }
509
510 const PointerCoords* getHistoricalRawPointerCoords(
511 size_t pointerIndex, size_t historicalIndex) const;
512
513 float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
514 size_t historicalIndex) const;
515
516 inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const {
517 return getHistoricalRawAxisValue(
518 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
519 }
520
521 inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const {
522 return getHistoricalRawAxisValue(
523 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
524 }
525
526 float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const;
527
528 inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const {
529 return getHistoricalAxisValue(
530 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
531 }
532
533 inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const {
534 return getHistoricalAxisValue(
535 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
536 }
537
538 inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const {
539 return getHistoricalAxisValue(
540 AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex);
541 }
542
543 inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const {
544 return getHistoricalAxisValue(
545 AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex);
546 }
547
548 inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const {
549 return getHistoricalAxisValue(
550 AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex);
551 }
552
553 inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const {
554 return getHistoricalAxisValue(
555 AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex);
556 }
557
558 inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const {
559 return getHistoricalAxisValue(
560 AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex);
561 }
562
563 inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const {
564 return getHistoricalAxisValue(
565 AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex);
566 }
567
568 inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const {
569 return getHistoricalAxisValue(
570 AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex);
571 }
572
573 ssize_t findPointerIndex(int32_t pointerId) const;
574
575 void initialize(
576 int32_t deviceId,
577 int32_t source,
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800578 int32_t displayId,
Jeff Brown5912f952013-07-01 19:10:31 -0700579 int32_t action,
Michael Wright7b159c92015-05-14 14:48:03 +0100580 int32_t actionButton,
Jeff Brown5912f952013-07-01 19:10:31 -0700581 int32_t flags,
582 int32_t edgeFlags,
583 int32_t metaState,
584 int32_t buttonState,
585 float xOffset,
586 float yOffset,
587 float xPrecision,
588 float yPrecision,
589 nsecs_t downTime,
590 nsecs_t eventTime,
591 size_t pointerCount,
592 const PointerProperties* pointerProperties,
593 const PointerCoords* pointerCoords);
594
595 void copyFrom(const MotionEvent* other, bool keepHistory);
596
597 void addSample(
598 nsecs_t eventTime,
599 const PointerCoords* pointerCoords);
600
601 void offsetLocation(float xOffset, float yOffset);
602
Robert Carre07e1032018-11-26 12:55:53 -0800603 void scale(float globalScaleFactor);
Jeff Brown5912f952013-07-01 19:10:31 -0700604
Jeff Brown5a2f68e2013-07-15 17:28:19 -0700605 // Apply 3x3 perspective matrix transformation.
606 // Matrix is in row-major form and compatible with SkMatrix.
607 void transform(const float matrix[9]);
Jeff Brown5912f952013-07-01 19:10:31 -0700608
Elliott Hughes6071da72015-08-12 15:27:47 -0700609#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700610 status_t readFromParcel(Parcel* parcel);
611 status_t writeToParcel(Parcel* parcel) const;
612#endif
613
614 static bool isTouchEvent(int32_t source, int32_t action);
615 inline bool isTouchEvent() const {
616 return isTouchEvent(mSource, mAction);
617 }
618
619 // Low-level accessors.
620 inline const PointerProperties* getPointerProperties() const {
621 return mPointerProperties.array();
622 }
623 inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); }
624 inline const PointerCoords* getSamplePointerCoords() const {
625 return mSamplePointerCoords.array();
626 }
627
Michael Wright872db4f2014-04-22 15:03:51 -0700628 static const char* getLabel(int32_t axis);
629 static int32_t getAxisFromLabel(const char* label);
630
Jeff Brown5912f952013-07-01 19:10:31 -0700631protected:
632 int32_t mAction;
Michael Wright7b159c92015-05-14 14:48:03 +0100633 int32_t mActionButton;
Jeff Brown5912f952013-07-01 19:10:31 -0700634 int32_t mFlags;
635 int32_t mEdgeFlags;
636 int32_t mMetaState;
637 int32_t mButtonState;
638 float mXOffset;
639 float mYOffset;
640 float mXPrecision;
641 float mYPrecision;
642 nsecs_t mDownTime;
643 Vector<PointerProperties> mPointerProperties;
644 Vector<nsecs_t> mSampleEventTimes;
645 Vector<PointerCoords> mSamplePointerCoords;
646};
647
648/*
649 * Input event factory.
650 */
651class InputEventFactoryInterface {
652protected:
653 virtual ~InputEventFactoryInterface() { }
654
655public:
656 InputEventFactoryInterface() { }
657
658 virtual KeyEvent* createKeyEvent() = 0;
659 virtual MotionEvent* createMotionEvent() = 0;
660};
661
662/*
663 * A simple input event factory implementation that uses a single preallocated instance
664 * of each type of input event that are reused for each request.
665 */
666class PreallocatedInputEventFactory : public InputEventFactoryInterface {
667public:
668 PreallocatedInputEventFactory() { }
669 virtual ~PreallocatedInputEventFactory() { }
670
671 virtual KeyEvent* createKeyEvent() { return & mKeyEvent; }
672 virtual MotionEvent* createMotionEvent() { return & mMotionEvent; }
673
674private:
675 KeyEvent mKeyEvent;
676 MotionEvent mMotionEvent;
677};
678
679/*
680 * An input event factory implementation that maintains a pool of input events.
681 */
682class PooledInputEventFactory : public InputEventFactoryInterface {
683public:
684 PooledInputEventFactory(size_t maxPoolSize = 20);
685 virtual ~PooledInputEventFactory();
686
687 virtual KeyEvent* createKeyEvent();
688 virtual MotionEvent* createMotionEvent();
689
690 void recycle(InputEvent* event);
691
692private:
693 const size_t mMaxPoolSize;
694
695 Vector<KeyEvent*> mKeyEventPool;
696 Vector<MotionEvent*> mMotionEventPool;
697};
698
699} // namespace android
700
701#endif // _LIBINPUT_INPUT_H