blob: 84c22cf9bc19369745abe4ceb2652586dbaec3d4 [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);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070061}
62
63bool Display::isValid() const {
64 return Output::isValid() && mPowerAdvisor;
65}
66
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020067DisplayId Display::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -070068 return mId;
69}
70
71bool Display::isSecure() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -070072 return getState().isSecure;
Lloyd Pique45a165a2018-10-19 11:54:47 -070073}
74
75bool Display::isVirtual() const {
Dominik Laskowski29fa1462021-04-27 15:51:50 -070076 return VirtualDisplayId::tryCast(mId).has_value();
Lloyd Pique45a165a2018-10-19 11:54:47 -070077}
78
Lloyd Pique6c564cf2019-05-17 17:31:36 -070079std::optional<DisplayId> Display::getDisplayId() const {
80 return mId;
81}
82
Lloyd Pique45a165a2018-10-19 11:54:47 -070083void Display::disconnect() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020084 if (mIsDisconnected) {
Lloyd Pique45a165a2018-10-19 11:54:47 -070085 return;
86 }
87
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020088 mIsDisconnected = true;
Dominik Laskowski13948602021-03-08 20:48:28 -080089
90 if (const auto id = HalDisplayId::tryCast(mId)) {
91 getCompositionEngine().getHwComposer().disconnectDisplay(*id);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020092 }
Lloyd Pique45a165a2018-10-19 11:54:47 -070093}
94
Lloyd Pique3eb1b212019-03-07 21:15:40 -080095void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
96 Output::setColorTransform(args);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020097 const auto halDisplayId = HalDisplayId::tryCast(mId);
98 if (mIsDisconnected || !halDisplayId || CC_LIKELY(!args.colorTransformMatrix)) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -080099 return;
100 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700101
102 auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200103 status_t result = hwc.setColorTransform(*halDisplayId, *args.colorTransformMatrix);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700104 ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200105 to_string(mId).c_str(), result);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700106}
107
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800108void Display::setColorProfile(const ColorProfile& colorProfile) {
109 const ui::Dataspace targetDataspace =
110 getDisplayColorProfile()->getTargetDataspace(colorProfile.mode, colorProfile.dataspace,
111 colorProfile.colorSpaceAgnosticDataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800112
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800113 if (colorProfile.mode == getState().colorMode &&
114 colorProfile.dataspace == getState().dataspace &&
115 colorProfile.renderIntent == getState().renderIntent &&
116 targetDataspace == getState().targetDataspace) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700117 return;
118 }
119
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700120 if (isVirtual()) {
121 ALOGW("%s: Invalid operation on virtual display", __func__);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700122 return;
123 }
124
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800125 Output::setColorProfile(colorProfile);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700126
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200127 const auto physicalId = PhysicalDisplayId::tryCast(mId);
128 LOG_FATAL_IF(!physicalId);
129 getCompositionEngine().getHwComposer().setActiveColorMode(*physicalId, colorProfile.mode,
130 colorProfile.renderIntent);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700131}
132
133void 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 ");
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700139 dumpVal(out, "isVirtual", isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200140 dumpVal(out, "DisplayId", to_string(mId));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700141 out.append("\n");
142
143 Output::dumpBase(out);
144}
145
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700146void Display::createDisplayColorProfile(const DisplayColorProfileCreationArgs& args) {
147 setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(args));
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700148}
149
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700150void Display::createRenderSurface(const RenderSurfaceCreationArgs& args) {
151 setRenderSurface(
152 compositionengine::impl::createRenderSurface(getCompositionEngine(), *this, args));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700153}
154
Vishnu Nair9b079a22020-01-21 14:36:08 -0800155void Display::createClientCompositionCache(uint32_t cacheSize) {
156 cacheClientCompositionRequests(cacheSize);
157}
158
Lloyd Piquedf336d92019-03-07 21:38:42 -0800159std::unique_ptr<compositionengine::OutputLayer> Display::createOutputLayer(
Lloyd Piquedf336d92019-03-07 21:38:42 -0800160 const sp<compositionengine::LayerFE>& layerFE) const {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200161 auto outputLayer = impl::createOutputLayer(*this, layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800162
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200163 if (const auto halDisplayId = HalDisplayId::tryCast(mId);
164 outputLayer && !mIsDisconnected && halDisplayId) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800165 auto& hwc = getCompositionEngine().getHwComposer();
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700166 auto hwcLayer = hwc.createLayer(*halDisplayId);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800167 ALOGE_IF(!hwcLayer, "Failed to create a HWC layer for a HWC supported display %s",
168 getName().c_str());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200169 outputLayer->setHwcLayer(std::move(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800170 }
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200171 return outputLayer;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800172}
173
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800174void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs& refreshArgs) {
175 Output::setReleasedLayers(refreshArgs);
176
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200177 if (mIsDisconnected || GpuVirtualDisplayId::tryCast(mId) ||
178 refreshArgs.layersWithQueuedFrames.empty()) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800179 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 Piquede196652020-01-22 17:29:58 -0800189 for (auto* outputLayer : getOutputLayersOrderedByZ()) {
190 if (!outputLayer) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800191 continue;
192 }
193
Lloyd Piquede196652020-01-22 17:29:58 -0800194 compositionengine::LayerFE* layerFE = &outputLayer->getLayerFE();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800195 const bool hasQueuedFrames =
Lloyd Piquede196652020-01-22 17:29:58 -0800196 std::any_of(refreshArgs.layersWithQueuedFrames.cbegin(),
197 refreshArgs.layersWithQueuedFrames.cend(),
198 [layerFE](sp<compositionengine::LayerFE> layerWithQueuedFrames) {
199 return layerFE == layerWithQueuedFrames.get();
200 });
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800201
202 if (hasQueuedFrames) {
203 releasedLayers.emplace_back(layerFE);
204 }
205 }
206
207 setReleasedLayers(std::move(releasedLayers));
208}
209
Vishnu Naira3140382022-02-24 14:07:11 -0800210void Display::beginFrame() {
211 Output::beginFrame();
Lloyd Pique66d68602019-02-13 14:23:31 -0800212
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200213 // If we don't have a HWC display, then we are done.
214 const auto halDisplayId = HalDisplayId::tryCast(mId);
215 if (!halDisplayId) {
Robert Carr6fe2bef2022-03-09 13:49:41 -0800216 return;
Lloyd Pique66d68602019-02-13 14:23:31 -0800217 }
218
Lloyd Pique66d68602019-02-13 14:23:31 -0800219 auto& hwc = getCompositionEngine().getHwComposer();
Alec Mouricdf16792021-12-10 13:16:06 -0800220 if (const auto physicalDisplayId = PhysicalDisplayId::tryCast(*halDisplayId);
221 physicalDisplayId && getState().displayBrightness) {
222 const status_t result =
223 hwc.setDisplayBrightness(*physicalDisplayId, *getState().displayBrightness,
224 Hwc2::Composer::DisplayBrightnessOptions{
225 .applyImmediately = false})
226 .get();
227 ALOGE_IF(result != NO_ERROR, "setDisplayBrightness failed for %s: %d, (%s)",
228 getName().c_str(), result, strerror(-result));
229 }
Vishnu Naira3140382022-02-24 14:07:11 -0800230 // Clear out the display brightness now that it's been communicated to composer.
231 editState().displayBrightness.reset();
232}
Alec Mouricdf16792021-12-10 13:16:06 -0800233
Vishnu Naira3140382022-02-24 14:07:11 -0800234bool Display::chooseCompositionStrategy(
235 std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) {
236 ATRACE_CALL();
237 ALOGV(__FUNCTION__);
238
239 if (mIsDisconnected) {
240 return false;
241 }
242
243 // If we don't have a HWC display, then we are done.
244 const auto halDisplayId = HalDisplayId::tryCast(mId);
245 if (!halDisplayId) {
246 return false;
247 }
248
249 // Get any composition changes requested by the HWC device, and apply them.
250 std::optional<android::HWComposer::DeviceRequestedChanges> changes;
251 auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200252 if (status_t result =
253 hwc.getDeviceCompositionChanges(*halDisplayId, anyLayersRequireClientComposition(),
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700254 getState().earliestPresentTime,
Ady Abraham43065bd2021-12-10 17:22:15 -0800255 getState().previousPresentFence,
Vishnu Naira3140382022-02-24 14:07:11 -0800256 getState().expectedPresentTime, outChanges);
Lloyd Pique66d68602019-02-13 14:23:31 -0800257 result != NO_ERROR) {
258 ALOGE("chooseCompositionStrategy failed for %s: %d (%s)", getName().c_str(), result,
259 strerror(-result));
Vishnu Naira3140382022-02-24 14:07:11 -0800260 return false;
Lloyd Pique66d68602019-02-13 14:23:31 -0800261 }
Vishnu Naira3140382022-02-24 14:07:11 -0800262
263 return true;
264}
265
266void Display::applyCompositionStrategy(const std::optional<DeviceRequestedChanges>& changes) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800267 if (changes) {
268 applyChangedTypesToLayers(changes->changedTypes);
269 applyDisplayRequests(changes->displayRequests);
270 applyLayerRequestsToLayers(changes->layerRequests);
Alec Mouri85065692022-03-18 00:58:26 +0000271 applyClientTargetRequests(changes->clientTargetProperty);
Lloyd Pique66d68602019-02-13 14:23:31 -0800272 }
273
274 // Determine what type of composition we are doing from the final state
275 auto& state = editState();
276 state.usesClientComposition = anyLayersRequireClientComposition();
277 state.usesDeviceComposition = !allLayersRequireClientComposition();
278}
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
Ady Abrahamde549d42022-01-26 19:19:17 -0800287 return hwc.hasCapability(Capability::SKIP_CLIENT_COLOR_TRANSFORM);
Lloyd Pique688abd42019-02-15 15:42:24 -0800288}
289
Lloyd Pique66d68602019-02-13 14:23:31 -0800290bool Display::allLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700291 const auto layers = getOutputLayersOrderedByZ();
292 return std::all_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800293 [](const auto& layer) { return layer->requiresClientComposition(); });
294}
295
296void Display::applyChangedTypesToLayers(const ChangedTypes& changedTypes) {
297 if (changedTypes.empty()) {
298 return;
299 }
300
Lloyd Pique01c77c12019-04-17 12:48:32 -0700301 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800302 auto hwcLayer = layer->getHwcLayer();
303 if (!hwcLayer) {
304 continue;
305 }
306
307 if (auto it = changedTypes.find(hwcLayer); it != changedTypes.end()) {
308 layer->applyDeviceCompositionTypeChange(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500309 static_cast<aidl::android::hardware::graphics::composer3::Composition>(
310 it->second));
Lloyd Pique66d68602019-02-13 14:23:31 -0800311 }
312 }
313}
314
315void Display::applyDisplayRequests(const DisplayRequests& displayRequests) {
316 auto& state = editState();
317 state.flipClientTarget = (static_cast<uint32_t>(displayRequests) &
Peiyong Line9d809e2020-04-14 13:10:48 -0700318 static_cast<uint32_t>(hal::DisplayRequest::FLIP_CLIENT_TARGET)) != 0;
Lloyd Pique66d68602019-02-13 14:23:31 -0800319 // Note: HWC2::DisplayRequest::WriteClientTargetToOutput is currently ignored.
320}
321
322void Display::applyLayerRequestsToLayers(const LayerRequests& layerRequests) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700323 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800324 layer->prepareForDeviceLayerRequests();
325
326 auto hwcLayer = layer->getHwcLayer();
327 if (!hwcLayer) {
328 continue;
329 }
330
331 if (auto it = layerRequests.find(hwcLayer); it != layerRequests.end()) {
332 layer->applyDeviceLayerRequest(
333 static_cast<Hwc2::IComposerClient::LayerRequest>(it->second));
334 }
335 }
336}
337
Alec Mouri85065692022-03-18 00:58:26 +0000338void Display::applyClientTargetRequests(const ClientTargetProperty& clientTargetProperty) {
339 if (static_cast<ui::Dataspace>(clientTargetProperty.clientTargetProperty.dataspace) ==
340 ui::Dataspace::UNKNOWN) {
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700341 return;
342 }
Ady Abraham0094dc62021-06-03 10:08:33 -0700343
Alec Mouri85065692022-03-18 00:58:26 +0000344 editState().dataspace =
345 static_cast<ui::Dataspace>(clientTargetProperty.clientTargetProperty.dataspace);
346 editState().clientTargetBrightness = clientTargetProperty.brightness;
347 editState().clientTargetDimmingStage = clientTargetProperty.dimmingStage;
348 getRenderSurface()->setBufferDataspace(editState().dataspace);
349 getRenderSurface()->setBufferPixelFormat(
350 static_cast<ui::PixelFormat>(clientTargetProperty.clientTargetProperty.pixelFormat));
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700351}
352
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800353compositionengine::Output::FrameFences Display::presentAndGetFrameFences() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200354 auto fences = impl::Output::presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800355
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200356 const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
357 if (mIsDisconnected || !halDisplayIdOpt) {
358 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800359 }
360
361 auto& hwc = getCompositionEngine().getHwComposer();
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700362 hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime,
363 getState().previousPresentFence);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800364
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200365 fences.presentFence = hwc.getPresentFence(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800366
367 // TODO(b/121291683): Change HWComposer call to return entire map
Lloyd Pique01c77c12019-04-17 12:48:32 -0700368 for (const auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800369 auto hwcLayer = layer->getHwcLayer();
370 if (!hwcLayer) {
371 continue;
372 }
373
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200374 fences.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*halDisplayIdOpt, hwcLayer));
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800375 }
376
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200377 hwc.clearReleaseFences(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800378
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200379 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800380}
381
Lloyd Pique688abd42019-02-15 15:42:24 -0800382void Display::setExpensiveRenderingExpected(bool enabled) {
383 Output::setExpensiveRenderingExpected(enabled);
384
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200385 if (mPowerAdvisor && !GpuVirtualDisplayId::tryCast(mId)) {
386 mPowerAdvisor->setExpensiveRenderingExpected(mId, enabled);
Lloyd Pique688abd42019-02-15 15:42:24 -0800387 }
388}
389
Vishnu Naira3140382022-02-24 14:07:11 -0800390void Display::finishFrame(const compositionengine::CompositionRefreshArgs& refreshArgs,
391 GpuCompositionResult&& result) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800392 // We only need to actually compose the display if:
393 // 1) It is being handled by hardware composer, which may need this to
394 // keep its virtual display state machine in sync, or
395 // 2) There is work to be done (the dirty region isn't empty)
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700396 if (GpuVirtualDisplayId::tryCast(mId) && getDirtyRegion().isEmpty()) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200397 ALOGV("Skipping display composition");
398 return;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800399 }
400
Vishnu Naira3140382022-02-24 14:07:11 -0800401 impl::Output::finishFrame(refreshArgs, std::move(result));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800402}
403
Lloyd Pique45a165a2018-10-19 11:54:47 -0700404} // namespace android::compositionengine::impl