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