1 /*
2  * Copyright 2019 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 #pragma once
18 
19 #include <cstdint>
20 #include <unordered_map>
21 #include <vector>
22 
23 // TODO(b/129481165): remove the #pragma below and fix conversion issues
24 #pragma clang diagnostic push
25 #pragma clang diagnostic ignored "-Wconversion"
26 
27 #include <ui/GraphicTypes.h>
28 
29 // TODO(b/129481165): remove the #pragma below and fix conversion issues
30 #pragma clang diagnostic pop // ignored "-Wconversion"
31 
32 #include <ui/HdrCapabilities.h>
33 
34 namespace android::compositionengine {
35 
36 /**
37  * A parameter object for creating DisplayColorProfile instances
38  */
39 struct DisplayColorProfileCreationArgs {
40     using HwcColorModes = std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>;
41 
42     // True if this display supports a wide color gamut
43     bool hasWideColorGamut;
44 
45     // The HDR capabilities supported by the HWC
46     HdrCapabilities hdrCapabilities;
47 
48     // The per-frame metadata supported by the HWC
49     int32_t supportedPerFrameMetadata;
50 
51     // The mapping of color modes and render intents supported by the HWC
52     HwcColorModes hwcColorModes;
53 };
54 
55 /**
56  * A helper for setting up a DisplayColorProfileCreationArgs value in-line.
57  *
58  * Prefer this builder over raw structure initialization.
59  *
60  * Instead of:
61  *
62  *   DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
63  *                                   HwcColorModes()}
64  *
65  * Prefer:
66  *
67  *  DisplayColorProfileCreationArgsBuilder().setHasWideColorGamut(false)
68  *      .setIsVirtual(false).setDisplayId(displayId).Build();
69  */
70 class DisplayColorProfileCreationArgsBuilder {
71 public:
Build()72     DisplayColorProfileCreationArgs Build() { return std::move(mArgs); }
73 
setHasWideColorGamut(bool hasWideColorGamut)74     DisplayColorProfileCreationArgsBuilder& setHasWideColorGamut(bool hasWideColorGamut) {
75         mArgs.hasWideColorGamut = hasWideColorGamut;
76         return *this;
77     }
setHdrCapabilities(HdrCapabilities && hdrCapabilities)78     DisplayColorProfileCreationArgsBuilder& setHdrCapabilities(HdrCapabilities&& hdrCapabilities) {
79         mArgs.hdrCapabilities = std::move(hdrCapabilities);
80         return *this;
81     }
setSupportedPerFrameMetadata(int32_t supportedPerFrameMetadata)82     DisplayColorProfileCreationArgsBuilder& setSupportedPerFrameMetadata(
83             int32_t supportedPerFrameMetadata) {
84         mArgs.supportedPerFrameMetadata = supportedPerFrameMetadata;
85         return *this;
86     }
setHwcColorModes(DisplayColorProfileCreationArgs::HwcColorModes && hwcColorModes)87     DisplayColorProfileCreationArgsBuilder& setHwcColorModes(
88             DisplayColorProfileCreationArgs::HwcColorModes&& hwcColorModes) {
89         mArgs.hwcColorModes = std::move(hwcColorModes);
90         return *this;
91     }
92 
93 private:
94     DisplayColorProfileCreationArgs mArgs;
95 };
96 
97 } // namespace android::compositionengine
98