blob: 7c4379eda129ef144afe935e68758c984f4b3dbd [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
20/**
21 * Native input event structures.
22 */
23
24#include <android/input.h>
Michael Wrightd0bd3912014-03-19 12:06:10 -070025#include <utils/BitSet.h>
Jeff Brown5912f952013-07-01 19:10:31 -070026#include <utils/KeyedVector.h>
Jeff Brown5912f952013-07-01 19:10:31 -070027#include <utils/RefBase.h>
28#include <utils/String8.h>
Michael Wrightd0bd3912014-03-19 12:06:10 -070029#include <utils/Timers.h>
30#include <utils/Vector.h>
Nick Kralevich834ac202015-10-22 07:09:23 -070031#include <stdint.h>
Jeff Brown5912f952013-07-01 19:10:31 -070032
Jeff Brown5912f952013-07-01 19:10:31 -070033/*
34 * Additional private constants not defined in ndk/ui/input.h.
35 */
36enum {
37 /* Signifies that the key is being predispatched */
38 AKEY_EVENT_FLAG_PREDISPATCH = 0x20000000,
39
40 /* Private control to determine when an app is tracking a key sequence. */
41 AKEY_EVENT_FLAG_START_TRACKING = 0x40000000,
42
43 /* Key event is inconsistent with previously sent key events. */
44 AKEY_EVENT_FLAG_TAINTED = 0x80000000,
45};
46
47enum {
Michael Wrightcdcd8f22016-03-22 16:52:13 -070048
49 /**
50 * This flag indicates that the window that received this motion event is partly
51 * or wholly obscured by another visible window above it. This flag is set to true
52 * even if the event did not directly pass through the obscured area.
53 * A security sensitive application can check this flag to identify situations in which
54 * a malicious application may have covered up part of its content for the purpose
55 * of misleading the user or hijacking touches. An appropriate response might be
56 * to drop the suspect touches or to take additional precautions to confirm the user's
57 * actual intent.
58 */
59 AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2,
60
Jeff Brown5912f952013-07-01 19:10:31 -070061 /* Motion event is inconsistent with previously sent motion events. */
62 AMOTION_EVENT_FLAG_TAINTED = 0x80000000,
63};
64
65enum {
66 /* Used when a motion event is not associated with any display.
67 * Typically used for non-pointer events. */
68 ADISPLAY_ID_NONE = -1,
69
70 /* The default display id. */
71 ADISPLAY_ID_DEFAULT = 0,
72};
73
74enum {
75 /*
76 * Indicates that an input device has switches.
77 * This input source flag is hidden from the API because switches are only used by the system
78 * and applications have no way to interact with them.
79 */
80 AINPUT_SOURCE_SWITCH = 0x80000000,
81};
82
Michael Wright962a1082013-10-17 17:35:53 -070083enum {
84 /**
85 * Constants for LEDs. Hidden from the API since we don't actually expose a way to interact
86 * with LEDs to developers
87 *
Michael Wright872db4f2014-04-22 15:03:51 -070088 * NOTE: If you add LEDs here, you must also add them to InputEventLabels.h
Michael Wright962a1082013-10-17 17:35:53 -070089 */
90
91 ALED_NUM_LOCK = 0x00,
92 ALED_CAPS_LOCK = 0x01,
93 ALED_SCROLL_LOCK = 0x02,
94 ALED_COMPOSE = 0x03,
95 ALED_KANA = 0x04,
96 ALED_SLEEP = 0x05,
97 ALED_SUSPEND = 0x06,
98 ALED_MUTE = 0x07,
99 ALED_MISC = 0x08,
100 ALED_MAIL = 0x09,
101 ALED_CHARGING = 0x0a,
102 ALED_CONTROLLER_1 = 0x10,
103 ALED_CONTROLLER_2 = 0x11,
104 ALED_CONTROLLER_3 = 0x12,
105 ALED_CONTROLLER_4 = 0x13,
106};
107
Michael Wright9b04f862013-10-18 17:53:50 -0700108/* Maximum number of controller LEDs we support */
109#define MAX_CONTROLLER_LEDS 4
110
Jeff Brown5912f952013-07-01 19:10:31 -0700111/*
112 * SystemUiVisibility constants from View.
113 */
114enum {
115 ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE = 0,
116 ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN = 0x00000001,
117};
118
119/*
120 * Maximum number of pointers supported per motion event.
121 * Smallest number of pointers is 1.
122 * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers
123 * will occasionally emit 11. There is not much harm making this constant bigger.)
124 */
125#define MAX_POINTERS 16
126
127/*
Flanker552a8a52015-09-07 15:28:58 +0800128 * Maximum number of samples supported per motion event.
129 */
130#define MAX_SAMPLES UINT16_MAX
131
132/*
Jeff Brown5912f952013-07-01 19:10:31 -0700133 * Maximum pointer id value supported in a motion event.
134 * Smallest pointer id is 0.
135 * (This is limited by our use of BitSet32 to track pointer assignments.)
136 */
137#define MAX_POINTER_ID 31
138
139/*
140 * Declare a concrete type for the NDK's input event forward declaration.
141 */
142struct AInputEvent {
143 virtual ~AInputEvent() { }
144};
145
146/*
147 * Declare a concrete type for the NDK's input device forward declaration.
148 */
149struct AInputDevice {
150 virtual ~AInputDevice() { }
151};
152
153
154namespace android {
155
Elliott Hughes6071da72015-08-12 15:27:47 -0700156#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700157class Parcel;
158#endif
159
160/*
161 * Flags that flow alongside events in the input dispatch system to help with certain
162 * policy decisions such as waking from device sleep.
163 *
164 * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java.
165 */
166enum {
167 /* These flags originate in RawEvents and are generally set in the key map.
Michael Wright872db4f2014-04-22 15:03:51 -0700168 * NOTE: If you want a flag to be able to set in a keylayout file, then you must add it to
169 * InputEventLabels.h as well. */
Jeff Brown5912f952013-07-01 19:10:31 -0700170
Jeff Brownc9aa6282015-02-11 19:03:28 -0800171 // Indicates that the event should wake the device.
Jeff Brown5912f952013-07-01 19:10:31 -0700172 POLICY_FLAG_WAKE = 0x00000001,
Jeff Brownc9aa6282015-02-11 19:03:28 -0800173
174 // Indicates that the key is virtual, such as a capacitive button, and should
175 // generate haptic feedback. Virtual keys may be suppressed for some time
176 // after a recent touch to prevent accidental activation of virtual keys adjacent
177 // to the touch screen during an edge swipe.
Michael Wright872db4f2014-04-22 15:03:51 -0700178 POLICY_FLAG_VIRTUAL = 0x00000002,
Jeff Brownc9aa6282015-02-11 19:03:28 -0800179
180 // Indicates that the key is the special function modifier.
Michael Wright872db4f2014-04-22 15:03:51 -0700181 POLICY_FLAG_FUNCTION = 0x00000004,
Jeff Brown5912f952013-07-01 19:10:31 -0700182
Jeff Brownc9aa6282015-02-11 19:03:28 -0800183 // Indicates that the key represents a special gesture that has been detected by
184 // the touch firmware or driver. Causes touch events from the same device to be canceled.
185 POLICY_FLAG_GESTURE = 0x00000008,
186
Jeff Brown5912f952013-07-01 19:10:31 -0700187 POLICY_FLAG_RAW_MASK = 0x0000ffff,
188
189 /* These flags are set by the input dispatcher. */
190
191 // Indicates that the input event was injected.
192 POLICY_FLAG_INJECTED = 0x01000000,
193
194 // Indicates that the input event is from a trusted source such as a directly attached
195 // input device or an application with system-wide event injection permission.
196 POLICY_FLAG_TRUSTED = 0x02000000,
197
198 // Indicates that the input event has passed through an input filter.
199 POLICY_FLAG_FILTERED = 0x04000000,
200
201 // Disables automatic key repeating behavior.
202 POLICY_FLAG_DISABLE_KEY_REPEAT = 0x08000000,
203
204 /* These flags are set by the input reader policy as it intercepts each event. */
205
Jeff Browndb19e462014-04-08 19:55:38 -0700206 // Indicates that the device was in an interactive state when the
207 // event was intercepted.
208 POLICY_FLAG_INTERACTIVE = 0x20000000,
Jeff Brown5912f952013-07-01 19:10:31 -0700209
210 // Indicates that the event should be dispatched to applications.
211 // The input event should still be sent to the InputDispatcher so that it can see all
212 // input events received include those that it will not deliver.
213 POLICY_FLAG_PASS_TO_USER = 0x40000000,
214};
215
216/*
217 * Pointer coordinate data.
218 */
219struct PointerCoords {
Michael Wright8f6710f2014-06-09 18:56:43 -0700220 enum { MAX_AXES = 30 }; // 30 so that sizeof(PointerCoords) == 128
Jeff Brown5912f952013-07-01 19:10:31 -0700221
222 // Bitfield of axes that are present in this structure.
Fengwei Yin83e0e422014-05-24 05:32:09 +0800223 uint64_t bits __attribute__((aligned(8)));
Jeff Brown5912f952013-07-01 19:10:31 -0700224
225 // Values of axes that are stored in this structure packed in order by axis id
226 // for each axis that is present in the structure according to 'bits'.
227 float values[MAX_AXES];
228
229 inline void clear() {
Michael Wrightd0bd3912014-03-19 12:06:10 -0700230 BitSet64::clear(bits);
231 }
232
233 bool isEmpty() const {
234 return BitSet64::isEmpty(bits);
Jeff Brown5912f952013-07-01 19:10:31 -0700235 }
236
237 float getAxisValue(int32_t axis) const;
238 status_t setAxisValue(int32_t axis, float value);
239
240 void scale(float scale);
Jeff Browned4d28d2014-02-11 14:28:48 -0800241 void applyOffset(float xOffset, float yOffset);
Jeff Brown5912f952013-07-01 19:10:31 -0700242
243 inline float getX() const {
244 return getAxisValue(AMOTION_EVENT_AXIS_X);
245 }
246
247 inline float getY() const {
248 return getAxisValue(AMOTION_EVENT_AXIS_Y);
249 }
250
Elliott Hughes6071da72015-08-12 15:27:47 -0700251#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700252 status_t readFromParcel(Parcel* parcel);
253 status_t writeToParcel(Parcel* parcel) const;
254#endif
255
256 bool operator==(const PointerCoords& other) const;
257 inline bool operator!=(const PointerCoords& other) const {
258 return !(*this == other);
259 }
260
261 void copyFrom(const PointerCoords& other);
262
263private:
264 void tooManyAxes(int axis);
265};
266
267/*
268 * Pointer property data.
269 */
270struct PointerProperties {
271 // The id of the pointer.
272 int32_t id;
273
274 // The pointer tool type.
275 int32_t toolType;
276
277 inline void clear() {
278 id = -1;
279 toolType = 0;
280 }
281
282 bool operator==(const PointerProperties& other) const;
283 inline bool operator!=(const PointerProperties& other) const {
284 return !(*this == other);
285 }
286
287 void copyFrom(const PointerProperties& other);
288};
289
290/*
291 * Input events.
292 */
293class InputEvent : public AInputEvent {
294public:
295 virtual ~InputEvent() { }
296
297 virtual int32_t getType() const = 0;
298
299 inline int32_t getDeviceId() const { return mDeviceId; }
300
301 inline int32_t getSource() const { return mSource; }
302
303 inline void setSource(int32_t source) { mSource = source; }
304
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100305 inline int32_t getDisplayId() const { return mDisplayId; }
306
307 inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; }
308
309
Jeff Brown5912f952013-07-01 19:10:31 -0700310protected:
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100311 void initialize(int32_t deviceId, int32_t source, int32_t displayId);
Jeff Brown5912f952013-07-01 19:10:31 -0700312 void initialize(const InputEvent& from);
313
314 int32_t mDeviceId;
315 int32_t mSource;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100316 int32_t mDisplayId;
Jeff Brown5912f952013-07-01 19:10:31 -0700317};
318
319/*
320 * Key events.
321 */
322class KeyEvent : public InputEvent {
323public:
324 virtual ~KeyEvent() { }
325
326 virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; }
327
328 inline int32_t getAction() const { return mAction; }
329
330 inline int32_t getFlags() const { return mFlags; }
331
332 inline void setFlags(int32_t flags) { mFlags = flags; }
333
334 inline int32_t getKeyCode() const { return mKeyCode; }
335
336 inline int32_t getScanCode() const { return mScanCode; }
337
338 inline int32_t getMetaState() const { return mMetaState; }
339
340 inline int32_t getRepeatCount() const { return mRepeatCount; }
341
342 inline nsecs_t getDownTime() const { return mDownTime; }
343
344 inline nsecs_t getEventTime() const { return mEventTime; }
345
Michael Wright872db4f2014-04-22 15:03:51 -0700346 static const char* getLabel(int32_t keyCode);
347 static int32_t getKeyCodeFromLabel(const char* label);
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800348
Jeff Brown5912f952013-07-01 19:10:31 -0700349 void initialize(
350 int32_t deviceId,
351 int32_t source,
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100352 int32_t displayId,
Jeff Brown5912f952013-07-01 19:10:31 -0700353 int32_t action,
354 int32_t flags,
355 int32_t keyCode,
356 int32_t scanCode,
357 int32_t metaState,
358 int32_t repeatCount,
359 nsecs_t downTime,
360 nsecs_t eventTime);
361 void initialize(const KeyEvent& from);
362
363protected:
364 int32_t mAction;
365 int32_t mFlags;
366 int32_t mKeyCode;
367 int32_t mScanCode;
368 int32_t mMetaState;
369 int32_t mRepeatCount;
370 nsecs_t mDownTime;
371 nsecs_t mEventTime;
372};
373
374/*
375 * Motion events.
376 */
377class MotionEvent : public InputEvent {
378public:
379 virtual ~MotionEvent() { }
380
381 virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }
382
383 inline int32_t getAction() const { return mAction; }
384
385 inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; }
386
387 inline int32_t getActionIndex() const {
388 return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
389 >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
390 }
391
392 inline void setAction(int32_t action) { mAction = action; }
393
394 inline int32_t getFlags() const { return mFlags; }
395
396 inline void setFlags(int32_t flags) { mFlags = flags; }
397
398 inline int32_t getEdgeFlags() const { return mEdgeFlags; }
399
400 inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; }
401
402 inline int32_t getMetaState() const { return mMetaState; }
403
404 inline void setMetaState(int32_t metaState) { mMetaState = metaState; }
405
406 inline int32_t getButtonState() const { return mButtonState; }
407
Michael Wright6db58792016-09-14 19:53:37 +0100408 inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; }
Michael Wright7b159c92015-05-14 14:48:03 +0100409
410 inline int32_t getActionButton() const { return mActionButton; }
411
Michael Wright21957b92015-06-17 21:06:54 +0100412 inline void setActionButton(int32_t button) { mActionButton = button; }
413
Jeff Brown5912f952013-07-01 19:10:31 -0700414 inline float getXOffset() const { return mXOffset; }
415
416 inline float getYOffset() const { return mYOffset; }
417
418 inline float getXPrecision() const { return mXPrecision; }
419
420 inline float getYPrecision() const { return mYPrecision; }
421
422 inline nsecs_t getDownTime() const { return mDownTime; }
423
424 inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; }
425
426 inline size_t getPointerCount() const { return mPointerProperties.size(); }
427
428 inline const PointerProperties* getPointerProperties(size_t pointerIndex) const {
429 return &mPointerProperties[pointerIndex];
430 }
431
432 inline int32_t getPointerId(size_t pointerIndex) const {
433 return mPointerProperties[pointerIndex].id;
434 }
435
436 inline int32_t getToolType(size_t pointerIndex) const {
437 return mPointerProperties[pointerIndex].toolType;
438 }
439
440 inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; }
441
442 const PointerCoords* getRawPointerCoords(size_t pointerIndex) const;
443
444 float getRawAxisValue(int32_t axis, size_t pointerIndex) const;
445
446 inline float getRawX(size_t pointerIndex) const {
447 return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
448 }
449
450 inline float getRawY(size_t pointerIndex) const {
451 return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
452 }
453
454 float getAxisValue(int32_t axis, size_t pointerIndex) const;
455
456 inline float getX(size_t pointerIndex) const {
457 return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
458 }
459
460 inline float getY(size_t pointerIndex) const {
461 return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
462 }
463
464 inline float getPressure(size_t pointerIndex) const {
465 return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex);
466 }
467
468 inline float getSize(size_t pointerIndex) const {
469 return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex);
470 }
471
472 inline float getTouchMajor(size_t pointerIndex) const {
473 return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex);
474 }
475
476 inline float getTouchMinor(size_t pointerIndex) const {
477 return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex);
478 }
479
480 inline float getToolMajor(size_t pointerIndex) const {
481 return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex);
482 }
483
484 inline float getToolMinor(size_t pointerIndex) const {
485 return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex);
486 }
487
488 inline float getOrientation(size_t pointerIndex) const {
489 return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex);
490 }
491
492 inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; }
493
494 inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const {
495 return mSampleEventTimes[historicalIndex];
496 }
497
498 const PointerCoords* getHistoricalRawPointerCoords(
499 size_t pointerIndex, size_t historicalIndex) const;
500
501 float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
502 size_t historicalIndex) const;
503
504 inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const {
505 return getHistoricalRawAxisValue(
506 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
507 }
508
509 inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const {
510 return getHistoricalRawAxisValue(
511 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
512 }
513
514 float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const;
515
516 inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const {
517 return getHistoricalAxisValue(
518 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
519 }
520
521 inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const {
522 return getHistoricalAxisValue(
523 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
524 }
525
526 inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const {
527 return getHistoricalAxisValue(
528 AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex);
529 }
530
531 inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const {
532 return getHistoricalAxisValue(
533 AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex);
534 }
535
536 inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const {
537 return getHistoricalAxisValue(
538 AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex);
539 }
540
541 inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const {
542 return getHistoricalAxisValue(
543 AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex);
544 }
545
546 inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const {
547 return getHistoricalAxisValue(
548 AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex);
549 }
550
551 inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const {
552 return getHistoricalAxisValue(
553 AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex);
554 }
555
556 inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const {
557 return getHistoricalAxisValue(
558 AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex);
559 }
560
561 ssize_t findPointerIndex(int32_t pointerId) const;
562
563 void initialize(
564 int32_t deviceId,
565 int32_t source,
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800566 int32_t displayId,
Jeff Brown5912f952013-07-01 19:10:31 -0700567 int32_t action,
Michael Wright7b159c92015-05-14 14:48:03 +0100568 int32_t actionButton,
Jeff Brown5912f952013-07-01 19:10:31 -0700569 int32_t flags,
570 int32_t edgeFlags,
571 int32_t metaState,
572 int32_t buttonState,
573 float xOffset,
574 float yOffset,
575 float xPrecision,
576 float yPrecision,
577 nsecs_t downTime,
578 nsecs_t eventTime,
579 size_t pointerCount,
580 const PointerProperties* pointerProperties,
581 const PointerCoords* pointerCoords);
582
583 void copyFrom(const MotionEvent* other, bool keepHistory);
584
585 void addSample(
586 nsecs_t eventTime,
587 const PointerCoords* pointerCoords);
588
589 void offsetLocation(float xOffset, float yOffset);
590
591 void scale(float scaleFactor);
592
Jeff Brown5a2f68e2013-07-15 17:28:19 -0700593 // Apply 3x3 perspective matrix transformation.
594 // Matrix is in row-major form and compatible with SkMatrix.
595 void transform(const float matrix[9]);
Jeff Brown5912f952013-07-01 19:10:31 -0700596
Elliott Hughes6071da72015-08-12 15:27:47 -0700597#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700598 status_t readFromParcel(Parcel* parcel);
599 status_t writeToParcel(Parcel* parcel) const;
600#endif
601
602 static bool isTouchEvent(int32_t source, int32_t action);
603 inline bool isTouchEvent() const {
604 return isTouchEvent(mSource, mAction);
605 }
606
607 // Low-level accessors.
608 inline const PointerProperties* getPointerProperties() const {
609 return mPointerProperties.array();
610 }
611 inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); }
612 inline const PointerCoords* getSamplePointerCoords() const {
613 return mSamplePointerCoords.array();
614 }
615
Michael Wright872db4f2014-04-22 15:03:51 -0700616 static const char* getLabel(int32_t axis);
617 static int32_t getAxisFromLabel(const char* label);
618
Jeff Brown5912f952013-07-01 19:10:31 -0700619protected:
620 int32_t mAction;
Michael Wright7b159c92015-05-14 14:48:03 +0100621 int32_t mActionButton;
Jeff Brown5912f952013-07-01 19:10:31 -0700622 int32_t mFlags;
623 int32_t mEdgeFlags;
624 int32_t mMetaState;
625 int32_t mButtonState;
626 float mXOffset;
627 float mYOffset;
628 float mXPrecision;
629 float mYPrecision;
630 nsecs_t mDownTime;
631 Vector<PointerProperties> mPointerProperties;
632 Vector<nsecs_t> mSampleEventTimes;
633 Vector<PointerCoords> mSamplePointerCoords;
634};
635
636/*
637 * Input event factory.
638 */
639class InputEventFactoryInterface {
640protected:
641 virtual ~InputEventFactoryInterface() { }
642
643public:
644 InputEventFactoryInterface() { }
645
646 virtual KeyEvent* createKeyEvent() = 0;
647 virtual MotionEvent* createMotionEvent() = 0;
648};
649
650/*
651 * A simple input event factory implementation that uses a single preallocated instance
652 * of each type of input event that are reused for each request.
653 */
654class PreallocatedInputEventFactory : public InputEventFactoryInterface {
655public:
656 PreallocatedInputEventFactory() { }
657 virtual ~PreallocatedInputEventFactory() { }
658
659 virtual KeyEvent* createKeyEvent() { return & mKeyEvent; }
660 virtual MotionEvent* createMotionEvent() { return & mMotionEvent; }
661
662private:
663 KeyEvent mKeyEvent;
664 MotionEvent mMotionEvent;
665};
666
667/*
668 * An input event factory implementation that maintains a pool of input events.
669 */
670class PooledInputEventFactory : public InputEventFactoryInterface {
671public:
672 PooledInputEventFactory(size_t maxPoolSize = 20);
673 virtual ~PooledInputEventFactory();
674
675 virtual KeyEvent* createKeyEvent();
676 virtual MotionEvent* createMotionEvent();
677
678 void recycle(InputEvent* event);
679
680private:
681 const size_t mMaxPoolSize;
682
683 Vector<KeyEvent*> mKeyEventPool;
684 Vector<MotionEvent*> mMotionEventPool;
685};
686
687} // namespace android
688
689#endif // _LIBINPUT_INPUT_H