blob: e37ce0a0eb880f1d80e6f155069dd49861d49a80 [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>
Vishnu Nairbe0ad902024-06-27 23:38:43 +000018#include <common/trace.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070019#include <compositionengine/CompositionEngine.h>
Lloyd Piqued3d69882019-02-28 16:03:46 -080020#include <compositionengine/CompositionRefreshArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070021#include <compositionengine/DisplayCreationArgs.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070022#include <compositionengine/DisplaySurface.h>
Lloyd Piquedf336d92019-03-07 21:38:42 -080023#include <compositionengine/LayerFE.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070024#include <compositionengine/impl/Display.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070025#include <compositionengine/impl/DisplayColorProfile.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070026#include <compositionengine/impl/DumpHelpers.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080027#include <compositionengine/impl/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070028#include <compositionengine/impl/RenderSurface.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070029
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080030// TODO(b/129481165): remove the #pragma below and fix conversion issues
31#pragma clang diagnostic push
32#pragma clang diagnostic ignored "-Wconversion"
33
Lloyd Pique45a165a2018-10-19 11:54:47 -070034#include "DisplayHardware/HWComposer.h"
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080035
36// TODO(b/129481165): remove the #pragma below and fix conversion issues
37#pragma clang diagnostic pop // ignored "-Wconversion"
38
Matt Buckley18b93522024-08-27 05:30:18 +000039#include "PowerAdvisor/PowerAdvisor.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070040
Ady Abrahamde549d42022-01-26 19:19:17 -080041using aidl::android::hardware::graphics::composer3::Capability;
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;
Brian Lindahl1a4ffd82024-10-30 11:00:37 -060057 mHasPictureProcessing = args.hasPictureProcessing;
58 mMaxLayerPictureProfiles = args.maxLayerPictureProfiles;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070059 editState().isSecure = args.isSecure;
Chavi Weingarten18fa7c62023-11-28 21:16:03 +000060 editState().isProtected = args.isProtected;
Angel Aguayob084e0c2021-08-04 23:27:28 +000061 editState().displaySpace.setBounds(args.pixels);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070062 setName(args.name);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070063}
64
65bool Display::isValid() const {
66 return Output::isValid() && mPowerAdvisor;
67}
68
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020069DisplayId Display::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -070070 return mId;
71}
72
73bool Display::isSecure() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -070074 return getState().isSecure;
Lloyd Pique45a165a2018-10-19 11:54:47 -070075}
76
Huihong Luo9ebb7a72023-06-27 17:01:50 -070077void Display::setSecure(bool secure) {
78 editState().isSecure = secure;
79}
80
Lloyd Pique45a165a2018-10-19 11:54:47 -070081bool Display::isVirtual() const {
Alan Dingc9de92a2024-05-24 00:27:11 -070082 return mId.isVirtual();
Lloyd Pique45a165a2018-10-19 11:54:47 -070083}
84
Brian Lindahl1a4ffd82024-10-30 11:00:37 -060085ftl::Optional<DisplayId> Display::getDisplayId() const {
Lloyd Pique6c564cf2019-05-17 17:31:36 -070086 return mId;
87}
88
Lloyd Pique45a165a2018-10-19 11:54:47 -070089void Display::disconnect() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020090 if (mIsDisconnected) {
Lloyd Pique45a165a2018-10-19 11:54:47 -070091 return;
92 }
93
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020094 mIsDisconnected = true;
Dominik Laskowski13948602021-03-08 20:48:28 -080095
96 if (const auto id = HalDisplayId::tryCast(mId)) {
97 getCompositionEngine().getHwComposer().disconnectDisplay(*id);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020098 }
Lloyd Pique45a165a2018-10-19 11:54:47 -070099}
100
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800101void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
102 Output::setColorTransform(args);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200103 const auto halDisplayId = HalDisplayId::tryCast(mId);
104 if (mIsDisconnected || !halDisplayId || CC_LIKELY(!args.colorTransformMatrix)) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800105 return;
106 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700107
108 auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200109 status_t result = hwc.setColorTransform(*halDisplayId, *args.colorTransformMatrix);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700110 ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200111 to_string(mId).c_str(), result);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700112}
113
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800114void Display::setColorProfile(const ColorProfile& colorProfile) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800115 if (colorProfile.mode == getState().colorMode &&
116 colorProfile.dataspace == getState().dataspace &&
Alec Mouri88790f32023-07-21 01:25:14 +0000117 colorProfile.renderIntent == getState().renderIntent) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700118 return;
119 }
120
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700121 if (isVirtual()) {
122 ALOGW("%s: Invalid operation on virtual display", __func__);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700123 return;
124 }
125
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800126 Output::setColorProfile(colorProfile);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700127
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200128 const auto physicalId = PhysicalDisplayId::tryCast(mId);
129 LOG_FATAL_IF(!physicalId);
130 getCompositionEngine().getHwComposer().setActiveColorMode(*physicalId, colorProfile.mode,
131 colorProfile.renderIntent);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700132}
133
134void Display::dump(std::string& out) const {
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700135 const char* const type = isVirtual() ? "virtual" : "physical";
136 base::StringAppendF(&out, "Display %s (%s, \"%s\")", to_string(mId).c_str(), type,
137 getName().c_str());
Lloyd Pique32cbe282018-10-19 13:09:22 -0700138
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700139 out.append("\n Composition Display State:\n");
Lloyd Pique32cbe282018-10-19 13:09:22 -0700140 Output::dumpBase(out);
141}
142
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700143void Display::createDisplayColorProfile(const DisplayColorProfileCreationArgs& args) {
144 setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(args));
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700145}
146
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700147void Display::createRenderSurface(const RenderSurfaceCreationArgs& args) {
148 setRenderSurface(
149 compositionengine::impl::createRenderSurface(getCompositionEngine(), *this, args));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700150}
151
Vishnu Nair9b079a22020-01-21 14:36:08 -0800152void Display::createClientCompositionCache(uint32_t cacheSize) {
153 cacheClientCompositionRequests(cacheSize);
154}
155
Lloyd Piquedf336d92019-03-07 21:38:42 -0800156std::unique_ptr<compositionengine::OutputLayer> Display::createOutputLayer(
Lloyd Piquedf336d92019-03-07 21:38:42 -0800157 const sp<compositionengine::LayerFE>& layerFE) const {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200158 auto outputLayer = impl::createOutputLayer(*this, layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800159
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200160 if (const auto halDisplayId = HalDisplayId::tryCast(mId);
161 outputLayer && !mIsDisconnected && halDisplayId) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800162 auto& hwc = getCompositionEngine().getHwComposer();
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700163 auto hwcLayer = hwc.createLayer(*halDisplayId);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800164 ALOGE_IF(!hwcLayer, "Failed to create a HWC layer for a HWC supported display %s",
165 getName().c_str());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200166 outputLayer->setHwcLayer(std::move(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800167 }
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200168 return outputLayer;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800169}
170
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800171void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs& refreshArgs) {
172 Output::setReleasedLayers(refreshArgs);
173
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200174 if (mIsDisconnected || GpuVirtualDisplayId::tryCast(mId) ||
175 refreshArgs.layersWithQueuedFrames.empty()) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800176 return;
177 }
178
179 // For layers that are being removed from a HWC display, and that have
180 // queued frames, add them to a a list of released layers so we can properly
181 // set a fence.
182 compositionengine::Output::ReleasedLayers releasedLayers;
183
184 // Any non-null entries in the current list of layers are layers that are no
185 // longer going to be visible
Lloyd Piquede196652020-01-22 17:29:58 -0800186 for (auto* outputLayer : getOutputLayersOrderedByZ()) {
187 if (!outputLayer) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800188 continue;
189 }
190
Lloyd Piquede196652020-01-22 17:29:58 -0800191 compositionengine::LayerFE* layerFE = &outputLayer->getLayerFE();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800192 const bool hasQueuedFrames =
Lloyd Piquede196652020-01-22 17:29:58 -0800193 std::any_of(refreshArgs.layersWithQueuedFrames.cbegin(),
194 refreshArgs.layersWithQueuedFrames.cend(),
195 [layerFE](sp<compositionengine::LayerFE> layerWithQueuedFrames) {
196 return layerFE == layerWithQueuedFrames.get();
197 });
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800198
199 if (hasQueuedFrames) {
Ady Abrahamd11bade2022-08-01 16:18:03 -0700200 releasedLayers.emplace_back(wp<LayerFE>::fromExisting(layerFE));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800201 }
202 }
203
204 setReleasedLayers(std::move(releasedLayers));
205}
206
Dominik Laskowskia42d5392022-09-29 14:26:53 -0400207void Display::applyDisplayBrightness(bool applyImmediately) {
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600208 if (!getState().displayBrightness) {
209 return;
210 }
211 if (auto displayId = PhysicalDisplayId::tryCast(mId)) {
Dominik Laskowskia42d5392022-09-29 14:26:53 -0400212 auto& hwc = getCompositionEngine().getHwComposer();
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600213 status_t result = hwc.setDisplayBrightness(*displayId, *getState().displayBrightness,
214 getState().displayBrightnessNits,
215 Hwc2::Composer::DisplayBrightnessOptions{
216 .applyImmediately = applyImmediately})
217 .get();
joenchene72ba5e2022-08-24 13:08:58 +0000218 ALOGE_IF(result != NO_ERROR, "setDisplayBrightness failed for %s: %d, (%s)",
219 getName().c_str(), result, strerror(-result));
220 }
221 // Clear out the display brightness now that it's been communicated to composer.
222 editState().displayBrightness.reset();
223}
224
Vishnu Naira3140382022-02-24 14:07:11 -0800225void Display::beginFrame() {
226 Output::beginFrame();
Lloyd Pique66d68602019-02-13 14:23:31 -0800227
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200228 // If we don't have a HWC display, then we are done.
229 const auto halDisplayId = HalDisplayId::tryCast(mId);
230 if (!halDisplayId) {
Robert Carr6fe2bef2022-03-09 13:49:41 -0800231 return;
Lloyd Pique66d68602019-02-13 14:23:31 -0800232 }
233
joenchene72ba5e2022-08-24 13:08:58 +0000234 applyDisplayBrightness(false);
Vishnu Naira3140382022-02-24 14:07:11 -0800235}
Alec Mouricdf16792021-12-10 13:16:06 -0800236
Vishnu Naira3140382022-02-24 14:07:11 -0800237bool Display::chooseCompositionStrategy(
238 std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) {
Vishnu Nairbe0ad902024-06-27 23:38:43 +0000239 SFTRACE_FORMAT("%s for %s", __func__, getNamePlusId().c_str());
Vishnu Naira3140382022-02-24 14:07:11 -0800240 ALOGV(__FUNCTION__);
241
242 if (mIsDisconnected) {
243 return false;
244 }
245
246 // If we don't have a HWC display, then we are done.
247 const auto halDisplayId = HalDisplayId::tryCast(mId);
248 if (!halDisplayId) {
249 return false;
250 }
251
252 // Get any composition changes requested by the HWC device, and apply them.
Vishnu Naira3140382022-02-24 14:07:11 -0800253 auto& hwc = getCompositionEngine().getHwComposer();
Matt Buckley50c44062022-01-17 20:48:10 +0000254 const bool requiresClientComposition = anyLayersRequireClientComposition();
Matt Buckley3d398a02022-10-28 09:03:37 +0000255
Matt Buckley3d398a02022-10-28 09:03:37 +0000256 const TimePoint hwcValidateStartTime = TimePoint::now();
257
ramindani4aac32c2023-10-30 14:13:30 -0700258 if (status_t result = hwc.getDeviceCompositionChanges(*halDisplayId, requiresClientComposition,
259 getState().earliestPresentTime,
260 getState().expectedPresentTime,
261 getState().frameInterval, outChanges);
Lloyd Pique66d68602019-02-13 14:23:31 -0800262 result != NO_ERROR) {
263 ALOGE("chooseCompositionStrategy failed for %s: %d (%s)", getName().c_str(), result,
264 strerror(-result));
Vishnu Naira3140382022-02-24 14:07:11 -0800265 return false;
Lloyd Pique66d68602019-02-13 14:23:31 -0800266 }
Vishnu Naira3140382022-02-24 14:07:11 -0800267
Matt Buckley50c44062022-01-17 20:48:10 +0000268 if (isPowerHintSessionEnabled()) {
Matt Buckley3d398a02022-10-28 09:03:37 +0000269 mPowerAdvisor->setHwcValidateTiming(mId, hwcValidateStartTime, TimePoint::now());
270 if (auto halDisplayId = HalDisplayId::tryCast(mId)) {
271 mPowerAdvisor->setSkippedValidate(mId, hwc.getValidateSkipped(*halDisplayId));
272 }
Matt Buckley50c44062022-01-17 20:48:10 +0000273 }
274
Vishnu Naira3140382022-02-24 14:07:11 -0800275 return true;
276}
277
278void Display::applyCompositionStrategy(const std::optional<DeviceRequestedChanges>& changes) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800279 if (changes) {
280 applyChangedTypesToLayers(changes->changedTypes);
281 applyDisplayRequests(changes->displayRequests);
282 applyLayerRequestsToLayers(changes->layerRequests);
Alec Mouri85065692022-03-18 00:58:26 +0000283 applyClientTargetRequests(changes->clientTargetProperty);
Sally Qi95f669a2024-08-27 11:31:42 -0700284 applyLayerLutsToLayers(changes->layerLuts);
Lloyd Pique66d68602019-02-13 14:23:31 -0800285 }
286
287 // Determine what type of composition we are doing from the final state
288 auto& state = editState();
289 state.usesClientComposition = anyLayersRequireClientComposition();
290 state.usesDeviceComposition = !allLayersRequireClientComposition();
291}
292
Lloyd Pique688abd42019-02-15 15:42:24 -0800293bool Display::getSkipColorTransform() const {
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600294 auto& hwc = getCompositionEngine().getHwComposer();
295 if (auto halDisplayId = HalDisplayId::tryCast(mId)) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200296 return hwc.hasDisplayCapability(*halDisplayId,
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500297 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200298 }
299
Ady Abrahamde549d42022-01-26 19:19:17 -0800300 return hwc.hasCapability(Capability::SKIP_CLIENT_COLOR_TRANSFORM);
Lloyd Pique688abd42019-02-15 15:42:24 -0800301}
302
Lloyd Pique66d68602019-02-13 14:23:31 -0800303bool Display::allLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700304 const auto layers = getOutputLayersOrderedByZ();
305 return std::all_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800306 [](const auto& layer) { return layer->requiresClientComposition(); });
307}
308
309void Display::applyChangedTypesToLayers(const ChangedTypes& changedTypes) {
310 if (changedTypes.empty()) {
311 return;
312 }
313
Lloyd Pique01c77c12019-04-17 12:48:32 -0700314 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800315 auto hwcLayer = layer->getHwcLayer();
316 if (!hwcLayer) {
317 continue;
318 }
319
320 if (auto it = changedTypes.find(hwcLayer); it != changedTypes.end()) {
321 layer->applyDeviceCompositionTypeChange(
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500322 static_cast<aidl::android::hardware::graphics::composer3::Composition>(
323 it->second));
Lloyd Pique66d68602019-02-13 14:23:31 -0800324 }
325 }
326}
327
328void Display::applyDisplayRequests(const DisplayRequests& displayRequests) {
329 auto& state = editState();
330 state.flipClientTarget = (static_cast<uint32_t>(displayRequests) &
Peiyong Line9d809e2020-04-14 13:10:48 -0700331 static_cast<uint32_t>(hal::DisplayRequest::FLIP_CLIENT_TARGET)) != 0;
Lloyd Pique66d68602019-02-13 14:23:31 -0800332 // Note: HWC2::DisplayRequest::WriteClientTargetToOutput is currently ignored.
333}
334
335void Display::applyLayerRequestsToLayers(const LayerRequests& layerRequests) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700336 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800337 layer->prepareForDeviceLayerRequests();
338
339 auto hwcLayer = layer->getHwcLayer();
340 if (!hwcLayer) {
341 continue;
342 }
343
344 if (auto it = layerRequests.find(hwcLayer); it != layerRequests.end()) {
345 layer->applyDeviceLayerRequest(
346 static_cast<Hwc2::IComposerClient::LayerRequest>(it->second));
347 }
348 }
349}
350
Alec Mouri85065692022-03-18 00:58:26 +0000351void Display::applyClientTargetRequests(const ClientTargetProperty& clientTargetProperty) {
352 if (static_cast<ui::Dataspace>(clientTargetProperty.clientTargetProperty.dataspace) ==
353 ui::Dataspace::UNKNOWN) {
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700354 return;
355 }
Ady Abraham0094dc62021-06-03 10:08:33 -0700356
Alec Mouri85065692022-03-18 00:58:26 +0000357 editState().dataspace =
358 static_cast<ui::Dataspace>(clientTargetProperty.clientTargetProperty.dataspace);
359 editState().clientTargetBrightness = clientTargetProperty.brightness;
360 editState().clientTargetDimmingStage = clientTargetProperty.dimmingStage;
361 getRenderSurface()->setBufferDataspace(editState().dataspace);
362 getRenderSurface()->setBufferPixelFormat(
363 static_cast<ui::PixelFormat>(clientTargetProperty.clientTargetProperty.pixelFormat));
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700364}
365
Sally Qi95f669a2024-08-27 11:31:42 -0700366void Display::applyLayerLutsToLayers(const LayerLuts& layerLuts) {
367 auto& mapper = getCompositionEngine().getHwComposer().getLutFileDescriptorMapper();
368 for (auto* layer : getOutputLayersOrderedByZ()) {
369 auto hwcLayer = layer->getHwcLayer();
370 if (!hwcLayer) {
371 continue;
372 }
373
374 if (auto lutsIt = layerLuts.find(hwcLayer); lutsIt != layerLuts.end()) {
375 if (auto mapperIt = mapper.find(hwcLayer); mapperIt != mapper.end()) {
Sally Qi0abc4a52024-09-26 16:13:06 -0700376 layer->applyDeviceLayerLut(ndk::ScopedFileDescriptor(mapperIt->second.release()),
377 lutsIt->second);
Sally Qi95f669a2024-08-27 11:31:42 -0700378 }
379 }
380 }
381
382 mapper.clear();
383}
384
Leon Scroggins IIIa3ba7fa2024-05-22 16:34:52 -0400385void Display::executeCommands() {
386 const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
387 if (mIsDisconnected || !halDisplayIdOpt) {
388 return;
389 }
390
391 getCompositionEngine().getHwComposer().executeCommands(*halDisplayIdOpt);
392}
393
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -0500394compositionengine::Output::FrameFences Display::presentFrame() {
395 auto fences = impl::Output::presentFrame();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800396
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200397 const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
398 if (mIsDisconnected || !halDisplayIdOpt) {
399 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800400 }
401
402 auto& hwc = getCompositionEngine().getHwComposer();
Matt Buckley50c44062022-01-17 20:48:10 +0000403
Matt Buckley2fa85012022-08-30 22:38:45 +0000404 const TimePoint startTime = TimePoint::now();
Matt Buckley50c44062022-01-17 20:48:10 +0000405
Ady Abrahamf1db8032023-03-24 17:52:34 -0700406 if (isPowerHintSessionEnabled() && getState().earliestPresentTime) {
407 mPowerAdvisor->setHwcPresentDelayedTime(mId, *getState().earliestPresentTime);
Matt Buckley50c44062022-01-17 20:48:10 +0000408 }
409
Ady Abrahamf1db8032023-03-24 17:52:34 -0700410 hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800411
Matt Buckley50c44062022-01-17 20:48:10 +0000412 if (isPowerHintSessionEnabled()) {
Matt Buckley2fa85012022-08-30 22:38:45 +0000413 mPowerAdvisor->setHwcPresentTiming(mId, startTime, TimePoint::now());
Matt Buckley50c44062022-01-17 20:48:10 +0000414 }
415
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200416 fences.presentFence = hwc.getPresentFence(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800417
418 // TODO(b/121291683): Change HWComposer call to return entire map
Lloyd Pique01c77c12019-04-17 12:48:32 -0700419 for (const auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800420 auto hwcLayer = layer->getHwcLayer();
421 if (!hwcLayer) {
422 continue;
423 }
424
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200425 fences.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*halDisplayIdOpt, hwcLayer));
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800426 }
427
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200428 hwc.clearReleaseFences(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800429
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200430 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800431}
432
Lloyd Pique688abd42019-02-15 15:42:24 -0800433void Display::setExpensiveRenderingExpected(bool enabled) {
434 Output::setExpensiveRenderingExpected(enabled);
435
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200436 if (mPowerAdvisor && !GpuVirtualDisplayId::tryCast(mId)) {
437 mPowerAdvisor->setExpensiveRenderingExpected(mId, enabled);
Lloyd Pique688abd42019-02-15 15:42:24 -0800438 }
439}
440
Matt Buckley50c44062022-01-17 20:48:10 +0000441bool Display::isPowerHintSessionEnabled() {
442 return mPowerAdvisor != nullptr && mPowerAdvisor->usePowerHintSession();
443}
444
Xiang Wangcb50bbd2024-04-18 16:57:54 -0700445bool Display::isPowerHintSessionGpuReportingEnabled() {
446 return mPowerAdvisor != nullptr && mPowerAdvisor->supportsGpuReporting();
447}
448
Xiang Wangaab31162024-03-12 19:48:08 -0700449// For ADPF GPU v0 this is expected to set start time to when the GPU commands are submitted with
450// fence returned, i.e. when RenderEngine flushes the commands and returns the draw fence.
451void Display::setHintSessionGpuStart(TimePoint startTime) {
452 mPowerAdvisor->setGpuStartTime(mId, startTime);
453}
454
Matt Buckley50c44062022-01-17 20:48:10 +0000455void Display::setHintSessionGpuFence(std::unique_ptr<FenceTime>&& gpuFence) {
456 mPowerAdvisor->setGpuFenceTime(mId, std::move(gpuFence));
457}
458
Xiang Wangaab31162024-03-12 19:48:08 -0700459void Display::setHintSessionRequiresRenderEngine(bool requiresRenderEngine) {
460 mPowerAdvisor->setRequiresRenderEngine(mId, requiresRenderEngine);
461}
462
Sally Qi0abc4a52024-09-26 16:13:06 -0700463const aidl::android::hardware::graphics::composer3::OverlayProperties*
464Display::getOverlaySupport() {
465 return &getCompositionEngine().getHwComposer().getOverlaySupport();
466}
467
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600468bool Display::hasPictureProcessing() const {
469 return mHasPictureProcessing;
470}
471
472int32_t Display::getMaxLayerPictureProfiles() const {
473 return mMaxLayerPictureProfiles;
474}
475
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000476void Display::finishFrame(GpuCompositionResult&& result) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800477 // We only need to actually compose the display if:
478 // 1) It is being handled by hardware composer, which may need this to
479 // keep its virtual display state machine in sync, or
480 // 2) There is work to be done (the dirty region isn't empty)
Chavi Weingarten09fa1d62022-08-17 21:57:04 +0000481 if (GpuVirtualDisplayId::tryCast(mId) && !mustRecompose()) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200482 ALOGV("Skipping display composition");
483 return;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800484 }
485
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000486 impl::Output::finishFrame(std::move(result));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800487}
488
Leon Scroggins III2f60d732022-09-12 14:42:38 -0400489bool Display::supportsOffloadPresent() const {
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600490 if (auto halDisplayId = HalDisplayId::tryCast(mId)) {
491 auto& hwc = getCompositionEngine().getHwComposer();
Leon Scroggins III2f60d732022-09-12 14:42:38 -0400492 return hwc.hasDisplayCapability(*halDisplayId, DisplayCapability::MULTI_THREADED_PRESENT);
493 }
494
495 return false;
496}
497
Lloyd Pique45a165a2018-10-19 11:54:47 -0700498} // namespace android::compositionengine::impl