blob: a3188f37720605f2aa6fada7a12d6ab4881ff671 [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
Ady Abrahamde549d42022-01-26 19:19:17 -080042using aidl::android::hardware::graphics::composer3::Capability;
Leon Scroggins III5967aec2021-12-29 11:14:22 -050043using aidl::android::hardware::graphics::composer3::DisplayCapability;
44
Lloyd Pique45a165a2018-10-19 11:54:47 -070045namespace android::compositionengine::impl {
46
Lloyd Pique35fca9d2019-02-13 14:24:11 -080047std::shared_ptr<Display> createDisplay(
Lloyd Pique45a165a2018-10-19 11:54:47 -070048 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070049 const compositionengine::DisplayCreationArgs& args) {
50 return createDisplayTemplated<Display>(compositionEngine, args);
Lloyd Pique45a165a2018-10-19 11:54:47 -070051}
52
Lloyd Pique45a165a2018-10-19 11:54:47 -070053Display::~Display() = default;
54
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070055void Display::setConfiguration(const compositionengine::DisplayCreationArgs& args) {
Dominik Laskowski13948602021-03-08 20:48:28 -080056 mId = args.id;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070057 mPowerAdvisor = args.powerAdvisor;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070058 editState().isSecure = args.isSecure;
Angel Aguayob084e0c2021-08-04 23:27:28 +000059 editState().displaySpace.setBounds(args.pixels);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070060 setName(args.name);
Kriti Dang646f8ec2022-01-18 14:35:02 +010061 bool isBootModeSupported = getCompositionEngine().getHwComposer().getBootDisplayModeSupport();
62 const auto physicalId = PhysicalDisplayId::tryCast(mId);
Kriti Dang16ca2972022-02-01 20:07:03 +010063 if (!physicalId || !isBootModeSupported) {
64 return;
65 }
66 std::optional<hal::HWConfigId> preferredBootModeId =
67 getCompositionEngine().getHwComposer().getPreferredBootDisplayMode(*physicalId);
68 if (preferredBootModeId.has_value()) {
69 mPreferredBootDisplayModeId = static_cast<int32_t>(preferredBootModeId.value());
Kriti Dang646f8ec2022-01-18 14:35:02 +010070 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070071}
72
73bool Display::isValid() const {
74 return Output::isValid() && mPowerAdvisor;
75}
76
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020077DisplayId Display::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -070078 return mId;
79}
80
81bool Display::isSecure() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -070082 return getState().isSecure;
Lloyd Pique45a165a2018-10-19 11:54:47 -070083}
84
85bool Display::isVirtual() const {
Dominik Laskowski29fa1462021-04-27 15:51:50 -070086 return VirtualDisplayId::tryCast(mId).has_value();
Lloyd Pique45a165a2018-10-19 11:54:47 -070087}
88
Lloyd Pique6c564cf2019-05-17 17:31:36 -070089std::optional<DisplayId> Display::getDisplayId() const {
90 return mId;
91}
92
Kriti Dang646f8ec2022-01-18 14:35:02 +010093int32_t Display::getPreferredBootModeId() const {
94 return mPreferredBootDisplayModeId;
95}
96
Lloyd Pique45a165a2018-10-19 11:54:47 -070097void Display::disconnect() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020098 if (mIsDisconnected) {
Lloyd Pique45a165a2018-10-19 11:54:47 -070099 return;
100 }
101
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200102 mIsDisconnected = true;
Dominik Laskowski13948602021-03-08 20:48:28 -0800103
104 if (const auto id = HalDisplayId::tryCast(mId)) {
105 getCompositionEngine().getHwComposer().disconnectDisplay(*id);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200106 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700107}
108
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800109void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
110 Output::setColorTransform(args);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200111 const auto halDisplayId = HalDisplayId::tryCast(mId);
112 if (mIsDisconnected || !halDisplayId || CC_LIKELY(!args.colorTransformMatrix)) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800113 return;
114 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700115
116 auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200117 status_t result = hwc.setColorTransform(*halDisplayId, *args.colorTransformMatrix);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700118 ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200119 to_string(mId).c_str(), result);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700120}
121
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800122void Display::setColorProfile(const ColorProfile& colorProfile) {
123 const ui::Dataspace targetDataspace =
124 getDisplayColorProfile()->getTargetDataspace(colorProfile.mode, colorProfile.dataspace,
125 colorProfile.colorSpaceAgnosticDataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800126
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800127 if (colorProfile.mode == getState().colorMode &&
128 colorProfile.dataspace == getState().dataspace &&
129 colorProfile.renderIntent == getState().renderIntent &&
130 targetDataspace == getState().targetDataspace) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700131 return;
132 }
133
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700134 if (isVirtual()) {
135 ALOGW("%s: Invalid operation on virtual display", __func__);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700136 return;
137 }
138
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800139 Output::setColorProfile(colorProfile);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700140
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200141 const auto physicalId = PhysicalDisplayId::tryCast(mId);
142 LOG_FATAL_IF(!physicalId);
143 getCompositionEngine().getHwComposer().setActiveColorMode(*physicalId, colorProfile.mode,
144 colorProfile.renderIntent);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700145}
146
147void Display::dump(std::string& out) const {
148 using android::base::StringAppendF;
149
150 StringAppendF(&out, " Composition Display State: [\"%s\"]", getName().c_str());
151
152 out.append("\n ");
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700153 dumpVal(out, "isVirtual", isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200154 dumpVal(out, "DisplayId", to_string(mId));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700155 out.append("\n");
156
157 Output::dumpBase(out);
158}
159
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700160void Display::createDisplayColorProfile(const DisplayColorProfileCreationArgs& args) {
161 setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(args));
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700162}
163
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700164void Display::createRenderSurface(const RenderSurfaceCreationArgs& args) {
165 setRenderSurface(
166 compositionengine::impl::createRenderSurface(getCompositionEngine(), *this, args));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700167}
168
Vishnu Nair9b079a22020-01-21 14:36:08 -0800169void Display::createClientCompositionCache(uint32_t cacheSize) {
170 cacheClientCompositionRequests(cacheSize);
171}
172
Lloyd Piquedf336d92019-03-07 21:38:42 -0800173std::unique_ptr<compositionengine::OutputLayer> Display::createOutputLayer(
Lloyd Piquedf336d92019-03-07 21:38:42 -0800174 const sp<compositionengine::LayerFE>& layerFE) const {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200175 auto outputLayer = impl::createOutputLayer(*this, layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800176
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200177 if (const auto halDisplayId = HalDisplayId::tryCast(mId);
178 outputLayer && !mIsDisconnected && halDisplayId) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800179 auto& hwc = getCompositionEngine().getHwComposer();
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700180 auto hwcLayer = hwc.createLayer(*halDisplayId);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800181 ALOGE_IF(!hwcLayer, "Failed to create a HWC layer for a HWC supported display %s",
182 getName().c_str());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200183 outputLayer->setHwcLayer(std::move(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800184 }
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200185 return outputLayer;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800186}
187
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800188void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs& refreshArgs) {
189 Output::setReleasedLayers(refreshArgs);
190
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200191 if (mIsDisconnected || GpuVirtualDisplayId::tryCast(mId) ||
192 refreshArgs.layersWithQueuedFrames.empty()) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800193 return;
194 }
195
196 // For layers that are being removed from a HWC display, and that have
197 // queued frames, add them to a a list of released layers so we can properly
198 // set a fence.
199 compositionengine::Output::ReleasedLayers releasedLayers;
200
201 // Any non-null entries in the current list of layers are layers that are no
202 // longer going to be visible
Lloyd Piquede196652020-01-22 17:29:58 -0800203 for (auto* outputLayer : getOutputLayersOrderedByZ()) {
204 if (!outputLayer) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800205 continue;
206 }
207
Lloyd Piquede196652020-01-22 17:29:58 -0800208 compositionengine::LayerFE* layerFE = &outputLayer->getLayerFE();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800209 const bool hasQueuedFrames =
Lloyd Piquede196652020-01-22 17:29:58 -0800210 std::any_of(refreshArgs.layersWithQueuedFrames.cbegin(),
211 refreshArgs.layersWithQueuedFrames.cend(),
212 [layerFE](sp<compositionengine::LayerFE> layerWithQueuedFrames) {
213 return layerFE == layerWithQueuedFrames.get();
214 });
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800215
216 if (hasQueuedFrames) {
217 releasedLayers.emplace_back(layerFE);
218 }
219 }
220
221 setReleasedLayers(std::move(releasedLayers));
222}
223
Lloyd Pique66d68602019-02-13 14:23:31 -0800224void Display::chooseCompositionStrategy() {
225 ATRACE_CALL();
226 ALOGV(__FUNCTION__);
227
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200228 if (mIsDisconnected) {
229 return;
230 }
231
Lloyd Pique66d68602019-02-13 14:23:31 -0800232 // Default to the base settings -- client composition only.
233 Output::chooseCompositionStrategy();
234
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200235 // If we don't have a HWC display, then we are done.
236 const auto halDisplayId = HalDisplayId::tryCast(mId);
237 if (!halDisplayId) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800238 return;
239 }
240
241 // Get any composition changes requested by the HWC device, and apply them.
242 std::optional<android::HWComposer::DeviceRequestedChanges> changes;
243 auto& hwc = getCompositionEngine().getHwComposer();
Alec Mouricdf16792021-12-10 13:16:06 -0800244 if (const auto physicalDisplayId = PhysicalDisplayId::tryCast(*halDisplayId);
245 physicalDisplayId && getState().displayBrightness) {
246 const status_t result =
247 hwc.setDisplayBrightness(*physicalDisplayId, *getState().displayBrightness,
248 Hwc2::Composer::DisplayBrightnessOptions{
249 .applyImmediately = false})
250 .get();
251 ALOGE_IF(result != NO_ERROR, "setDisplayBrightness failed for %s: %d, (%s)",
252 getName().c_str(), result, strerror(-result));
253 }
254
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200255 if (status_t result =
256 hwc.getDeviceCompositionChanges(*halDisplayId, anyLayersRequireClientComposition(),
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700257 getState().earliestPresentTime,
Ady Abraham43065bd2021-12-10 17:22:15 -0800258 getState().previousPresentFence,
259 getState().expectedPresentTime, &changes);
Lloyd Pique66d68602019-02-13 14:23:31 -0800260 result != NO_ERROR) {
261 ALOGE("chooseCompositionStrategy failed for %s: %d (%s)", getName().c_str(), result,
262 strerror(-result));
263 return;
264 }
265 if (changes) {
266 applyChangedTypesToLayers(changes->changedTypes);
267 applyDisplayRequests(changes->displayRequests);
268 applyLayerRequestsToLayers(changes->layerRequests);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700269 applyClientTargetRequests(changes->clientTargetProperty,
270 changes->clientTargetWhitePointNits);
Lloyd Pique66d68602019-02-13 14:23:31 -0800271 }
272
273 // Determine what type of composition we are doing from the final state
274 auto& state = editState();
275 state.usesClientComposition = anyLayersRequireClientComposition();
276 state.usesDeviceComposition = !allLayersRequireClientComposition();
Alec Mouricdf16792021-12-10 13:16:06 -0800277 // Clear out the display brightness now that it's been communicated to composer.
278 state.displayBrightness.reset();
Lloyd Pique66d68602019-02-13 14:23:31 -0800279}
280
Lloyd Pique688abd42019-02-15 15:42:24 -0800281bool Display::getSkipColorTransform() const {
Dominik Laskowski1162e472020-04-02 19:02:47 -0700282 const auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200283 if (const auto halDisplayId = HalDisplayId::tryCast(mId)) {
284 return hwc.hasDisplayCapability(*halDisplayId,
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500285 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200286 }
287
Ady Abrahamde549d42022-01-26 19:19:17 -0800288 return hwc.hasCapability(Capability::SKIP_CLIENT_COLOR_TRANSFORM);
Lloyd Pique688abd42019-02-15 15:42:24 -0800289}
290
Lloyd Pique66d68602019-02-13 14:23:31 -0800291bool Display::anyLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700292 const auto layers = getOutputLayersOrderedByZ();
293 return std::any_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800294 [](const auto& layer) { return layer->requiresClientComposition(); });
295}
296
297bool Display::allLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700298 const auto layers = getOutputLayersOrderedByZ();
299 return std::all_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800300 [](const auto& layer) { return layer->requiresClientComposition(); });
301}
302
303void Display::applyChangedTypesToLayers(const ChangedTypes& changedTypes) {
304 if (changedTypes.empty()) {
305 return;
306 }
307
Lloyd Pique01c77c12019-04-17 12:48:32 -0700308 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800309 auto hwcLayer = layer->getHwcLayer();
310 if (!hwcLayer) {
311 continue;
312 }
313
314 if (auto it = changedTypes.find(hwcLayer); it != changedTypes.end()) {
315 layer->applyDeviceCompositionTypeChange(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500316 static_cast<aidl::android::hardware::graphics::composer3::Composition>(
317 it->second));
Lloyd Pique66d68602019-02-13 14:23:31 -0800318 }
319 }
320}
321
322void Display::applyDisplayRequests(const DisplayRequests& displayRequests) {
323 auto& state = editState();
324 state.flipClientTarget = (static_cast<uint32_t>(displayRequests) &
Peiyong Line9d809e2020-04-14 13:10:48 -0700325 static_cast<uint32_t>(hal::DisplayRequest::FLIP_CLIENT_TARGET)) != 0;
Lloyd Pique66d68602019-02-13 14:23:31 -0800326 // Note: HWC2::DisplayRequest::WriteClientTargetToOutput is currently ignored.
327}
328
329void Display::applyLayerRequestsToLayers(const LayerRequests& layerRequests) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700330 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800331 layer->prepareForDeviceLayerRequests();
332
333 auto hwcLayer = layer->getHwcLayer();
334 if (!hwcLayer) {
335 continue;
336 }
337
338 if (auto it = layerRequests.find(hwcLayer); it != layerRequests.end()) {
339 layer->applyDeviceLayerRequest(
340 static_cast<Hwc2::IComposerClient::LayerRequest>(it->second));
341 }
342 }
343}
344
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700345void Display::applyClientTargetRequests(const ClientTargetProperty& clientTargetProperty,
346 float whitePointNits) {
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700347 if (clientTargetProperty.dataspace == ui::Dataspace::UNKNOWN) {
348 return;
349 }
Ady Abraham0094dc62021-06-03 10:08:33 -0700350
351 editState().dataspace = clientTargetProperty.dataspace;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700352 editState().clientTargetWhitePointNits = whitePointNits;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700353 getRenderSurface()->setBufferDataspace(clientTargetProperty.dataspace);
354 getRenderSurface()->setBufferPixelFormat(clientTargetProperty.pixelFormat);
355}
356
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800357compositionengine::Output::FrameFences Display::presentAndGetFrameFences() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200358 auto fences = impl::Output::presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800359
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200360 const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
361 if (mIsDisconnected || !halDisplayIdOpt) {
362 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800363 }
364
365 auto& hwc = getCompositionEngine().getHwComposer();
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700366 hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime,
367 getState().previousPresentFence);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800368
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200369 fences.presentFence = hwc.getPresentFence(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800370
371 // TODO(b/121291683): Change HWComposer call to return entire map
Lloyd Pique01c77c12019-04-17 12:48:32 -0700372 for (const auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800373 auto hwcLayer = layer->getHwcLayer();
374 if (!hwcLayer) {
375 continue;
376 }
377
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200378 fences.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*halDisplayIdOpt, hwcLayer));
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800379 }
380
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200381 hwc.clearReleaseFences(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800382
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200383 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800384}
385
Lloyd Pique688abd42019-02-15 15:42:24 -0800386void Display::setExpensiveRenderingExpected(bool enabled) {
387 Output::setExpensiveRenderingExpected(enabled);
388
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200389 if (mPowerAdvisor && !GpuVirtualDisplayId::tryCast(mId)) {
390 mPowerAdvisor->setExpensiveRenderingExpected(mId, enabled);
Lloyd Pique688abd42019-02-15 15:42:24 -0800391 }
392}
393
Lloyd Piqued3d69882019-02-28 16:03:46 -0800394void Display::finishFrame(const compositionengine::CompositionRefreshArgs& refreshArgs) {
395 // We only need to actually compose the display if:
396 // 1) It is being handled by hardware composer, which may need this to
397 // keep its virtual display state machine in sync, or
398 // 2) There is work to be done (the dirty region isn't empty)
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700399 if (GpuVirtualDisplayId::tryCast(mId) && getDirtyRegion().isEmpty()) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200400 ALOGV("Skipping display composition");
401 return;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800402 }
403
404 impl::Output::finishFrame(refreshArgs);
405}
406
Lloyd Pique45a165a2018-10-19 11:54:47 -0700407} // namespace android::compositionengine::impl