blob: 3edb6381d4d9833d6f89cd730bcc3facbf5e5bc7 [file] [log] [blame]
Siarhei Vishniakouf2652122021-03-05 21:39:46 +00001/*
2 * Copyright (C) 2021 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#include "InputEventTimeline.h"
18
19namespace android::inputdispatcher {
20
21ConnectionTimeline::ConnectionTimeline(nsecs_t deliveryTime, nsecs_t consumeTime,
22 nsecs_t finishTime)
23 : deliveryTime(deliveryTime),
24 consumeTime(consumeTime),
25 finishTime(finishTime),
26 mHasDispatchTimeline(true) {}
27
28ConnectionTimeline::ConnectionTimeline(std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline)
29 : graphicsTimeline(std::move(graphicsTimeline)), mHasGraphicsTimeline(true) {}
30
31bool ConnectionTimeline::isComplete() const {
32 return mHasDispatchTimeline && mHasGraphicsTimeline;
33}
34
35bool ConnectionTimeline::setDispatchTimeline(nsecs_t inDeliveryTime, nsecs_t inConsumeTime,
36 nsecs_t inFinishTime) {
37 if (mHasDispatchTimeline) {
38 return false;
39 }
40 deliveryTime = inDeliveryTime;
41 consumeTime = inConsumeTime;
42 finishTime = inFinishTime;
43 mHasDispatchTimeline = true;
44 return true;
45}
46
47bool ConnectionTimeline::setGraphicsTimeline(std::array<nsecs_t, GraphicsTimeline::SIZE> timeline) {
48 if (mHasGraphicsTimeline) {
49 return false;
50 }
51 graphicsTimeline = std::move(timeline);
52 mHasGraphicsTimeline = true;
53 return true;
54}
55
56bool ConnectionTimeline::operator==(const ConnectionTimeline& rhs) const {
57 return deliveryTime == rhs.deliveryTime && consumeTime == rhs.consumeTime &&
58 finishTime == rhs.finishTime && graphicsTimeline == rhs.graphicsTimeline &&
59 mHasDispatchTimeline == rhs.mHasDispatchTimeline &&
60 mHasGraphicsTimeline == rhs.mHasGraphicsTimeline;
61}
62
63bool ConnectionTimeline::operator!=(const ConnectionTimeline& rhs) const {
64 return !operator==(rhs);
65}
66
67InputEventTimeline::InputEventTimeline(bool isDown, nsecs_t eventTime, nsecs_t readTime)
68 : isDown(isDown), eventTime(eventTime), readTime(readTime) {}
69
70bool InputEventTimeline::operator==(const InputEventTimeline& rhs) const {
71 if (connectionTimelines.size() != rhs.connectionTimelines.size()) {
72 return false;
73 }
74 for (const auto& [connectionToken, connectionTimeline] : connectionTimelines) {
75 auto it = rhs.connectionTimelines.find(connectionToken);
76 if (it == rhs.connectionTimelines.end()) {
77 return false;
78 }
79 if (connectionTimeline != it->second) {
80 return false;
81 }
82 }
83 return isDown == rhs.isDown && eventTime == rhs.eventTime && readTime == rhs.readTime;
84}
85
86} // namespace android::inputdispatcher