• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
107 static inline bool operator==(const DisplaySettings& lhs, const DisplaySettings& rhs) {
108     return lhs.namePlusId == rhs.namePlusId && lhs.physicalDisplay == rhs.physicalDisplay &&
109             lhs.clip == rhs.clip && lhs.maxLuminance == rhs.maxLuminance &&
110             lhs.currentLuminanceNits == rhs.currentLuminanceNits &&
111             lhs.outputDataspace == rhs.outputDataspace &&
112             lhs.colorTransform == rhs.colorTransform &&
113             lhs.deviceHandlesColorTransform == rhs.deviceHandlesColorTransform &&
114             lhs.orientation == rhs.orientation &&
115             lhs.targetLuminanceNits == rhs.targetLuminanceNits &&
116             lhs.dimmingStage == rhs.dimmingStage && lhs.renderIntent == rhs.renderIntent;
117 }
118 
orientation_to_string(uint32_t orientation)119 static const char* orientation_to_string(uint32_t orientation) {
120     switch (orientation) {
121         case ui::Transform::ROT_0:
122             return "ROT_0";
123         case ui::Transform::FLIP_H:
124             return "FLIP_H";
125         case ui::Transform::FLIP_V:
126             return "FLIP_V";
127         case ui::Transform::ROT_90:
128             return "ROT_90";
129         case ui::Transform::ROT_180:
130             return "ROT_180";
131         case ui::Transform::ROT_270:
132             return "ROT_270";
133         case ui::Transform::ROT_INVALID:
134             return "ROT_INVALID";
135         default:
136             ALOGE("invalid orientation!");
137             return "invalid orientation";
138     }
139 }
140 
PrintTo(const DisplaySettings & settings,::std::ostream * os)141 static inline void PrintTo(const DisplaySettings& settings, ::std::ostream* os) {
142     *os << "DisplaySettings {";
143     *os << "\n    .display = " << settings.namePlusId;
144     *os << "\n    .physicalDisplay = ";
145     PrintTo(settings.physicalDisplay, os);
146     *os << "\n    .clip = ";
147     PrintTo(settings.clip, os);
148     *os << "\n    .maxLuminance = " << settings.maxLuminance;
149     *os << "\n    .currentLuminanceNits = " << settings.currentLuminanceNits;
150     *os << "\n    .outputDataspace = ";
151     PrintTo(settings.outputDataspace, os);
152     *os << "\n    .colorTransform = ";
153     PrintMatrix(settings.colorTransform, os);
154     *os << "\n    .deviceHandlesColorTransform = " << settings.deviceHandlesColorTransform;
155     *os << "\n    .orientation = " << orientation_to_string(settings.orientation);
156     *os << "\n    .targetLuminanceNits = " << settings.targetLuminanceNits;
157     *os << "\n    .dimmingStage = "
158         << aidl::android::hardware::graphics::composer3::toString(settings.dimmingStage).c_str();
159     *os << "\n    .renderIntent = "
160         << aidl::android::hardware::graphics::composer3::toString(settings.renderIntent).c_str();
161     *os << "\n}";
162 }
163 
164 } // namespace renderengine
165 } // namespace android
166