blob: 76c60c23c4a92abe217f01404b0ec872e5ce44b1 [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 Lee08847112023-02-16 11:07:48 -080026static_assert(VsyncEventData::kFrameTimelinesLength == 7,
27 "Must update value in DisplayEventReceiver.java#FRAME_TIMELINES_LENGTH (and here)");
28
Rachel Leeb9c5a772022-02-04 21:17:37 -080029int64_t VsyncEventData::preferredVsyncId() const {
30 return frameTimelines[preferredFrameTimelineIndex].vsyncId;
31}
32
33int64_t VsyncEventData::preferredDeadlineTimestamp() const {
34 return frameTimelines[preferredFrameTimelineIndex].deadlineTimestamp;
35}
36
37int64_t VsyncEventData::preferredExpectedPresentationTime() const {
38 return frameTimelines[preferredFrameTimelineIndex].expectedPresentationTime;
39}
40
41status_t ParcelableVsyncEventData::readFromParcel(const Parcel* parcel) {
Rachel Lee18c34372022-01-20 13:57:18 -080042 if (parcel == nullptr) {
43 ALOGE("%s: Null parcel", __func__);
44 return BAD_VALUE;
45 }
46
Rachel Leeb9c5a772022-02-04 21:17:37 -080047 SAFE_PARCEL(parcel->readInt64, &vsync.frameInterval);
Rachel Lee18c34372022-01-20 13:57:18 -080048
49 uint64_t uintPreferredFrameTimelineIndex;
50 SAFE_PARCEL(parcel->readUint64, &uintPreferredFrameTimelineIndex);
Rachel Leeb9c5a772022-02-04 21:17:37 -080051 vsync.preferredFrameTimelineIndex = static_cast<size_t>(uintPreferredFrameTimelineIndex);
Rachel Lee18c34372022-01-20 13:57:18 -080052
Rachel Leeb9c5a772022-02-04 21:17:37 -080053 for (int i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) {
54 SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].vsyncId);
55 SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].deadlineTimestamp);
56 SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].expectedPresentationTime);
Rachel Lee18c34372022-01-20 13:57:18 -080057 }
58
Rachel Lee18c34372022-01-20 13:57:18 -080059 return OK;
60}
Rachel Leeb9c5a772022-02-04 21:17:37 -080061status_t ParcelableVsyncEventData::writeToParcel(Parcel* parcel) const {
62 SAFE_PARCEL(parcel->writeInt64, vsync.frameInterval);
63 SAFE_PARCEL(parcel->writeUint64, vsync.preferredFrameTimelineIndex);
64 for (int i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) {
65 SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].vsyncId);
66 SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].deadlineTimestamp);
67 SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].expectedPresentationTime);
68 }
Rachel Lee18c34372022-01-20 13:57:18 -080069
70 return OK;
71}
72
73}; // namespace android::gui