blob: 09648c356d8617c7d5c64fc1ca8dcfdbd764e01c [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()) {
Kriti Dang30e378d2022-02-18 15:09:12 +010069 mPreferredBootHwcConfigId = 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 Dang30e378d2022-02-18 15:09:12 +010093int32_t Display::getPreferredBootHwcConfigId() const {
94 return mPreferredBootHwcConfigId;
Kriti Dang646f8ec2022-01-18 14:35:02 +010095}
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
Vishnu Nair7234fa52022-02-24 14:07:11 -0800224std::optional<android::HWComposer::DeviceRequestedChanges> Display::chooseCompositionStrategy() {
Lloyd Pique66d68602019-02-13 14:23:31 -0800225 ATRACE_CALL();
226 ALOGV(__FUNCTION__);
227
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200228 if (mIsDisconnected) {
Vishnu Nair7234fa52022-02-24 14:07:11 -0800229 return {};
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200230 }
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) {
Vishnu Nair7234fa52022-02-24 14:07:11 -0800238 return {};
Lloyd Pique66d68602019-02-13 14:23:31 -0800239 }
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));
Vishnu Nair7234fa52022-02-24 14:07:11 -0800263 return {};
Lloyd Pique66d68602019-02-13 14:23:31 -0800264 }
Vishnu Nair7234fa52022-02-24 14:07:11 -0800265
266 return changes;
267}
268
269void Display::applyCompositionStrategy(const std::optional<DeviceRequestedChanges>& changes) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800270 if (changes) {
271 applyChangedTypesToLayers(changes->changedTypes);
272 applyDisplayRequests(changes->displayRequests);
273 applyLayerRequestsToLayers(changes->layerRequests);
Alec Mourif8d093d2022-02-10 15:16:59 -0800274 applyClientTargetRequests(changes->clientTargetProperty, changes->clientTargetBrightness);
Lloyd Pique66d68602019-02-13 14:23:31 -0800275 }
276
277 // Determine what type of composition we are doing from the final state
278 auto& state = editState();
279 state.usesClientComposition = anyLayersRequireClientComposition();
280 state.usesDeviceComposition = !allLayersRequireClientComposition();
Alec Mouricdf16792021-12-10 13:16:06 -0800281 // Clear out the display brightness now that it's been communicated to composer.
282 state.displayBrightness.reset();
Lloyd Pique66d68602019-02-13 14:23:31 -0800283}
284
Lloyd Pique688abd42019-02-15 15:42:24 -0800285bool Display::getSkipColorTransform() const {
Dominik Laskowski1162e472020-04-02 19:02:47 -0700286 const auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200287 if (const auto halDisplayId = HalDisplayId::tryCast(mId)) {
288 return hwc.hasDisplayCapability(*halDisplayId,
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500289 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200290 }
291
Ady Abrahamde549d42022-01-26 19:19:17 -0800292 return hwc.hasCapability(Capability::SKIP_CLIENT_COLOR_TRANSFORM);
Lloyd Pique688abd42019-02-15 15:42:24 -0800293}
294
Lloyd Pique66d68602019-02-13 14:23:31 -0800295bool Display::allLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700296 const auto layers = getOutputLayersOrderedByZ();
297 return std::all_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800298 [](const auto& layer) { return layer->requiresClientComposition(); });
299}
300
301void Display::applyChangedTypesToLayers(const ChangedTypes& changedTypes) {
302 if (changedTypes.empty()) {
303 return;
304 }
305
Lloyd Pique01c77c12019-04-17 12:48:32 -0700306 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800307 auto hwcLayer = layer->getHwcLayer();
308 if (!hwcLayer) {
309 continue;
310 }
311
312 if (auto it = changedTypes.find(hwcLayer); it != changedTypes.end()) {
313 layer->applyDeviceCompositionTypeChange(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500314 static_cast<aidl::android::hardware::graphics::composer3::Composition>(
315 it->second));
Lloyd Pique66d68602019-02-13 14:23:31 -0800316 }
317 }
318}
319
320void Display::applyDisplayRequests(const DisplayRequests& displayRequests) {
321 auto& state = editState();
322 state.flipClientTarget = (static_cast<uint32_t>(displayRequests) &
Peiyong Line9d809e2020-04-14 13:10:48 -0700323 static_cast<uint32_t>(hal::DisplayRequest::FLIP_CLIENT_TARGET)) != 0;
Lloyd Pique66d68602019-02-13 14:23:31 -0800324 // Note: HWC2::DisplayRequest::WriteClientTargetToOutput is currently ignored.
325}
326
327void Display::applyLayerRequestsToLayers(const LayerRequests& layerRequests) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700328 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800329 layer->prepareForDeviceLayerRequests();
330
331 auto hwcLayer = layer->getHwcLayer();
332 if (!hwcLayer) {
333 continue;
334 }
335
336 if (auto it = layerRequests.find(hwcLayer); it != layerRequests.end()) {
337 layer->applyDeviceLayerRequest(
338 static_cast<Hwc2::IComposerClient::LayerRequest>(it->second));
339 }
340 }
341}
342
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700343void Display::applyClientTargetRequests(const ClientTargetProperty& clientTargetProperty,
Alec Mourif8d093d2022-02-10 15:16:59 -0800344 float brightness) {
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700345 if (clientTargetProperty.dataspace == ui::Dataspace::UNKNOWN) {
346 return;
347 }
Ady Abraham0094dc62021-06-03 10:08:33 -0700348
349 editState().dataspace = clientTargetProperty.dataspace;
Alec Mourif8d093d2022-02-10 15:16:59 -0800350 editState().clientTargetBrightness = brightness;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700351 getRenderSurface()->setBufferDataspace(clientTargetProperty.dataspace);
352 getRenderSurface()->setBufferPixelFormat(clientTargetProperty.pixelFormat);
353}
354
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800355compositionengine::Output::FrameFences Display::presentAndGetFrameFences() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200356 auto fences = impl::Output::presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800357
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200358 const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
359 if (mIsDisconnected || !halDisplayIdOpt) {
360 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800361 }
362
363 auto& hwc = getCompositionEngine().getHwComposer();
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700364 hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime,
365 getState().previousPresentFence);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800366
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200367 fences.presentFence = hwc.getPresentFence(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800368
369 // TODO(b/121291683): Change HWComposer call to return entire map
Lloyd Pique01c77c12019-04-17 12:48:32 -0700370 for (const auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800371 auto hwcLayer = layer->getHwcLayer();
372 if (!hwcLayer) {
373 continue;
374 }
375
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200376 fences.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*halDisplayIdOpt, hwcLayer));
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800377 }
378
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200379 hwc.clearReleaseFences(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800380
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200381 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800382}
383
Lloyd Pique688abd42019-02-15 15:42:24 -0800384void Display::setExpensiveRenderingExpected(bool enabled) {
385 Output::setExpensiveRenderingExpected(enabled);
386
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200387 if (mPowerAdvisor && !GpuVirtualDisplayId::tryCast(mId)) {
388 mPowerAdvisor->setExpensiveRenderingExpected(mId, enabled);
Lloyd Pique688abd42019-02-15 15:42:24 -0800389 }
390}
391
Vishnu Nair7234fa52022-02-24 14:07:11 -0800392void Display::finishFrame(const compositionengine::CompositionRefreshArgs& refreshArgs,
393 GpuCompositionResult&& result) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800394 // 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
Vishnu Nair7234fa52022-02-24 14:07:11 -0800403 impl::Output::finishFrame(refreshArgs, std::move(result));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800404}
405
Lloyd Pique45a165a2018-10-19 11:54:47 -0700406} // namespace android::compositionengine::impl