Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 17 | #include <android-base/stringprintf.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 18 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 19 | #include <compositionengine/CompositionRefreshArgs.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 20 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 21 | #include <compositionengine/DisplaySurface.h> |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 22 | #include <compositionengine/LayerFE.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 23 | #include <compositionengine/impl/Display.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 24 | #include <compositionengine/impl/DisplayColorProfile.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 25 | #include <compositionengine/impl/DumpHelpers.h> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 26 | #include <compositionengine/impl/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 27 | #include <compositionengine/impl/RenderSurface.h> |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 28 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 29 | #include <utils/Trace.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 30 | |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 31 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 32 | #pragma clang diagnostic push |
| 33 | #pragma clang diagnostic ignored "-Wconversion" |
| 34 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 35 | #include "DisplayHardware/HWComposer.h" |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 36 | |
| 37 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 38 | #pragma clang diagnostic pop // ignored "-Wconversion" |
| 39 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 40 | #include "DisplayHardware/PowerAdvisor.h" |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 41 | |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 42 | using aidl::android::hardware::graphics::composer3::DisplayCapability; |
| 43 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 44 | namespace android::compositionengine::impl { |
| 45 | |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 46 | std::shared_ptr<Display> createDisplay( |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 47 | const compositionengine::CompositionEngine& compositionEngine, |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 48 | const compositionengine::DisplayCreationArgs& args) { |
| 49 | return createDisplayTemplated<Display>(compositionEngine, args); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 52 | Display::~Display() = default; |
| 53 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 54 | void Display::setConfiguration(const compositionengine::DisplayCreationArgs& args) { |
Dominik Laskowski | 1394860 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 55 | mId = args.id; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 56 | mPowerAdvisor = args.powerAdvisor; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 57 | editState().isSecure = args.isSecure; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 58 | editState().displaySpace.setBounds(args.pixels); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 59 | setName(args.name); |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame^] | 60 | bool isBootModeSupported = getCompositionEngine().getHwComposer().getBootDisplayModeSupport(); |
| 61 | const auto physicalId = PhysicalDisplayId::tryCast(mId); |
| 62 | if (physicalId && isBootModeSupported) { |
| 63 | mPreferredBootDisplayModeId = static_cast<int32_t>( |
| 64 | getCompositionEngine().getHwComposer().getPreferredBootDisplayMode(*physicalId)); |
| 65 | } |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | bool Display::isValid() const { |
| 69 | return Output::isValid() && mPowerAdvisor; |
| 70 | } |
| 71 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 72 | DisplayId Display::getId() const { |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 73 | return mId; |
| 74 | } |
| 75 | |
| 76 | bool Display::isSecure() const { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 77 | return getState().isSecure; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | bool Display::isVirtual() const { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 81 | return VirtualDisplayId::tryCast(mId).has_value(); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Lloyd Pique | 6c564cf | 2019-05-17 17:31:36 -0700 | [diff] [blame] | 84 | std::optional<DisplayId> Display::getDisplayId() const { |
| 85 | return mId; |
| 86 | } |
| 87 | |
Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame^] | 88 | int32_t Display::getPreferredBootModeId() const { |
| 89 | return mPreferredBootDisplayModeId; |
| 90 | } |
| 91 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 92 | void Display::disconnect() { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 93 | if (mIsDisconnected) { |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 94 | return; |
| 95 | } |
| 96 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 97 | mIsDisconnected = true; |
Dominik Laskowski | 1394860 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 98 | |
| 99 | if (const auto id = HalDisplayId::tryCast(mId)) { |
| 100 | getCompositionEngine().getHwComposer().disconnectDisplay(*id); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 101 | } |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 104 | void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) { |
| 105 | Output::setColorTransform(args); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 106 | const auto halDisplayId = HalDisplayId::tryCast(mId); |
| 107 | if (mIsDisconnected || !halDisplayId || CC_LIKELY(!args.colorTransformMatrix)) { |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 108 | return; |
| 109 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 110 | |
| 111 | auto& hwc = getCompositionEngine().getHwComposer(); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 112 | status_t result = hwc.setColorTransform(*halDisplayId, *args.colorTransformMatrix); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 113 | ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d", |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 114 | to_string(mId).c_str(), result); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 117 | void Display::setColorProfile(const ColorProfile& colorProfile) { |
| 118 | const ui::Dataspace targetDataspace = |
| 119 | getDisplayColorProfile()->getTargetDataspace(colorProfile.mode, colorProfile.dataspace, |
| 120 | colorProfile.colorSpaceAgnosticDataspace); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 121 | |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 122 | if (colorProfile.mode == getState().colorMode && |
| 123 | colorProfile.dataspace == getState().dataspace && |
| 124 | colorProfile.renderIntent == getState().renderIntent && |
| 125 | targetDataspace == getState().targetDataspace) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 126 | return; |
| 127 | } |
| 128 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 129 | if (isVirtual()) { |
| 130 | ALOGW("%s: Invalid operation on virtual display", __func__); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 131 | return; |
| 132 | } |
| 133 | |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 134 | Output::setColorProfile(colorProfile); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 135 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 136 | const auto physicalId = PhysicalDisplayId::tryCast(mId); |
| 137 | LOG_FATAL_IF(!physicalId); |
| 138 | getCompositionEngine().getHwComposer().setActiveColorMode(*physicalId, colorProfile.mode, |
| 139 | colorProfile.renderIntent); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void Display::dump(std::string& out) const { |
| 143 | using android::base::StringAppendF; |
| 144 | |
| 145 | StringAppendF(&out, " Composition Display State: [\"%s\"]", getName().c_str()); |
| 146 | |
| 147 | out.append("\n "); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 148 | dumpVal(out, "isVirtual", isVirtual()); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 149 | dumpVal(out, "DisplayId", to_string(mId)); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 150 | out.append("\n"); |
| 151 | |
| 152 | Output::dumpBase(out); |
| 153 | } |
| 154 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 155 | void Display::createDisplayColorProfile(const DisplayColorProfileCreationArgs& args) { |
| 156 | setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(args)); |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 159 | void Display::createRenderSurface(const RenderSurfaceCreationArgs& args) { |
| 160 | setRenderSurface( |
| 161 | compositionengine::impl::createRenderSurface(getCompositionEngine(), *this, args)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 164 | void Display::createClientCompositionCache(uint32_t cacheSize) { |
| 165 | cacheClientCompositionRequests(cacheSize); |
| 166 | } |
| 167 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 168 | std::unique_ptr<compositionengine::OutputLayer> Display::createOutputLayer( |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 169 | const sp<compositionengine::LayerFE>& layerFE) const { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 170 | auto outputLayer = impl::createOutputLayer(*this, layerFE); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 171 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 172 | if (const auto halDisplayId = HalDisplayId::tryCast(mId); |
| 173 | outputLayer && !mIsDisconnected && halDisplayId) { |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 174 | auto& hwc = getCompositionEngine().getHwComposer(); |
Lloyd Pique | 1b33fc3 | 2021-05-07 14:36:58 -0700 | [diff] [blame] | 175 | auto hwcLayer = hwc.createLayer(*halDisplayId); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 176 | ALOGE_IF(!hwcLayer, "Failed to create a HWC layer for a HWC supported display %s", |
| 177 | getName().c_str()); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 178 | outputLayer->setHwcLayer(std::move(hwcLayer)); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 179 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 180 | return outputLayer; |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 183 | void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs& refreshArgs) { |
| 184 | Output::setReleasedLayers(refreshArgs); |
| 185 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 186 | if (mIsDisconnected || GpuVirtualDisplayId::tryCast(mId) || |
| 187 | refreshArgs.layersWithQueuedFrames.empty()) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 188 | return; |
| 189 | } |
| 190 | |
| 191 | // For layers that are being removed from a HWC display, and that have |
| 192 | // queued frames, add them to a a list of released layers so we can properly |
| 193 | // set a fence. |
| 194 | compositionengine::Output::ReleasedLayers releasedLayers; |
| 195 | |
| 196 | // Any non-null entries in the current list of layers are layers that are no |
| 197 | // longer going to be visible |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 198 | for (auto* outputLayer : getOutputLayersOrderedByZ()) { |
| 199 | if (!outputLayer) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 200 | continue; |
| 201 | } |
| 202 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 203 | compositionengine::LayerFE* layerFE = &outputLayer->getLayerFE(); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 204 | const bool hasQueuedFrames = |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 205 | std::any_of(refreshArgs.layersWithQueuedFrames.cbegin(), |
| 206 | refreshArgs.layersWithQueuedFrames.cend(), |
| 207 | [layerFE](sp<compositionengine::LayerFE> layerWithQueuedFrames) { |
| 208 | return layerFE == layerWithQueuedFrames.get(); |
| 209 | }); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 210 | |
| 211 | if (hasQueuedFrames) { |
| 212 | releasedLayers.emplace_back(layerFE); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | setReleasedLayers(std::move(releasedLayers)); |
| 217 | } |
| 218 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 219 | void Display::chooseCompositionStrategy() { |
| 220 | ATRACE_CALL(); |
| 221 | ALOGV(__FUNCTION__); |
| 222 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 223 | if (mIsDisconnected) { |
| 224 | return; |
| 225 | } |
| 226 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 227 | // Default to the base settings -- client composition only. |
| 228 | Output::chooseCompositionStrategy(); |
| 229 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 230 | // If we don't have a HWC display, then we are done. |
| 231 | const auto halDisplayId = HalDisplayId::tryCast(mId); |
| 232 | if (!halDisplayId) { |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 233 | return; |
| 234 | } |
| 235 | |
| 236 | // Get any composition changes requested by the HWC device, and apply them. |
| 237 | std::optional<android::HWComposer::DeviceRequestedChanges> changes; |
| 238 | auto& hwc = getCompositionEngine().getHwComposer(); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 239 | if (const auto physicalDisplayId = PhysicalDisplayId::tryCast(*halDisplayId); |
| 240 | physicalDisplayId && getState().displayBrightness) { |
| 241 | const status_t result = |
| 242 | hwc.setDisplayBrightness(*physicalDisplayId, *getState().displayBrightness, |
| 243 | Hwc2::Composer::DisplayBrightnessOptions{ |
| 244 | .applyImmediately = false}) |
| 245 | .get(); |
| 246 | ALOGE_IF(result != NO_ERROR, "setDisplayBrightness failed for %s: %d, (%s)", |
| 247 | getName().c_str(), result, strerror(-result)); |
| 248 | } |
| 249 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 250 | if (status_t result = |
| 251 | hwc.getDeviceCompositionChanges(*halDisplayId, anyLayersRequireClientComposition(), |
Ady Abraham | ec7aa8a | 2021-06-28 12:37:09 -0700 | [diff] [blame] | 252 | getState().earliestPresentTime, |
Ady Abraham | 43065bd | 2021-12-10 17:22:15 -0800 | [diff] [blame] | 253 | getState().previousPresentFence, |
| 254 | getState().expectedPresentTime, &changes); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 255 | result != NO_ERROR) { |
| 256 | ALOGE("chooseCompositionStrategy failed for %s: %d (%s)", getName().c_str(), result, |
| 257 | strerror(-result)); |
| 258 | return; |
| 259 | } |
| 260 | if (changes) { |
| 261 | applyChangedTypesToLayers(changes->changedTypes); |
| 262 | applyDisplayRequests(changes->displayRequests); |
| 263 | applyLayerRequestsToLayers(changes->layerRequests); |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 264 | applyClientTargetRequests(changes->clientTargetProperty, |
| 265 | changes->clientTargetWhitePointNits); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | // Determine what type of composition we are doing from the final state |
| 269 | auto& state = editState(); |
| 270 | state.usesClientComposition = anyLayersRequireClientComposition(); |
| 271 | state.usesDeviceComposition = !allLayersRequireClientComposition(); |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 272 | // Clear out the display brightness now that it's been communicated to composer. |
| 273 | state.displayBrightness.reset(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 276 | bool Display::getSkipColorTransform() const { |
Dominik Laskowski | 1162e47 | 2020-04-02 19:02:47 -0700 | [diff] [blame] | 277 | const auto& hwc = getCompositionEngine().getHwComposer(); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 278 | if (const auto halDisplayId = HalDisplayId::tryCast(mId)) { |
| 279 | return hwc.hasDisplayCapability(*halDisplayId, |
Leon Scroggins III | 5967aec | 2021-12-29 11:14:22 -0500 | [diff] [blame] | 280 | DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | return hwc.hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 286 | bool Display::anyLayersRequireClientComposition() const { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 287 | const auto layers = getOutputLayersOrderedByZ(); |
| 288 | return std::any_of(layers.begin(), layers.end(), |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 289 | [](const auto& layer) { return layer->requiresClientComposition(); }); |
| 290 | } |
| 291 | |
| 292 | bool Display::allLayersRequireClientComposition() const { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 293 | const auto layers = getOutputLayersOrderedByZ(); |
| 294 | return std::all_of(layers.begin(), layers.end(), |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 295 | [](const auto& layer) { return layer->requiresClientComposition(); }); |
| 296 | } |
| 297 | |
| 298 | void Display::applyChangedTypesToLayers(const ChangedTypes& changedTypes) { |
| 299 | if (changedTypes.empty()) { |
| 300 | return; |
| 301 | } |
| 302 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 303 | for (auto* layer : getOutputLayersOrderedByZ()) { |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 304 | auto hwcLayer = layer->getHwcLayer(); |
| 305 | if (!hwcLayer) { |
| 306 | continue; |
| 307 | } |
| 308 | |
| 309 | if (auto it = changedTypes.find(hwcLayer); it != changedTypes.end()) { |
| 310 | layer->applyDeviceCompositionTypeChange( |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 311 | static_cast<aidl::android::hardware::graphics::composer3::Composition>( |
| 312 | it->second)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | void Display::applyDisplayRequests(const DisplayRequests& displayRequests) { |
| 318 | auto& state = editState(); |
| 319 | state.flipClientTarget = (static_cast<uint32_t>(displayRequests) & |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 320 | static_cast<uint32_t>(hal::DisplayRequest::FLIP_CLIENT_TARGET)) != 0; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 321 | // Note: HWC2::DisplayRequest::WriteClientTargetToOutput is currently ignored. |
| 322 | } |
| 323 | |
| 324 | void Display::applyLayerRequestsToLayers(const LayerRequests& layerRequests) { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 325 | for (auto* layer : getOutputLayersOrderedByZ()) { |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 326 | layer->prepareForDeviceLayerRequests(); |
| 327 | |
| 328 | auto hwcLayer = layer->getHwcLayer(); |
| 329 | if (!hwcLayer) { |
| 330 | continue; |
| 331 | } |
| 332 | |
| 333 | if (auto it = layerRequests.find(hwcLayer); it != layerRequests.end()) { |
| 334 | layer->applyDeviceLayerRequest( |
| 335 | static_cast<Hwc2::IComposerClient::LayerRequest>(it->second)); |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 340 | void Display::applyClientTargetRequests(const ClientTargetProperty& clientTargetProperty, |
| 341 | float whitePointNits) { |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 342 | if (clientTargetProperty.dataspace == ui::Dataspace::UNKNOWN) { |
| 343 | return; |
| 344 | } |
Ady Abraham | 0094dc6 | 2021-06-03 10:08:33 -0700 | [diff] [blame] | 345 | |
| 346 | editState().dataspace = clientTargetProperty.dataspace; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 347 | editState().clientTargetWhitePointNits = whitePointNits; |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 348 | getRenderSurface()->setBufferDataspace(clientTargetProperty.dataspace); |
| 349 | getRenderSurface()->setBufferPixelFormat(clientTargetProperty.pixelFormat); |
| 350 | } |
| 351 | |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 352 | compositionengine::Output::FrameFences Display::presentAndGetFrameFences() { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 353 | auto fences = impl::Output::presentAndGetFrameFences(); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 354 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 355 | const auto halDisplayIdOpt = HalDisplayId::tryCast(mId); |
| 356 | if (mIsDisconnected || !halDisplayIdOpt) { |
| 357 | return fences; |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | auto& hwc = getCompositionEngine().getHwComposer(); |
Ady Abraham | ec7aa8a | 2021-06-28 12:37:09 -0700 | [diff] [blame] | 361 | hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime, |
| 362 | getState().previousPresentFence); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 363 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 364 | fences.presentFence = hwc.getPresentFence(*halDisplayIdOpt); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 365 | |
| 366 | // TODO(b/121291683): Change HWComposer call to return entire map |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 367 | for (const auto* layer : getOutputLayersOrderedByZ()) { |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 368 | auto hwcLayer = layer->getHwcLayer(); |
| 369 | if (!hwcLayer) { |
| 370 | continue; |
| 371 | } |
| 372 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 373 | fences.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*halDisplayIdOpt, hwcLayer)); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 376 | hwc.clearReleaseFences(*halDisplayIdOpt); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 377 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 378 | return fences; |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 379 | } |
| 380 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 381 | void Display::setExpensiveRenderingExpected(bool enabled) { |
| 382 | Output::setExpensiveRenderingExpected(enabled); |
| 383 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 384 | if (mPowerAdvisor && !GpuVirtualDisplayId::tryCast(mId)) { |
| 385 | mPowerAdvisor->setExpensiveRenderingExpected(mId, enabled); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 389 | void Display::finishFrame(const compositionengine::CompositionRefreshArgs& refreshArgs) { |
| 390 | // We only need to actually compose the display if: |
| 391 | // 1) It is being handled by hardware composer, which may need this to |
| 392 | // keep its virtual display state machine in sync, or |
| 393 | // 2) There is work to be done (the dirty region isn't empty) |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 394 | if (GpuVirtualDisplayId::tryCast(mId) && getDirtyRegion().isEmpty()) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 395 | ALOGV("Skipping display composition"); |
| 396 | return; |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | impl::Output::finishFrame(refreshArgs); |
| 400 | } |
| 401 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 402 | } // namespace android::compositionengine::impl |