blob: bde2d0561ac8c7a6c61d52a499e69ed0b34692d3 [file] [log] [blame]
Vishnu Nairdc4d31b2022-11-17 03:20:58 +00001/*
2 * Copyright 2022 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
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18#undef LOG_TAG
19#define LOG_TAG "RequestedLayerState"
20
Vishnu Naircfb2d252023-01-19 04:44:02 +000021#include <log/log.h>
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000022#include <private/android_filesystem_config.h>
23#include <sys/types.h>
24
25#include "Layer.h"
Vishnu Naircfb2d252023-01-19 04:44:02 +000026#include "LayerCreationArgs.h"
Vishnu Naircfb2d252023-01-19 04:44:02 +000027#include "LayerLog.h"
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000028#include "RequestedLayerState.h"
29
30namespace android::surfaceflinger::frontend {
31using ftl::Flags;
32using namespace ftl::flag_operators;
33
34namespace {
Vishnu Naira9c43762023-01-27 19:10:25 +000035std::string layerIdsToString(const std::vector<uint32_t>& layerIds) {
36 std::stringstream stream;
37 stream << "{";
38 for (auto layerId : layerIds) {
39 stream << layerId << ",";
40 }
41 stream << "}";
42 return stream.str();
43}
44
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000045} // namespace
46
47RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args)
48 : id(args.sequence),
Vishnu Naircfb2d252023-01-19 04:44:02 +000049 name(args.name + "#" + std::to_string(args.sequence)),
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000050 canBeRoot(args.addToRoot),
51 layerCreationFlags(args.flags),
52 textureName(args.textureName),
53 ownerUid(args.ownerUid),
Vishnu Nair1391de22023-03-05 19:56:14 -080054 ownerPid(args.ownerPid),
55 parentId(args.parentId),
56 layerIdToMirror(args.layerIdToMirror) {
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000057 layerId = static_cast<int32_t>(args.sequence);
58 changes |= RequestedLayerState::Changes::Created;
59 metadata.merge(args.metadata);
60 changes |= RequestedLayerState::Changes::Metadata;
61 handleAlive = true;
Vishnu Nair1391de22023-03-05 19:56:14 -080062 if (parentId != UNASSIGNED_LAYER_ID) {
Vishnu Naircfb2d252023-01-19 04:44:02 +000063 canBeRoot = false;
64 }
Vishnu Naira9c43762023-01-27 19:10:25 +000065 if (layerIdToMirror != UNASSIGNED_LAYER_ID) {
66 changes |= RequestedLayerState::Changes::Mirror;
67 } else if (args.layerStackToMirror != ui::INVALID_LAYER_STACK) {
68 layerStackToMirror = args.layerStackToMirror;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000069 changes |= RequestedLayerState::Changes::Mirror;
70 }
71
72 flags = 0;
73 if (args.flags & ISurfaceComposerClient::eHidden) flags |= layer_state_t::eLayerHidden;
74 if (args.flags & ISurfaceComposerClient::eOpaque) flags |= layer_state_t::eLayerOpaque;
75 if (args.flags & ISurfaceComposerClient::eSecure) flags |= layer_state_t::eLayerSecure;
76 if (args.flags & ISurfaceComposerClient::eSkipScreenshot) {
77 flags |= layer_state_t::eLayerSkipScreenshot;
78 }
79 premultipliedAlpha = !(args.flags & ISurfaceComposerClient::eNonPremultiplied);
80 potentialCursor = args.flags & ISurfaceComposerClient::eCursorWindow;
81 protectedByApp = args.flags & ISurfaceComposerClient::eProtectedByApp;
82 if (args.flags & ISurfaceComposerClient::eNoColorFill) {
83 // Set an invalid color so there is no color fill.
84 // (b/259981098) use an explicit flag instead of relying on invalid values.
85 color.r = -1.0_hf;
86 color.g = -1.0_hf;
87 color.b = -1.0_hf;
88 } else {
89 color.rgb = {0.0_hf, 0.0_hf, 0.0_hf};
90 }
Vishnu Naircfb2d252023-01-19 04:44:02 +000091 LLOGV(layerId, "Created %s flags=%d", getDebugString().c_str(), flags);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000092 color.a = 1.0f;
93
94 crop.makeInvalid();
95 z = 0;
96 layerStack = ui::DEFAULT_LAYER_STACK;
97 transformToDisplayInverse = false;
98 dataspace = ui::Dataspace::UNKNOWN;
Sally Qi963049b2023-03-23 14:06:21 -070099 desiredHdrSdrRatio = 1.f;
100 currentHdrSdrRatio = 1.f;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000101 dataspaceRequested = false;
102 hdrMetadata.validTypes = 0;
103 surfaceDamageRegion = Region::INVALID_REGION;
104 cornerRadius = 0.0f;
105 backgroundBlurRadius = 0;
106 api = -1;
107 hasColorTransform = false;
108 bufferTransform = 0;
109 requestedTransform.reset();
110 bufferData = std::make_shared<BufferData>();
111 bufferData->frameNumber = 0;
112 bufferData->acquireFence = sp<Fence>::make(-1);
113 acquireFenceTime = std::make_shared<FenceTime>(bufferData->acquireFence);
114 colorSpaceAgnostic = false;
115 frameRateSelectionPriority = Layer::PRIORITY_UNSET;
116 shadowRadius = 0.f;
117 fixedTransformHint = ui::Transform::ROT_INVALID;
118 destinationFrame.makeInvalid();
119 isTrustedOverlay = false;
120 dropInputMode = gui::DropInputMode::NONE;
121 dimmingEnabled = true;
122 defaultFrameRateCompatibility =
123 static_cast<int8_t>(scheduler::LayerInfo::FrameRateCompatibility::Default);
124 dataspace = ui::Dataspace::V0_SRGB;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000125 gameMode = gui::GameMode::Unsupported;
126 requestedFrameRate = {};
Alec Mourif4af03e2023-02-11 00:25:24 +0000127 cachingHint = gui::CachingHint::Enabled;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000128}
129
130void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerState) {
Vishnu Naircfb2d252023-01-19 04:44:02 +0000131 const uint32_t oldFlags = flags;
132 const half oldAlpha = color.a;
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700133 const bool hadBuffer = externalTexture != nullptr;
Vishnu Naird1f74982023-06-15 20:16:51 -0700134 uint64_t oldFramenumber = hadBuffer ? bufferData->frameNumber : 0;
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700135 const bool hadSideStream = sidebandStream != nullptr;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000136 const layer_state_t& clientState = resolvedComposerState.state;
Vishnu Nair80a5a702023-02-11 01:21:51 +0000137 const bool hadBlur = hasBlur();
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000138 uint64_t clientChanges = what | layer_state_t::diff(clientState);
139 layer_state_t::merge(clientState);
140 what = clientChanges;
141
142 if (clientState.what & layer_state_t::eFlagsChanged) {
143 if ((oldFlags ^ flags) & layer_state_t::eLayerHidden) {
Vishnu Naircfb2d252023-01-19 04:44:02 +0000144 changes |= RequestedLayerState::Changes::Visibility |
145 RequestedLayerState::Changes::VisibleRegion;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000146 }
147 if ((oldFlags ^ flags) & layer_state_t::eIgnoreDestinationFrame) {
148 changes |= RequestedLayerState::Changes::Geometry;
149 }
150 }
Vishnu Naird1f74982023-06-15 20:16:51 -0700151
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700152 if (clientState.what & layer_state_t::eBufferChanged) {
153 externalTexture = resolvedComposerState.externalTexture;
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700154 const bool hasBuffer = externalTexture != nullptr;
155 if (hasBuffer || hasBuffer != hadBuffer) {
156 changes |= RequestedLayerState::Changes::Buffer;
157 }
158
159 if (hasBuffer != hadBuffer) {
Vishnu Naircfb2d252023-01-19 04:44:02 +0000160 changes |= RequestedLayerState::Changes::Geometry |
161 RequestedLayerState::Changes::VisibleRegion |
Vishnu Naird47bcee2023-02-24 18:08:51 +0000162 RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Input;
163 }
Vishnu Naird1f74982023-06-15 20:16:51 -0700164
165 if (hasBuffer) {
166 const bool frameNumberChanged =
167 bufferData->flags.test(BufferData::BufferDataChange::frameNumberChanged);
168 const uint64_t frameNumber =
169 frameNumberChanged ? bufferData->frameNumber : oldFramenumber + 1;
170 bufferData->frameNumber = frameNumber;
171
172 if ((barrierProducerId > bufferData->producerId) ||
173 ((barrierProducerId == bufferData->producerId) &&
174 (barrierFrameNumber > bufferData->frameNumber))) {
175 ALOGE("Out of order buffers detected for %s producedId=%d frameNumber=%" PRIu64
176 " -> producedId=%d frameNumber=%" PRIu64,
177 getDebugString().c_str(), bufferData->producerId, bufferData->frameNumber,
178 bufferData->producerId, frameNumber);
179 TransactionTraceWriter::getInstance().invoke("out_of_order_buffers_",
180 /*overwrite=*/false);
181 }
182
183 barrierProducerId = std::max(bufferData->producerId, barrierProducerId);
184 barrierFrameNumber = std::max(bufferData->frameNumber, barrierFrameNumber);
185 }
Vishnu Nair63221212023-04-06 15:17:37 -0700186 }
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700187
Vishnu Nair63221212023-04-06 15:17:37 -0700188 if (clientState.what & layer_state_t::eSidebandStreamChanged) {
189 changes |= RequestedLayerState::Changes::SidebandStream;
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700190 const bool hasSideStream = sidebandStream != nullptr;
191 if (hasSideStream != hadSideStream) {
192 changes |= RequestedLayerState::Changes::Geometry |
193 RequestedLayerState::Changes::VisibleRegion |
194 RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Input;
195 }
Vishnu Naircfb2d252023-01-19 04:44:02 +0000196 }
197 if (what & (layer_state_t::eAlphaChanged)) {
198 if (oldAlpha == 0 || color.a == 0) {
199 changes |= RequestedLayerState::Changes::Visibility |
200 RequestedLayerState::Changes::VisibleRegion;
201 }
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000202 }
Vishnu Nair80a5a702023-02-11 01:21:51 +0000203 if (what & (layer_state_t::eBackgroundBlurRadiusChanged | layer_state_t::eBlurRegionsChanged)) {
204 if (hadBlur != hasBlur()) {
205 changes |= RequestedLayerState::Changes::Visibility |
206 RequestedLayerState::Changes::VisibleRegion;
207 }
208 }
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000209 if (clientChanges & layer_state_t::HIERARCHY_CHANGES)
210 changes |= RequestedLayerState::Changes::Hierarchy;
211 if (clientChanges & layer_state_t::CONTENT_CHANGES)
212 changes |= RequestedLayerState::Changes::Content;
213 if (clientChanges & layer_state_t::GEOMETRY_CHANGES)
214 changes |= RequestedLayerState::Changes::Geometry;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000215 if (clientChanges & layer_state_t::AFFECTS_CHILDREN)
216 changes |= RequestedLayerState::Changes::AffectsChildren;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000217 if (clientChanges & layer_state_t::INPUT_CHANGES)
218 changes |= RequestedLayerState::Changes::Input;
219 if (clientChanges & layer_state_t::VISIBLE_REGION_CHANGES)
220 changes |= RequestedLayerState::Changes::VisibleRegion;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000221 if (clientState.what & layer_state_t::eColorTransformChanged) {
222 static const mat4 identityMatrix = mat4();
223 hasColorTransform = colorTransform != identityMatrix;
224 }
Vishnu Naird47bcee2023-02-24 18:08:51 +0000225 if (clientState.what &
226 (layer_state_t::eLayerChanged | layer_state_t::eRelativeLayerChanged |
227 layer_state_t::eLayerStackChanged)) {
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000228 changes |= RequestedLayerState::Changes::Z;
229 }
230 if (clientState.what & layer_state_t::eReparent) {
231 changes |= RequestedLayerState::Changes::Parent;
Vishnu Nair1391de22023-03-05 19:56:14 -0800232 parentId = resolvedComposerState.parentId;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000233 parentSurfaceControlForChild = nullptr;
Vishnu Nair04f89692022-11-16 23:21:05 +0000234 // Once a layer has be reparented, it cannot be placed at the root. It sounds odd
235 // but thats the existing logic and until we make this behavior more explicit, we need
236 // to maintain this logic.
237 canBeRoot = false;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000238 }
239 if (clientState.what & layer_state_t::eRelativeLayerChanged) {
240 changes |= RequestedLayerState::Changes::RelativeParent;
Vishnu Nair1391de22023-03-05 19:56:14 -0800241 relativeParentId = resolvedComposerState.relativeParentId;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000242 isRelativeOf = true;
243 relativeLayerSurfaceControl = nullptr;
244 }
245 if ((clientState.what & layer_state_t::eLayerChanged ||
246 (clientState.what & layer_state_t::eReparent && parentId == UNASSIGNED_LAYER_ID)) &&
247 isRelativeOf) {
248 // clear out relz data
249 relativeParentId = UNASSIGNED_LAYER_ID;
250 isRelativeOf = false;
251 changes |= RequestedLayerState::Changes::RelativeParent;
252 }
253 if (clientState.what & layer_state_t::eReparent && parentId == relativeParentId) {
254 // provide a hint that we are are now a direct child and not a relative child.
255 changes |= RequestedLayerState::Changes::RelativeParent;
256 }
257 if (clientState.what & layer_state_t::eInputInfoChanged) {
Vishnu Nair1391de22023-03-05 19:56:14 -0800258 touchCropId = resolvedComposerState.touchCropId;
259 windowInfoHandle->editInfo()->touchableRegionCropHandle.clear();
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000260 }
261 if (clientState.what & layer_state_t::eStretchChanged) {
262 stretchEffect.sanitize();
263 }
264
265 if (clientState.what & layer_state_t::eHasListenerCallbacksChanged) {
266 // TODO(b/238781169) handle callbacks
267 }
268
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000269 if (clientState.what & layer_state_t::ePositionChanged) {
270 requestedTransform.set(x, y);
271 }
272
273 if (clientState.what & layer_state_t::eMatrixChanged) {
274 requestedTransform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
275 }
Vishnu Naircfb2d252023-01-19 04:44:02 +0000276 if (clientState.what & layer_state_t::eMetadataChanged) {
277 const int32_t requestedGameMode =
278 clientState.metadata.getInt32(gui::METADATA_GAME_MODE, -1);
279 if (requestedGameMode != -1) {
280 // The transaction will be received on the Task layer and needs to be applied to all
281 // child layers.
282 if (static_cast<int32_t>(gameMode) != requestedGameMode) {
283 gameMode = static_cast<gui::GameMode>(requestedGameMode);
284 changes |= RequestedLayerState::Changes::AffectsChildren;
285 }
286 }
287 }
288 if (clientState.what & layer_state_t::eFrameRateChanged) {
289 const auto compatibility =
290 Layer::FrameRate::convertCompatibility(clientState.frameRateCompatibility);
291 const auto strategy = Layer::FrameRate::convertChangeFrameRateStrategy(
292 clientState.changeFrameRateStrategy);
293 requestedFrameRate =
294 Layer::FrameRate(Fps::fromValue(clientState.frameRate), compatibility, strategy);
295 changes |= RequestedLayerState::Changes::FrameRate;
296 }
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000297}
298
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000299ui::Size RequestedLayerState::getUnrotatedBufferSize(uint32_t displayRotationFlags) const {
300 uint32_t bufferWidth = externalTexture->getWidth();
301 uint32_t bufferHeight = externalTexture->getHeight();
302 // Undo any transformations on the buffer.
303 if (bufferTransform & ui::Transform::ROT_90) {
304 std::swap(bufferWidth, bufferHeight);
305 }
306 if (transformToDisplayInverse) {
307 if (displayRotationFlags & ui::Transform::ROT_90) {
308 std::swap(bufferWidth, bufferHeight);
309 }
310 }
311 return {bufferWidth, bufferHeight};
312}
313
314ui::Transform RequestedLayerState::getTransform(uint32_t displayRotationFlags) const {
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000315 if ((flags & layer_state_t::eIgnoreDestinationFrame) || destinationFrame.isEmpty()) {
316 // If destination frame is not set, use the requested transform set via
317 // Transaction::setPosition and Transaction::setMatrix.
318 return requestedTransform;
319 }
320
321 Rect destRect = destinationFrame;
322 int32_t destW = destRect.width();
323 int32_t destH = destRect.height();
324 if (destRect.left < 0) {
325 destRect.left = 0;
326 destRect.right = destW;
327 }
328 if (destRect.top < 0) {
329 destRect.top = 0;
330 destRect.bottom = destH;
331 }
332
333 if (!externalTexture) {
334 ui::Transform transform;
335 transform.set(static_cast<float>(destRect.left), static_cast<float>(destRect.top));
336 return transform;
337 }
338
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000339 ui::Size bufferSize = getUnrotatedBufferSize(displayRotationFlags);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000340
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000341 float sx = static_cast<float>(destW) / static_cast<float>(bufferSize.width);
342 float sy = static_cast<float>(destH) / static_cast<float>(bufferSize.height);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000343 ui::Transform transform;
344 transform.set(sx, 0, 0, sy);
345 transform.set(static_cast<float>(destRect.left), static_cast<float>(destRect.top));
346 return transform;
347}
348
349std::string RequestedLayerState::getDebugString() const {
Vishnu Nair80a5a702023-02-11 01:21:51 +0000350 std::stringstream debug;
Vishnu Nair444f3952023-04-11 13:01:02 -0700351 debug << "RequestedLayerState{" << name;
352 if (parentId != UNASSIGNED_LAYER_ID) debug << " parentId=" << parentId;
353 if (relativeParentId != UNASSIGNED_LAYER_ID) debug << " relativeParentId=" << relativeParentId;
354 if (!mirrorIds.empty()) debug << " mirrorId=" << layerIdsToString(mirrorIds);
355 if (!handleAlive) debug << " !handle";
356 if (z != 0) debug << " z=" << z;
357 if (layerStack.id != 0) debug << " layerStack=" << layerStack.id;
Vishnu Nair80a5a702023-02-11 01:21:51 +0000358 return debug.str();
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000359}
360
361std::string RequestedLayerState::getDebugStringShort() const {
362 return "[" + std::to_string(id) + "]" + name;
363}
364
365bool RequestedLayerState::canBeDestroyed() const {
366 return !handleAlive && parentId == UNASSIGNED_LAYER_ID;
367}
368bool RequestedLayerState::isRoot() const {
369 return canBeRoot && parentId == UNASSIGNED_LAYER_ID;
370}
371bool RequestedLayerState::isHiddenByPolicy() const {
372 return (flags & layer_state_t::eLayerHidden) == layer_state_t::eLayerHidden;
373};
374half4 RequestedLayerState::getColor() const {
375 if ((sidebandStream != nullptr) || (externalTexture != nullptr)) {
376 return {0._hf, 0._hf, 0._hf, color.a};
377 }
378 return color;
379}
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000380Rect RequestedLayerState::getBufferSize(uint32_t displayRotationFlags) const {
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000381 // for buffer state layers we use the display frame size as the buffer size.
382 if (!externalTexture) {
383 return Rect::INVALID_RECT;
384 }
385
386 uint32_t bufWidth = externalTexture->getWidth();
387 uint32_t bufHeight = externalTexture->getHeight();
388
389 // Undo any transformations on the buffer and return the result.
390 if (bufferTransform & ui::Transform::ROT_90) {
391 std::swap(bufWidth, bufHeight);
392 }
393
394 if (transformToDisplayInverse) {
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000395 uint32_t invTransform = displayRotationFlags;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000396 if (invTransform & ui::Transform::ROT_90) {
397 std::swap(bufWidth, bufHeight);
398 }
399 }
400
401 return Rect(0, 0, static_cast<int32_t>(bufWidth), static_cast<int32_t>(bufHeight));
402}
403
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000404Rect RequestedLayerState::getCroppedBufferSize(const Rect& bufferSize) const {
405 Rect size = bufferSize;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000406 if (!crop.isEmpty() && size.isValid()) {
407 size.intersect(crop, &size);
408 } else if (!crop.isEmpty()) {
409 size = crop;
410 }
411 return size;
412}
413
414Rect RequestedLayerState::getBufferCrop() const {
415 // this is the crop rectangle that applies to the buffer
416 // itself (as opposed to the window)
417 if (!bufferCrop.isEmpty()) {
418 // if the buffer crop is defined, we use that
419 return bufferCrop;
420 } else if (externalTexture != nullptr) {
421 // otherwise we use the whole buffer
422 return externalTexture->getBounds();
423 } else {
424 // if we don't have a buffer yet, we use an empty/invalid crop
425 return Rect();
426 }
427}
428
429aidl::android::hardware::graphics::composer3::Composition RequestedLayerState::getCompositionType()
430 const {
431 using aidl::android::hardware::graphics::composer3::Composition;
432 // TODO(b/238781169) check about sidestream ready flag
433 if (sidebandStream.get()) {
434 return Composition::SIDEBAND;
435 }
436 if (!externalTexture) {
437 return Composition::SOLID_COLOR;
438 }
439 if (flags & layer_state_t::eLayerIsDisplayDecoration) {
440 return Composition::DISPLAY_DECORATION;
441 }
442 if (potentialCursor) {
443 return Composition::CURSOR;
444 }
445 return Composition::DEVICE;
446}
447
448Rect RequestedLayerState::reduce(const Rect& win, const Region& exclude) {
449 if (CC_LIKELY(exclude.isEmpty())) {
450 return win;
451 }
452 if (exclude.isRect()) {
453 return win.reduce(exclude.getBounds());
454 }
455 return Region(win).subtract(exclude).getBounds();
456}
457
Vishnu Nair04f89692022-11-16 23:21:05 +0000458// Returns true if the layer has a relative parent that is not its own parent. This is an input
459// error from the client, and this check allows us to handle it gracefully. If both parentId and
460// relativeParentId is unassigned then the layer does not have a valid relative parent.
461// If the relative parentid is unassigned, the layer will be considered relative but won't be
462// reachable.
463bool RequestedLayerState::hasValidRelativeParent() const {
Vishnu Naircfb2d252023-01-19 04:44:02 +0000464 return isRelativeOf &&
465 (parentId != relativeParentId || relativeParentId == UNASSIGNED_LAYER_ID);
Vishnu Nair04f89692022-11-16 23:21:05 +0000466}
467
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000468bool RequestedLayerState::hasInputInfo() const {
469 if (!windowInfoHandle) {
470 return false;
471 }
472 const auto windowInfo = windowInfoHandle->getInfo();
473 return windowInfo->token != nullptr ||
474 windowInfo->inputConfig.test(gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL);
475}
476
Vishnu Nair80a5a702023-02-11 01:21:51 +0000477bool RequestedLayerState::hasBlur() const {
478 return backgroundBlurRadius > 0 || blurRegions.size() > 0;
479}
480
Vishnu Naird47bcee2023-02-24 18:08:51 +0000481bool RequestedLayerState::hasFrameUpdate() const {
482 return what & layer_state_t::CONTENT_DIRTY &&
483 (externalTexture || bgColorLayerId != UNASSIGNED_LAYER_ID);
484}
485
486bool RequestedLayerState::hasReadyFrame() const {
487 return hasFrameUpdate() || changes.test(Changes::SidebandStream) || autoRefresh;
488}
489
490bool RequestedLayerState::hasSidebandStreamFrame() const {
491 return hasFrameUpdate() && sidebandStream.get();
492}
493
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700494bool RequestedLayerState::willReleaseBufferOnLatch() const {
495 return changes.test(Changes::Buffer) && !externalTexture;
496}
497
Vishnu Naird47bcee2023-02-24 18:08:51 +0000498void RequestedLayerState::clearChanges() {
499 what = 0;
500 changes.clear();
501}
502
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000503} // namespace android::surfaceflinger::frontend