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