blob: 8e00c2fe325a5d4b6ceaccc96af25f177ab5b001 [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 Lee40aef422023-04-25 14:35:47 -070026static_assert(VsyncEventData::kFrameTimelinesCapacity == 7,
27 "Must update value in DisplayEventReceiver.java#FRAME_TIMELINES_CAPACITY (and here)");
Rachel Lee08847112023-02-16 11:07:48 -080028
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
Rachel Lee0655a912023-04-20 19:54:18 -070049 uint32_t uintPreferredFrameTimelineIndex;
50 SAFE_PARCEL(parcel->readUint32, &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 Lee0655a912023-04-20 19:54:18 -070053 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++) {
Rachel Leeb9c5a772022-02-04 21:17:37 -080058 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);
Rachel Lee18c34372022-01-20 13:57:18 -080061 }
62
Rachel Lee18c34372022-01-20 13:57:18 -080063 return OK;
64}
Rachel Leeb9c5a772022-02-04 21:17:37 -080065status_t ParcelableVsyncEventData::writeToParcel(Parcel* parcel) const {
66 SAFE_PARCEL(parcel->writeInt64, vsync.frameInterval);
Rachel Lee0655a912023-04-20 19:54:18 -070067 SAFE_PARCEL(parcel->writeUint32, vsync.preferredFrameTimelineIndex);
68 SAFE_PARCEL(parcel->writeUint32, vsync.frameTimelinesLength);
69 for (size_t i = 0; i < vsync.frameTimelinesLength; i++) {
Rachel Leeb9c5a772022-02-04 21:17:37 -080070 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 }
Rachel Lee18c34372022-01-20 13:57:18 -080074
75 return OK;
76}
77
78}; // namespace android::gui