| 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 | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 26 | int64_t VsyncEventData::preferredVsyncId() const { | 
 | 27 |     return frameTimelines[preferredFrameTimelineIndex].vsyncId; | 
 | 28 | } | 
 | 29 |  | 
 | 30 | int64_t VsyncEventData::preferredDeadlineTimestamp() const { | 
 | 31 |     return frameTimelines[preferredFrameTimelineIndex].deadlineTimestamp; | 
 | 32 | } | 
 | 33 |  | 
 | 34 | int64_t VsyncEventData::preferredExpectedPresentationTime() const { | 
 | 35 |     return frameTimelines[preferredFrameTimelineIndex].expectedPresentationTime; | 
 | 36 | } | 
 | 37 |  | 
 | 38 | status_t ParcelableVsyncEventData::readFromParcel(const Parcel* parcel) { | 
| Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 39 |     if (parcel == nullptr) { | 
 | 40 |         ALOGE("%s: Null parcel", __func__); | 
 | 41 |         return BAD_VALUE; | 
 | 42 |     } | 
 | 43 |  | 
| Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 44 |     SAFE_PARCEL(parcel->readInt64, &vsync.frameInterval); | 
| Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 45 |  | 
 | 46 |     uint64_t uintPreferredFrameTimelineIndex; | 
 | 47 |     SAFE_PARCEL(parcel->readUint64, &uintPreferredFrameTimelineIndex); | 
| Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 48 |     vsync.preferredFrameTimelineIndex = static_cast<size_t>(uintPreferredFrameTimelineIndex); | 
| Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 49 |  | 
| Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 50 |     for (int i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) { | 
 | 51 |         SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].vsyncId); | 
 | 52 |         SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].deadlineTimestamp); | 
 | 53 |         SAFE_PARCEL(parcel->readInt64, &vsync.frameTimelines[i].expectedPresentationTime); | 
| Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 54 |     } | 
 | 55 |  | 
| Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 56 |     return OK; | 
 | 57 | } | 
| Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 58 | status_t ParcelableVsyncEventData::writeToParcel(Parcel* parcel) const { | 
 | 59 |     SAFE_PARCEL(parcel->writeInt64, vsync.frameInterval); | 
 | 60 |     SAFE_PARCEL(parcel->writeUint64, vsync.preferredFrameTimelineIndex); | 
 | 61 |     for (int i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) { | 
 | 62 |         SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].vsyncId); | 
 | 63 |         SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].deadlineTimestamp); | 
 | 64 |         SAFE_PARCEL(parcel->writeInt64, vsync.frameTimelines[i].expectedPresentationTime); | 
 | 65 |     } | 
| Rachel Lee | 18c3437 | 2022-01-20 13:57:18 -0800 | [diff] [blame] | 66 |  | 
 | 67 |     return OK; | 
 | 68 | } | 
 | 69 |  | 
 | 70 | }; // namespace android::gui |