|
16 | 16 |
|
17 | 17 | #include "ScreenCaptureOutput.h" |
18 | 18 | #include "ScreenCaptureRenderSurface.h" |
| 19 | +#include "common/include/common/FlagManager.h" |
19 | 20 | #include "ui/Rotation.h" |
20 | 21 |
|
21 | 22 | #include <compositionengine/CompositionEngine.h> |
22 | 23 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
23 | 24 | #include <compositionengine/impl/DisplayColorProfile.h> |
| 25 | +#include <ui/HdrRenderTypeUtils.h> |
24 | 26 | #include <ui/Rotation.h> |
25 | 27 |
|
26 | 28 | namespace android { |
@@ -104,14 +106,84 @@ renderengine::DisplaySettings ScreenCaptureOutput::generateClientCompositionDisp |
104 | 106 | return clientCompositionDisplay; |
105 | 107 | } |
106 | 108 |
|
| 109 | +std::unordered_map<int32_t, aidl::android::hardware::graphics::composer3::Luts> |
| 110 | +ScreenCaptureOutput::generateLuts() { |
| 111 | + std::unordered_map<int32_t, aidl::android::hardware::graphics::composer3::Luts> lutsMapper; |
| 112 | + if (FlagManager::getInstance().luts_api()) { |
| 113 | + std::vector<sp<GraphicBuffer>> buffers; |
| 114 | + std::vector<int32_t> layerIds; |
| 115 | + |
| 116 | + for (const auto* layer : getOutputLayersOrderedByZ()) { |
| 117 | + const auto& layerState = layer->getState(); |
| 118 | + const auto* layerFEState = layer->getLayerFE().getCompositionState(); |
| 119 | + auto pixelFormat = layerFEState->buffer |
| 120 | + ? std::make_optional( |
| 121 | + static_cast<ui::PixelFormat>(layerFEState->buffer->getPixelFormat())) |
| 122 | + : std::nullopt; |
| 123 | + const auto hdrType = getHdrRenderType(layerState.dataspace, pixelFormat, |
| 124 | + layerFEState->desiredHdrSdrRatio); |
| 125 | + if (layerFEState->buffer && !layerFEState->luts && |
| 126 | + hdrType == HdrRenderType::GENERIC_HDR) { |
| 127 | + buffers.push_back(layerFEState->buffer); |
| 128 | + layerIds.push_back(layer->getLayerFE().getSequence()); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + std::vector<aidl::android::hardware::graphics::composer3::Luts> luts; |
| 133 | + if (auto displayDevice = mRenderArea.getDisplayDevice()) { |
| 134 | + const auto id = PhysicalDisplayId::tryCast(displayDevice->getId()); |
| 135 | + if (id) { |
| 136 | + auto& hwc = getCompositionEngine().getHwComposer(); |
| 137 | + hwc.getLuts(*id, buffers, &luts); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + if (buffers.size() == luts.size()) { |
| 142 | + for (size_t i = 0; i < luts.size(); i++) { |
| 143 | + lutsMapper[layerIds[i]] = std::move(luts[i]); |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + return lutsMapper; |
| 148 | +} |
| 149 | + |
107 | 150 | std::vector<compositionengine::LayerFE::LayerSettings> |
108 | 151 | ScreenCaptureOutput::generateClientCompositionRequests( |
109 | 152 | bool supportsProtectedContent, ui::Dataspace outputDataspace, |
110 | 153 | std::vector<compositionengine::LayerFE*>& outLayerFEs) { |
| 154 | + // This map maps the layer unique id to a Lut |
| 155 | + std::unordered_map<int32_t, aidl::android::hardware::graphics::composer3::Luts> lutsMapper = |
| 156 | + generateLuts(); |
| 157 | + |
111 | 158 | auto clientCompositionLayers = compositionengine::impl::Output:: |
112 | 159 | generateClientCompositionRequests(supportsProtectedContent, outputDataspace, |
113 | 160 | outLayerFEs); |
114 | 161 |
|
| 162 | + for (auto& layer : clientCompositionLayers) { |
| 163 | + if (lutsMapper.find(layer.sequence) != lutsMapper.end()) { |
| 164 | + auto& aidlLuts = lutsMapper[layer.sequence]; |
| 165 | + if (aidlLuts.pfd.get() >= 0 && aidlLuts.offsets) { |
| 166 | + std::vector<int32_t> offsets = *aidlLuts.offsets; |
| 167 | + std::vector<int32_t> dimensions; |
| 168 | + dimensions.reserve(offsets.size()); |
| 169 | + std::vector<int32_t> sizes; |
| 170 | + sizes.reserve(offsets.size()); |
| 171 | + std::vector<int32_t> keys; |
| 172 | + keys.reserve(offsets.size()); |
| 173 | + for (size_t j = 0; j < offsets.size(); j++) { |
| 174 | + dimensions.emplace_back( |
| 175 | + static_cast<int32_t>(aidlLuts.lutProperties[j].dimension)); |
| 176 | + sizes.emplace_back(aidlLuts.lutProperties[j].size); |
| 177 | + keys.emplace_back( |
| 178 | + static_cast<int32_t>(aidlLuts.lutProperties[j].samplingKeys[0])); |
| 179 | + } |
| 180 | + layer.luts = std::make_shared<gui::DisplayLuts>(base::unique_fd( |
| 181 | + aidlLuts.pfd.dup().get()), |
| 182 | + offsets, dimensions, sizes, keys); |
| 183 | + } |
| 184 | + } |
| 185 | + } |
| 186 | + |
115 | 187 | if (mRegionSampling) { |
116 | 188 | for (auto& layer : clientCompositionLayers) { |
117 | 189 | layer.backgroundBlurRadius = 0; |
|
0 commit comments