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/StaticDisplayInfo.h>
18
19 #include <cstdint>
20
21 #include <ui/FlattenableHelpers.h>
22
23 #define RETURN_IF_ERROR(op) \
24 if (const status_t status = (op); status != OK) return status;
25
26 namespace android::ui {
27
getFlattenedSize() const28 size_t StaticDisplayInfo::getFlattenedSize() const {
29 return FlattenableHelpers::getFlattenedSize(connectionType) +
30 FlattenableHelpers::getFlattenedSize(density) +
31 FlattenableHelpers::getFlattenedSize(secure) +
32 FlattenableHelpers::getFlattenedSize(deviceProductInfo) +
33 FlattenableHelpers::getFlattenedSize(installOrientation);
34 }
35
flatten(void * buffer,size_t size) const36 status_t StaticDisplayInfo::flatten(void* buffer, size_t size) const {
37 if (size < getFlattenedSize()) {
38 return NO_MEMORY;
39 }
40 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));
44 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, installOrientation));
45 return OK;
46 }
47
unflatten(void const * buffer,size_t size)48 status_t StaticDisplayInfo::unflatten(void const* buffer, size_t size) {
49 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));
53 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &installOrientation));
54 return OK;
55 }
56
57 } // namespace android::ui
58