Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 <ui/DisplayInfo.h> |
| 18 | |
| 19 | #include <cstdint> |
| 20 | |
| 21 | #include <ui/FlattenableHelpers.h> |
| 22 | |
Marin Shalamanov | 896e630 | 2020-04-06 16:11:25 +0200 | [diff] [blame] | 23 | #define RETURN_IF_ERROR(op) \ |
| 24 | if (const status_t status = (op); status != OK) return status; |
| 25 | |
Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 26 | namespace android { |
| 27 | |
| 28 | size_t DisplayInfo::getFlattenedSize() const { |
Marin Shalamanov | 896e630 | 2020-04-06 16:11:25 +0200 | [diff] [blame] | 29 | return FlattenableHelpers::getFlattenedSize(connectionType) + |
| 30 | FlattenableHelpers::getFlattenedSize(density) + |
| 31 | FlattenableHelpers::getFlattenedSize(secure) + |
Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 32 | FlattenableHelpers::getFlattenedSize(deviceProductInfo); |
| 33 | } |
| 34 | |
| 35 | status_t DisplayInfo::flatten(void* buffer, size_t size) const { |
| 36 | if (size < getFlattenedSize()) { |
| 37 | return NO_MEMORY; |
| 38 | } |
Marin Shalamanov | 896e630 | 2020-04-06 16:11:25 +0200 | [diff] [blame] | 39 | RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, connectionType)); |
| 40 | RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, density)); |
| 41 | RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, secure)); |
| 42 | RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, deviceProductInfo)); |
| 43 | return OK; |
Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | status_t DisplayInfo::unflatten(void const* buffer, size_t size) { |
Marin Shalamanov | 896e630 | 2020-04-06 16:11:25 +0200 | [diff] [blame] | 47 | RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &connectionType)); |
| 48 | RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &density)); |
| 49 | RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &secure)); |
| 50 | RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &deviceProductInfo)); |
| 51 | return OK; |
Marin Shalamanov | 359a7e7 | 2020-02-17 17:03:07 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | } // namespace android |