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