Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 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 | |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 19 | #include <aidl/android/hardware/graphics/composer3/DimmingStage.h> |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 20 | #include <aidl/android/hardware/graphics/composer3/RenderIntent.h> |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 21 | #include <iosfwd> |
| 22 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 23 | #include <math/mat4.h> |
Leon Scroggins III | 191b877 | 2022-04-06 14:38:22 -0400 | [diff] [blame] | 24 | #include <renderengine/PrintMatrix.h> |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 25 | #include <renderengine/BorderRenderInfo.h> |
Leon Scroggins III | 5a655b8 | 2022-09-07 13:17:09 -0400 | [diff] [blame] | 26 | #include <ui/DisplayId.h> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 27 | #include <ui/GraphicTypes.h> |
| 28 | #include <ui/Rect.h> |
| 29 | #include <ui/Region.h> |
Peiyong Lin | b192596 | 2019-04-01 16:37:10 -0700 | [diff] [blame] | 30 | #include <ui/Transform.h> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 31 | |
Leon Scroggins III | 5a655b8 | 2022-09-07 13:17:09 -0400 | [diff] [blame] | 32 | #include <optional> |
| 33 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 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 { |
Leon Scroggins III | 5a655b8 | 2022-09-07 13:17:09 -0400 | [diff] [blame] | 40 | // A string containing the name of the display, along with its id, if it has |
| 41 | // one. |
| 42 | std::string namePlusId; |
| 43 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 44 | // Rectangle describing the physical display. We will project from the |
| 45 | // logical clip onto this rectangle. |
Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 46 | Rect physicalDisplay = Rect::INVALID_RECT; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 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. |
Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 52 | Rect clip = Rect::INVALID_RECT; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 53 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 54 | // Maximum luminance pulled from the display's HDR capabilities. |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 55 | float maxLuminance = 1.0f; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 56 | |
Alec Mouri | b21d94e | 2022-01-13 17:44:10 -0800 | [diff] [blame] | 57 | // Current luminance of the display |
| 58 | float currentLuminanceNits = -1.f; |
| 59 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 60 | // Output dataspace that will be populated if wide color gamut is used, or |
| 61 | // DataSpace::UNKNOWN otherwise. |
Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 62 | ui::Dataspace outputDataspace = ui::Dataspace::UNKNOWN; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 63 | |
Alec Mouri | b34f0b7 | 2020-10-02 13:18:34 -0700 | [diff] [blame] | 64 | // Additional color transform to apply after transforming to the output |
| 65 | // dataspace, in non-linear space. |
Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 66 | mat4 colorTransform = mat4(); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 67 | |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 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 | |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 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. |
Peiyong Lin | b192596 | 2019-04-01 16:37:10 -0700 | [diff] [blame] | 76 | uint32_t orientation = ui::Transform::ROT_0; |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 77 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 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; |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 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; |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 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; |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 90 | |
| 91 | std::vector<renderengine::BorderRenderInfo> borderInfoList; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 94 | static inline bool operator==(const DisplaySettings& lhs, const DisplaySettings& rhs) { |
Leon Scroggins III | 5a655b8 | 2022-09-07 13:17:09 -0400 | [diff] [blame] | 95 | return lhs.namePlusId == rhs.namePlusId && lhs.physicalDisplay == rhs.physicalDisplay && |
| 96 | lhs.clip == rhs.clip && lhs.maxLuminance == rhs.maxLuminance && |
Leon Scroggins III | 191b877 | 2022-04-06 14:38:22 -0400 | [diff] [blame] | 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 && |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 103 | lhs.dimmingStage == rhs.dimmingStage && lhs.renderIntent == rhs.renderIntent && |
| 104 | lhs.borderInfoList == rhs.borderInfoList; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Leon Scroggins III | 191b877 | 2022-04-06 14:38:22 -0400 | [diff] [blame] | 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 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 129 | static inline void PrintTo(const DisplaySettings& settings, ::std::ostream* os) { |
| 130 | *os << "DisplaySettings {"; |
Leon Scroggins III | 5a655b8 | 2022-09-07 13:17:09 -0400 | [diff] [blame] | 131 | *os << "\n .display = " << settings.namePlusId; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 132 | *os << "\n .physicalDisplay = "; |
| 133 | PrintTo(settings.physicalDisplay, os); |
| 134 | *os << "\n .clip = "; |
| 135 | PrintTo(settings.clip, os); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 136 | *os << "\n .maxLuminance = " << settings.maxLuminance; |
Leon Scroggins III | 191b877 | 2022-04-06 14:38:22 -0400 | [diff] [blame] | 137 | *os << "\n .currentLuminanceNits = " << settings.currentLuminanceNits; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 138 | *os << "\n .outputDataspace = "; |
| 139 | PrintTo(settings.outputDataspace, os); |
Leon Scroggins III | 191b877 | 2022-04-06 14:38:22 -0400 | [diff] [blame] | 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}"; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 152 | } // namespace renderengine |
| 153 | } // namespace android |