1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2021 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker *
4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker *
8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker *
10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker */
16*38e8c45fSAndroid Build Coastguard Worker
17*38e8c45fSAndroid Build Coastguard Worker #include "InputEventTimeline.h"
18*38e8c45fSAndroid Build Coastguard Worker
19*38e8c45fSAndroid Build Coastguard Worker #include "../InputDeviceMetricsSource.h"
20*38e8c45fSAndroid Build Coastguard Worker
21*38e8c45fSAndroid Build Coastguard Worker namespace android::inputdispatcher {
22*38e8c45fSAndroid Build Coastguard Worker
ConnectionTimeline(nsecs_t deliveryTime,nsecs_t consumeTime,nsecs_t finishTime)23*38e8c45fSAndroid Build Coastguard Worker ConnectionTimeline::ConnectionTimeline(nsecs_t deliveryTime, nsecs_t consumeTime,
24*38e8c45fSAndroid Build Coastguard Worker nsecs_t finishTime)
25*38e8c45fSAndroid Build Coastguard Worker : deliveryTime(deliveryTime),
26*38e8c45fSAndroid Build Coastguard Worker consumeTime(consumeTime),
27*38e8c45fSAndroid Build Coastguard Worker finishTime(finishTime),
28*38e8c45fSAndroid Build Coastguard Worker mHasDispatchTimeline(true) {}
29*38e8c45fSAndroid Build Coastguard Worker
ConnectionTimeline(std::array<nsecs_t,GraphicsTimeline::SIZE> graphicsTimeline)30*38e8c45fSAndroid Build Coastguard Worker ConnectionTimeline::ConnectionTimeline(std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline)
31*38e8c45fSAndroid Build Coastguard Worker : graphicsTimeline(std::move(graphicsTimeline)), mHasGraphicsTimeline(true) {}
32*38e8c45fSAndroid Build Coastguard Worker
isComplete() const33*38e8c45fSAndroid Build Coastguard Worker bool ConnectionTimeline::isComplete() const {
34*38e8c45fSAndroid Build Coastguard Worker return mHasDispatchTimeline && mHasGraphicsTimeline;
35*38e8c45fSAndroid Build Coastguard Worker }
36*38e8c45fSAndroid Build Coastguard Worker
setDispatchTimeline(nsecs_t inDeliveryTime,nsecs_t inConsumeTime,nsecs_t inFinishTime)37*38e8c45fSAndroid Build Coastguard Worker bool ConnectionTimeline::setDispatchTimeline(nsecs_t inDeliveryTime, nsecs_t inConsumeTime,
38*38e8c45fSAndroid Build Coastguard Worker nsecs_t inFinishTime) {
39*38e8c45fSAndroid Build Coastguard Worker if (mHasDispatchTimeline) {
40*38e8c45fSAndroid Build Coastguard Worker return false;
41*38e8c45fSAndroid Build Coastguard Worker }
42*38e8c45fSAndroid Build Coastguard Worker deliveryTime = inDeliveryTime;
43*38e8c45fSAndroid Build Coastguard Worker consumeTime = inConsumeTime;
44*38e8c45fSAndroid Build Coastguard Worker finishTime = inFinishTime;
45*38e8c45fSAndroid Build Coastguard Worker mHasDispatchTimeline = true;
46*38e8c45fSAndroid Build Coastguard Worker return true;
47*38e8c45fSAndroid Build Coastguard Worker }
48*38e8c45fSAndroid Build Coastguard Worker
setGraphicsTimeline(std::array<nsecs_t,GraphicsTimeline::SIZE> timeline)49*38e8c45fSAndroid Build Coastguard Worker bool ConnectionTimeline::setGraphicsTimeline(std::array<nsecs_t, GraphicsTimeline::SIZE> timeline) {
50*38e8c45fSAndroid Build Coastguard Worker if (mHasGraphicsTimeline) {
51*38e8c45fSAndroid Build Coastguard Worker return false;
52*38e8c45fSAndroid Build Coastguard Worker }
53*38e8c45fSAndroid Build Coastguard Worker graphicsTimeline = std::move(timeline);
54*38e8c45fSAndroid Build Coastguard Worker mHasGraphicsTimeline = true;
55*38e8c45fSAndroid Build Coastguard Worker return true;
56*38e8c45fSAndroid Build Coastguard Worker }
57*38e8c45fSAndroid Build Coastguard Worker
operator ==(const ConnectionTimeline & rhs) const58*38e8c45fSAndroid Build Coastguard Worker bool ConnectionTimeline::operator==(const ConnectionTimeline& rhs) const {
59*38e8c45fSAndroid Build Coastguard Worker return deliveryTime == rhs.deliveryTime && consumeTime == rhs.consumeTime &&
60*38e8c45fSAndroid Build Coastguard Worker finishTime == rhs.finishTime && graphicsTimeline == rhs.graphicsTimeline &&
61*38e8c45fSAndroid Build Coastguard Worker mHasDispatchTimeline == rhs.mHasDispatchTimeline &&
62*38e8c45fSAndroid Build Coastguard Worker mHasGraphicsTimeline == rhs.mHasGraphicsTimeline;
63*38e8c45fSAndroid Build Coastguard Worker }
64*38e8c45fSAndroid Build Coastguard Worker
operator !=(const ConnectionTimeline & rhs) const65*38e8c45fSAndroid Build Coastguard Worker bool ConnectionTimeline::operator!=(const ConnectionTimeline& rhs) const {
66*38e8c45fSAndroid Build Coastguard Worker return !operator==(rhs);
67*38e8c45fSAndroid Build Coastguard Worker }
68*38e8c45fSAndroid Build Coastguard Worker
InputEventTimeline(nsecs_t eventTime,nsecs_t readTime,uint16_t vendorId,uint16_t productId,const std::set<InputDeviceUsageSource> & sources,InputEventActionType inputEventActionType)69*38e8c45fSAndroid Build Coastguard Worker InputEventTimeline::InputEventTimeline(nsecs_t eventTime, nsecs_t readTime, uint16_t vendorId,
70*38e8c45fSAndroid Build Coastguard Worker uint16_t productId,
71*38e8c45fSAndroid Build Coastguard Worker const std::set<InputDeviceUsageSource>& sources,
72*38e8c45fSAndroid Build Coastguard Worker InputEventActionType inputEventActionType)
73*38e8c45fSAndroid Build Coastguard Worker : eventTime(eventTime),
74*38e8c45fSAndroid Build Coastguard Worker readTime(readTime),
75*38e8c45fSAndroid Build Coastguard Worker vendorId(vendorId),
76*38e8c45fSAndroid Build Coastguard Worker productId(productId),
77*38e8c45fSAndroid Build Coastguard Worker sources(sources),
78*38e8c45fSAndroid Build Coastguard Worker inputEventActionType(inputEventActionType) {}
79*38e8c45fSAndroid Build Coastguard Worker
operator ==(const InputEventTimeline & rhs) const80*38e8c45fSAndroid Build Coastguard Worker bool InputEventTimeline::operator==(const InputEventTimeline& rhs) const {
81*38e8c45fSAndroid Build Coastguard Worker if (connectionTimelines.size() != rhs.connectionTimelines.size()) {
82*38e8c45fSAndroid Build Coastguard Worker return false;
83*38e8c45fSAndroid Build Coastguard Worker }
84*38e8c45fSAndroid Build Coastguard Worker for (const auto& [connectionToken, connectionTimeline] : connectionTimelines) {
85*38e8c45fSAndroid Build Coastguard Worker auto it = rhs.connectionTimelines.find(connectionToken);
86*38e8c45fSAndroid Build Coastguard Worker if (it == rhs.connectionTimelines.end()) {
87*38e8c45fSAndroid Build Coastguard Worker return false;
88*38e8c45fSAndroid Build Coastguard Worker }
89*38e8c45fSAndroid Build Coastguard Worker if (connectionTimeline != it->second) {
90*38e8c45fSAndroid Build Coastguard Worker return false;
91*38e8c45fSAndroid Build Coastguard Worker }
92*38e8c45fSAndroid Build Coastguard Worker }
93*38e8c45fSAndroid Build Coastguard Worker return eventTime == rhs.eventTime && readTime == rhs.readTime && vendorId == rhs.vendorId &&
94*38e8c45fSAndroid Build Coastguard Worker productId == rhs.productId && sources == rhs.sources &&
95*38e8c45fSAndroid Build Coastguard Worker inputEventActionType == rhs.inputEventActionType;
96*38e8c45fSAndroid Build Coastguard Worker }
97*38e8c45fSAndroid Build Coastguard Worker
98*38e8c45fSAndroid Build Coastguard Worker } // namespace android::inputdispatcher
99