1 /*
2 * Copyright 2018 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 <aidl/android/hardware/graphics/composer3/DimmingStage.h>
20 #include <aidl/android/hardware/graphics/composer3/RenderIntent.h>
21 #include <iosfwd>
22
23 #include <math/mat4.h>
24 #include <renderengine/PrintMatrix.h>
25 #include <ui/DisplayId.h>
26 #include <ui/GraphicTypes.h>
27 #include <ui/Rect.h>
28 #include <ui/Region.h>
29 #include <ui/Transform.h>
30
31 #include <optional>
32
33 namespace android {
34 namespace renderengine {
35
36 // DisplaySettings contains the settings that are applicable when drawing all
37 // layers for a given display.
38 struct DisplaySettings {
39 // A string containing the name of the display, along with its id, if it has
40 // one.
41 std::string namePlusId;
42
43 // Rectangle describing the physical display. We will project from the
44 // logical clip onto this rectangle.
45 Rect physicalDisplay = Rect::INVALID_RECT;
46
47 // Rectangle bounded by the x,y- clipping planes in the logical display, so
48 // that the orthographic projection matrix can be computed. When
49 // constructing this matrix, z-coordinate bound are assumed to be at z=0 and
50 // z=1.
51 Rect clip = Rect::INVALID_RECT;
52
53 // Maximum luminance pulled from the display's HDR capabilities.
54 float maxLuminance = 1.0f;
55
56 // Current luminance of the display
57 float currentLuminanceNits = -1.f;
58
59 // Output dataspace that will be populated if wide color gamut is used, or
60 // DataSpace::UNKNOWN otherwise.
61 ui::Dataspace outputDataspace = ui::Dataspace::UNKNOWN;
62
63 // Additional color transform to apply after transforming to the output
64 // dataspace, in non-linear space.
65 mat4 colorTransform = mat4();
66
67 // If true, and colorTransform is non-identity, most client draw calls can
68 // ignore it. Some draws (e.g. screen decorations) may need it, though.
69 bool deviceHandlesColorTransform = false;
70
71 // An additional orientation flag to be applied after clipping the output.
72 // By way of example, this may be used for supporting fullscreen screenshot
73 // capture of a device in landscape while the buffer is in portrait
74 // orientation.
75 uint32_t orientation = ui::Transform::ROT_0;
76
77 // Target luminance of the display. -1f if unknown.
78 // All layers will be dimmed by (max(layer white points) / targetLuminanceNits).
79 // If the target luminance is unknown, then no display-level dimming occurs.
80 float targetLuminanceNits = -1.f;
81
82 // Configures when dimming should be applied for each layer.
83 aidl::android::hardware::graphics::composer3::DimmingStage dimmingStage =
84 aidl::android::hardware::graphics::composer3::DimmingStage::NONE;
85
86 // Configures the rendering intent of the output display. This is used for tonemapping.
87 aidl::android::hardware::graphics::composer3::RenderIntent renderIntent =
88 aidl::android::hardware::graphics::composer3::RenderIntent::TONE_MAP_COLORIMETRIC;
89
90 // Tonemapping strategy to use for each layer. This is only used for tonemapping HDR source
91 // content
92 enum class TonemapStrategy {
93 // Use a tonemapper defined by libtonemap. This may be OEM-defined as of Android 13, aka
94 // undefined.
95 // This is typically a global tonemapper, designed to match what is on screen.
96 Libtonemap,
97 // Use a local tonemapper. Because local tonemapping uses large intermediate allocations,
98 // this
99 // method is primarily recommended for infrequent rendering that does not need to exactly
100 // match
101 // pixels that are on-screen.
102 Local,
103 };
104 TonemapStrategy tonemapStrategy = TonemapStrategy::Libtonemap;
105
106 // For now, meaningful primarily when the TonemappingStrategy is Local
107 float targetHdrSdrRatio = 1.f;
108 };
109
110 static inline bool operator==(const DisplaySettings& lhs, const DisplaySettings& rhs) {
111 return lhs.namePlusId == rhs.namePlusId && lhs.physicalDisplay == rhs.physicalDisplay &&
112 lhs.clip == rhs.clip && lhs.maxLuminance == rhs.maxLuminance &&
113 lhs.currentLuminanceNits == rhs.currentLuminanceNits &&
114 lhs.outputDataspace == rhs.outputDataspace &&
115 lhs.colorTransform == rhs.colorTransform &&
116 lhs.deviceHandlesColorTransform == rhs.deviceHandlesColorTransform &&
117 lhs.orientation == rhs.orientation &&
118 lhs.targetLuminanceNits == rhs.targetLuminanceNits &&
119 lhs.dimmingStage == rhs.dimmingStage && lhs.renderIntent == rhs.renderIntent;
120 }
121
orientation_to_string(uint32_t orientation)122 static const char* orientation_to_string(uint32_t orientation) {
123 switch (orientation) {
124 case ui::Transform::ROT_0:
125 return "ROT_0";
126 case ui::Transform::FLIP_H:
127 return "FLIP_H";
128 case ui::Transform::FLIP_V:
129 return "FLIP_V";
130 case ui::Transform::ROT_90:
131 return "ROT_90";
132 case ui::Transform::ROT_180:
133 return "ROT_180";
134 case ui::Transform::ROT_270:
135 return "ROT_270";
136 case ui::Transform::ROT_INVALID:
137 return "ROT_INVALID";
138 default:
139 ALOGE("invalid orientation!");
140 return "invalid orientation";
141 }
142 }
143
PrintTo(const DisplaySettings & settings,::std::ostream * os)144 static inline void PrintTo(const DisplaySettings& settings, ::std::ostream* os) {
145 *os << "DisplaySettings {";
146 *os << "\n .display = " << settings.namePlusId;
147 *os << "\n .physicalDisplay = ";
148 PrintTo(settings.physicalDisplay, os);
149 *os << "\n .clip = ";
150 PrintTo(settings.clip, os);
151 *os << "\n .maxLuminance = " << settings.maxLuminance;
152 *os << "\n .currentLuminanceNits = " << settings.currentLuminanceNits;
153 *os << "\n .outputDataspace = ";
154 PrintTo(settings.outputDataspace, os);
155 *os << "\n .colorTransform = ";
156 PrintMatrix(settings.colorTransform, os);
157 *os << "\n .deviceHandlesColorTransform = " << settings.deviceHandlesColorTransform;
158 *os << "\n .orientation = " << orientation_to_string(settings.orientation);
159 *os << "\n .targetLuminanceNits = " << settings.targetLuminanceNits;
160 *os << "\n .dimmingStage = "
161 << aidl::android::hardware::graphics::composer3::toString(settings.dimmingStage).c_str();
162 *os << "\n .renderIntent = "
163 << aidl::android::hardware::graphics::composer3::toString(settings.renderIntent).c_str();
164 *os << "\n}";
165 }
166
167 } // namespace renderengine
168 } // namespace android
169