blob: 73a78af186b510eb1d205f4a2454445eec76668f [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
17#include <ui/DisplayInfo.h>
18
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 Shalamanov359a7e72020-02-17 17:03:07 +010026namespace android {
27
28size_t DisplayInfo::getFlattenedSize() const {
Marin Shalamanov896e6302020-04-06 16:11:25 +020029 return FlattenableHelpers::getFlattenedSize(connectionType) +
30 FlattenableHelpers::getFlattenedSize(density) +
31 FlattenableHelpers::getFlattenedSize(secure) +
Marin Shalamanov359a7e72020-02-17 17:03:07 +010032 FlattenableHelpers::getFlattenedSize(deviceProductInfo);
33}
34
35status_t DisplayInfo::flatten(void* buffer, size_t size) const {
36 if (size < getFlattenedSize()) {
37 return NO_MEMORY;
38 }
Marin Shalamanov896e6302020-04-06 16:11:25 +020039 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 Shalamanov359a7e72020-02-17 17:03:07 +010044}
45
46status_t DisplayInfo::unflatten(void const* buffer, size_t size) {
Marin Shalamanov896e6302020-04-06 16:11:25 +020047 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 Shalamanov359a7e72020-02-17 17:03:07 +010052}
53
54} // namespace android