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