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