blob: 8d7c13cb1826020ceffd58fa0cce0b63cefd0db2 [file] [log] [blame]
Alec Mouri6e57f682018-09-29 20:45:08 -07001/*
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
Alec Mouri85065692022-03-18 00:58:26 +000019#include <aidl/android/hardware/graphics/composer3/DimmingStage.h>
Alec Mourifcedb9c2022-04-11 20:02:17 +000020#include <aidl/android/hardware/graphics/composer3/RenderIntent.h>
Lloyd Pique6818fa52019-12-03 12:32:13 -080021#include <iosfwd>
22
Alec Mouri6e57f682018-09-29 20:45:08 -070023#include <math/mat4.h>
Leon Scroggins III191b8772022-04-06 14:38:22 -040024#include <renderengine/PrintMatrix.h>
Tianhao Yao67dd7122022-02-22 17:48:33 +000025#include <renderengine/BorderRenderInfo.h>
Leon Scroggins III5a655b82022-09-07 13:17:09 -040026#include <ui/DisplayId.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070027#include <ui/GraphicTypes.h>
28#include <ui/Rect.h>
29#include <ui/Region.h>
Peiyong Linb1925962019-04-01 16:37:10 -070030#include <ui/Transform.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070031
Leon Scroggins III5a655b82022-09-07 13:17:09 -040032#include <optional>
33
Alec Mouri6e57f682018-09-29 20:45:08 -070034namespace android {
35namespace renderengine {
36
37// DisplaySettings contains the settings that are applicable when drawing all
38// layers for a given display.
39struct DisplaySettings {
Leon Scroggins III5a655b82022-09-07 13:17:09 -040040 // A string containing the name of the display, along with its id, if it has
41 // one.
42 std::string namePlusId;
43
Alec Mouri6e57f682018-09-29 20:45:08 -070044 // Rectangle describing the physical display. We will project from the
45 // logical clip onto this rectangle.
Alec Mouri1441bf72018-12-03 19:55:28 -080046 Rect physicalDisplay = Rect::INVALID_RECT;
Alec Mouri6e57f682018-09-29 20:45:08 -070047
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.
Alec Mouri1441bf72018-12-03 19:55:28 -080052 Rect clip = Rect::INVALID_RECT;
Alec Mouri6e57f682018-09-29 20:45:08 -070053
Alec Mouri6e57f682018-09-29 20:45:08 -070054 // Maximum luminance pulled from the display's HDR capabilities.
Alec Mouri1089aed2018-10-25 21:33:57 -070055 float maxLuminance = 1.0f;
Alec Mouri6e57f682018-09-29 20:45:08 -070056
Alec Mourib21d94e2022-01-13 17:44:10 -080057 // Current luminance of the display
58 float currentLuminanceNits = -1.f;
59
Alec Mouri6e57f682018-09-29 20:45:08 -070060 // Output dataspace that will be populated if wide color gamut is used, or
61 // DataSpace::UNKNOWN otherwise.
Alec Mouri1441bf72018-12-03 19:55:28 -080062 ui::Dataspace outputDataspace = ui::Dataspace::UNKNOWN;
Alec Mouri6e57f682018-09-29 20:45:08 -070063
Alec Mourib34f0b72020-10-02 13:18:34 -070064 // Additional color transform to apply after transforming to the output
65 // dataspace, in non-linear space.
Alec Mouri1441bf72018-12-03 19:55:28 -080066 mat4 colorTransform = mat4();
Alec Mouri6e57f682018-09-29 20:45:08 -070067
Leon Scroggins III745dcaa2022-01-26 11:55:58 -050068 // 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
Alec Mouri5a6d8572020-03-23 23:56:15 -070072 // 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.
Peiyong Linb1925962019-04-01 16:37:10 -070076 uint32_t orientation = ui::Transform::ROT_0;
John Reckac09e452021-04-07 16:35:37 -040077
Alec Mouricdf6cbc2021-11-01 17:21:15 -070078 // 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;
Alec Mouri85065692022-03-18 00:58:26 +000082
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;
Alec Mourifcedb9c2022-04-11 20:02:17 +000086
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;
Tianhao Yao67dd7122022-02-22 17:48:33 +000090
91 std::vector<renderengine::BorderRenderInfo> borderInfoList;
Alec Mouri6e57f682018-09-29 20:45:08 -070092};
93
Lloyd Pique6818fa52019-12-03 12:32:13 -080094static inline bool operator==(const DisplaySettings& lhs, const DisplaySettings& rhs) {
Leon Scroggins III5a655b82022-09-07 13:17:09 -040095 return lhs.namePlusId == rhs.namePlusId && lhs.physicalDisplay == rhs.physicalDisplay &&
96 lhs.clip == rhs.clip && lhs.maxLuminance == rhs.maxLuminance &&
Leon Scroggins III191b8772022-04-06 14:38:22 -040097 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 &&
Tianhao Yao67dd7122022-02-22 17:48:33 +0000103 lhs.dimmingStage == rhs.dimmingStage && lhs.renderIntent == rhs.renderIntent &&
104 lhs.borderInfoList == rhs.borderInfoList;
Lloyd Pique6818fa52019-12-03 12:32:13 -0800105}
106
Leon Scroggins III191b8772022-04-06 14:38:22 -0400107static 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
Lloyd Pique6818fa52019-12-03 12:32:13 -0800129static inline void PrintTo(const DisplaySettings& settings, ::std::ostream* os) {
130 *os << "DisplaySettings {";
Leon Scroggins III5a655b82022-09-07 13:17:09 -0400131 *os << "\n .display = " << settings.namePlusId;
Lloyd Pique6818fa52019-12-03 12:32:13 -0800132 *os << "\n .physicalDisplay = ";
133 PrintTo(settings.physicalDisplay, os);
134 *os << "\n .clip = ";
135 PrintTo(settings.clip, os);
Lloyd Pique6818fa52019-12-03 12:32:13 -0800136 *os << "\n .maxLuminance = " << settings.maxLuminance;
Leon Scroggins III191b8772022-04-06 14:38:22 -0400137 *os << "\n .currentLuminanceNits = " << settings.currentLuminanceNits;
Lloyd Pique6818fa52019-12-03 12:32:13 -0800138 *os << "\n .outputDataspace = ";
139 PrintTo(settings.outputDataspace, os);
Leon Scroggins III191b8772022-04-06 14:38:22 -0400140 *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}";
Lloyd Pique6818fa52019-12-03 12:32:13 -0800150}
151
Alec Mouri6e57f682018-09-29 20:45:08 -0700152} // namespace renderengine
153} // namespace android