Siarhei Vishniakou | f265212 | 2021-03-05 21:39:46 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
Asmita Poddar | dd9a6cd | 2023-09-26 15:35:12 +0000 | [diff] [blame] | 19 | #include "../InputDeviceMetricsSource.h" |
| 20 | |
Siarhei Vishniakou | f265212 | 2021-03-05 21:39:46 +0000 | [diff] [blame] | 21 | namespace android::inputdispatcher { |
| 22 | |
| 23 | ConnectionTimeline::ConnectionTimeline(nsecs_t deliveryTime, nsecs_t consumeTime, |
| 24 | nsecs_t finishTime) |
| 25 | : deliveryTime(deliveryTime), |
| 26 | consumeTime(consumeTime), |
| 27 | finishTime(finishTime), |
| 28 | mHasDispatchTimeline(true) {} |
| 29 | |
| 30 | ConnectionTimeline::ConnectionTimeline(std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline) |
| 31 | : graphicsTimeline(std::move(graphicsTimeline)), mHasGraphicsTimeline(true) {} |
| 32 | |
| 33 | bool ConnectionTimeline::isComplete() const { |
| 34 | return mHasDispatchTimeline && mHasGraphicsTimeline; |
| 35 | } |
| 36 | |
| 37 | bool ConnectionTimeline::setDispatchTimeline(nsecs_t inDeliveryTime, nsecs_t inConsumeTime, |
| 38 | nsecs_t inFinishTime) { |
| 39 | if (mHasDispatchTimeline) { |
| 40 | return false; |
| 41 | } |
| 42 | deliveryTime = inDeliveryTime; |
| 43 | consumeTime = inConsumeTime; |
| 44 | finishTime = inFinishTime; |
| 45 | mHasDispatchTimeline = true; |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | bool ConnectionTimeline::setGraphicsTimeline(std::array<nsecs_t, GraphicsTimeline::SIZE> timeline) { |
| 50 | if (mHasGraphicsTimeline) { |
| 51 | return false; |
| 52 | } |
| 53 | graphicsTimeline = std::move(timeline); |
| 54 | mHasGraphicsTimeline = true; |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | bool ConnectionTimeline::operator==(const ConnectionTimeline& rhs) const { |
| 59 | return deliveryTime == rhs.deliveryTime && consumeTime == rhs.consumeTime && |
| 60 | finishTime == rhs.finishTime && graphicsTimeline == rhs.graphicsTimeline && |
| 61 | mHasDispatchTimeline == rhs.mHasDispatchTimeline && |
| 62 | mHasGraphicsTimeline == rhs.mHasGraphicsTimeline; |
| 63 | } |
| 64 | |
| 65 | bool ConnectionTimeline::operator!=(const ConnectionTimeline& rhs) const { |
| 66 | return !operator==(rhs); |
| 67 | } |
| 68 | |
jioana | 97cc8ac | 2024-09-09 15:01:43 +0000 | [diff] [blame] | 69 | InputEventTimeline::InputEventTimeline(nsecs_t eventTime, nsecs_t readTime, uint16_t vendorId, |
| 70 | uint16_t productId, |
jioana | 0bdbea1 | 2024-08-10 19:26:04 +0000 | [diff] [blame] | 71 | const std::set<InputDeviceUsageSource>& sources, |
| 72 | InputEventActionType inputEventActionType) |
jioana | 97cc8ac | 2024-09-09 15:01:43 +0000 | [diff] [blame] | 73 | : eventTime(eventTime), |
Asmita Poddar | dd9a6cd | 2023-09-26 15:35:12 +0000 | [diff] [blame] | 74 | readTime(readTime), |
| 75 | vendorId(vendorId), |
| 76 | productId(productId), |
jioana | 0bdbea1 | 2024-08-10 19:26:04 +0000 | [diff] [blame] | 77 | sources(sources), |
| 78 | inputEventActionType(inputEventActionType) {} |
Siarhei Vishniakou | f265212 | 2021-03-05 21:39:46 +0000 | [diff] [blame] | 79 | |
| 80 | bool InputEventTimeline::operator==(const InputEventTimeline& rhs) const { |
| 81 | if (connectionTimelines.size() != rhs.connectionTimelines.size()) { |
| 82 | return false; |
| 83 | } |
| 84 | for (const auto& [connectionToken, connectionTimeline] : connectionTimelines) { |
| 85 | auto it = rhs.connectionTimelines.find(connectionToken); |
| 86 | if (it == rhs.connectionTimelines.end()) { |
| 87 | return false; |
| 88 | } |
| 89 | if (connectionTimeline != it->second) { |
| 90 | return false; |
| 91 | } |
| 92 | } |
jioana | 97cc8ac | 2024-09-09 15:01:43 +0000 | [diff] [blame] | 93 | return eventTime == rhs.eventTime && readTime == rhs.readTime && vendorId == rhs.vendorId && |
| 94 | productId == rhs.productId && sources == rhs.sources && |
jioana | 0bdbea1 | 2024-08-10 19:26:04 +0000 | [diff] [blame] | 95 | inputEventActionType == rhs.inputEventActionType; |
Siarhei Vishniakou | f265212 | 2021-03-05 21:39:46 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | } // namespace android::inputdispatcher |