blob: 03d15e46948075613fad1bf32bd1c63f0de122da [file] [log] [blame]
Marin Shalamanov359a7e72020-02-17 17:03:07 +01001/*
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
Marin Shalamanov228f46b2021-01-28 21:11:45 +010017#include <ui/StaticDisplayInfo.h>
Marin Shalamanov359a7e72020-02-17 17:03:07 +010018
19#include <cstdint>
20
21#include <ui/FlattenableHelpers.h>
22
Marin Shalamanov896e6302020-04-06 16:11:25 +020023#define RETURN_IF_ERROR(op) \
24 if (const status_t status = (op); status != OK) return status;
25
Marin Shalamanov228f46b2021-01-28 21:11:45 +010026namespace android::ui {
Marin Shalamanov359a7e72020-02-17 17:03:07 +010027
Marin Shalamanov228f46b2021-01-28 21:11:45 +010028size_t StaticDisplayInfo::getFlattenedSize() const {
Marin Shalamanov896e6302020-04-06 16:11:25 +020029 return FlattenableHelpers::getFlattenedSize(connectionType) +
30 FlattenableHelpers::getFlattenedSize(density) +
31 FlattenableHelpers::getFlattenedSize(secure) +
Vishnu Naird0a89652022-01-13 12:05:54 -080032 FlattenableHelpers::getFlattenedSize(deviceProductInfo) +
33 FlattenableHelpers::getFlattenedSize(installOrientation);
Marin Shalamanov359a7e72020-02-17 17:03:07 +010034}
35
Marin Shalamanov228f46b2021-01-28 21:11:45 +010036status_t StaticDisplayInfo::flatten(void* buffer, size_t size) const {
Marin Shalamanov359a7e72020-02-17 17:03:07 +010037 if (size < getFlattenedSize()) {
38 return NO_MEMORY;
39 }
Marin Shalamanov896e6302020-04-06 16:11:25 +020040 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, connectionType));
41 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, density));
42 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, secure));
43 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, deviceProductInfo));
Vishnu Naird0a89652022-01-13 12:05:54 -080044 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, installOrientation));
Marin Shalamanov896e6302020-04-06 16:11:25 +020045 return OK;
Marin Shalamanov359a7e72020-02-17 17:03:07 +010046}
47
Marin Shalamanov228f46b2021-01-28 21:11:45 +010048status_t StaticDisplayInfo::unflatten(void const* buffer, size_t size) {
Marin Shalamanov896e6302020-04-06 16:11:25 +020049 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &connectionType));
50 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &density));
51 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &secure));
52 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &deviceProductInfo));
Vishnu Naird0a89652022-01-13 12:05:54 -080053 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &installOrientation));
Marin Shalamanov896e6302020-04-06 16:11:25 +020054 return OK;
Marin Shalamanov359a7e72020-02-17 17:03:07 +010055}
56
Marin Shalamanov228f46b2021-01-28 21:11:45 +010057} // namespace android::ui