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