1 /*
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
24 namespace android::gui {
25
26 static_assert(VsyncEventData::kFrameTimelinesCapacity == 7,
27 "Must update value in DisplayEventReceiver.java#FRAME_TIMELINES_CAPACITY (and here)");
28
preferredVsyncId() const29 int64_t VsyncEventData::preferredVsyncId() const {
30 return frameTimelines[preferredFrameTimelineIndex].vsyncId;
31 }
32
preferredDeadlineTimestamp() const33 int64_t VsyncEventData::preferredDeadlineTimestamp() const {
34 return frameTimelines[preferredFrameTimelineIndex].deadlineTimestamp;
35 }
36
preferredExpectedPresentationTime() const37 int64_t VsyncEventData::preferredExpectedPresentationTime() const {
38 return frameTimelines[preferredFrameTimelineIndex].expectedPresentationTime;
39 }
40
readFromParcel(const Parcel * parcel)41 status_t ParcelableVsyncEventData::readFromParcel(const Parcel* parcel) {
42 if (parcel == nullptr) {
43 ALOGE("%s: Null parcel", __func__);
44 return BAD_VALUE;
45 }
46
47 SAFE_PARCEL(parcel->readInt64, &vsync.frameInterval);
48
49 uint32_t uintPreferredFrameTimelineIndex;
50 SAFE_PARCEL(parcel->readUint32, &uintPreferredFrameTimelineIndex);
51 vsync.preferredFrameTimelineIndex = static_cast<size_t>(uintPreferredFrameTimelineIndex);
52
53 uint32_t uintFrameTimelinesLength;
54 SAFE_PARCEL(parcel->readUint32, &uintFrameTimelinesLength);
55 vsync.frameTimelinesLength = static_cast<size_t>(uintFrameTimelinesLength);
56
57 for (size_t i = 0; i < vsync.frameTimelinesLength; i++) {
58 SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].vsyncId);
59 SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].deadlineTimestamp);
60 SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].expectedPresentationTime);
61 }
62
63 return OK;
64 }
writeToParcel(Parcel * parcel) const65 status_t ParcelableVsyncEventData::writeToParcel(Parcel* parcel) const {
66 SAFE_PARCEL(parcel->writeInt64, vsync.frameInterval);
67 SAFE_PARCEL(parcel->writeUint32, vsync.preferredFrameTimelineIndex);
68 SAFE_PARCEL(parcel->writeUint32, vsync.frameTimelinesLength);
69 for (size_t i = 0; i < vsync.frameTimelinesLength; i++) {
70 SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].vsyncId);
71 SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].deadlineTimestamp);
72 SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].expectedPresentationTime);
73 }
74
75 return OK;
76 }
77
78 }; // namespace android::gui
79