blob: cccf9072b10cd0d4fd907b1ad12fbc655ba6a930 [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 {
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700134 const char* const type = isVirtual() ? "virtual" : "physical";
135 base::StringAppendF(&out, "Display %s (%s, \"%s\")", to_string(mId).c_str(), type,
136 getName().c_str());
Lloyd Pique32cbe282018-10-19 13:09:22 -0700137
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700138 out.append("\n Composition Display State:\n");
Lloyd Pique32cbe282018-10-19 13:09:22 -0700139 Output::dumpBase(out);
140}
141
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700142void Display::createDisplayColorProfile(const DisplayColorProfileCreationArgs& args) {
143 setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(args));
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700144}
145
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700146void Display::createRenderSurface(const RenderSurfaceCreationArgs& args) {
147 setRenderSurface(
148 compositionengine::impl::createRenderSurface(getCompositionEngine(), *this, args));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700149}
150
Vishnu Nair9b079a22020-01-21 14:36:08 -0800151void Display::createClientCompositionCache(uint32_t cacheSize) {
152 cacheClientCompositionRequests(cacheSize);
153}
154
Lloyd Piquedf336d92019-03-07 21:38:42 -0800155std::unique_ptr<compositionengine::OutputLayer> Display::createOutputLayer(
Lloyd Piquedf336d92019-03-07 21:38:42 -0800156 const sp<compositionengine::LayerFE>& layerFE) const {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200157 auto outputLayer = impl::createOutputLayer(*this, layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800158
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200159 if (const auto halDisplayId = HalDisplayId::tryCast(mId);
160 outputLayer && !mIsDisconnected && halDisplayId) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800161 auto& hwc = getCompositionEngine().getHwComposer();
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700162 auto hwcLayer = hwc.createLayer(*halDisplayId);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800163 ALOGE_IF(!hwcLayer, "Failed to create a HWC layer for a HWC supported display %s",
164 getName().c_str());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200165 outputLayer->setHwcLayer(std::move(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800166 }
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200167 return outputLayer;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800168}
169
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800170void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs& refreshArgs) {
171 Output::setReleasedLayers(refreshArgs);
172
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200173 if (mIsDisconnected || GpuVirtualDisplayId::tryCast(mId) ||
174 refreshArgs.layersWithQueuedFrames.empty()) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800175 return;
176 }
177
178 // For layers that are being removed from a HWC display, and that have
179 // queued frames, add them to a a list of released layers so we can properly
180 // set a fence.
181 compositionengine::Output::ReleasedLayers releasedLayers;
182
183 // Any non-null entries in the current list of layers are layers that are no
184 // longer going to be visible
Lloyd Piquede196652020-01-22 17:29:58 -0800185 for (auto* outputLayer : getOutputLayersOrderedByZ()) {
186 if (!outputLayer) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800187 continue;
188 }
189
Lloyd Piquede196652020-01-22 17:29:58 -0800190 compositionengine::LayerFE* layerFE = &outputLayer->getLayerFE();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800191 const bool hasQueuedFrames =
Lloyd Piquede196652020-01-22 17:29:58 -0800192 std::any_of(refreshArgs.layersWithQueuedFrames.cbegin(),
193 refreshArgs.layersWithQueuedFrames.cend(),
194 [layerFE](sp<compositionengine::LayerFE> layerWithQueuedFrames) {
195 return layerFE == layerWithQueuedFrames.get();
196 });
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800197
198 if (hasQueuedFrames) {
199 releasedLayers.emplace_back(layerFE);
200 }
201 }
202
203 setReleasedLayers(std::move(releasedLayers));
204}
205
Vishnu Naira3140382022-02-24 14:07:11 -0800206void Display::beginFrame() {
207 Output::beginFrame();
Lloyd Pique66d68602019-02-13 14:23:31 -0800208
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200209 // If we don't have a HWC display, then we are done.
210 const auto halDisplayId = HalDisplayId::tryCast(mId);
211 if (!halDisplayId) {
Robert Carr6fe2bef2022-03-09 13:49:41 -0800212 return;
Lloyd Pique66d68602019-02-13 14:23:31 -0800213 }
214
Lloyd Pique66d68602019-02-13 14:23:31 -0800215 auto& hwc = getCompositionEngine().getHwComposer();
Alec Mouricdf16792021-12-10 13:16:06 -0800216 if (const auto physicalDisplayId = PhysicalDisplayId::tryCast(*halDisplayId);
217 physicalDisplayId && getState().displayBrightness) {
218 const status_t result =
219 hwc.setDisplayBrightness(*physicalDisplayId, *getState().displayBrightness,
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000220 getState().displayBrightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -0800221 Hwc2::Composer::DisplayBrightnessOptions{
222 .applyImmediately = false})
223 .get();
224 ALOGE_IF(result != NO_ERROR, "setDisplayBrightness failed for %s: %d, (%s)",
225 getName().c_str(), result, strerror(-result));
226 }
Vishnu Naira3140382022-02-24 14:07:11 -0800227 // Clear out the display brightness now that it's been communicated to composer.
228 editState().displayBrightness.reset();
229}
Alec Mouricdf16792021-12-10 13:16:06 -0800230
Vishnu Naira3140382022-02-24 14:07:11 -0800231bool Display::chooseCompositionStrategy(
232 std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) {
233 ATRACE_CALL();
234 ALOGV(__FUNCTION__);
235
236 if (mIsDisconnected) {
237 return false;
238 }
239
240 // If we don't have a HWC display, then we are done.
241 const auto halDisplayId = HalDisplayId::tryCast(mId);
242 if (!halDisplayId) {
243 return false;
244 }
245
Matt Buckley50c44062022-01-17 20:48:10 +0000246 const nsecs_t startTime = systemTime();
247
Vishnu Naira3140382022-02-24 14:07:11 -0800248 // Get any composition changes requested by the HWC device, and apply them.
249 std::optional<android::HWComposer::DeviceRequestedChanges> changes;
250 auto& hwc = getCompositionEngine().getHwComposer();
Matt Buckley50c44062022-01-17 20:48:10 +0000251 const bool requiresClientComposition = anyLayersRequireClientComposition();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200252 if (status_t result =
Matt Buckley50c44062022-01-17 20:48:10 +0000253 hwc.getDeviceCompositionChanges(*halDisplayId, requiresClientComposition,
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
Matt Buckley50c44062022-01-17 20:48:10 +0000263 if (isPowerHintSessionEnabled()) {
264 mPowerAdvisor->setValidateTiming(mId, startTime, systemTime());
265 mPowerAdvisor->setRequiresClientComposition(mId, requiresClientComposition);
266 }
267
Vishnu Naira3140382022-02-24 14:07:11 -0800268 return true;
269}
270
271void Display::applyCompositionStrategy(const std::optional<DeviceRequestedChanges>& changes) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800272 if (changes) {
273 applyChangedTypesToLayers(changes->changedTypes);
274 applyDisplayRequests(changes->displayRequests);
275 applyLayerRequestsToLayers(changes->layerRequests);
Alec Mouri85065692022-03-18 00:58:26 +0000276 applyClientTargetRequests(changes->clientTargetProperty);
Lloyd Pique66d68602019-02-13 14:23:31 -0800277 }
278
279 // Determine what type of composition we are doing from the final state
280 auto& state = editState();
281 state.usesClientComposition = anyLayersRequireClientComposition();
282 state.usesDeviceComposition = !allLayersRequireClientComposition();
283}
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 Mouri85065692022-03-18 00:58:26 +0000343void Display::applyClientTargetRequests(const ClientTargetProperty& clientTargetProperty) {
344 if (static_cast<ui::Dataspace>(clientTargetProperty.clientTargetProperty.dataspace) ==
345 ui::Dataspace::UNKNOWN) {
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700346 return;
347 }
Ady Abraham0094dc62021-06-03 10:08:33 -0700348
Alec Mouri85065692022-03-18 00:58:26 +0000349 editState().dataspace =
350 static_cast<ui::Dataspace>(clientTargetProperty.clientTargetProperty.dataspace);
351 editState().clientTargetBrightness = clientTargetProperty.brightness;
352 editState().clientTargetDimmingStage = clientTargetProperty.dimmingStage;
353 getRenderSurface()->setBufferDataspace(editState().dataspace);
354 getRenderSurface()->setBufferPixelFormat(
355 static_cast<ui::PixelFormat>(clientTargetProperty.clientTargetProperty.pixelFormat));
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700356}
357
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800358compositionengine::Output::FrameFences Display::presentAndGetFrameFences() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200359 auto fences = impl::Output::presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800360
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200361 const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
362 if (mIsDisconnected || !halDisplayIdOpt) {
363 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800364 }
365
366 auto& hwc = getCompositionEngine().getHwComposer();
Matt Buckley50c44062022-01-17 20:48:10 +0000367
368 const nsecs_t startTime = systemTime();
369
370 if (isPowerHintSessionEnabled()) {
371 if (!getCompositionEngine().getHwComposer().getComposer()->isSupported(
372 Hwc2::Composer::OptionalFeature::ExpectedPresentTime) &&
373 getState().previousPresentFence->getSignalTime() != Fence::SIGNAL_TIME_PENDING) {
374 mPowerAdvisor->setPresentDelayedTime(mId, getState().earliestPresentTime);
375 }
376 }
377
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700378 hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime,
379 getState().previousPresentFence);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800380
Matt Buckley50c44062022-01-17 20:48:10 +0000381 if (isPowerHintSessionEnabled()) {
382 mPowerAdvisor->setPresentTiming(mId, startTime, systemTime());
383 }
384
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200385 fences.presentFence = hwc.getPresentFence(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800386
387 // TODO(b/121291683): Change HWComposer call to return entire map
Lloyd Pique01c77c12019-04-17 12:48:32 -0700388 for (const auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800389 auto hwcLayer = layer->getHwcLayer();
390 if (!hwcLayer) {
391 continue;
392 }
393
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200394 fences.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*halDisplayIdOpt, hwcLayer));
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800395 }
396
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200397 hwc.clearReleaseFences(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800398
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200399 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800400}
401
Lloyd Pique688abd42019-02-15 15:42:24 -0800402void Display::setExpensiveRenderingExpected(bool enabled) {
403 Output::setExpensiveRenderingExpected(enabled);
404
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200405 if (mPowerAdvisor && !GpuVirtualDisplayId::tryCast(mId)) {
406 mPowerAdvisor->setExpensiveRenderingExpected(mId, enabled);
Lloyd Pique688abd42019-02-15 15:42:24 -0800407 }
408}
409
Matt Buckley50c44062022-01-17 20:48:10 +0000410bool Display::isPowerHintSessionEnabled() {
411 return mPowerAdvisor != nullptr && mPowerAdvisor->usePowerHintSession();
412}
413
414void Display::setHintSessionGpuFence(std::unique_ptr<FenceTime>&& gpuFence) {
415 mPowerAdvisor->setGpuFenceTime(mId, std::move(gpuFence));
416}
417
Vishnu Naira3140382022-02-24 14:07:11 -0800418void Display::finishFrame(const compositionengine::CompositionRefreshArgs& refreshArgs,
419 GpuCompositionResult&& result) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800420 // We only need to actually compose the display if:
421 // 1) It is being handled by hardware composer, which may need this to
422 // keep its virtual display state machine in sync, or
423 // 2) There is work to be done (the dirty region isn't empty)
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700424 if (GpuVirtualDisplayId::tryCast(mId) && getDirtyRegion().isEmpty()) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200425 ALOGV("Skipping display composition");
426 return;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800427 }
428
Vishnu Naira3140382022-02-24 14:07:11 -0800429 impl::Output::finishFrame(refreshArgs, std::move(result));
Matt Buckley50c44062022-01-17 20:48:10 +0000430
431 if (isPowerHintSessionEnabled()) {
432 auto& hwc = getCompositionEngine().getHwComposer();
433 if (auto halDisplayId = HalDisplayId::tryCast(mId)) {
434 mPowerAdvisor->setSkippedValidate(mId, hwc.getValidateSkipped(*halDisplayId));
435 }
436 }
Lloyd Piqued3d69882019-02-28 16:03:46 -0800437}
438
Lloyd Pique45a165a2018-10-19 11:54:47 -0700439} // namespace android::compositionengine::impl