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