diff options
| author | 2012-03-13 15:15:48 -0700 | |
|---|---|---|
| committer | 2012-03-13 15:15:48 -0700 | |
| commit | 9dc348d75688faba645c03ecd6e72de7cecc87ba (patch) | |
| tree | 5bf27444139c7889bcb966823c54c7da296410a2 /libs/androidfw/Input.cpp | |
| parent | f2fbd2eda54cc6083d302ab00367af3db2b7e793 (diff) | |
| parent | 2b6c32ca4177f1a97307f9cbd81ca485df28762c (diff) | |
Merge "Fix spurious ANRs in native activities."
Diffstat (limited to 'libs/androidfw/Input.cpp')
| -rw-r--r-- | libs/androidfw/Input.cpp | 52 | 
1 files changed, 52 insertions, 0 deletions
diff --git a/libs/androidfw/Input.cpp b/libs/androidfw/Input.cpp index ca09caf6a255..da578395500e 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;  |