diff options
Diffstat (limited to 'libs/androidfw/Input.cpp')
| -rw-r--r-- | libs/androidfw/Input.cpp | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/libs/androidfw/Input.cpp b/libs/androidfw/Input.cpp index ca09caf..2e4b26f 100644 --- a/libs/androidfw/Input.cpp +++ b/libs/androidfw/Input.cpp @@ -683,6 +683,58 @@ bool MotionEvent::isTouchEvent(int32_t source, int32_t action) { } +// --- PooledInputEventFactory --- + +PooledInputEventFactory::PooledInputEventFactory(size_t maxPoolSize) : + mMaxPoolSize(maxPoolSize) { +} + +PooledInputEventFactory::~PooledInputEventFactory() { + for (size_t i = 0; i < mKeyEventPool.size(); i++) { + delete mKeyEventPool.itemAt(i); + } + for (size_t i = 0; i < mMotionEventPool.size(); i++) { + delete mMotionEventPool.itemAt(i); + } +} + +KeyEvent* PooledInputEventFactory::createKeyEvent() { + if (!mKeyEventPool.isEmpty()) { + KeyEvent* event = mKeyEventPool.top(); + mKeyEventPool.pop(); + return event; + } + return new KeyEvent(); +} + +MotionEvent* PooledInputEventFactory::createMotionEvent() { + if (!mMotionEventPool.isEmpty()) { + MotionEvent* event = mMotionEventPool.top(); + mMotionEventPool.pop(); + return event; + } + return new MotionEvent(); +} + +void PooledInputEventFactory::recycle(InputEvent* event) { + switch (event->getType()) { + case AINPUT_EVENT_TYPE_KEY: + if (mKeyEventPool.size() < mMaxPoolSize) { + mKeyEventPool.push(static_cast<KeyEvent*>(event)); + return; + } + break; + case AINPUT_EVENT_TYPE_MOTION: + if (mMotionEventPool.size() < mMaxPoolSize) { + mMotionEventPool.push(static_cast<MotionEvent*>(event)); + return; + } + break; + } + delete event; +} + + // --- VelocityTracker --- const uint32_t VelocityTracker::DEFAULT_DEGREE; @@ -1174,21 +1226,24 @@ void VelocityControl::move(nsecs_t eventTime, float* deltaX, float* deltaY) { // --- InputDeviceInfo --- InputDeviceInfo::InputDeviceInfo() { - initialize(-1, String8("uninitialized device info")); + initialize(-1, String8("uninitialized device info"), String8("unknown")); } InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) : - mId(other.mId), mName(other.mName), mSources(other.mSources), + mId(other.mId), mName(other.mName), mDescriptor(other.mDescriptor), + mSources(other.mSources), mKeyboardType(other.mKeyboardType), + mKeyCharacterMapFile(other.mKeyCharacterMapFile), mMotionRanges(other.mMotionRanges) { } InputDeviceInfo::~InputDeviceInfo() { } -void InputDeviceInfo::initialize(int32_t id, const String8& name) { +void InputDeviceInfo::initialize(int32_t id, const String8& name, const String8& descriptor) { mId = id; mName = name; + mDescriptor = descriptor; mSources = 0; mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE; mMotionRanges.clear(); |
