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 | |
| 26 | status_t VsyncEventData::readFromParcel(const Parcel* parcel) { |
| 27 | if (parcel == nullptr) { |
| 28 | ALOGE("%s: Null parcel", __func__); |
| 29 | return BAD_VALUE; |
| 30 | } |
| 31 | |
| 32 | SAFE_PARCEL(parcel->readInt64, &id) |
| 33 | SAFE_PARCEL(parcel->readInt64, &deadlineTimestamp); |
| 34 | SAFE_PARCEL(parcel->readInt64, &frameInterval); |
| 35 | |
| 36 | uint64_t uintPreferredFrameTimelineIndex; |
| 37 | SAFE_PARCEL(parcel->readUint64, &uintPreferredFrameTimelineIndex); |
| 38 | preferredFrameTimelineIndex = static_cast<size_t>(uintPreferredFrameTimelineIndex); |
| 39 | |
| 40 | std::vector<FrameTimeline> timelines; |
| 41 | SAFE_PARCEL(parcel->readParcelableVector, &timelines); |
| 42 | std::copy_n(timelines.begin(), timelines.size(), frameTimelines.begin()); |
| 43 | |
| 44 | return OK; |
| 45 | } |
| 46 | status_t VsyncEventData::writeToParcel(Parcel* parcel) const { |
| 47 | SAFE_PARCEL(parcel->writeInt64, id) |
| 48 | SAFE_PARCEL(parcel->writeInt64, deadlineTimestamp); |
| 49 | SAFE_PARCEL(parcel->writeInt64, frameInterval); |
| 50 | SAFE_PARCEL(parcel->writeUint64, preferredFrameTimelineIndex); |
| 51 | SAFE_PARCEL(parcel->writeParcelableVector, |
| 52 | std::vector(frameTimelines.begin(), frameTimelines.end())); |
| 53 | |
| 54 | return OK; |
| 55 | } |
| 56 | status_t VsyncEventData::FrameTimeline::readFromParcel(const Parcel* parcel) { |
| 57 | if (parcel == nullptr) { |
| 58 | ALOGE("%s: Null parcel", __func__); |
| 59 | return BAD_VALUE; |
| 60 | } |
| 61 | |
| 62 | SAFE_PARCEL(parcel->readInt64, &id) |
| 63 | SAFE_PARCEL(parcel->readInt64, &deadlineTimestamp); |
| 64 | SAFE_PARCEL(parcel->readInt64, &expectedPresentTime); |
| 65 | |
| 66 | return OK; |
| 67 | } |
| 68 | status_t VsyncEventData::FrameTimeline::writeToParcel(Parcel* parcel) const { |
| 69 | SAFE_PARCEL(parcel->writeInt64, id); |
| 70 | SAFE_PARCEL(parcel->writeInt64, deadlineTimestamp); |
| 71 | SAFE_PARCEL(parcel->writeInt64, expectedPresentTime); |
| 72 | |
| 73 | return OK; |
| 74 | } |
| 75 | |
| 76 | }; // namespace android::gui |