blob: 11acdae921371c00ed92e3dc23422b8d3fc2ebe9 [file] [log] [blame]
Marin Shalamanov228f46b2021-01-28 21:11:45 +01001/*
2 * Copyright 2021 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/DynamicDisplayInfo.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
26namespace android::ui {
27
28std::optional<ui::DisplayMode> DynamicDisplayInfo::getActiveDisplayMode() const {
29 for (const auto& currMode : supportedDisplayModes) {
30 if (currMode.id == activeDisplayModeId) {
31 return currMode;
32 }
33 }
34 return {};
35}
36
37size_t DynamicDisplayInfo::getFlattenedSize() const {
38 return FlattenableHelpers::getFlattenedSize(supportedDisplayModes) +
39 FlattenableHelpers::getFlattenedSize(activeDisplayModeId) +
40 FlattenableHelpers::getFlattenedSize(supportedColorModes) +
41 FlattenableHelpers::getFlattenedSize(activeColorMode) +
42 FlattenableHelpers::getFlattenedSize(hdrCapabilities);
43}
44
45status_t DynamicDisplayInfo::flatten(void* buffer, size_t size) const {
46 if (size < getFlattenedSize()) {
47 return NO_MEMORY;
48 }
49 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, supportedDisplayModes));
50 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, activeDisplayModeId));
51 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, supportedColorModes));
52 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, activeColorMode));
53 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, hdrCapabilities));
54 return OK;
55}
56
57status_t DynamicDisplayInfo::unflatten(const void* buffer, size_t size) {
58 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &supportedDisplayModes));
59 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &activeDisplayModeId));
60 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &supportedColorModes));
61 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &activeColorMode));
62 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &hdrCapabilities));
63 return OK;
64}
65
66} // namespace android::ui