blob: 23f0921e99f261f9682decd2a81b020c28b81691 [file] [log] [blame]
Rachel Lee18c34372022-01-20 13:57:18 -08001/*
2 * Copyright (C) 2022 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 "gui/VsyncEventData.h"
18#include <gui/DisplayEventReceiver.h>
19#include <private/gui/ParcelUtils.h>
20#include <utils/Log.h>
21#include <utils/Looper.h>
22#include <cstdint>
23
24namespace android::gui {
25
Rachel Leeb9c5a772022-02-04 21:17:37 -080026int64_t VsyncEventData::preferredVsyncId() const {
27 return frameTimelines[preferredFrameTimelineIndex].vsyncId;
28}
29
30int64_t VsyncEventData::preferredDeadlineTimestamp() const {
31 return frameTimelines[preferredFrameTimelineIndex].deadlineTimestamp;
32}
33
34int64_t VsyncEventData::preferredExpectedPresentationTime() const {
35 return frameTimelines[preferredFrameTimelineIndex].expectedPresentationTime;
36}
37
38status_t ParcelableVsyncEventData::readFromParcel(const Parcel* parcel) {
Rachel Lee18c34372022-01-20 13:57:18 -080039 if (parcel == nullptr) {
40 ALOGE("%s: Null parcel", __func__);
41 return BAD_VALUE;
42 }
43
Rachel Leeb9c5a772022-02-04 21:17:37 -080044 SAFE_PARCEL(parcel->readInt64, &vsync.frameInterval);
Rachel Lee18c34372022-01-20 13:57:18 -080045
46 uint64_t uintPreferredFrameTimelineIndex;
47 SAFE_PARCEL(parcel->readUint64, &uintPreferredFrameTimelineIndex);
Rachel Leeb9c5a772022-02-04 21:17:37 -080048 vsync.preferredFrameTimelineIndex = static_cast<size_t>(uintPreferredFrameTimelineIndex);
Rachel Lee18c34372022-01-20 13:57:18 -080049
Rachel Leeb9c5a772022-02-04 21:17:37 -080050 for (int i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) {
51 SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].vsyncId);
52 SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].deadlineTimestamp);
53 SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].expectedPresentationTime);
Rachel Lee18c34372022-01-20 13:57:18 -080054 }
55
Rachel Lee18c34372022-01-20 13:57:18 -080056 return OK;
57}
Rachel Leeb9c5a772022-02-04 21:17:37 -080058status_t ParcelableVsyncEventData::writeToParcel(Parcel* parcel) const {
59 SAFE_PARCEL(parcel->writeInt64, vsync.frameInterval);
60 SAFE_PARCEL(parcel->writeUint64, vsync.preferredFrameTimelineIndex);
61 for (int i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) {
62 SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].vsyncId);
63 SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].deadlineTimestamp);
64 SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].expectedPresentationTime);
65 }
Rachel Lee18c34372022-01-20 13:57:18 -080066
67 return OK;
68}
69
70}; // namespace android::gui