blob: 8c8331c757056a127a8aca9637456deeea6299aa [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
42namespace android::compositionengine::impl {
43
Lloyd Pique35fca9d2019-02-13 14:24:11 -080044std::shared_ptr<Display> createDisplay(
Lloyd Pique45a165a2018-10-19 11:54:47 -070045 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070046 const compositionengine::DisplayCreationArgs& args) {
47 return createDisplayTemplated<Display>(compositionEngine, args);
Lloyd Pique45a165a2018-10-19 11:54:47 -070048}
49
Lloyd Pique45a165a2018-10-19 11:54:47 -070050Display::~Display() = default;
51
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070052void Display::setConfiguration(const compositionengine::DisplayCreationArgs& args) {
53 mIsVirtual = !args.physical;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070054 mPowerAdvisor = args.powerAdvisor;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070055 editState().isSecure = args.isSecure;
Marin Shalamanovb15d2272020-09-17 21:41:52 +020056 editState().displaySpace.bounds = Rect(args.pixels);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070057 setLayerStackFilter(args.layerStackId,
Marin Shalamanov228f46b2021-01-28 21:11:45 +010058 args.physical &&
59 args.physical->type == ui::DisplayConnectionType::Internal);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070060 setName(args.name);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020061 mGpuVirtualDisplayIdGenerator = args.gpuVirtualDisplayIdGenerator;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070062
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020063 if (args.physical) {
64 mId = args.physical->id;
65 } else {
66 std::optional<DisplayId> id;
67 if (args.useHwcVirtualDisplays) {
68 id = maybeAllocateDisplayIdForVirtualDisplay(args.pixels, args.pixelFormat);
69 }
70 if (!id) {
71 id = mGpuVirtualDisplayIdGenerator->nextId();
72 }
73 LOG_ALWAYS_FATAL_IF(!id, "Failed to generate display ID");
74 mId = *id;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070075 }
76}
77
78std::optional<DisplayId> Display::maybeAllocateDisplayIdForVirtualDisplay(
79 ui::Size pixels, ui::PixelFormat pixelFormat) const {
80 auto& hwc = getCompositionEngine().getHwComposer();
81 return hwc.allocateVirtualDisplay(static_cast<uint32_t>(pixels.width),
82 static_cast<uint32_t>(pixels.height), &pixelFormat);
83}
84
85bool Display::isValid() const {
86 return Output::isValid() && mPowerAdvisor;
87}
88
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020089DisplayId Display::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -070090 return mId;
91}
92
93bool Display::isSecure() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -070094 return getState().isSecure;
Lloyd Pique45a165a2018-10-19 11:54:47 -070095}
96
97bool Display::isVirtual() const {
98 return mIsVirtual;
99}
100
Lloyd Pique6c564cf2019-05-17 17:31:36 -0700101std::optional<DisplayId> Display::getDisplayId() const {
102 return mId;
103}
104
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200105void Display::setDisplayIdForTesting(DisplayId displayId) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700106 mId = displayId;
107}
108
Lloyd Pique45a165a2018-10-19 11:54:47 -0700109void Display::disconnect() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200110 if (mIsDisconnected) {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700111 return;
112 }
113
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200114 mIsDisconnected = true;
115 if (const auto id = GpuVirtualDisplayId::tryCast(mId)) {
116 mGpuVirtualDisplayIdGenerator->markUnused(*id);
117 return;
118 }
119 const auto halDisplayId = HalDisplayId::tryCast(mId);
120 LOG_FATAL_IF(!halDisplayId);
121 getCompositionEngine().getHwComposer().disconnectDisplay(*halDisplayId);
Lloyd Pique45a165a2018-10-19 11:54:47 -0700122}
123
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800124void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
125 Output::setColorTransform(args);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200126 const auto halDisplayId = HalDisplayId::tryCast(mId);
127 if (mIsDisconnected || !halDisplayId || CC_LIKELY(!args.colorTransformMatrix)) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800128 return;
129 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700130
131 auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200132 status_t result = hwc.setColorTransform(*halDisplayId, *args.colorTransformMatrix);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700133 ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200134 to_string(mId).c_str(), result);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700135}
136
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800137void Display::setColorProfile(const ColorProfile& colorProfile) {
138 const ui::Dataspace targetDataspace =
139 getDisplayColorProfile()->getTargetDataspace(colorProfile.mode, colorProfile.dataspace,
140 colorProfile.colorSpaceAgnosticDataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800141
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800142 if (colorProfile.mode == getState().colorMode &&
143 colorProfile.dataspace == getState().dataspace &&
144 colorProfile.renderIntent == getState().renderIntent &&
145 targetDataspace == getState().targetDataspace) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700146 return;
147 }
148
149 if (mIsVirtual) {
150 ALOGW("%s: Invalid operation on virtual display", __FUNCTION__);
151 return;
152 }
153
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800154 Output::setColorProfile(colorProfile);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700155
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200156 const auto physicalId = PhysicalDisplayId::tryCast(mId);
157 LOG_FATAL_IF(!physicalId);
158 getCompositionEngine().getHwComposer().setActiveColorMode(*physicalId, colorProfile.mode,
159 colorProfile.renderIntent);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700160}
161
162void Display::dump(std::string& out) const {
163 using android::base::StringAppendF;
164
165 StringAppendF(&out, " Composition Display State: [\"%s\"]", getName().c_str());
166
167 out.append("\n ");
Lloyd Pique32cbe282018-10-19 13:09:22 -0700168 dumpVal(out, "isVirtual", mIsVirtual);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200169 dumpVal(out, "DisplayId", to_string(mId));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700170 out.append("\n");
171
172 Output::dumpBase(out);
173}
174
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700175void Display::createDisplayColorProfile(const DisplayColorProfileCreationArgs& args) {
176 setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(args));
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700177}
178
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700179void Display::createRenderSurface(const RenderSurfaceCreationArgs& args) {
180 setRenderSurface(
181 compositionengine::impl::createRenderSurface(getCompositionEngine(), *this, args));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700182}
183
Vishnu Nair9b079a22020-01-21 14:36:08 -0800184void Display::createClientCompositionCache(uint32_t cacheSize) {
185 cacheClientCompositionRequests(cacheSize);
186}
187
Lloyd Piquedf336d92019-03-07 21:38:42 -0800188std::unique_ptr<compositionengine::OutputLayer> Display::createOutputLayer(
Lloyd Piquedf336d92019-03-07 21:38:42 -0800189 const sp<compositionengine::LayerFE>& layerFE) const {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200190 auto outputLayer = impl::createOutputLayer(*this, layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800191
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200192 if (const auto halDisplayId = HalDisplayId::tryCast(mId);
193 outputLayer && !mIsDisconnected && halDisplayId) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800194 auto& hwc = getCompositionEngine().getHwComposer();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800195 // Note: For the moment we ensure it is safe to take a reference to the
196 // HWComposer implementation by destroying all the OutputLayers (and
197 // hence the HWC2::Layers they own) before setting a new HWComposer. See
198 // for example SurfaceFlinger::updateVrFlinger().
199 // TODO(b/121291683): Make this safer.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200200 auto hwcLayer =
201 std::shared_ptr<HWC2::Layer>(hwc.createLayer(*halDisplayId),
202 [&hwc, id = *halDisplayId](HWC2::Layer* layer) {
203 hwc.destroyLayer(id, layer);
204 });
Lloyd Piquedf336d92019-03-07 21:38:42 -0800205 ALOGE_IF(!hwcLayer, "Failed to create a HWC layer for a HWC supported display %s",
206 getName().c_str());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200207 outputLayer->setHwcLayer(std::move(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800208 }
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200209 return outputLayer;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800210}
211
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800212void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs& refreshArgs) {
213 Output::setReleasedLayers(refreshArgs);
214
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200215 if (mIsDisconnected || GpuVirtualDisplayId::tryCast(mId) ||
216 refreshArgs.layersWithQueuedFrames.empty()) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800217 return;
218 }
219
220 // For layers that are being removed from a HWC display, and that have
221 // queued frames, add them to a a list of released layers so we can properly
222 // set a fence.
223 compositionengine::Output::ReleasedLayers releasedLayers;
224
225 // Any non-null entries in the current list of layers are layers that are no
226 // longer going to be visible
Lloyd Piquede196652020-01-22 17:29:58 -0800227 for (auto* outputLayer : getOutputLayersOrderedByZ()) {
228 if (!outputLayer) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800229 continue;
230 }
231
Lloyd Piquede196652020-01-22 17:29:58 -0800232 compositionengine::LayerFE* layerFE = &outputLayer->getLayerFE();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800233 const bool hasQueuedFrames =
Lloyd Piquede196652020-01-22 17:29:58 -0800234 std::any_of(refreshArgs.layersWithQueuedFrames.cbegin(),
235 refreshArgs.layersWithQueuedFrames.cend(),
236 [layerFE](sp<compositionengine::LayerFE> layerWithQueuedFrames) {
237 return layerFE == layerWithQueuedFrames.get();
238 });
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800239
240 if (hasQueuedFrames) {
241 releasedLayers.emplace_back(layerFE);
242 }
243 }
244
245 setReleasedLayers(std::move(releasedLayers));
246}
247
Lloyd Pique66d68602019-02-13 14:23:31 -0800248void Display::chooseCompositionStrategy() {
249 ATRACE_CALL();
250 ALOGV(__FUNCTION__);
251
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200252 if (mIsDisconnected) {
253 return;
254 }
255
Lloyd Pique66d68602019-02-13 14:23:31 -0800256 // Default to the base settings -- client composition only.
257 Output::chooseCompositionStrategy();
258
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200259 // If we don't have a HWC display, then we are done.
260 const auto halDisplayId = HalDisplayId::tryCast(mId);
261 if (!halDisplayId) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800262 return;
263 }
264
265 // Get any composition changes requested by the HWC device, and apply them.
266 std::optional<android::HWComposer::DeviceRequestedChanges> changes;
267 auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200268 if (status_t result =
269 hwc.getDeviceCompositionChanges(*halDisplayId, anyLayersRequireClientComposition(),
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700270 getState().earliestPresentTime, &changes);
Lloyd Pique66d68602019-02-13 14:23:31 -0800271 result != NO_ERROR) {
272 ALOGE("chooseCompositionStrategy failed for %s: %d (%s)", getName().c_str(), result,
273 strerror(-result));
274 return;
275 }
276 if (changes) {
277 applyChangedTypesToLayers(changes->changedTypes);
278 applyDisplayRequests(changes->displayRequests);
279 applyLayerRequestsToLayers(changes->layerRequests);
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700280 applyClientTargetRequests(changes->clientTargetProperty);
Lloyd Pique66d68602019-02-13 14:23:31 -0800281 }
282
283 // Determine what type of composition we are doing from the final state
284 auto& state = editState();
285 state.usesClientComposition = anyLayersRequireClientComposition();
286 state.usesDeviceComposition = !allLayersRequireClientComposition();
287}
288
Lloyd Pique688abd42019-02-15 15:42:24 -0800289bool Display::getSkipColorTransform() const {
Dominik Laskowski1162e472020-04-02 19:02:47 -0700290 const auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200291 if (const auto halDisplayId = HalDisplayId::tryCast(mId)) {
292 return hwc.hasDisplayCapability(*halDisplayId,
293 hal::DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM);
294 }
295
296 return hwc.hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM);
Lloyd Pique688abd42019-02-15 15:42:24 -0800297}
298
Lloyd Pique66d68602019-02-13 14:23:31 -0800299bool Display::anyLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700300 const auto layers = getOutputLayersOrderedByZ();
301 return std::any_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800302 [](const auto& layer) { return layer->requiresClientComposition(); });
303}
304
305bool Display::allLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700306 const auto layers = getOutputLayersOrderedByZ();
307 return std::all_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800308 [](const auto& layer) { return layer->requiresClientComposition(); });
309}
310
311void Display::applyChangedTypesToLayers(const ChangedTypes& changedTypes) {
312 if (changedTypes.empty()) {
313 return;
314 }
315
Lloyd Pique01c77c12019-04-17 12:48:32 -0700316 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800317 auto hwcLayer = layer->getHwcLayer();
318 if (!hwcLayer) {
319 continue;
320 }
321
322 if (auto it = changedTypes.find(hwcLayer); it != changedTypes.end()) {
323 layer->applyDeviceCompositionTypeChange(
324 static_cast<Hwc2::IComposerClient::Composition>(it->second));
325 }
326 }
327}
328
329void Display::applyDisplayRequests(const DisplayRequests& displayRequests) {
330 auto& state = editState();
331 state.flipClientTarget = (static_cast<uint32_t>(displayRequests) &
Peiyong Line9d809e2020-04-14 13:10:48 -0700332 static_cast<uint32_t>(hal::DisplayRequest::FLIP_CLIENT_TARGET)) != 0;
Lloyd Pique66d68602019-02-13 14:23:31 -0800333 // Note: HWC2::DisplayRequest::WriteClientTargetToOutput is currently ignored.
334}
335
336void Display::applyLayerRequestsToLayers(const LayerRequests& layerRequests) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700337 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800338 layer->prepareForDeviceLayerRequests();
339
340 auto hwcLayer = layer->getHwcLayer();
341 if (!hwcLayer) {
342 continue;
343 }
344
345 if (auto it = layerRequests.find(hwcLayer); it != layerRequests.end()) {
346 layer->applyDeviceLayerRequest(
347 static_cast<Hwc2::IComposerClient::LayerRequest>(it->second));
348 }
349 }
350}
351
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700352void Display::applyClientTargetRequests(const ClientTargetProperty& clientTargetProperty) {
353 if (clientTargetProperty.dataspace == ui::Dataspace::UNKNOWN) {
354 return;
355 }
356 auto outputState = editState();
357 outputState.dataspace = clientTargetProperty.dataspace;
358 getRenderSurface()->setBufferDataspace(clientTargetProperty.dataspace);
359 getRenderSurface()->setBufferPixelFormat(clientTargetProperty.pixelFormat);
360}
361
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800362compositionengine::Output::FrameFences Display::presentAndGetFrameFences() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200363 auto fences = impl::Output::presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800364
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200365 const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
366 if (mIsDisconnected || !halDisplayIdOpt) {
367 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800368 }
369
370 auto& hwc = getCompositionEngine().getHwComposer();
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700371 hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800372
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200373 fences.presentFence = hwc.getPresentFence(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800374
375 // TODO(b/121291683): Change HWComposer call to return entire map
Lloyd Pique01c77c12019-04-17 12:48:32 -0700376 for (const auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800377 auto hwcLayer = layer->getHwcLayer();
378 if (!hwcLayer) {
379 continue;
380 }
381
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200382 fences.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*halDisplayIdOpt, hwcLayer));
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800383 }
384
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200385 hwc.clearReleaseFences(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800386
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200387 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800388}
389
Lloyd Pique688abd42019-02-15 15:42:24 -0800390void Display::setExpensiveRenderingExpected(bool enabled) {
391 Output::setExpensiveRenderingExpected(enabled);
392
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200393 if (mPowerAdvisor && !GpuVirtualDisplayId::tryCast(mId)) {
394 mPowerAdvisor->setExpensiveRenderingExpected(mId, enabled);
Lloyd Pique688abd42019-02-15 15:42:24 -0800395 }
396}
397
Lloyd Piqued3d69882019-02-28 16:03:46 -0800398void Display::finishFrame(const compositionengine::CompositionRefreshArgs& refreshArgs) {
399 // We only need to actually compose the display if:
400 // 1) It is being handled by hardware composer, which may need this to
401 // keep its virtual display state machine in sync, or
402 // 2) There is work to be done (the dirty region isn't empty)
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200403 if (GpuVirtualDisplayId::tryCast(mId) &&
404 getDirtyRegion(refreshArgs.repaintEverything).isEmpty()) {
405 ALOGV("Skipping display composition");
406 return;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800407 }
408
409 impl::Output::finishFrame(refreshArgs);
410}
411
Lloyd Pique45a165a2018-10-19 11:54:47 -0700412} // namespace android::compositionengine::impl