diff options
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/input/InputTransport.cpp | 75 | ||||
| -rw-r--r-- | libs/input/tests/InputPublisherAndConsumer_test.cpp | 96 | ||||
| -rw-r--r-- | libs/input/tests/StructLayout_test.cpp | 7 |
3 files changed, 132 insertions, 46 deletions
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index c2a3cf1816..f7962e0f09 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -110,6 +110,12 @@ bool InputMessage::isValid(size_t actualSize) const { return true; case Type::DRAG: return true; + case Type::TIMELINE: + const nsecs_t gpuCompletedTime = + body.timeline.graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME]; + const nsecs_t presentTime = + body.timeline.graphicsTimeline[GraphicsTimeline::PRESENT_TIME]; + return presentTime > gpuCompletedTime; } } return false; @@ -129,6 +135,8 @@ size_t InputMessage::size() const { return sizeof(Header) + body.capture.size(); case Type::DRAG: return sizeof(Header) + body.drag.size(); + case Type::TIMELINE: + return sizeof(Header) + body.timeline.size(); } return sizeof(Header); } @@ -260,6 +268,11 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { msg->body.drag.isExiting = body.drag.isExiting; break; } + case InputMessage::Type::TIMELINE: { + msg->body.timeline.eventId = body.timeline.eventId; + msg->body.timeline.graphicsTimeline = body.timeline.graphicsTimeline; + break; + } } } @@ -629,7 +642,7 @@ status_t InputPublisher::publishDragEvent(uint32_t seq, int32_t eventId, float x return mChannel->sendMessage(&msg); } -android::base::Result<InputPublisher::Finished> InputPublisher::receiveFinishedSignal() { +android::base::Result<InputPublisher::ConsumerResponse> InputPublisher::receiveConsumerResponse() { if (DEBUG_TRANSPORT_ACTIONS) { ALOGD("channel '%s' publisher ~ %s", mChannel->getName().c_str(), __func__); } @@ -639,16 +652,24 @@ android::base::Result<InputPublisher::Finished> InputPublisher::receiveFinishedS if (result) { return android::base::Error(result); } - if (msg.header.type != InputMessage::Type::FINISHED) { - ALOGE("channel '%s' publisher ~ Received unexpected %s message from consumer", - mChannel->getName().c_str(), NamedEnum::string(msg.header.type).c_str()); - return android::base::Error(UNKNOWN_ERROR); + if (msg.header.type == InputMessage::Type::FINISHED) { + return Finished{ + .seq = msg.header.seq, + .handled = msg.body.finished.handled, + .consumeTime = msg.body.finished.consumeTime, + }; + } + + if (msg.header.type == InputMessage::Type::TIMELINE) { + return Timeline{ + .inputEventId = msg.body.timeline.eventId, + .graphicsTimeline = msg.body.timeline.graphicsTimeline, + }; } - return Finished{ - .seq = msg.header.seq, - .handled = msg.body.finished.handled, - .consumeTime = msg.body.finished.consumeTime, - }; + + ALOGE("channel '%s' publisher ~ Received unexpected %s message from consumer", + mChannel->getName().c_str(), NamedEnum::string(msg.header.type).c_str()); + return android::base::Error(UNKNOWN_ERROR); } // --- InputConsumer --- @@ -785,7 +806,8 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consum break; } - case InputMessage::Type::FINISHED: { + case InputMessage::Type::FINISHED: + case InputMessage::Type::TIMELINE: { LOG_ALWAYS_FATAL("Consumed a %s message, which should never be seen by " "InputConsumer!", NamedEnum::string(mMsg.header.type).c_str()); @@ -1193,6 +1215,24 @@ status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) { return sendUnchainedFinishedSignal(seq, handled); } +status_t InputConsumer::sendTimeline(int32_t inputEventId, + std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline) { + if (DEBUG_TRANSPORT_ACTIONS) { + ALOGD("channel '%s' consumer ~ sendTimeline: inputEventId=%" PRId32 + ", gpuCompletedTime=%" PRId64 ", presentTime=%" PRId64, + mChannel->getName().c_str(), inputEventId, + graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME], + graphicsTimeline[GraphicsTimeline::PRESENT_TIME]); + } + + InputMessage msg; + msg.header.type = InputMessage::Type::TIMELINE; + msg.header.seq = 0; + msg.body.timeline.eventId = inputEventId; + msg.body.timeline.graphicsTimeline = std::move(graphicsTimeline); + return mChannel->sendMessage(&msg); +} + nsecs_t InputConsumer::getConsumeTime(uint32_t seq) const { auto it = mConsumeTimes.find(seq); // Consume time will be missing if either 'finishInputEvent' is called twice, or if it was @@ -1399,6 +1439,19 @@ std::string InputConsumer::dump() const { toString(msg.body.drag.isExiting)); break; } + case InputMessage::Type::TIMELINE: { + const nsecs_t gpuCompletedTime = + msg.body.timeline + .graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME]; + const nsecs_t presentTime = + msg.body.timeline.graphicsTimeline[GraphicsTimeline::PRESENT_TIME]; + out += android::base::StringPrintf("inputEventId=%" PRId32 + ", gpuCompletedTime=%" PRId64 + ", presentTime=%" PRId64, + msg.body.timeline.eventId, gpuCompletedTime, + presentTime); + break; + } } out += "\n"; } diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp index fc31715668..088e00b59c 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -124,13 +124,15 @@ void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() { ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK"; - Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal(); - ASSERT_TRUE(result.ok()) << "publisher receiveFinishedSignal should return OK"; - ASSERT_EQ(seq, result->seq) - << "receiveFinishedSignal should have returned the original sequence number"; - ASSERT_TRUE(result->handled) - << "receiveFinishedSignal should have set handled to consumer's reply"; - ASSERT_GE(result->consumeTime, publishTime) + Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse(); + ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK"; + ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result)); + const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result); + ASSERT_EQ(seq, finish.seq) + << "receiveConsumerResponse should have returned the original sequence number"; + ASSERT_TRUE(finish.handled) + << "receiveConsumerResponse should have set handled to consumer's reply"; + ASSERT_GE(finish.consumeTime, publishTime) << "finished signal's consume time should be greater than publish time"; } @@ -264,13 +266,15 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK"; - Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal(); - ASSERT_TRUE(result.ok()) << "receiveFinishedSignal should return OK"; - ASSERT_EQ(seq, result->seq) - << "receiveFinishedSignal should have returned the original sequence number"; - ASSERT_FALSE(result->handled) - << "receiveFinishedSignal should have set handled to consumer's reply"; - ASSERT_GE(result->consumeTime, publishTime) + Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse(); + ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK"; + ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result)); + const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result); + ASSERT_EQ(seq, finish.seq) + << "receiveConsumerResponse should have returned the original sequence number"; + ASSERT_FALSE(finish.handled) + << "receiveConsumerResponse should have set handled to consumer's reply"; + ASSERT_GE(finish.consumeTime, publishTime) << "finished signal's consume time should be greater than publish time"; } @@ -304,14 +308,16 @@ void InputPublisherAndConsumerTest::PublishAndConsumeFocusEvent() { status = mConsumer->sendFinishedSignal(seq, true); ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK"; - Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal(); + Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse(); + ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK"; + ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result)); + const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result); - ASSERT_TRUE(result.ok()) << "receiveFinishedSignal should return OK"; - ASSERT_EQ(seq, result->seq) - << "receiveFinishedSignal should have returned the original sequence number"; - ASSERT_TRUE(result->handled) - << "receiveFinishedSignal should have set handled to consumer's reply"; - ASSERT_GE(result->consumeTime, publishTime) + ASSERT_EQ(seq, finish.seq) + << "receiveConsumerResponse should have returned the original sequence number"; + ASSERT_TRUE(finish.handled) + << "receiveConsumerResponse should have set handled to consumer's reply"; + ASSERT_GE(finish.consumeTime, publishTime) << "finished signal's consume time should be greater than publish time"; } @@ -343,13 +349,15 @@ void InputPublisherAndConsumerTest::PublishAndConsumeCaptureEvent() { status = mConsumer->sendFinishedSignal(seq, true); ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK"; - android::base::Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal(); - ASSERT_TRUE(result.ok()) << "publisher receiveFinishedSignal should return OK"; - ASSERT_EQ(seq, result->seq) - << "receiveFinishedSignal should have returned the original sequence number"; - ASSERT_TRUE(result->handled) - << "receiveFinishedSignal should have set handled to consumer's reply"; - ASSERT_GE(result->consumeTime, publishTime) + Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse(); + ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK"; + ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result)); + const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result); + ASSERT_EQ(seq, finish.seq) + << "receiveConsumerResponse should have returned the original sequence number"; + ASSERT_TRUE(finish.handled) + << "receiveConsumerResponse should have set handled to consumer's reply"; + ASSERT_GE(finish.consumeTime, publishTime) << "finished signal's consume time should be greater than publish time"; } @@ -385,16 +393,34 @@ void InputPublisherAndConsumerTest::PublishAndConsumeDragEvent() { status = mConsumer->sendFinishedSignal(seq, true); ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK"; - android::base::Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal(); - ASSERT_TRUE(result.ok()) << "publisher receiveFinishedSignal should return OK"; - ASSERT_EQ(seq, result->seq) - << "publisher receiveFinishedSignal should have returned the original sequence number"; - ASSERT_TRUE(result->handled) - << "publisher receiveFinishedSignal should have set handled to consumer's reply"; - ASSERT_GE(result->consumeTime, publishTime) + Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse(); + ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK"; + ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result)); + const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result); + ASSERT_EQ(seq, finish.seq) + << "receiveConsumerResponse should have returned the original sequence number"; + ASSERT_TRUE(finish.handled) + << "receiveConsumerResponse should have set handled to consumer's reply"; + ASSERT_GE(finish.consumeTime, publishTime) << "finished signal's consume time should be greater than publish time"; } +TEST_F(InputPublisherAndConsumerTest, SendTimeline) { + const int32_t inputEventId = 20; + std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline; + graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 30; + graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 40; + status_t status = mConsumer->sendTimeline(inputEventId, graphicsTimeline); + ASSERT_EQ(OK, status); + + Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse(); + ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK"; + ASSERT_TRUE(std::holds_alternative<InputPublisher::Timeline>(*result)); + const InputPublisher::Timeline& timeline = std::get<InputPublisher::Timeline>(*result); + ASSERT_EQ(inputEventId, timeline.inputEventId); + ASSERT_EQ(graphicsTimeline, timeline.graphicsTimeline); +} + TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) { ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent()); } diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp index 3d80b38636..585779e472 100644 --- a/libs/input/tests/StructLayout_test.cpp +++ b/libs/input/tests/StructLayout_test.cpp @@ -96,6 +96,10 @@ void TestInputMessageAlignment() { CHECK_OFFSET(InputMessage::Body::Finished, handled, 0); CHECK_OFFSET(InputMessage::Body::Finished, empty, 1); CHECK_OFFSET(InputMessage::Body::Finished, consumeTime, 8); + + CHECK_OFFSET(InputMessage::Body::Timeline, eventId, 0); + CHECK_OFFSET(InputMessage::Body::Timeline, empty, 4); + CHECK_OFFSET(InputMessage::Body::Timeline, graphicsTimeline, 8); } void TestHeaderSize() { @@ -117,6 +121,9 @@ void TestBodySize() { static_assert(sizeof(InputMessage::Body::Focus) == 8); static_assert(sizeof(InputMessage::Body::Capture) == 8); static_assert(sizeof(InputMessage::Body::Drag) == 16); + // Timeline + static_assert(GraphicsTimeline::SIZE == 2); + static_assert(sizeof(InputMessage::Body::Timeline) == 24); } // --- VerifiedInputEvent --- |