• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define LOG_TAG "FrameTimelineInfo"
18 
19 #include <inttypes.h>
20 
21 #include <android/os/IInputConstants.h>
22 #include <gui/FrameTimelineInfo.h>
23 #include <gui/LayerState.h>
24 #include <private/gui/ParcelUtils.h>
25 #include <utils/Errors.h>
26 
27 #include <cmath>
28 
29 using android::os::IInputConstants;
30 
31 namespace android {
32 
write(Parcel & output) const33 status_t FrameTimelineInfo::write(Parcel& output) const {
34     SAFE_PARCEL(output.writeInt64, vsyncId);
35     SAFE_PARCEL(output.writeInt32, inputEventId);
36     SAFE_PARCEL(output.writeInt64, startTimeNanos);
37     return NO_ERROR;
38 }
39 
read(const Parcel & input)40 status_t FrameTimelineInfo::read(const Parcel& input) {
41     SAFE_PARCEL(input.readInt64, &vsyncId);
42     SAFE_PARCEL(input.readInt32, &inputEventId);
43     SAFE_PARCEL(input.readInt64, &startTimeNanos);
44     return NO_ERROR;
45 }
46 
merge(const FrameTimelineInfo & other)47 void FrameTimelineInfo::merge(const FrameTimelineInfo& other) {
48     // When merging vsync Ids we take the oldest valid one
49     if (vsyncId != INVALID_VSYNC_ID && other.vsyncId != INVALID_VSYNC_ID) {
50         if (other.vsyncId > vsyncId) {
51             vsyncId = other.vsyncId;
52             inputEventId = other.inputEventId;
53             startTimeNanos = other.startTimeNanos;
54         }
55     } else if (vsyncId == INVALID_VSYNC_ID) {
56         vsyncId = other.vsyncId;
57         inputEventId = other.inputEventId;
58         startTimeNanos = other.startTimeNanos;
59     }
60 }
61 
clear()62 void FrameTimelineInfo::clear() {
63     vsyncId = INVALID_VSYNC_ID;
64     inputEventId = IInputConstants::INVALID_INPUT_EVENT_ID;
65     startTimeNanos = 0;
66 }
67 
68 }; // namespace android
69