blob: 0b0b8d5e9c6a03f19745d7652a2d5aefbc34d404 [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 Shalamanov0f10d0d2020-08-06 20:04:06 +020058 args.physical && args.physical->type == DisplayConnectionType::Internal);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070059 setName(args.name);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020060 mGpuVirtualDisplayIdGenerator = args.gpuVirtualDisplayIdGenerator;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070061
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020062 if (args.physical) {
63 mId = args.physical->id;
64 } else {
65 std::optional<DisplayId> id;
66 if (args.useHwcVirtualDisplays) {
67 id = maybeAllocateDisplayIdForVirtualDisplay(args.pixels, args.pixelFormat);
68 }
69 if (!id) {
70 id = mGpuVirtualDisplayIdGenerator->nextId();
71 }
72 LOG_ALWAYS_FATAL_IF(!id, "Failed to generate display ID");
73 mId = *id;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070074 }
75}
76
77std::optional<DisplayId> Display::maybeAllocateDisplayIdForVirtualDisplay(
78 ui::Size pixels, ui::PixelFormat pixelFormat) const {
79 auto& hwc = getCompositionEngine().getHwComposer();
80 return hwc.allocateVirtualDisplay(static_cast<uint32_t>(pixels.width),
81 static_cast<uint32_t>(pixels.height), &pixelFormat);
82}
83
84bool Display::isValid() const {
85 return Output::isValid() && mPowerAdvisor;
86}
87
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020088DisplayId Display::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -070089 return mId;
90}
91
92bool Display::isSecure() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -070093 return getState().isSecure;
Lloyd Pique45a165a2018-10-19 11:54:47 -070094}
95
96bool Display::isVirtual() const {
97 return mIsVirtual;
98}
99
Lloyd Pique6c564cf2019-05-17 17:31:36 -0700100std::optional<DisplayId> Display::getDisplayId() const {
101 return mId;
102}
103
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200104void Display::setDisplayIdForTesting(DisplayId displayId) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700105 mId = displayId;
106}
107
Lloyd Pique45a165a2018-10-19 11:54:47 -0700108void Display::disconnect() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200109 if (mIsDisconnected) {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700110 return;
111 }
112
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200113 mIsDisconnected = true;
114 if (const auto id = GpuVirtualDisplayId::tryCast(mId)) {
115 mGpuVirtualDisplayIdGenerator->markUnused(*id);
116 return;
117 }
118 const auto halDisplayId = HalDisplayId::tryCast(mId);
119 LOG_FATAL_IF(!halDisplayId);
120 getCompositionEngine().getHwComposer().disconnectDisplay(*halDisplayId);
Lloyd Pique45a165a2018-10-19 11:54:47 -0700121}
122
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800123void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
124 Output::setColorTransform(args);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200125 const auto halDisplayId = HalDisplayId::tryCast(mId);
126 if (mIsDisconnected || !halDisplayId || CC_LIKELY(!args.colorTransformMatrix)) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800127 return;
128 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700129
130 auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200131 status_t result = hwc.setColorTransform(*halDisplayId, *args.colorTransformMatrix);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700132 ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200133 to_string(mId).c_str(), result);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700134}
135
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800136void Display::setColorProfile(const ColorProfile& colorProfile) {
137 const ui::Dataspace targetDataspace =
138 getDisplayColorProfile()->getTargetDataspace(colorProfile.mode, colorProfile.dataspace,
139 colorProfile.colorSpaceAgnosticDataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800140
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800141 if (colorProfile.mode == getState().colorMode &&
142 colorProfile.dataspace == getState().dataspace &&
143 colorProfile.renderIntent == getState().renderIntent &&
144 targetDataspace == getState().targetDataspace) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700145 return;
146 }
147
148 if (mIsVirtual) {
149 ALOGW("%s: Invalid operation on virtual display", __FUNCTION__);
150 return;
151 }
152
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800153 Output::setColorProfile(colorProfile);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700154
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200155 const auto physicalId = PhysicalDisplayId::tryCast(mId);
156 LOG_FATAL_IF(!physicalId);
157 getCompositionEngine().getHwComposer().setActiveColorMode(*physicalId, colorProfile.mode,
158 colorProfile.renderIntent);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700159}
160
161void Display::dump(std::string& out) const {
162 using android::base::StringAppendF;
163
164 StringAppendF(&out, " Composition Display State: [\"%s\"]", getName().c_str());
165
166 out.append("\n ");
Lloyd Pique32cbe282018-10-19 13:09:22 -0700167 dumpVal(out, "isVirtual", mIsVirtual);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200168 dumpVal(out, "DisplayId", to_string(mId));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700169 out.append("\n");
170
171 Output::dumpBase(out);
172}
173
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700174void Display::createDisplayColorProfile(const DisplayColorProfileCreationArgs& args) {
175 setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(args));
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700176}
177
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700178void Display::createRenderSurface(const RenderSurfaceCreationArgs& args) {
179 setRenderSurface(
180 compositionengine::impl::createRenderSurface(getCompositionEngine(), *this, args));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700181}
182
Vishnu Nair9b079a22020-01-21 14:36:08 -0800183void Display::createClientCompositionCache(uint32_t cacheSize) {
184 cacheClientCompositionRequests(cacheSize);
185}
186
Lloyd Piquedf336d92019-03-07 21:38:42 -0800187std::unique_ptr<compositionengine::OutputLayer> Display::createOutputLayer(
Lloyd Piquedf336d92019-03-07 21:38:42 -0800188 const sp<compositionengine::LayerFE>& layerFE) const {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200189 auto outputLayer = impl::createOutputLayer(*this, layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800190
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200191 if (const auto halDisplayId = HalDisplayId::tryCast(mId);
192 outputLayer && !mIsDisconnected && halDisplayId) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800193 auto& hwc = getCompositionEngine().getHwComposer();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800194 // Note: For the moment we ensure it is safe to take a reference to the
195 // HWComposer implementation by destroying all the OutputLayers (and
196 // hence the HWC2::Layers they own) before setting a new HWComposer. See
197 // for example SurfaceFlinger::updateVrFlinger().
198 // TODO(b/121291683): Make this safer.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200199 auto hwcLayer =
200 std::shared_ptr<HWC2::Layer>(hwc.createLayer(*halDisplayId),
201 [&hwc, id = *halDisplayId](HWC2::Layer* layer) {
202 hwc.destroyLayer(id, layer);
203 });
Lloyd Piquedf336d92019-03-07 21:38:42 -0800204 ALOGE_IF(!hwcLayer, "Failed to create a HWC layer for a HWC supported display %s",
205 getName().c_str());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200206 outputLayer->setHwcLayer(std::move(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800207 }
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200208 return outputLayer;
Lloyd Piquedf336d92019-03-07 21:38:42 -0800209}
210
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800211void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs& refreshArgs) {
212 Output::setReleasedLayers(refreshArgs);
213
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200214 if (mIsDisconnected || GpuVirtualDisplayId::tryCast(mId) ||
215 refreshArgs.layersWithQueuedFrames.empty()) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800216 return;
217 }
218
219 // For layers that are being removed from a HWC display, and that have
220 // queued frames, add them to a a list of released layers so we can properly
221 // set a fence.
222 compositionengine::Output::ReleasedLayers releasedLayers;
223
224 // Any non-null entries in the current list of layers are layers that are no
225 // longer going to be visible
Lloyd Piquede196652020-01-22 17:29:58 -0800226 for (auto* outputLayer : getOutputLayersOrderedByZ()) {
227 if (!outputLayer) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800228 continue;
229 }
230
Lloyd Piquede196652020-01-22 17:29:58 -0800231 compositionengine::LayerFE* layerFE = &outputLayer->getLayerFE();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800232 const bool hasQueuedFrames =
Lloyd Piquede196652020-01-22 17:29:58 -0800233 std::any_of(refreshArgs.layersWithQueuedFrames.cbegin(),
234 refreshArgs.layersWithQueuedFrames.cend(),
235 [layerFE](sp<compositionengine::LayerFE> layerWithQueuedFrames) {
236 return layerFE == layerWithQueuedFrames.get();
237 });
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800238
239 if (hasQueuedFrames) {
240 releasedLayers.emplace_back(layerFE);
241 }
242 }
243
244 setReleasedLayers(std::move(releasedLayers));
245}
246
Lloyd Pique66d68602019-02-13 14:23:31 -0800247void Display::chooseCompositionStrategy() {
248 ATRACE_CALL();
249 ALOGV(__FUNCTION__);
250
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200251 if (mIsDisconnected) {
252 return;
253 }
254
Lloyd Pique66d68602019-02-13 14:23:31 -0800255 // Default to the base settings -- client composition only.
256 Output::chooseCompositionStrategy();
257
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200258 // If we don't have a HWC display, then we are done.
259 const auto halDisplayId = HalDisplayId::tryCast(mId);
260 if (!halDisplayId) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800261 return;
262 }
263
264 // Get any composition changes requested by the HWC device, and apply them.
265 std::optional<android::HWComposer::DeviceRequestedChanges> changes;
266 auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200267 if (status_t result =
268 hwc.getDeviceCompositionChanges(*halDisplayId, anyLayersRequireClientComposition(),
269 &changes);
Lloyd Pique66d68602019-02-13 14:23:31 -0800270 result != NO_ERROR) {
271 ALOGE("chooseCompositionStrategy failed for %s: %d (%s)", getName().c_str(), result,
272 strerror(-result));
273 return;
274 }
275 if (changes) {
276 applyChangedTypesToLayers(changes->changedTypes);
277 applyDisplayRequests(changes->displayRequests);
278 applyLayerRequestsToLayers(changes->layerRequests);
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700279 applyClientTargetRequests(changes->clientTargetProperty);
Lloyd Pique66d68602019-02-13 14:23:31 -0800280 }
281
282 // Determine what type of composition we are doing from the final state
283 auto& state = editState();
284 state.usesClientComposition = anyLayersRequireClientComposition();
285 state.usesDeviceComposition = !allLayersRequireClientComposition();
286}
287
Lloyd Pique688abd42019-02-15 15:42:24 -0800288bool Display::getSkipColorTransform() const {
Dominik Laskowski1162e472020-04-02 19:02:47 -0700289 const auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200290 if (const auto halDisplayId = HalDisplayId::tryCast(mId)) {
291 return hwc.hasDisplayCapability(*halDisplayId,
292 hal::DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM);
293 }
294
295 return hwc.hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM);
Lloyd Pique688abd42019-02-15 15:42:24 -0800296}
297
Lloyd Pique66d68602019-02-13 14:23:31 -0800298bool Display::anyLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700299 const auto layers = getOutputLayersOrderedByZ();
300 return std::any_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800301 [](const auto& layer) { return layer->requiresClientComposition(); });
302}
303
304bool Display::allLayersRequireClientComposition() const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700305 const auto layers = getOutputLayersOrderedByZ();
306 return std::all_of(layers.begin(), layers.end(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800307 [](const auto& layer) { return layer->requiresClientComposition(); });
308}
309
310void Display::applyChangedTypesToLayers(const ChangedTypes& changedTypes) {
311 if (changedTypes.empty()) {
312 return;
313 }
314
Lloyd Pique01c77c12019-04-17 12:48:32 -0700315 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800316 auto hwcLayer = layer->getHwcLayer();
317 if (!hwcLayer) {
318 continue;
319 }
320
321 if (auto it = changedTypes.find(hwcLayer); it != changedTypes.end()) {
322 layer->applyDeviceCompositionTypeChange(
323 static_cast<Hwc2::IComposerClient::Composition>(it->second));
324 }
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
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700351void Display::applyClientTargetRequests(const ClientTargetProperty& clientTargetProperty) {
352 if (clientTargetProperty.dataspace == ui::Dataspace::UNKNOWN) {
353 return;
354 }
355 auto outputState = editState();
356 outputState.dataspace = clientTargetProperty.dataspace;
357 getRenderSurface()->setBufferDataspace(clientTargetProperty.dataspace);
358 getRenderSurface()->setBufferPixelFormat(clientTargetProperty.pixelFormat);
359}
360
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800361compositionengine::Output::FrameFences Display::presentAndGetFrameFences() {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200362 auto fences = impl::Output::presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800363
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200364 const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
365 if (mIsDisconnected || !halDisplayIdOpt) {
366 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800367 }
368
369 auto& hwc = getCompositionEngine().getHwComposer();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200370 hwc.presentAndGetReleaseFences(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800371
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200372 fences.presentFence = hwc.getPresentFence(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800373
374 // TODO(b/121291683): Change HWComposer call to return entire map
Lloyd Pique01c77c12019-04-17 12:48:32 -0700375 for (const auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800376 auto hwcLayer = layer->getHwcLayer();
377 if (!hwcLayer) {
378 continue;
379 }
380
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200381 fences.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*halDisplayIdOpt, hwcLayer));
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800382 }
383
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200384 hwc.clearReleaseFences(*halDisplayIdOpt);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800385
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200386 return fences;
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800387}
388
Lloyd Pique688abd42019-02-15 15:42:24 -0800389void Display::setExpensiveRenderingExpected(bool enabled) {
390 Output::setExpensiveRenderingExpected(enabled);
391
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200392 if (mPowerAdvisor && !GpuVirtualDisplayId::tryCast(mId)) {
393 mPowerAdvisor->setExpensiveRenderingExpected(mId, enabled);
Lloyd Pique688abd42019-02-15 15:42:24 -0800394 }
395}
396
Lloyd Piqued3d69882019-02-28 16:03:46 -0800397void Display::finishFrame(const compositionengine::CompositionRefreshArgs& refreshArgs) {
398 // We only need to actually compose the display if:
399 // 1) It is being handled by hardware composer, which may need this to
400 // keep its virtual display state machine in sync, or
401 // 2) There is work to be done (the dirty region isn't empty)
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200402 if (GpuVirtualDisplayId::tryCast(mId) &&
403 getDirtyRegion(refreshArgs.repaintEverything).isEmpty()) {
404 ALOGV("Skipping display composition");
405 return;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800406 }
407
408 impl::Output::finishFrame(refreshArgs);
409}
410
Lloyd Pique45a165a2018-10-19 11:54:47 -0700411} // namespace android::compositionengine::impl