blob: ded2dccd35d2ff3cfac84c5b2a9ba8a61c83165b [file] [log] [blame]
Lloyd Pique32cbe282018-10-19 13:09:22 -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 Piquef8cf14d2019-02-28 16:03:12 -080017#include <thread>
18
Lloyd Pique32cbe282018-10-19 13:09:22 -070019#include <android-base/stringprintf.h>
20#include <compositionengine/CompositionEngine.h>
Lloyd Piquef8cf14d2019-02-28 16:03:12 -080021#include <compositionengine/CompositionRefreshArgs.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070022#include <compositionengine/DisplayColorProfile.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080023#include <compositionengine/LayerFE.h>
Lloyd Pique9755fb72019-03-26 14:44:40 -070024#include <compositionengine/LayerFECompositionState.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070025#include <compositionengine/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070026#include <compositionengine/impl/Output.h>
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070027#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080028#include <compositionengine/impl/OutputLayer.h>
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070029#include <compositionengine/impl/OutputLayerCompositionState.h>
Dan Stoza269dc4d2021-01-15 15:07:43 -080030#include <compositionengine/impl/planner/Planner.h>
31
32#include <SurfaceFlingerProperties.sysprop.h>
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080033
34// TODO(b/129481165): remove the #pragma below and fix conversion issues
35#pragma clang diagnostic push
36#pragma clang diagnostic ignored "-Wconversion"
37
Lloyd Pique688abd42019-02-15 15:42:24 -080038#include <renderengine/DisplaySettings.h>
39#include <renderengine/RenderEngine.h>
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080040
41// TODO(b/129481165): remove the #pragma below and fix conversion issues
42#pragma clang diagnostic pop // ignored "-Wconversion"
43
Dan Stoza269dc4d2021-01-15 15:07:43 -080044#include <android-base/properties.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070045#include <ui/DebugUtils.h>
Lloyd Pique688abd42019-02-15 15:42:24 -080046#include <ui/HdrCapabilities.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080047#include <utils/Trace.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070048
Lloyd Pique688abd42019-02-15 15:42:24 -080049#include "TracedOrdinal.h"
50
Lloyd Piquefeb73d72018-12-04 17:23:44 -080051namespace android::compositionengine {
52
53Output::~Output() = default;
54
55namespace impl {
Lloyd Pique32cbe282018-10-19 13:09:22 -070056
Dan Stoza269dc4d2021-01-15 15:07:43 -080057Output::Output() {
58 const bool enableLayerCaching = [] {
59 const bool enable =
60 android::sysprop::SurfaceFlingerProperties::enable_layer_caching().value_or(false);
61 return base::GetBoolProperty(std::string("debug.sf.enable_layer_caching"), enable);
62 }();
63
64 if (enableLayerCaching) {
65 mPlanner = std::make_unique<planner::Planner>();
66 }
67}
68
Lloyd Piquec29e4c62019-03-07 21:48:19 -080069namespace {
70
71template <typename T>
72class Reversed {
73public:
74 explicit Reversed(const T& container) : mContainer(container) {}
75 auto begin() { return mContainer.rbegin(); }
76 auto end() { return mContainer.rend(); }
77
78private:
79 const T& mContainer;
80};
81
82// Helper for enumerating over a container in reverse order
83template <typename T>
84Reversed<T> reversed(const T& c) {
85 return Reversed<T>(c);
86}
87
Marin Shalamanovb15d2272020-09-17 21:41:52 +020088struct ScaleVector {
89 float x;
90 float y;
91};
92
93// Returns a ScaleVector (x, y) such that from.scale(x, y) = to',
94// where to' will have the same size as "to". In the case where "from" and "to"
95// start at the origin to'=to.
96ScaleVector getScale(const Rect& from, const Rect& to) {
97 return {.x = static_cast<float>(to.width()) / from.width(),
98 .y = static_cast<float>(to.height()) / from.height()};
99}
100
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800101} // namespace
102
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700103std::shared_ptr<Output> createOutput(
104 const compositionengine::CompositionEngine& compositionEngine) {
105 return createOutputTemplated<Output>(compositionEngine);
106}
Lloyd Pique32cbe282018-10-19 13:09:22 -0700107
108Output::~Output() = default;
109
Lloyd Pique32cbe282018-10-19 13:09:22 -0700110bool Output::isValid() const {
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700111 return mDisplayColorProfile && mDisplayColorProfile->isValid() && mRenderSurface &&
112 mRenderSurface->isValid();
Lloyd Pique32cbe282018-10-19 13:09:22 -0700113}
114
Lloyd Pique6c564cf2019-05-17 17:31:36 -0700115std::optional<DisplayId> Output::getDisplayId() const {
116 return {};
117}
118
Lloyd Pique32cbe282018-10-19 13:09:22 -0700119const std::string& Output::getName() const {
120 return mName;
121}
122
123void Output::setName(const std::string& name) {
124 mName = name;
125}
126
127void Output::setCompositionEnabled(bool enabled) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700128 auto& outputState = editState();
129 if (outputState.isEnabled == enabled) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700130 return;
131 }
132
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700133 outputState.isEnabled = enabled;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700134 dirtyEntireOutput();
135}
136
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200137void Output::setProjection(ui::Rotation orientation, const Rect& layerStackSpaceRect,
138 const Rect& orientedDisplaySpaceRect) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700139 auto& outputState = editState();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200140
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200141 outputState.displaySpace.orientation = orientation;
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200142 LOG_FATAL_IF(outputState.displaySpace.bounds == Rect::INVALID_RECT,
143 "The display bounds are unknown.");
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200144
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200145 // Compute orientedDisplaySpace
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200146 ui::Size orientedSize = outputState.displaySpace.bounds.getSize();
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200147 if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200148 std::swap(orientedSize.width, orientedSize.height);
149 }
150 outputState.orientedDisplaySpace.bounds = Rect(orientedSize);
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200151 outputState.orientedDisplaySpace.content = orientedDisplaySpaceRect;
152
153 // Compute displaySpace.content
154 const uint32_t transformOrientationFlags = ui::Transform::toRotationFlags(orientation);
155 ui::Transform rotation;
156 if (transformOrientationFlags != ui::Transform::ROT_INVALID) {
157 const auto displaySize = outputState.displaySpace.bounds;
158 rotation.set(transformOrientationFlags, displaySize.width(), displaySize.height());
159 }
160 outputState.displaySpace.content = rotation.transform(orientedDisplaySpaceRect);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200161
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200162 // Compute framebufferSpace
163 outputState.framebufferSpace.orientation = orientation;
164 LOG_FATAL_IF(outputState.framebufferSpace.bounds == Rect::INVALID_RECT,
165 "The framebuffer bounds are unknown.");
166 const auto scale =
Marin Shalamanov209ae612020-10-01 00:17:39 +0200167 getScale(outputState.displaySpace.bounds, outputState.framebufferSpace.bounds);
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200168 outputState.framebufferSpace.content = outputState.displaySpace.content.scale(scale.x, scale.y);
169
170 // Compute layerStackSpace
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200171 outputState.layerStackSpace.content = layerStackSpaceRect;
172 outputState.layerStackSpace.bounds = layerStackSpaceRect;
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200173
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200174 outputState.transform = outputState.layerStackSpace.getTransform(outputState.displaySpace);
175 outputState.needsFiltering = outputState.transform.needsBilinearFiltering();
Lloyd Pique32cbe282018-10-19 13:09:22 -0700176 dirtyEntireOutput();
177}
178
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200179void Output::setDisplaySize(const ui::Size& size) {
Lloyd Pique31cb2942018-10-19 17:23:03 -0700180 mRenderSurface->setDisplaySize(size);
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200181
182 auto& state = editState();
183
184 // Update framebuffer space
185 const Rect newBounds(size);
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200186 state.framebufferSpace.bounds = newBounds;
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200187
188 // Update display space
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200189 state.displaySpace.bounds = newBounds;
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200190 state.transform = state.layerStackSpace.getTransform(state.displaySpace);
191
192 // Update oriented display space
193 const auto orientation = state.displaySpace.orientation;
194 ui::Size orientedSize = size;
195 if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) {
196 std::swap(orientedSize.width, orientedSize.height);
197 }
198 const Rect newOrientedBounds(orientedSize);
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200199 state.orientedDisplaySpace.bounds = newOrientedBounds;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700200
Dan Stoza6166c312021-01-15 16:34:05 -0800201 if (mPlanner) {
202 mPlanner->setDisplaySize(size);
203 }
204
Lloyd Pique32cbe282018-10-19 13:09:22 -0700205 dirtyEntireOutput();
206}
207
Garfield Tan54edd912020-10-21 16:31:41 -0700208ui::Transform::RotationFlags Output::getTransformHint() const {
209 return static_cast<ui::Transform::RotationFlags>(getState().transform.getOrientation());
210}
211
Lloyd Piqueef36b002019-01-23 17:52:04 -0800212void Output::setLayerStackFilter(uint32_t layerStackId, bool isInternal) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700213 auto& outputState = editState();
214 outputState.layerStackId = layerStackId;
215 outputState.layerStackInternal = isInternal;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700216
217 dirtyEntireOutput();
218}
219
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800220void Output::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700221 auto& colorTransformMatrix = editState().colorTransformMatrix;
222 if (!args.colorTransformMatrix || colorTransformMatrix == args.colorTransformMatrix) {
Lloyd Pique77f79a22019-04-29 15:55:40 -0700223 return;
224 }
225
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700226 colorTransformMatrix = *args.colorTransformMatrix;
Lloyd Piqueef958122019-02-05 18:00:12 -0800227
228 dirtyEntireOutput();
Lloyd Pique32cbe282018-10-19 13:09:22 -0700229}
230
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800231void Output::setColorProfile(const ColorProfile& colorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700232 ui::Dataspace targetDataspace =
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800233 getDisplayColorProfile()->getTargetDataspace(colorProfile.mode, colorProfile.dataspace,
234 colorProfile.colorSpaceAgnosticDataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800235
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700236 auto& outputState = editState();
237 if (outputState.colorMode == colorProfile.mode &&
238 outputState.dataspace == colorProfile.dataspace &&
239 outputState.renderIntent == colorProfile.renderIntent &&
240 outputState.targetDataspace == targetDataspace) {
Lloyd Piqueef958122019-02-05 18:00:12 -0800241 return;
242 }
243
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700244 outputState.colorMode = colorProfile.mode;
245 outputState.dataspace = colorProfile.dataspace;
246 outputState.renderIntent = colorProfile.renderIntent;
247 outputState.targetDataspace = targetDataspace;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700248
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800249 mRenderSurface->setBufferDataspace(colorProfile.dataspace);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700250
Lloyd Pique32cbe282018-10-19 13:09:22 -0700251 ALOGV("Set active color mode: %s (%d), active render intent: %s (%d)",
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800252 decodeColorMode(colorProfile.mode).c_str(), colorProfile.mode,
253 decodeRenderIntent(colorProfile.renderIntent).c_str(), colorProfile.renderIntent);
Lloyd Piqueef958122019-02-05 18:00:12 -0800254
255 dirtyEntireOutput();
Lloyd Pique32cbe282018-10-19 13:09:22 -0700256}
257
258void Output::dump(std::string& out) const {
259 using android::base::StringAppendF;
260
261 StringAppendF(&out, " Composition Output State: [\"%s\"]", mName.c_str());
262
263 out.append("\n ");
264
265 dumpBase(out);
266}
267
268void Output::dumpBase(std::string& out) const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700269 dumpState(out);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700270
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700271 if (mDisplayColorProfile) {
272 mDisplayColorProfile->dump(out);
273 } else {
274 out.append(" No display color profile!\n");
275 }
276
Lloyd Pique31cb2942018-10-19 17:23:03 -0700277 if (mRenderSurface) {
278 mRenderSurface->dump(out);
279 } else {
280 out.append(" No render surface!\n");
281 }
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800282
Lloyd Pique01c77c12019-04-17 12:48:32 -0700283 android::base::StringAppendF(&out, "\n %zu Layers\n", getOutputLayerCount());
284 for (const auto* outputLayer : getOutputLayersOrderedByZ()) {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800285 if (!outputLayer) {
286 continue;
287 }
288 outputLayer->dump(out);
289 }
Lloyd Pique31cb2942018-10-19 17:23:03 -0700290}
291
Dan Stoza269dc4d2021-01-15 15:07:43 -0800292void Output::dumpPlannerInfo(const Vector<String16>& args, std::string& out) const {
293 if (!mPlanner) {
294 base::StringAppendF(&out, "Planner is disabled\n");
295 return;
296 }
297 base::StringAppendF(&out, "Planner info for display [%s]\n", mName.c_str());
298 mPlanner->dump(args, out);
299}
300
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700301compositionengine::DisplayColorProfile* Output::getDisplayColorProfile() const {
302 return mDisplayColorProfile.get();
303}
304
305void Output::setDisplayColorProfile(std::unique_ptr<compositionengine::DisplayColorProfile> mode) {
306 mDisplayColorProfile = std::move(mode);
307}
308
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800309const Output::ReleasedLayers& Output::getReleasedLayersForTest() const {
310 return mReleasedLayers;
311}
312
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700313void Output::setDisplayColorProfileForTest(
314 std::unique_ptr<compositionengine::DisplayColorProfile> mode) {
315 mDisplayColorProfile = std::move(mode);
316}
317
Lloyd Pique31cb2942018-10-19 17:23:03 -0700318compositionengine::RenderSurface* Output::getRenderSurface() const {
319 return mRenderSurface.get();
320}
321
322void Output::setRenderSurface(std::unique_ptr<compositionengine::RenderSurface> surface) {
323 mRenderSurface = std::move(surface);
Dan Stoza6166c312021-01-15 16:34:05 -0800324 const auto size = mRenderSurface->getSize();
325 editState().framebufferSpace.bounds = Rect(size);
326 if (mPlanner) {
327 mPlanner->setDisplaySize(size);
328 }
Lloyd Pique31cb2942018-10-19 17:23:03 -0700329 dirtyEntireOutput();
330}
331
Vishnu Nair9b079a22020-01-21 14:36:08 -0800332void Output::cacheClientCompositionRequests(uint32_t cacheSize) {
333 if (cacheSize == 0) {
334 mClientCompositionRequestCache.reset();
335 } else {
336 mClientCompositionRequestCache = std::make_unique<ClientCompositionRequestCache>(cacheSize);
337 }
338};
339
Lloyd Pique31cb2942018-10-19 17:23:03 -0700340void Output::setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSurface> surface) {
341 mRenderSurface = std::move(surface);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700342}
343
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000344Region Output::getDirtyRegion(bool repaintEverything) const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700345 const auto& outputState = getState();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200346 Region dirty(outputState.layerStackSpace.content);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000347 if (!repaintEverything) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700348 dirty.andSelf(outputState.dirtyRegion);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700349 }
350 return dirty;
351}
352
Lloyd Piquec6687342019-03-07 21:34:57 -0800353bool Output::belongsInOutput(std::optional<uint32_t> layerStackId, bool internalOnly) const {
Lloyd Piqueef36b002019-01-23 17:52:04 -0800354 // The layerStackId's must match, and also the layer must not be internal
355 // only when not on an internal output.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700356 const auto& outputState = getState();
357 return layerStackId && (*layerStackId == outputState.layerStackId) &&
358 (!internalOnly || outputState.layerStackInternal);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700359}
360
Lloyd Piquede196652020-01-22 17:29:58 -0800361bool Output::belongsInOutput(const sp<compositionengine::LayerFE>& layerFE) const {
362 const auto* layerFEState = layerFE->getCompositionState();
363 return layerFEState && belongsInOutput(layerFEState->layerStackId, layerFEState->internalOnly);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800364}
365
Lloyd Piquedf336d92019-03-07 21:38:42 -0800366std::unique_ptr<compositionengine::OutputLayer> Output::createOutputLayer(
Lloyd Piquede196652020-01-22 17:29:58 -0800367 const sp<LayerFE>& layerFE) const {
368 return impl::createOutputLayer(*this, layerFE);
Lloyd Piquecc01a452018-12-04 17:24:00 -0800369}
370
Lloyd Piquede196652020-01-22 17:29:58 -0800371compositionengine::OutputLayer* Output::getOutputLayerForLayer(const sp<LayerFE>& layerFE) const {
372 auto index = findCurrentOutputLayerForLayer(layerFE);
Lloyd Pique01c77c12019-04-17 12:48:32 -0700373 return index ? getOutputLayerOrderedByZByIndex(*index) : nullptr;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800374}
375
Lloyd Pique01c77c12019-04-17 12:48:32 -0700376std::optional<size_t> Output::findCurrentOutputLayerForLayer(
Lloyd Piquede196652020-01-22 17:29:58 -0800377 const sp<compositionengine::LayerFE>& layer) const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700378 for (size_t i = 0; i < getOutputLayerCount(); i++) {
379 auto outputLayer = getOutputLayerOrderedByZByIndex(i);
Lloyd Piquede196652020-01-22 17:29:58 -0800380 if (outputLayer && &outputLayer->getLayerFE() == layer.get()) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700381 return i;
382 }
383 }
384 return std::nullopt;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800385}
386
Lloyd Piquec7ef21b2019-01-29 18:43:00 -0800387void Output::setReleasedLayers(Output::ReleasedLayers&& layers) {
388 mReleasedLayers = std::move(layers);
389}
390
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800391void Output::prepare(const compositionengine::CompositionRefreshArgs& refreshArgs,
392 LayerFESet& geomSnapshots) {
393 ATRACE_CALL();
394 ALOGV(__FUNCTION__);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800395
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800396 rebuildLayerStacks(refreshArgs, geomSnapshots);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800397}
398
Lloyd Piqued7b429f2019-03-07 21:11:02 -0800399void Output::present(const compositionengine::CompositionRefreshArgs& refreshArgs) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800400 ATRACE_CALL();
401 ALOGV(__FUNCTION__);
402
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800403 updateColorProfile(refreshArgs);
Dan Stoza269dc4d2021-01-15 15:07:43 -0800404 updateCompositionState(refreshArgs);
405 planComposition();
406 writeCompositionState(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800407 setColorTransform(refreshArgs);
Lloyd Piqued7b429f2019-03-07 21:11:02 -0800408 beginFrame();
409 prepareFrame();
410 devOptRepaintFlash(refreshArgs);
411 finishFrame(refreshArgs);
412 postFramebuffer();
Dan Stoza6166c312021-01-15 16:34:05 -0800413 renderCachedSets();
Lloyd Piqued7b429f2019-03-07 21:11:02 -0800414}
415
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800416void Output::rebuildLayerStacks(const compositionengine::CompositionRefreshArgs& refreshArgs,
417 LayerFESet& layerFESet) {
418 ATRACE_CALL();
419 ALOGV(__FUNCTION__);
420
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700421 auto& outputState = editState();
422
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800423 // Do nothing if this output is not enabled or there is no need to perform this update
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700424 if (!outputState.isEnabled || CC_LIKELY(!refreshArgs.updatingOutputGeometryThisFrame)) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800425 return;
426 }
427
428 // Process the layers to determine visibility and coverage
429 compositionengine::Output::CoverageState coverage{layerFESet};
430 collectVisibleLayers(refreshArgs, coverage);
431
432 // Compute the resulting coverage for this output, and store it for later
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700433 const ui::Transform& tr = outputState.transform;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200434 Region undefinedRegion{outputState.displaySpace.bounds};
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800435 undefinedRegion.subtractSelf(tr.transform(coverage.aboveOpaqueLayers));
436
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700437 outputState.undefinedRegion = undefinedRegion;
438 outputState.dirtyRegion.orSelf(coverage.dirtyRegion);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800439}
440
441void Output::collectVisibleLayers(const compositionengine::CompositionRefreshArgs& refreshArgs,
442 compositionengine::Output::CoverageState& coverage) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800443 // Evaluate the layers from front to back to determine what is visible. This
444 // also incrementally calculates the coverage information for each layer as
445 // well as the entire output.
Lloyd Piquede196652020-01-22 17:29:58 -0800446 for (auto layer : reversed(refreshArgs.layers)) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700447 // Incrementally process the coverage for each layer
448 ensureOutputLayerIfVisible(layer, coverage);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800449
450 // TODO(b/121291683): Stop early if the output is completely covered and
451 // no more layers could even be visible underneath the ones on top.
452 }
453
Lloyd Pique01c77c12019-04-17 12:48:32 -0700454 setReleasedLayers(refreshArgs);
455
456 finalizePendingOutputLayers();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800457
458 // Generate a simple Z-order values to each visible output layer
459 uint32_t zOrder = 0;
Lloyd Pique01c77c12019-04-17 12:48:32 -0700460 for (auto* outputLayer : getOutputLayersOrderedByZ()) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800461 outputLayer->editState().z = zOrder++;
462 }
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800463}
464
Lloyd Piquede196652020-01-22 17:29:58 -0800465void Output::ensureOutputLayerIfVisible(sp<compositionengine::LayerFE>& layerFE,
Lloyd Pique01c77c12019-04-17 12:48:32 -0700466 compositionengine::Output::CoverageState& coverage) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800467 // Ensure we have a snapshot of the basic geometry layer state. Limit the
468 // snapshots to once per frame for each candidate layer, as layers may
469 // appear on multiple outputs.
470 if (!coverage.latchedLayers.count(layerFE)) {
471 coverage.latchedLayers.insert(layerFE);
Lloyd Piquede196652020-01-22 17:29:58 -0800472 layerFE->prepareCompositionState(compositionengine::LayerFE::StateSubset::BasicGeometry);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800473 }
474
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800475 // Only consider the layers on the given layer stack
Lloyd Piquede196652020-01-22 17:29:58 -0800476 if (!belongsInOutput(layerFE)) {
477 return;
478 }
479
480 // Obtain a read-only pointer to the front-end layer state
481 const auto* layerFEState = layerFE->getCompositionState();
482 if (CC_UNLIKELY(!layerFEState)) {
483 return;
484 }
485
486 // handle hidden surfaces by setting the visible region to empty
487 if (CC_UNLIKELY(!layerFEState->isVisible)) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700488 return;
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800489 }
490
491 /*
492 * opaqueRegion: area of a surface that is fully opaque.
493 */
494 Region opaqueRegion;
495
496 /*
497 * visibleRegion: area of a surface that is visible on screen and not fully
498 * transparent. This is essentially the layer's footprint minus the opaque
499 * regions above it. Areas covered by a translucent surface are considered
500 * visible.
501 */
502 Region visibleRegion;
503
504 /*
505 * coveredRegion: area of a surface that is covered by all visible regions
506 * above it (which includes the translucent areas).
507 */
508 Region coveredRegion;
509
510 /*
511 * transparentRegion: area of a surface that is hinted to be completely
512 * transparent. This is only used to tell when the layer has no visible non-
513 * transparent regions and can be removed from the layer list. It does not
514 * affect the visibleRegion of this layer or any layers beneath it. The hint
515 * may not be correct if apps don't respect the SurfaceView restrictions
516 * (which, sadly, some don't).
517 */
518 Region transparentRegion;
519
Vishnu Naira483b4a2019-12-12 15:07:52 -0800520 /*
521 * shadowRegion: Region cast by the layer's shadow.
522 */
523 Region shadowRegion;
524
Lloyd Piquede196652020-01-22 17:29:58 -0800525 const ui::Transform& tr = layerFEState->geomLayerTransform;
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800526
527 // Get the visible region
528 // TODO(b/121291683): Is it worth creating helper methods on LayerFEState
529 // for computations like this?
Lloyd Piquede196652020-01-22 17:29:58 -0800530 const Rect visibleRect(tr.transform(layerFEState->geomLayerBounds));
Vishnu Naira483b4a2019-12-12 15:07:52 -0800531 visibleRegion.set(visibleRect);
532
Lloyd Piquede196652020-01-22 17:29:58 -0800533 if (layerFEState->shadowRadius > 0.0f) {
Vishnu Naira483b4a2019-12-12 15:07:52 -0800534 // if the layer casts a shadow, offset the layers visible region and
535 // calculate the shadow region.
Lloyd Piquede196652020-01-22 17:29:58 -0800536 const auto inset = static_cast<int32_t>(ceilf(layerFEState->shadowRadius) * -1.0f);
Vishnu Naira483b4a2019-12-12 15:07:52 -0800537 Rect visibleRectWithShadows(visibleRect);
538 visibleRectWithShadows.inset(inset, inset, inset, inset);
539 visibleRegion.set(visibleRectWithShadows);
540 shadowRegion = visibleRegion.subtract(visibleRect);
541 }
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800542
543 if (visibleRegion.isEmpty()) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700544 return;
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800545 }
546
547 // Remove the transparent area from the visible region
Lloyd Piquede196652020-01-22 17:29:58 -0800548 if (!layerFEState->isOpaque) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800549 if (tr.preserveRects()) {
550 // transform the transparent region
Lloyd Piquede196652020-01-22 17:29:58 -0800551 transparentRegion = tr.transform(layerFEState->transparentRegionHint);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800552 } else {
553 // transformation too complex, can't do the
554 // transparent region optimization.
555 transparentRegion.clear();
556 }
557 }
558
559 // compute the opaque region
Lloyd Pique0a456232020-01-16 17:51:13 -0800560 const auto layerOrientation = tr.getOrientation();
Lloyd Piquede196652020-01-22 17:29:58 -0800561 if (layerFEState->isOpaque && ((layerOrientation & ui::Transform::ROT_INVALID) == 0)) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800562 // If we one of the simple category of transforms (0/90/180/270 rotation
563 // + any flip), then the opaque region is the layer's footprint.
564 // Otherwise we don't try and compute the opaque region since there may
565 // be errors at the edges, and we treat the entire layer as
566 // translucent.
Vishnu Naira483b4a2019-12-12 15:07:52 -0800567 opaqueRegion.set(visibleRect);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800568 }
569
570 // Clip the covered region to the visible region
571 coveredRegion = coverage.aboveCoveredLayers.intersect(visibleRegion);
572
573 // Update accumAboveCoveredLayers for next (lower) layer
574 coverage.aboveCoveredLayers.orSelf(visibleRegion);
575
576 // subtract the opaque region covered by the layers above us
577 visibleRegion.subtractSelf(coverage.aboveOpaqueLayers);
578
579 if (visibleRegion.isEmpty()) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700580 return;
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800581 }
582
583 // Get coverage information for the layer as previously displayed,
584 // also taking over ownership from mOutputLayersorderedByZ.
Lloyd Piquede196652020-01-22 17:29:58 -0800585 auto prevOutputLayerIndex = findCurrentOutputLayerForLayer(layerFE);
Lloyd Pique01c77c12019-04-17 12:48:32 -0700586 auto prevOutputLayer =
587 prevOutputLayerIndex ? getOutputLayerOrderedByZByIndex(*prevOutputLayerIndex) : nullptr;
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800588
589 // Get coverage information for the layer as previously displayed
590 // TODO(b/121291683): Define kEmptyRegion as a constant in Region.h
591 const Region kEmptyRegion;
592 const Region& oldVisibleRegion =
593 prevOutputLayer ? prevOutputLayer->getState().visibleRegion : kEmptyRegion;
594 const Region& oldCoveredRegion =
595 prevOutputLayer ? prevOutputLayer->getState().coveredRegion : kEmptyRegion;
596
597 // compute this layer's dirty region
598 Region dirty;
Lloyd Piquede196652020-01-22 17:29:58 -0800599 if (layerFEState->contentDirty) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800600 // we need to invalidate the whole region
601 dirty = visibleRegion;
602 // as well, as the old visible region
603 dirty.orSelf(oldVisibleRegion);
604 } else {
605 /* compute the exposed region:
606 * the exposed region consists of two components:
607 * 1) what's VISIBLE now and was COVERED before
608 * 2) what's EXPOSED now less what was EXPOSED before
609 *
610 * note that (1) is conservative, we start with the whole visible region
611 * but only keep what used to be covered by something -- which mean it
612 * may have been exposed.
613 *
614 * (2) handles areas that were not covered by anything but got exposed
615 * because of a resize.
616 *
617 */
618 const Region newExposed = visibleRegion - coveredRegion;
619 const Region oldExposed = oldVisibleRegion - oldCoveredRegion;
620 dirty = (visibleRegion & oldCoveredRegion) | (newExposed - oldExposed);
621 }
622 dirty.subtractSelf(coverage.aboveOpaqueLayers);
623
624 // accumulate to the screen dirty region
625 coverage.dirtyRegion.orSelf(dirty);
626
627 // Update accumAboveOpaqueLayers for next (lower) layer
628 coverage.aboveOpaqueLayers.orSelf(opaqueRegion);
629
630 // Compute the visible non-transparent region
631 Region visibleNonTransparentRegion = visibleRegion.subtract(transparentRegion);
632
Vishnu Naira483b4a2019-12-12 15:07:52 -0800633 // Perform the final check to see if this layer is visible on this output
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800634 // TODO(b/121291683): Why does this not use visibleRegion? (see outputSpaceVisibleRegion below)
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700635 const auto& outputState = getState();
636 Region drawRegion(outputState.transform.transform(visibleNonTransparentRegion));
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200637 drawRegion.andSelf(outputState.displaySpace.bounds);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800638 if (drawRegion.isEmpty()) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700639 return;
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800640 }
641
Vishnu Naira483b4a2019-12-12 15:07:52 -0800642 Region visibleNonShadowRegion = visibleRegion.subtract(shadowRegion);
643
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800644 // The layer is visible. Either reuse the existing outputLayer if we have
645 // one, or create a new one if we do not.
Lloyd Piquede196652020-01-22 17:29:58 -0800646 auto result = ensureOutputLayer(prevOutputLayerIndex, layerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800647
648 // Store the layer coverage information into the layer state as some of it
649 // is useful later.
650 auto& outputLayerState = result->editState();
651 outputLayerState.visibleRegion = visibleRegion;
652 outputLayerState.visibleNonTransparentRegion = visibleNonTransparentRegion;
653 outputLayerState.coveredRegion = coveredRegion;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200654 outputLayerState.outputSpaceVisibleRegion = outputState.transform.transform(
655 visibleNonShadowRegion.intersect(outputState.layerStackSpace.content));
Vishnu Naira483b4a2019-12-12 15:07:52 -0800656 outputLayerState.shadowRegion = shadowRegion;
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800657}
658
659void Output::setReleasedLayers(const compositionengine::CompositionRefreshArgs&) {
660 // The base class does nothing with this call.
661}
662
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800663void Output::updateLayerStateFromFE(const CompositionRefreshArgs& args) const {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700664 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Piquede196652020-01-22 17:29:58 -0800665 layer->getLayerFE().prepareCompositionState(
666 args.updatingGeometryThisFrame ? LayerFE::StateSubset::GeometryAndContent
667 : LayerFE::StateSubset::Content);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800668 }
669}
670
Dan Stoza269dc4d2021-01-15 15:07:43 -0800671void Output::updateCompositionState(const compositionengine::CompositionRefreshArgs& refreshArgs) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800672 ATRACE_CALL();
673 ALOGV(__FUNCTION__);
674
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800675 if (!getState().isEnabled) {
676 return;
677 }
678
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800679 mLayerRequestingBackgroundBlur = findLayerRequestingBackgroundComposition();
680 bool forceClientComposition = mLayerRequestingBackgroundBlur != nullptr;
681
Lloyd Pique01c77c12019-04-17 12:48:32 -0700682 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique7a234912019-10-03 11:54:27 -0700683 layer->updateCompositionState(refreshArgs.updatingGeometryThisFrame,
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800684 refreshArgs.devOptForceClientComposition ||
Snild Dolkow9e217d62020-04-22 15:53:42 +0200685 forceClientComposition,
686 refreshArgs.internalDisplayRotationFlags);
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800687
688 if (mLayerRequestingBackgroundBlur == layer) {
689 forceClientComposition = false;
690 }
Dan Stoza269dc4d2021-01-15 15:07:43 -0800691 }
692}
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800693
Dan Stoza269dc4d2021-01-15 15:07:43 -0800694void Output::planComposition() {
695 if (!mPlanner || !getState().isEnabled) {
696 return;
697 }
698
699 ATRACE_CALL();
700 ALOGV(__FUNCTION__);
701
702 mPlanner->plan(getOutputLayersOrderedByZ());
703}
704
705void Output::writeCompositionState(const compositionengine::CompositionRefreshArgs& refreshArgs) {
706 ATRACE_CALL();
707 ALOGV(__FUNCTION__);
708
709 if (!getState().isEnabled) {
710 return;
711 }
712
Dan Stoza6166c312021-01-15 16:34:05 -0800713 sp<GraphicBuffer> previousOverride = nullptr;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800714 for (auto* layer : getOutputLayersOrderedByZ()) {
Dan Stoza6166c312021-01-15 16:34:05 -0800715 bool skipLayer = false;
716 if (layer->getState().overrideInfo.buffer != nullptr) {
717 if (previousOverride != nullptr &&
718 layer->getState().overrideInfo.buffer == previousOverride) {
719 ALOGV("Skipping redundant buffer");
720 skipLayer = true;
721 }
722 previousOverride = layer->getState().overrideInfo.buffer;
723 }
724
725 // TODO(b/181172795): We now update geometry for all flattened layers. We should update it
726 // only when the geometry actually changes
727 const bool includeGeometry = refreshArgs.updatingGeometryThisFrame ||
728 layer->getState().overrideInfo.buffer != nullptr || skipLayer;
729 layer->writeStateToHWC(includeGeometry, skipLayer);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800730 }
731}
732
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800733compositionengine::OutputLayer* Output::findLayerRequestingBackgroundComposition() const {
734 compositionengine::OutputLayer* layerRequestingBgComposition = nullptr;
735 for (auto* layer : getOutputLayersOrderedByZ()) {
Galia Peycheva66eaf4a2020-11-09 13:17:57 +0100736 auto* compState = layer->getLayerFE().getCompositionState();
737
738 // If any layer has a sideband stream, we will disable blurs. In that case, we don't
739 // want to force client composition because of the blur.
740 if (compState->sidebandStream != nullptr) {
741 return nullptr;
742 }
743 if (compState->backgroundBlurRadius > 0 || compState->blurRegions.size() > 0) {
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800744 layerRequestingBgComposition = layer;
745 }
746 }
747 return layerRequestingBgComposition;
748}
749
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800750void Output::updateColorProfile(const compositionengine::CompositionRefreshArgs& refreshArgs) {
751 setColorProfile(pickColorProfile(refreshArgs));
752}
753
754// Returns a data space that fits all visible layers. The returned data space
755// can only be one of
756// - Dataspace::SRGB (use legacy dataspace and let HWC saturate when colors are enhanced)
757// - Dataspace::DISPLAY_P3
758// - Dataspace::DISPLAY_BT2020
759// The returned HDR data space is one of
760// - Dataspace::UNKNOWN
761// - Dataspace::BT2020_HLG
762// - Dataspace::BT2020_PQ
763ui::Dataspace Output::getBestDataspace(ui::Dataspace* outHdrDataSpace,
764 bool* outIsHdrClientComposition) const {
765 ui::Dataspace bestDataSpace = ui::Dataspace::V0_SRGB;
766 *outHdrDataSpace = ui::Dataspace::UNKNOWN;
767
Lloyd Pique01c77c12019-04-17 12:48:32 -0700768 for (const auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Piquede196652020-01-22 17:29:58 -0800769 switch (layer->getLayerFE().getCompositionState()->dataspace) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800770 case ui::Dataspace::V0_SCRGB:
771 case ui::Dataspace::V0_SCRGB_LINEAR:
772 case ui::Dataspace::BT2020:
773 case ui::Dataspace::BT2020_ITU:
774 case ui::Dataspace::BT2020_LINEAR:
775 case ui::Dataspace::DISPLAY_BT2020:
776 bestDataSpace = ui::Dataspace::DISPLAY_BT2020;
777 break;
778 case ui::Dataspace::DISPLAY_P3:
779 bestDataSpace = ui::Dataspace::DISPLAY_P3;
780 break;
781 case ui::Dataspace::BT2020_PQ:
782 case ui::Dataspace::BT2020_ITU_PQ:
783 bestDataSpace = ui::Dataspace::DISPLAY_P3;
784 *outHdrDataSpace = ui::Dataspace::BT2020_PQ;
Lloyd Piquede196652020-01-22 17:29:58 -0800785 *outIsHdrClientComposition =
786 layer->getLayerFE().getCompositionState()->forceClientComposition;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800787 break;
788 case ui::Dataspace::BT2020_HLG:
789 case ui::Dataspace::BT2020_ITU_HLG:
790 bestDataSpace = ui::Dataspace::DISPLAY_P3;
791 // When there's mixed PQ content and HLG content, we set the HDR
792 // data space to be BT2020_PQ and convert HLG to PQ.
793 if (*outHdrDataSpace == ui::Dataspace::UNKNOWN) {
794 *outHdrDataSpace = ui::Dataspace::BT2020_HLG;
795 }
796 break;
797 default:
798 break;
799 }
800 }
801
802 return bestDataSpace;
803}
804
805compositionengine::Output::ColorProfile Output::pickColorProfile(
806 const compositionengine::CompositionRefreshArgs& refreshArgs) const {
807 if (refreshArgs.outputColorSetting == OutputColorSetting::kUnmanaged) {
808 return ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
809 ui::RenderIntent::COLORIMETRIC,
810 refreshArgs.colorSpaceAgnosticDataspace};
811 }
812
813 ui::Dataspace hdrDataSpace;
814 bool isHdrClientComposition = false;
815 ui::Dataspace bestDataSpace = getBestDataspace(&hdrDataSpace, &isHdrClientComposition);
816
817 switch (refreshArgs.forceOutputColorMode) {
818 case ui::ColorMode::SRGB:
819 bestDataSpace = ui::Dataspace::V0_SRGB;
820 break;
821 case ui::ColorMode::DISPLAY_P3:
822 bestDataSpace = ui::Dataspace::DISPLAY_P3;
823 break;
824 default:
825 break;
826 }
827
828 // respect hdrDataSpace only when there is no legacy HDR support
829 const bool isHdr = hdrDataSpace != ui::Dataspace::UNKNOWN &&
830 !mDisplayColorProfile->hasLegacyHdrSupport(hdrDataSpace) && !isHdrClientComposition;
831 if (isHdr) {
832 bestDataSpace = hdrDataSpace;
833 }
834
835 ui::RenderIntent intent;
836 switch (refreshArgs.outputColorSetting) {
837 case OutputColorSetting::kManaged:
838 case OutputColorSetting::kUnmanaged:
839 intent = isHdr ? ui::RenderIntent::TONE_MAP_COLORIMETRIC
840 : ui::RenderIntent::COLORIMETRIC;
841 break;
842 case OutputColorSetting::kEnhanced:
843 intent = isHdr ? ui::RenderIntent::TONE_MAP_ENHANCE : ui::RenderIntent::ENHANCE;
844 break;
845 default: // vendor display color setting
846 intent = static_cast<ui::RenderIntent>(refreshArgs.outputColorSetting);
847 break;
848 }
849
850 ui::ColorMode outMode;
851 ui::Dataspace outDataSpace;
852 ui::RenderIntent outRenderIntent;
853 mDisplayColorProfile->getBestColorMode(bestDataSpace, intent, &outDataSpace, &outMode,
854 &outRenderIntent);
855
856 return ColorProfile{outMode, outDataSpace, outRenderIntent,
857 refreshArgs.colorSpaceAgnosticDataspace};
858}
859
Lloyd Piqued0a92a02019-02-19 17:47:26 -0800860void Output::beginFrame() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700861 auto& outputState = editState();
Lloyd Piqued0a92a02019-02-19 17:47:26 -0800862 const bool dirty = !getDirtyRegion(false).isEmpty();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700863 const bool empty = getOutputLayerCount() == 0;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700864 const bool wasEmpty = !outputState.lastCompositionHadVisibleLayers;
Lloyd Piqued0a92a02019-02-19 17:47:26 -0800865
866 // If nothing has changed (!dirty), don't recompose.
867 // If something changed, but we don't currently have any visible layers,
868 // and didn't when we last did a composition, then skip it this time.
869 // The second rule does two things:
870 // - When all layers are removed from a display, we'll emit one black
871 // frame, then nothing more until we get new layers.
872 // - When a display is created with a private layer stack, we won't
873 // emit any black frames until a layer is added to the layer stack.
874 const bool mustRecompose = dirty && !(empty && wasEmpty);
875
876 const char flagPrefix[] = {'-', '+'};
877 static_cast<void>(flagPrefix);
878 ALOGV_IF("%s: %s composition for %s (%cdirty %cempty %cwasEmpty)", __FUNCTION__,
879 mustRecompose ? "doing" : "skipping", getName().c_str(), flagPrefix[dirty],
880 flagPrefix[empty], flagPrefix[wasEmpty]);
881
882 mRenderSurface->beginFrame(mustRecompose);
883
884 if (mustRecompose) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700885 outputState.lastCompositionHadVisibleLayers = !empty;
Lloyd Piqued0a92a02019-02-19 17:47:26 -0800886 }
887}
888
Lloyd Pique66d68602019-02-13 14:23:31 -0800889void Output::prepareFrame() {
890 ATRACE_CALL();
891 ALOGV(__FUNCTION__);
892
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700893 const auto& outputState = getState();
894 if (!outputState.isEnabled) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800895 return;
896 }
897
898 chooseCompositionStrategy();
899
Dan Stoza47437bb2021-01-15 16:21:07 -0800900 if (mPlanner) {
901 mPlanner->reportFinalPlan(getOutputLayersOrderedByZ());
902 }
903
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700904 mRenderSurface->prepareFrame(outputState.usesClientComposition,
905 outputState.usesDeviceComposition);
Lloyd Pique66d68602019-02-13 14:23:31 -0800906}
907
Lloyd Piquef8cf14d2019-02-28 16:03:12 -0800908void Output::devOptRepaintFlash(const compositionengine::CompositionRefreshArgs& refreshArgs) {
909 if (CC_LIKELY(!refreshArgs.devOptFlashDirtyRegionsDelay)) {
910 return;
911 }
912
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700913 if (getState().isEnabled) {
Lloyd Piquef8cf14d2019-02-28 16:03:12 -0800914 // transform the dirty region into this screen's coordinate space
915 const Region dirtyRegion = getDirtyRegion(refreshArgs.repaintEverything);
916 if (!dirtyRegion.isEmpty()) {
917 base::unique_fd readyFence;
918 // redraw the whole screen
Lucas Dupin2dd6f392020-02-18 17:43:36 -0800919 static_cast<void>(composeSurfaces(dirtyRegion, refreshArgs));
Lloyd Piquef8cf14d2019-02-28 16:03:12 -0800920
921 mRenderSurface->queueBuffer(std::move(readyFence));
922 }
923 }
924
925 postFramebuffer();
926
927 std::this_thread::sleep_for(*refreshArgs.devOptFlashDirtyRegionsDelay);
928
929 prepareFrame();
930}
931
Lucas Dupin2dd6f392020-02-18 17:43:36 -0800932void Output::finishFrame(const compositionengine::CompositionRefreshArgs& refreshArgs) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800933 ATRACE_CALL();
934 ALOGV(__FUNCTION__);
935
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700936 if (!getState().isEnabled) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800937 return;
938 }
939
940 // Repaint the framebuffer (if needed), getting the optional fence for when
941 // the composition completes.
Lucas Dupin2dd6f392020-02-18 17:43:36 -0800942 auto optReadyFence = composeSurfaces(Region::INVALID_REGION, refreshArgs);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800943 if (!optReadyFence) {
944 return;
945 }
946
947 // swap buffers (presentation)
948 mRenderSurface->queueBuffer(std::move(*optReadyFence));
949}
950
Lucas Dupin2dd6f392020-02-18 17:43:36 -0800951std::optional<base::unique_fd> Output::composeSurfaces(
952 const Region& debugRegion, const compositionengine::CompositionRefreshArgs& refreshArgs) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800953 ATRACE_CALL();
954 ALOGV(__FUNCTION__);
955
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700956 const auto& outputState = getState();
Vishnu Nair9b079a22020-01-21 14:36:08 -0800957 OutputCompositionState& outputCompositionState = editState();
Lloyd Pique688abd42019-02-15 15:42:24 -0800958 const TracedOrdinal<bool> hasClientComposition = {"hasClientComposition",
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700959 outputState.usesClientComposition};
Lloyd Piquee9eff972020-05-05 12:36:44 -0700960
961 auto& renderEngine = getCompositionEngine().getRenderEngine();
962 const bool supportsProtectedContent = renderEngine.supportsProtectedContent();
963
964 // If we the display is secure, protected content support is enabled, and at
965 // least one layer has protected content, we need to use a secure back
966 // buffer.
967 if (outputState.isSecure && supportsProtectedContent) {
968 auto layers = getOutputLayersOrderedByZ();
969 bool needsProtected = std::any_of(layers.begin(), layers.end(), [](auto* layer) {
970 return layer->getLayerFE().getCompositionState()->hasProtectedContent;
971 });
972 if (needsProtected != renderEngine.isProtected()) {
973 renderEngine.useProtectedContext(needsProtected);
974 }
975 if (needsProtected != mRenderSurface->isProtected() &&
976 needsProtected == renderEngine.isProtected()) {
977 mRenderSurface->setProtected(needsProtected);
978 }
Peiyong Lin09f910f2020-09-25 10:54:13 -0700979 } else if (!outputState.isSecure && renderEngine.isProtected()) {
980 renderEngine.useProtectedContext(false);
Lloyd Piquee9eff972020-05-05 12:36:44 -0700981 }
982
983 base::unique_fd fd;
984 sp<GraphicBuffer> buf;
985
986 // If we aren't doing client composition on this output, but do have a
987 // flipClientTarget request for this frame on this output, we still need to
988 // dequeue a buffer.
989 if (hasClientComposition || outputState.flipClientTarget) {
990 buf = mRenderSurface->dequeueBuffer(&fd);
991 if (buf == nullptr) {
992 ALOGW("Dequeuing buffer for display [%s] failed, bailing out of "
993 "client composition for this frame",
994 mName.c_str());
995 return {};
996 }
997 }
998
Lloyd Piqued3d69882019-02-28 16:03:46 -0800999 base::unique_fd readyFence;
Lloyd Pique688abd42019-02-15 15:42:24 -08001000 if (!hasClientComposition) {
Lloyd Piquea76ce462020-01-14 13:06:37 -08001001 setExpensiveRenderingExpected(false);
Lloyd Piqued3d69882019-02-28 16:03:46 -08001002 return readyFence;
Lloyd Pique688abd42019-02-15 15:42:24 -08001003 }
1004
1005 ALOGV("hasClientComposition");
1006
Lloyd Pique688abd42019-02-15 15:42:24 -08001007 renderengine::DisplaySettings clientCompositionDisplay;
Marin Shalamanovb15d2272020-09-17 21:41:52 +02001008 clientCompositionDisplay.physicalDisplay = outputState.framebufferSpace.content;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001009 clientCompositionDisplay.clip = outputState.layerStackSpace.content;
Marin Shalamanov68933fb2020-09-10 17:58:12 +02001010 clientCompositionDisplay.orientation =
1011 ui::Transform::toRotationFlags(outputState.displaySpace.orientation);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001012 clientCompositionDisplay.outputDataspace = mDisplayColorProfile->hasWideColorGamut()
1013 ? outputState.dataspace
1014 : ui::Dataspace::UNKNOWN;
Lloyd Pique688abd42019-02-15 15:42:24 -08001015 clientCompositionDisplay.maxLuminance =
1016 mDisplayColorProfile->getHdrCapabilities().getDesiredMaxLuminance();
1017
1018 // Compute the global color transform matrix.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001019 if (!outputState.usesDeviceComposition && !getSkipColorTransform()) {
1020 clientCompositionDisplay.colorTransform = outputState.colorTransformMatrix;
Lloyd Pique688abd42019-02-15 15:42:24 -08001021 }
1022
1023 // Note: Updated by generateClientCompositionRequests
1024 clientCompositionDisplay.clearRegion = Region::INVALID_REGION;
1025
1026 // Generate the client composition requests for the layers on this output.
Vishnu Nair9b079a22020-01-21 14:36:08 -08001027 std::vector<LayerFE::LayerSettings> clientCompositionLayers =
Lloyd Pique688abd42019-02-15 15:42:24 -08001028 generateClientCompositionRequests(supportsProtectedContent,
Vishnu Nair3a7346c2019-12-04 08:09:09 -08001029 clientCompositionDisplay.clearRegion,
1030 clientCompositionDisplay.outputDataspace);
Lloyd Pique688abd42019-02-15 15:42:24 -08001031 appendRegionFlashRequests(debugRegion, clientCompositionLayers);
1032
Vishnu Nair9b079a22020-01-21 14:36:08 -08001033 // Check if the client composition requests were rendered into the provided graphic buffer. If
1034 // so, we can reuse the buffer and avoid client composition.
1035 if (mClientCompositionRequestCache) {
1036 if (mClientCompositionRequestCache->exists(buf->getId(), clientCompositionDisplay,
1037 clientCompositionLayers)) {
1038 outputCompositionState.reusedClientComposition = true;
1039 setExpensiveRenderingExpected(false);
1040 return readyFence;
1041 }
1042 mClientCompositionRequestCache->add(buf->getId(), clientCompositionDisplay,
1043 clientCompositionLayers);
1044 }
1045
Lloyd Pique688abd42019-02-15 15:42:24 -08001046 // We boost GPU frequency here because there will be color spaces conversion
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08001047 // or complex GPU shaders and it's expensive. We boost the GPU frequency so that
1048 // GPU composition can finish in time. We must reset GPU frequency afterwards,
1049 // because high frequency consumes extra battery.
Lucas Dupin2dd6f392020-02-18 17:43:36 -08001050 const bool expensiveBlurs =
1051 refreshArgs.blursAreExpensive && mLayerRequestingBackgroundBlur != nullptr;
Lloyd Pique688abd42019-02-15 15:42:24 -08001052 const bool expensiveRenderingExpected =
Lucas Dupin2dd6f392020-02-18 17:43:36 -08001053 clientCompositionDisplay.outputDataspace == ui::Dataspace::DISPLAY_P3 || expensiveBlurs;
Lloyd Pique688abd42019-02-15 15:42:24 -08001054 if (expensiveRenderingExpected) {
1055 setExpensiveRenderingExpected(true);
1056 }
1057
Vishnu Nair9b079a22020-01-21 14:36:08 -08001058 std::vector<const renderengine::LayerSettings*> clientCompositionLayerPointers;
1059 clientCompositionLayerPointers.reserve(clientCompositionLayers.size());
1060 std::transform(clientCompositionLayers.begin(), clientCompositionLayers.end(),
1061 std::back_inserter(clientCompositionLayerPointers),
1062 [](LayerFE::LayerSettings& settings) -> renderengine::LayerSettings* {
1063 return &settings;
1064 });
1065
Alec Mourie4034bb2019-11-19 12:45:54 -08001066 const nsecs_t renderEngineStart = systemTime();
Alec Mouri1684c702021-02-04 12:27:26 -08001067 // Only use the framebuffer cache when rendering to an internal display
1068 // TODO(b/173560331): This is only to help mitigate memory leaks from virtual displays because
1069 // right now we don't have a concrete eviction policy for output buffers: GLESRenderEngine
1070 // bounds its framebuffer cache but Skia RenderEngine has no current policy. The best fix is
1071 // probably to encapsulate the output buffer into a structure that dispatches resource cleanup
1072 // over to RenderEngine, in which case this flag can be removed from the drawLayers interface.
1073 const bool useFramebufferCache = outputState.layerStackInternal;
Vishnu Nair9b079a22020-01-21 14:36:08 -08001074 status_t status =
Ana Krulecfc874ae2020-02-22 15:39:32 -08001075 renderEngine.drawLayers(clientCompositionDisplay, clientCompositionLayerPointers, buf,
Alec Mouri1684c702021-02-04 12:27:26 -08001076 useFramebufferCache, std::move(fd), &readyFence);
Vishnu Nair9b079a22020-01-21 14:36:08 -08001077
1078 if (status != NO_ERROR && mClientCompositionRequestCache) {
1079 // If rendering was not successful, remove the request from the cache.
1080 mClientCompositionRequestCache->remove(buf->getId());
1081 }
1082
Alec Mourie4034bb2019-11-19 12:45:54 -08001083 auto& timeStats = getCompositionEngine().getTimeStats();
1084 if (readyFence.get() < 0) {
1085 timeStats.recordRenderEngineDuration(renderEngineStart, systemTime());
1086 } else {
1087 timeStats.recordRenderEngineDuration(renderEngineStart,
1088 std::make_shared<FenceTime>(
1089 new Fence(dup(readyFence.get()))));
1090 }
Lloyd Pique688abd42019-02-15 15:42:24 -08001091
Lloyd Piqued3d69882019-02-28 16:03:46 -08001092 return readyFence;
Lloyd Pique688abd42019-02-15 15:42:24 -08001093}
1094
Vishnu Nair9b079a22020-01-21 14:36:08 -08001095std::vector<LayerFE::LayerSettings> Output::generateClientCompositionRequests(
Vishnu Nair3a7346c2019-12-04 08:09:09 -08001096 bool supportsProtectedContent, Region& clearRegion, ui::Dataspace outputDataspace) {
Vishnu Nair9b079a22020-01-21 14:36:08 -08001097 std::vector<LayerFE::LayerSettings> clientCompositionLayers;
Lloyd Pique688abd42019-02-15 15:42:24 -08001098 ALOGV("Rendering client layers");
1099
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001100 const auto& outputState = getState();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001101 const Region viewportRegion(outputState.layerStackSpace.content);
Lloyd Pique688abd42019-02-15 15:42:24 -08001102 bool firstLayer = true;
1103 // Used when a layer clears part of the buffer.
Peiyong Lind8460c82020-07-28 16:04:22 -07001104 Region stubRegion;
Lloyd Pique688abd42019-02-15 15:42:24 -08001105
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01001106 bool disableBlurs = false;
1107
Lloyd Pique01c77c12019-04-17 12:48:32 -07001108 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique688abd42019-02-15 15:42:24 -08001109 const auto& layerState = layer->getState();
Lloyd Piquede196652020-01-22 17:29:58 -08001110 const auto* layerFEState = layer->getLayerFE().getCompositionState();
Lloyd Pique688abd42019-02-15 15:42:24 -08001111 auto& layerFE = layer->getLayerFE();
1112
Lloyd Piquea2468662019-03-07 21:31:06 -08001113 const Region clip(viewportRegion.intersect(layerState.visibleRegion));
Lloyd Pique688abd42019-02-15 15:42:24 -08001114 ALOGV("Layer: %s", layerFE.getDebugName());
1115 if (clip.isEmpty()) {
1116 ALOGV(" Skipping for empty clip");
1117 firstLayer = false;
1118 continue;
1119 }
1120
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01001121 disableBlurs |= layerFEState->sidebandStream != nullptr;
1122
Vishnu Naira483b4a2019-12-12 15:07:52 -08001123 const bool clientComposition = layer->requiresClientComposition();
Lloyd Pique688abd42019-02-15 15:42:24 -08001124
1125 // We clear the client target for non-client composed layers if
1126 // requested by the HWC. We skip this if the layer is not an opaque
1127 // rectangle, as by definition the layer must blend with whatever is
1128 // underneath. We also skip the first layer as the buffer target is
1129 // guaranteed to start out cleared.
Vishnu Nairb87d94f2020-02-13 09:17:36 -08001130 const bool clearClientComposition =
Lloyd Piquede196652020-01-22 17:29:58 -08001131 layerState.clearClientTarget && layerFEState->isOpaque && !firstLayer;
Lloyd Pique688abd42019-02-15 15:42:24 -08001132
1133 ALOGV(" Composition type: client %d clear %d", clientComposition, clearClientComposition);
1134
Vishnu Nairb87d94f2020-02-13 09:17:36 -08001135 // If the layer casts a shadow but the content casting the shadow is occluded, skip
1136 // composing the non-shadow content and only draw the shadows.
1137 const bool realContentIsVisible = clientComposition &&
1138 !layerState.visibleRegion.subtract(layerState.shadowRegion).isEmpty();
1139
Lloyd Pique688abd42019-02-15 15:42:24 -08001140 if (clientComposition || clearClientComposition) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001141 compositionengine::LayerFE::ClientCompositionTargetSettings
1142 targetSettings{.clip = clip,
1143 .needsFiltering =
1144 layer->needsFiltering() || outputState.needsFiltering,
1145 .isSecure = outputState.isSecure,
1146 .supportsProtectedContent = supportsProtectedContent,
1147 .clearRegion = clientComposition ? clearRegion : stubRegion,
1148 .viewport = outputState.layerStackSpace.content,
1149 .dataspace = outputDataspace,
1150 .realContentIsVisible = realContentIsVisible,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01001151 .clearContent = !clientComposition,
1152 .disableBlurs = disableBlurs};
Dan Stoza6166c312021-01-15 16:34:05 -08001153
1154 std::vector<LayerFE::LayerSettings> results;
1155 if (layer->getState().overrideInfo.buffer != nullptr) {
1156 results = layer->getOverrideCompositionList();
1157 ALOGV("Replacing [%s] with override in RE", layer->getLayerFE().getDebugName());
1158 } else {
1159 results = layerFE.prepareClientCompositionList(targetSettings);
1160 if (realContentIsVisible && !results.empty()) {
1161 layer->editState().clientCompositionTimestamp = systemTime();
1162 }
Lloyd Pique688abd42019-02-15 15:42:24 -08001163 }
Vishnu Nairb87d94f2020-02-13 09:17:36 -08001164
1165 clientCompositionLayers.insert(clientCompositionLayers.end(),
1166 std::make_move_iterator(results.begin()),
1167 std::make_move_iterator(results.end()));
1168 results.clear();
Lloyd Pique688abd42019-02-15 15:42:24 -08001169 }
1170
1171 firstLayer = false;
1172 }
1173
1174 return clientCompositionLayers;
1175}
1176
1177void Output::appendRegionFlashRequests(
Vishnu Nair9b079a22020-01-21 14:36:08 -08001178 const Region& flashRegion, std::vector<LayerFE::LayerSettings>& clientCompositionLayers) {
Lloyd Pique688abd42019-02-15 15:42:24 -08001179 if (flashRegion.isEmpty()) {
1180 return;
1181 }
1182
Vishnu Nair9b079a22020-01-21 14:36:08 -08001183 LayerFE::LayerSettings layerSettings;
Lloyd Pique688abd42019-02-15 15:42:24 -08001184 layerSettings.source.buffer.buffer = nullptr;
1185 layerSettings.source.solidColor = half3(1.0, 0.0, 1.0);
1186 layerSettings.alpha = half(1.0);
1187
1188 for (const auto& rect : flashRegion) {
1189 layerSettings.geometry.boundaries = rect.toFloatRect();
1190 clientCompositionLayers.push_back(layerSettings);
1191 }
1192}
1193
1194void Output::setExpensiveRenderingExpected(bool) {
1195 // The base class does nothing with this call.
1196}
1197
Lloyd Pique35fca9d2019-02-13 14:24:11 -08001198void Output::postFramebuffer() {
1199 ATRACE_CALL();
1200 ALOGV(__FUNCTION__);
1201
1202 if (!getState().isEnabled) {
1203 return;
1204 }
1205
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001206 auto& outputState = editState();
1207 outputState.dirtyRegion.clear();
Lloyd Piqued3d69882019-02-28 16:03:46 -08001208 mRenderSurface->flip();
1209
Lloyd Pique35fca9d2019-02-13 14:24:11 -08001210 auto frame = presentAndGetFrameFences();
1211
Lloyd Pique7d90ba52019-08-08 11:57:53 -07001212 mRenderSurface->onPresentDisplayCompleted();
1213
Lloyd Pique01c77c12019-04-17 12:48:32 -07001214 for (auto* layer : getOutputLayersOrderedByZ()) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -08001215 // The layer buffer from the previous frame (if any) is released
1216 // by HWC only when the release fence from this frame (if any) is
1217 // signaled. Always get the release fence from HWC first.
1218 sp<Fence> releaseFence = Fence::NO_FENCE;
1219
1220 if (auto hwcLayer = layer->getHwcLayer()) {
1221 if (auto f = frame.layerFences.find(hwcLayer); f != frame.layerFences.end()) {
1222 releaseFence = f->second;
1223 }
1224 }
1225
1226 // If the layer was client composited in the previous frame, we
1227 // need to merge with the previous client target acquire fence.
1228 // Since we do not track that, always merge with the current
1229 // client target acquire fence when it is available, even though
1230 // this is suboptimal.
1231 // TODO(b/121291683): Track previous frame client target acquire fence.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001232 if (outputState.usesClientComposition) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -08001233 releaseFence =
1234 Fence::merge("LayerRelease", releaseFence, frame.clientTargetAcquireFence);
1235 }
1236
1237 layer->getLayerFE().onLayerDisplayed(releaseFence);
1238 }
1239
1240 // We've got a list of layers needing fences, that are disjoint with
Lloyd Pique01c77c12019-04-17 12:48:32 -07001241 // OutputLayersOrderedByZ. The best we can do is to
Lloyd Pique35fca9d2019-02-13 14:24:11 -08001242 // supply them with the present fence.
1243 for (auto& weakLayer : mReleasedLayers) {
1244 if (auto layer = weakLayer.promote(); layer != nullptr) {
1245 layer->onLayerDisplayed(frame.presentFence);
1246 }
1247 }
1248
1249 // Clear out the released layers now that we're done with them.
1250 mReleasedLayers.clear();
1251}
1252
Dan Stoza6166c312021-01-15 16:34:05 -08001253void Output::renderCachedSets() {
1254 if (mPlanner) {
Alec Mouri9c8fce02021-03-12 18:30:42 -08001255 mPlanner->renderCachedSets(getCompositionEngine().getRenderEngine(), getState().dataspace);
Dan Stoza6166c312021-01-15 16:34:05 -08001256 }
1257}
1258
Lloyd Pique32cbe282018-10-19 13:09:22 -07001259void Output::dirtyEntireOutput() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001260 auto& outputState = editState();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001261 outputState.dirtyRegion.set(outputState.displaySpace.bounds);
Lloyd Pique32cbe282018-10-19 13:09:22 -07001262}
1263
Lloyd Pique66d68602019-02-13 14:23:31 -08001264void Output::chooseCompositionStrategy() {
1265 // The base output implementation can only do client composition
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001266 auto& outputState = editState();
1267 outputState.usesClientComposition = true;
1268 outputState.usesDeviceComposition = false;
Vishnu Nair9b079a22020-01-21 14:36:08 -08001269 outputState.reusedClientComposition = false;
Lloyd Pique66d68602019-02-13 14:23:31 -08001270}
1271
Lloyd Pique688abd42019-02-15 15:42:24 -08001272bool Output::getSkipColorTransform() const {
1273 return true;
1274}
1275
Lloyd Pique35fca9d2019-02-13 14:24:11 -08001276compositionengine::Output::FrameFences Output::presentAndGetFrameFences() {
1277 compositionengine::Output::FrameFences result;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001278 if (getState().usesClientComposition) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -08001279 result.clientTargetAcquireFence = mRenderSurface->getClientTargetAcquireFence();
1280 }
1281 return result;
1282}
1283
Lloyd Piquefeb73d72018-12-04 17:23:44 -08001284} // namespace impl
1285} // namespace android::compositionengine