blob: d5c4ef0c179a78a3797ffacca7f7f3c257c3540a [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) +
Marin Shalamanovb173f752021-02-16 19:38:36 +010042 FlattenableHelpers::getFlattenedSize(hdrCapabilities) +
43 FlattenableHelpers::getFlattenedSize(autoLowLatencyModeSupported) +
44 FlattenableHelpers::getFlattenedSize(gameContentTypeSupported);
Marin Shalamanov228f46b2021-01-28 21:11:45 +010045}
46
47status_t DynamicDisplayInfo::flatten(void* buffer, size_t size) const {
48 if (size < getFlattenedSize()) {
49 return NO_MEMORY;
50 }
51 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, supportedDisplayModes));
52 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, activeDisplayModeId));
53 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, supportedColorModes));
54 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, activeColorMode));
55 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, hdrCapabilities));
Marin Shalamanovb173f752021-02-16 19:38:36 +010056 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, autoLowLatencyModeSupported));
57 RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, gameContentTypeSupported));
Marin Shalamanov228f46b2021-01-28 21:11:45 +010058 return OK;
59}
60
61status_t DynamicDisplayInfo::unflatten(const void* buffer, size_t size) {
62 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &supportedDisplayModes));
63 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &activeDisplayModeId));
64 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &supportedColorModes));
65 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &activeColorMode));
66 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &hdrCapabilities));
Marin Shalamanovb173f752021-02-16 19:38:36 +010067 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &autoLowLatencyModeSupported));
68 RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &gameContentTypeSupported));
Marin Shalamanov228f46b2021-01-28 21:11:45 +010069 return OK;
70}
71
72} // namespace android::ui