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