| 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 | 40aef42 | 2023-04-25 14:35:47 -0700 | [diff] [blame] | 26 | static_assert(VsyncEventData::kFrameTimelinesCapacity == 7, | 
|  | 27 | "Must update value in DisplayEventReceiver.java#FRAME_TIMELINES_CAPACITY (and here)"); | 
| Rachel Lee | 0884711 | 2023-02-16 11:07:48 -0800 | [diff] [blame] | 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 |  | 
| Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 49 | uint32_t uintPreferredFrameTimelineIndex; | 
|  | 50 | SAFE_PARCEL(parcel->readUint32, &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 | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 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++) { | 
| Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 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); | 
| Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 61 | } | 
|  | 62 |  | 
| Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 63 | return OK; | 
|  | 64 | } | 
| Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 65 | status_t ParcelableVsyncEventData::writeToParcel(Parcel* parcel) const { | 
|  | 66 | SAFE_PARCEL(parcel->writeInt64, vsync.frameInterval); | 
| Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 67 | SAFE_PARCEL(parcel->writeUint32, vsync.preferredFrameTimelineIndex); | 
|  | 68 | SAFE_PARCEL(parcel->writeUint32, vsync.frameTimelinesLength); | 
|  | 69 | for (size_t i = 0; i < vsync.frameTimelinesLength; i++) { | 
| Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 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 | } | 
| Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 74 |  | 
|  | 75 | return OK; | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | }; // namespace android::gui |