Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 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 | |
Rachel Lee | 0884711 | 2023-02-16 11:07:48 -0800 | [diff] [blame] | 26 | static_assert(VsyncEventData::kFrameTimelinesLength == 7, |
| 27 | "Must update value in DisplayEventReceiver.java#FRAME_TIMELINES_LENGTH (and here)"); |
| 28 | |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 29 | int64_t VsyncEventData::preferredVsyncId() const { |
| 30 | return frameTimelines[preferredFrameTimelineIndex].vsyncId; |
| 31 | } |
| 32 | |
| 33 | int64_t VsyncEventData::preferredDeadlineTimestamp() const { |
| 34 | return frameTimelines[preferredFrameTimelineIndex].deadlineTimestamp; |
| 35 | } |
| 36 | |
| 37 | int64_t VsyncEventData::preferredExpectedPresentationTime() const { |
| 38 | return frameTimelines[preferredFrameTimelineIndex].expectedPresentationTime; |
| 39 | } |
| 40 | |
| 41 | status_t ParcelableVsyncEventData::readFromParcel(const Parcel* parcel) { |
Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 42 | if (parcel == nullptr) { |
| 43 | ALOGE("%s: Null parcel", __func__); |
| 44 | return BAD_VALUE; |
| 45 | } |
| 46 | |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 47 | SAFE_PARCEL(parcel->readInt64, &vsync.frameInterval); |
Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 48 | |
| 49 | uint64_t uintPreferredFrameTimelineIndex; |
| 50 | SAFE_PARCEL(parcel->readUint64, &uintPreferredFrameTimelineIndex); |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 51 | vsync.preferredFrameTimelineIndex = static_cast<size_t>(uintPreferredFrameTimelineIndex); |
Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 52 | |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 53 | 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 Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 59 | return OK; |
| 60 | } |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 61 | status_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 Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 69 | |
| 70 | return OK; |
| 71 | } |
| 72 | |
| 73 | }; // namespace android::gui |