Created
July 5, 2014 00:07
-
-
Save omo/b2b0a5d4d680bf5ad39f to your computer and use it in GitHub Desktop.
status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consumeBatches, nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
status_t InputConsumer::consume(InputEventFactoryInterface* factory, | |
bool consumeBatches, nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent) { | |
... | |
*outSeq = 0; | |
*outEvent = NULL; | |
// Fetch the next input message. | |
// Loop until an event can be returned or no additional events are received. | |
while (!*outEvent) { | |
if (mMsgDeferred) { | |
... | |
} else { | |
// Receive a fresh message. | |
status_t result = mChannel->receiveMessage(&mMsg); | |
if (result) { | |
// Consume the next batched event unless batches are being held for later. | |
if (consumeBatches || result != WOULD_BLOCK) { | |
result = consumeBatch(factory, frameTime, outSeq, outEvent); | |
if (*outEvent) { | |
... | |
break; | |
} | |
} | |
return result; | |
} | |
} | |
switch (mMsg.header.type) { | |
case InputMessage::TYPE_KEY: { | |
KeyEvent* keyEvent = factory->createKeyEvent(); | |
... | |
*outSeq = mMsg.body.key.seq; | |
*outEvent = keyEvent; | |
... | |
break; | |
} | |
case AINPUT_EVENT_TYPE_MOTION: { | |
ssize_t batchIndex = findBatch(mMsg.body.motion.deviceId, mMsg.body.motion.source); | |
if (batchIndex >= 0) { | |
Batch& batch = mBatches.editItemAt(batchIndex); | |
if (canAddSample(batch, &mMsg)) { | |
batch.samples.push(mMsg); | |
... | |
break; | |
} else { | |
// We cannot append to the batch in progress, so we need to consume | |
// the previous batch right now and defer the new message until later. | |
mMsgDeferred = true; | |
status_t result = consumeSamples(factory, | |
batch, batch.samples.size(), outSeq, outEvent); | |
mBatches.removeAt(batchIndex); | |
... | |
break; | |
} | |
} | |
// Start a new batch if needed. | |
if (mMsg.body.motion.action == AMOTION_EVENT_ACTION_MOVE | |
|| mMsg.body.motion.action == AMOTION_EVENT_ACTION_HOVER_MOVE) { | |
mBatches.push(); | |
Batch& batch = mBatches.editTop(); | |
batch.samples.push(mMsg); | |
... | |
break; | |
} | |
MotionEvent* motionEvent = factory->createMotionEvent(); | |
if (! motionEvent) return NO_MEMORY; | |
updateTouchState(&mMsg); | |
initializeMotionEvent(motionEvent, &mMsg); | |
*outSeq = mMsg.body.motion.seq; | |
*outEvent = motionEvent; | |
... | |
break; | |
} | |
default: | |
... | |
return UNKNOWN_ERROR; | |
} | |
} | |
return OK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment