Patrick Williams | d828f30 | 2023-04-28 17:52:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 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/WindowInfosUpdate.h> |
| 18 | #include <private/gui/ParcelUtils.h> |
| 19 | |
| 20 | namespace android::gui { |
| 21 | |
| 22 | status_t WindowInfosUpdate::readFromParcel(const android::Parcel* parcel) { |
| 23 | if (parcel == nullptr) { |
| 24 | ALOGE("%s: Null parcel", __func__); |
| 25 | return BAD_VALUE; |
| 26 | } |
| 27 | |
| 28 | uint32_t size; |
| 29 | |
| 30 | SAFE_PARCEL(parcel->readUint32, &size); |
| 31 | windowInfos.reserve(size); |
| 32 | for (uint32_t i = 0; i < size; i++) { |
| 33 | windowInfos.push_back({}); |
| 34 | SAFE_PARCEL(windowInfos.back().readFromParcel, parcel); |
| 35 | } |
| 36 | |
| 37 | SAFE_PARCEL(parcel->readUint32, &size); |
| 38 | displayInfos.reserve(size); |
| 39 | for (uint32_t i = 0; i < size; i++) { |
| 40 | displayInfos.push_back({}); |
| 41 | SAFE_PARCEL(displayInfos.back().readFromParcel, parcel); |
| 42 | } |
| 43 | |
| 44 | SAFE_PARCEL(parcel->readInt64, &vsyncId); |
| 45 | SAFE_PARCEL(parcel->readInt64, ×tamp); |
| 46 | |
| 47 | return OK; |
| 48 | } |
| 49 | |
| 50 | status_t WindowInfosUpdate::writeToParcel(android::Parcel* parcel) const { |
| 51 | if (parcel == nullptr) { |
| 52 | ALOGE("%s: Null parcel", __func__); |
| 53 | return BAD_VALUE; |
| 54 | } |
| 55 | |
| 56 | SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(windowInfos.size())); |
| 57 | for (auto& windowInfo : windowInfos) { |
| 58 | SAFE_PARCEL(windowInfo.writeToParcel, parcel); |
| 59 | } |
| 60 | |
| 61 | SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(displayInfos.size())); |
| 62 | for (auto& displayInfo : displayInfos) { |
| 63 | SAFE_PARCEL(displayInfo.writeToParcel, parcel); |
| 64 | } |
| 65 | |
| 66 | SAFE_PARCEL(parcel->writeInt64, vsyncId); |
| 67 | SAFE_PARCEL(parcel->writeInt64, timestamp); |
| 68 | |
| 69 | return OK; |
| 70 | } |
| 71 | |
| 72 | } // namespace android::gui |