blob: 29c146b013dae85049dc11b8e14e8cf2e8dd5dae [file] [log] [blame]
Lloyd Pique45a165a2018-10-19 11:54:47 -07001/*
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 Pique32cbe282018-10-19 13:09:22 -070017#include <android-base/stringprintf.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070018#include <compositionengine/CompositionEngine.h>
Lloyd Piqued3d69882019-02-28 16:03:46 -080019#include <compositionengine/CompositionRefreshArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070020#include <compositionengine/DisplayCreationArgs.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070021#include <compositionengine/DisplaySurface.h>
Lloyd Piquedf336d92019-03-07 21:38:42 -080022#include <compositionengine/LayerFE.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070023#include <compositionengine/impl/Display.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070024#include <compositionengine/impl/DisplayColorProfile.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070025#include <compositionengine/impl/DumpHelpers.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080026#include <compositionengine/impl/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070027#include <compositionengine/impl/RenderSurface.h>
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080028
Lloyd Pique66d68602019-02-13 14:23:31 -080029#include <utils/Trace.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070030
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080031// TODO(b/129481165): remove the #pragma below and fix conversion issues
32#pragma clang diagnostic push
33#pragma clang diagnostic ignored "-Wconversion"
34
Lloyd Pique45a165a2018-10-19 11:54:47 -070035#include "DisplayHardware/HWComposer.h"
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080036
37// TODO(b/129481165): remove the #pragma below and fix conversion issues
38#pragma clang diagnostic pop // ignored "-Wconversion"
39
Lloyd Pique688abd42019-02-15 15:42:24 -080040#include "DisplayHardware/PowerAdvisor.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070041
Leon Scroggins III5967aec2021-12-29 11:14:22 -050042using aidl::android::hardware::graphics::composer3::DisplayCapability;
43
Lloyd Pique45a165a2018-10-19 11:54:47 -070044namespace android::compositionengine::impl {
45
Lloyd Pique35fca9d2019-02-13 14:24:11 -080046std::shared_ptr<Display> createDisplay(
Lloyd Pique45a165a2018-10-19 11:54:47 -070047 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070048 const compositionengine::DisplayCreationArgs& args) {
49 return createDisplayTemplated<Display>(compositionEngine, args);
Lloyd Pique45a165a2018-10-19 11:54:47 -070050}
51
Lloyd Pique45a165a2018-10-19 11:54:47 -070052Display::~Display() = default;
53
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070054void Display::setConfiguration(const compositionengine::DisplayCreationArgs& args) {
Dominik Laskowski13948602021-03-08 20:48:28 -080055 mId = args.id;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070056 mPowerAdvisor = args.powerAdvisor;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070057 editState().isSecure = args.isSecure;
Angel Aguayob084e0c2021-08-04 23:27:28 +000058 editState().displaySpace.setBounds(args.pixels);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070059 setName(args.name);
Kriti Dang646f8ec2022-01-18 14:35:02 +010060 bool isBootModeSupported = getCompositionEngine().getHwComposer().getBootDisplayModeSupport();
61 const auto physicalId = PhysicalDisplayId::tryCast(mId);
Kriti Dang16ca2972022-02-01 20:07:03 +010062 if (!physicalId || !isBootModeSupported) {
63 return;
64 }
65 std::optional<hal::HWConfigId> preferredBootModeId =
66 getCompositionEngine().getHwComposer().getPreferredBootDisplayMode(*physicalId);
67 if (preferredBootModeId.has_value()) {
68 mPreferredBootDisplayModeId = static_cast<int32_t>(preferredBootModeId.value());
Kriti Dang646f8ec2022-01-18 14:35:02 +010069 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070070}
71
72bool Display::isValid() const {
73 return Output::isValid() && mPowerAdvisor;
74}
75
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020076DisplayId Display::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -070077 return mId;
78}
79
80bool Display::isSecure() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -070081 return getState().isSecure;
Lloyd Pique45a165a2018-10-19 11:54:47 -070082}
83
84bool Display::isVirtual() const {
Dominik Laskowski29fa1462021-04-27 15:51:50 -070085 return VirtualDisplayId::tryCast(mId).has_value();
Lloyd Pique45a165a2018-10-19 11:54:47 -070086}
87
Lloyd Pique6c564cf2019-05-17 17:31:36 -070088std::optional<DisplayId> Display::getDisplayId() const {
89 return mId;
90}
91
Kriti Dang646f8ec2022-01-18 14:35:02 +010092int32_t Display::getPreferredBootModeId() const {
93 return mPreferredBootDisplayModeId;
94}
95
Lloyd Pique45a165a2018-10-19 11:54:47 -070096void Display::disconnect() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020097 if (mIsDisconnected) {
Lloyd Pique45a165a2018-10-19 11:54:47 -070098 return;
99 }
100
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200101 mIsDisconnected = true;
Dominik Laskowski13948602021-03-08 20:48:28 -0800102
103 if (const auto id = HalDisplayId::tryCast(mId)) {
104 getCompositionEngine().getHwComposer().disconnectDisplay(*id);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200105 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700106}
107
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800108void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
109 Output::setColorTransform(args);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200110 const auto halDisplayId = HalDisplayId::tryCast(mId);
111 if (mIsDisconnected || !halDisplayId || CC_LIKELY(!args.colorTransformMatrix)) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800112 return;
113 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700114
115 auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200116 status_t result = hwc.setColorTransform(*halDisplayId, *args.colorTransformMatrix);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700117 ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200118 to_string(mId).c_str(), result);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700119}
120
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800121void Display::setColorProfile(const ColorProfile& colorProfile) {
122 const ui::Dataspace targetDataspace =
123 getDisplayColorProfile()->getTargetDataspace(colorProfile.mode, colorProfile.dataspace,
124 colorProfile.colorSpaceAgnosticDataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800125
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800126 if (colorProfile.mode == getState().colorMode &&
127 colorProfile.dataspace == getState().dataspace &&
128 colorProfile.renderIntent == getState().renderIntent &&
129 targetDataspace == getState().targetDataspace) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700130 return;
131 }
132
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700133 if (isVirtual()) {
134 ALOGW("%s: Invalid operation on virtual display", __func__);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700135 return;
136 }
137
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800138 Output::setColorProfile(colorProfile);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700139
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200140 const auto physicalId = PhysicalDisplayId::tryCast(mId);
141 LOG_FATAL_IF(!physicalId);
142 getCompositionEngine().getHwComposer().setActiveColorMode(*physicalId, colorProfile.mode,
143 colorProfile.renderIntent);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700144}
145
146void 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 ");
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700152 dumpVal(out, "isVirtual", isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200153 dumpVal(out, "DisplayId", to_string(mId));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700154 out.append("\n");
155
156 Output::dumpBase(out);
157}
158
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700159void Display::createDisplayColorProfile(const DisplayColorProfileCreationArgs& args) {
160 setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(args));
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700161}
162
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700163void Display::createRenderSurface(const RenderSurfaceCreationArgs& args) {
164 setRenderSurface(
165 compositionengine::impl::createRenderSurface(getCompositionEngine(), *this, args));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700166}
167
Vishnu Nair9b079a22020-01-21 14:36:08 -0800168void Display::createClientCompositionCache(uint32_t cacheSize) {
169 cacheClientCompositionRequests(cacheSize);
170}
171
Lloyd Piquedf336d92019-03-07 21:38:42 -0800172std::unique_ptr<compositionengine::OutputLayer> Display::createOutputLayer(
Lloyd Piquedf336d92019-03-07 21:38:42 -0800173 const sp<compositionengine::LayerFE>& layerFE) const {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200174 auto outputLayer = impl::createOutputLayer(*this, layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800175
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200176 if (const auto halDisplayId = HalDisplayId::tryCast(mId);
177 outputLayer && !mIsDisconnected && halDisplayId) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800178 auto& hwc = getCompositionEngine().getHwComposer();
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700179 auto hwcLayer = hwc.createLayer(*halDisplayId);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800180 ALOGE_IF(!hwcLayer, "Failed to create a HWC layer for a HWC supported display %s",
181 getName().c_str());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200182 outputLayer->setHwcLayer(std::move(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800183 }
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200184 return outputLayer;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800185}
186
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800187void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs& refreshArgs) {
188 Output::setReleasedLayers(refreshArgs);
189
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200190 if (mIsDisconnected || GpuVirtualDisplayId::tryCast(mId) ||
191 refreshArgs.layersWithQueuedFrames.empty()) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800192 return;
193 }
194
195 // For layers that are being removed from a HWC display, and that have
196 // queued frames, add them to a a list of released layers so we can properly
197 // set a fence.
198 compositionengine::Output::ReleasedLayers releasedLayers;
199
200 // Any non-null entries in the current list of layers are layers that are no
201 // longer going to be visible
Lloyd Piquede196652020-01-22 17:29:58 -0800202 for (auto* outputLayer : getOutputLayersOrderedByZ()) {
203 if (!outputLayer) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800204 continue;
205 }
206
Lloyd Piquede196652020-01-22 17:29:58 -0800207 compositionengine::LayerFE* layerFE = &outputLayer->getLayerFE();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800208 const bool hasQueuedFrames =
Lloyd Piquede196652020-01-22 17:29:58 -0800209 std::any_of(refreshArgs.layersWithQueuedFrames.cbegin(),
210 refreshArgs.layersWithQueuedFrames.cend(),
211 [layerFE](sp<compositionengine::LayerFE> layerWithQueuedFrames) {
212 return layerFE == layerWithQueuedFrames.get();
213 });
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800214
215 if (hasQueuedFrames) {
216 releasedLayers.emplace_back(layerFE);
217 }
218 }
219
220 setReleasedLayers(std::move(releasedLayers));
221}
222
Lloyd Pique66d68602019-02-13 14:23:31 -0800223void Display::chooseCompositionStrategy() {
224 ATRACE_CALL();
225 ALOGV(__FUNCTION__);
226
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200227 if (mIsDisconnected) {
228 return;
229 }
230
Lloyd Pique66d68602019-02-13 14:23:31 -0800231 // Default to the base settings -- client composition only.
232 Output::chooseCompositionStrategy();
233
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200234 // If we don't have a HWC display, then we are done.
235 const auto halDisplayId = HalDisplayId::tryCast(mId);
236 if (!halDisplayId) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800237 return;
238 }
239
240 // Get any composition changes requested by the HWC device, and apply them.
241 std::optional<android::HWComposer::DeviceRequestedChanges> changes;
242 auto& hwc = getCompositionEngine().getHwComposer();
Alec Mouricdf16792021-12-10 13:16:06 -0800243 if (const auto physicalDisplayId = PhysicalDisplayId::tryCast(*halDisplayId);
244 physicalDisplayId && getState().displayBrightness) {
245 const status_t result =
246 hwc.setDisplayBrightness(*physicalDisplayId, *getState().displayBrightness,
247 Hwc2::Composer::DisplayBrightnessOptions{
248 .applyImmediately = false})
249 .get();
250 ALOGE_IF(result != NO_ERROR, "setDisplayBrightness failed for %s: %d, (%s)",
251 getName().c_str(), result, strerror(-result));
252 }
253
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200254 if (status_t result =
255 hwc.getDeviceCompositionChanges(*halDisplayId, anyLayersRequireClientComposition(),
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700256 getState().earliestPresentTime,
Ady Abraham43065bd2021-12-10 17:22:15 -0800257 getState().previousPresentFence,
258 getState().expectedPresentTime, &changes);
Lloyd Pique66d68602019-02-13 14:23:31 -0800259 result != NO_ERROR) {
260 ALOGE("chooseCompositionStrategy failed for %s: %d (%s)", getName().c_str(), result,
261 strerror(-result));
262 return;
263 }
264 if (changes) {
265 applyChangedTypesToLayers(changes->changedTypes);
266 applyDisplayRequests(changes->displayRequests);
267 applyLayerRequestsToLayers(changes->layerRequests);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700268 applyClientTargetRequests(changes->clientTargetProperty,
269 changes->clientTargetWhitePointNits);
Lloyd Pique66d68602019-02-13 14:23:31 -0800270 }
271
272 // Determine what type of composition we are doing from the final state
273 auto& state = editState();
274 state.usesClientComposition = anyLayersRequireClientComposition();
275 state.usesDeviceComposition = !allLayersRequireClientComposition();
Alec Mouricdf16792021-12-10 13:16:06 -0800276 // Clear out the display brightness now that it's been communicated to composer.
277 state.displayBrightness.reset();
Lloyd Pique66d68602019-02-13 14:23:31 -0800278}
279
Lloyd Pique688abd42019-02-15 15:42:24 -0800280bool Display::getSkipColorTransform() const {
Dominik Laskowski1162e472020-04-02 19:02:47 -0700281 const auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200282 if (const auto halDisplayId = HalDisplayId::tryCast(mId)) {
283 return hwc.hasDisplayCapability(*halDisplayId,
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500284 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200285 }
286
287 return hwc.hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM);
Lloyd Pique688abd42019-02-15 15:42:24 -0800288}
289
Lloyd Pique66d68602019-02-13 14:23:31 -0800290bool Display::anyLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700291 const auto layers = getOutputLayersOrderedByZ();
292 return std::any_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800293 [](const auto& layer) { return layer->requiresClientComposition(); });
294}
295
296bool Display::allLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700297 const auto layers = getOutputLayersOrderedByZ();
298 return std::all_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800299 [](const auto& layer) { return layer->requiresClientComposition(); });
300}
301
302void Display::applyChangedTypesToLayers(const ChangedTypes& changedTypes) {
303 if (changedTypes.empty()) {
304 return;
305 }
306
Lloyd Pique01c77c12019-04-17 12:48:32 -0700307 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800308 auto hwcLayer = layer->getHwcLayer();
309 if (!hwcLayer) {
310 continue;
311 }
312
313 if (auto it = changedTypes.find(hwcLayer); it != changedTypes.end()) {
314 layer->applyDeviceCompositionTypeChange(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500315 static_cast<aidl::android::hardware::graphics::composer3::Composition>(
316 it->second));
Lloyd Pique66d68602019-02-13 14:23:31 -0800317 }
318 }
319}
320
321void Display::applyDisplayRequests(const DisplayRequests& displayRequests) {
322 auto& state = editState();
323 state.flipClientTarget = (static_cast<uint32_t>(displayRequests) &
Peiyong Line9d809e2020-04-14 13:10:48 -0700324 static_cast<uint32_t>(hal::DisplayRequest::FLIP_CLIENT_TARGET)) != 0;
Lloyd Pique66d68602019-02-13 14:23:31 -0800325 // Note: HWC2::DisplayRequest::WriteClientTargetToOutput is currently ignored.
326}
327
328void Display::applyLayerRequestsToLayers(const LayerRequests& layerRequests) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700329 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800330 layer->prepareForDeviceLayerRequests();
331
332 auto hwcLayer = layer->getHwcLayer();
333 if (!hwcLayer) {
334 continue;
335 }
336
337 if (auto it = layerRequests.find(hwcLayer); it != layerRequests.end()) {
338 layer->applyDeviceLayerRequest(
339 static_cast<Hwc2::IComposerClient::LayerRequest>(it->second));
340 }
341 }
342}
343
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700344void Display::applyClientTargetRequests(const ClientTargetProperty& clientTargetProperty,
345 float whitePointNits) {
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700346 if (clientTargetProperty.dataspace == ui::Dataspace::UNKNOWN) {
347 return;
348 }
Ady Abraham0094dc62021-06-03 10:08:33 -0700349
350 editState().dataspace = clientTargetProperty.dataspace;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700351 editState().clientTargetWhitePointNits = whitePointNits;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700352 getRenderSurface()->setBufferDataspace(clientTargetProperty.dataspace);
353 getRenderSurface()->setBufferPixelFormat(clientTargetProperty.pixelFormat);
354}
355
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800356compositionengine::Output::FrameFences Display::presentAndGetFrameFences() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200357 auto fences = impl::Output::presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800358
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200359 const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
360 if (mIsDisconnected || !halDisplayIdOpt) {
361 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800362 }
363
364 auto& hwc = getCompositionEngine().getHwComposer();
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700365 hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime,
366 getState().previousPresentFence);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800367
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200368 fences.presentFence = hwc.getPresentFence(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800369
370 // TODO(b/121291683): Change HWComposer call to return entire map
Lloyd Pique01c77c12019-04-17 12:48:32 -0700371 for (const auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800372 auto hwcLayer = layer->getHwcLayer();
373 if (!hwcLayer) {
374 continue;
375 }
376
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200377 fences.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*halDisplayIdOpt, hwcLayer));
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800378 }
379
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200380 hwc.clearReleaseFences(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800381
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200382 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800383}
384
Lloyd Pique688abd42019-02-15 15:42:24 -0800385void Display::setExpensiveRenderingExpected(bool enabled) {
386 Output::setExpensiveRenderingExpected(enabled);
387
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200388 if (mPowerAdvisor && !GpuVirtualDisplayId::tryCast(mId)) {
389 mPowerAdvisor->setExpensiveRenderingExpected(mId, enabled);
Lloyd Pique688abd42019-02-15 15:42:24 -0800390 }
391}
392
Lloyd Piqued3d69882019-02-28 16:03:46 -0800393void Display::finishFrame(const compositionengine::CompositionRefreshArgs& refreshArgs) {
394 // We only need to actually compose the display if:
395 // 1) It is being handled by hardware composer, which may need this to
396 // keep its virtual display state machine in sync, or
397 // 2) There is work to be done (the dirty region isn't empty)
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700398 if (GpuVirtualDisplayId::tryCast(mId) && getDirtyRegion().isEmpty()) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200399 ALOGV("Skipping display composition");
400 return;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800401 }
402
403 impl::Output::finishFrame(refreshArgs);
404}
405
Lloyd Pique45a165a2018-10-19 11:54:47 -0700406} // namespace android::compositionengine::impl