blob: 3800b88ab0ddbff709a7f937bb1d288e6f78be77 [file] [log] [blame]
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -10001/*
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>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010024#include <private/gui/ParcelUtils.h>
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100025#include <utils/Errors.h>
26
27#include <cmath>
28
29using android::os::IInputConstants;
30
31namespace android {
32
33status_t FrameTimelineInfo::write(Parcel& output) const {
34 SAFE_PARCEL(output.writeInt64, vsyncId);
35 SAFE_PARCEL(output.writeInt32, inputEventId);
Rachel Leeed511ef2021-10-11 15:09:51 -070036 SAFE_PARCEL(output.writeInt64, startTimeNanos);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100037 return NO_ERROR;
38}
39
40status_t FrameTimelineInfo::read(const Parcel& input) {
41 SAFE_PARCEL(input.readInt64, &vsyncId);
42 SAFE_PARCEL(input.readInt32, &inputEventId);
Rachel Leeed511ef2021-10-11 15:09:51 -070043 SAFE_PARCEL(input.readInt64, &startTimeNanos);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100044 return NO_ERROR;
45}
46
47void 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;
Rachel Leeed511ef2021-10-11 15:09:51 -070053 startTimeNanos = other.startTimeNanos;
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100054 }
55 } else if (vsyncId == INVALID_VSYNC_ID) {
56 vsyncId = other.vsyncId;
57 inputEventId = other.inputEventId;
Rachel Leeed511ef2021-10-11 15:09:51 -070058 startTimeNanos = other.startTimeNanos;
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100059 }
60}
61
62void FrameTimelineInfo::clear() {
63 vsyncId = INVALID_VSYNC_ID;
64 inputEventId = IInputConstants::INVALID_INPUT_EVENT_ID;
Rachel Leeed511ef2021-10-11 15:09:51 -070065 startTimeNanos = 0;
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100066}
67
68}; // namespace android