Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 1 | /* |
| 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 Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | #undef LOG_TAG |
| 19 | #define LOG_TAG "RequestedLayerState" |
| 20 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 21 | #include <log/log.h> |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 22 | #include <private/android_filesystem_config.h> |
| 23 | #include <sys/types.h> |
| 24 | |
| 25 | #include "Layer.h" |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 26 | #include "LayerCreationArgs.h" |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 27 | #include "LayerHandle.h" |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 28 | #include "LayerLog.h" |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 29 | #include "RequestedLayerState.h" |
| 30 | |
| 31 | namespace android::surfaceflinger::frontend { |
| 32 | using ftl::Flags; |
| 33 | using namespace ftl::flag_operators; |
| 34 | |
| 35 | namespace { |
| 36 | uint32_t getLayerIdFromSurfaceControl(sp<SurfaceControl> surfaceControl) { |
| 37 | if (!surfaceControl) { |
| 38 | return UNASSIGNED_LAYER_ID; |
| 39 | } |
| 40 | |
| 41 | return LayerHandle::getLayerId(surfaceControl->getHandle()); |
| 42 | } |
| 43 | |
| 44 | std::string layerIdToString(uint32_t layerId) { |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 45 | return layerId == UNASSIGNED_LAYER_ID ? "none" : std::to_string(layerId); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | } // namespace |
| 49 | |
| 50 | RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args) |
| 51 | : id(args.sequence), |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 52 | name(args.name + "#" + std::to_string(args.sequence)), |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 53 | canBeRoot(args.addToRoot), |
| 54 | layerCreationFlags(args.flags), |
| 55 | textureName(args.textureName), |
| 56 | ownerUid(args.ownerUid), |
| 57 | ownerPid(args.ownerPid) { |
| 58 | layerId = static_cast<int32_t>(args.sequence); |
| 59 | changes |= RequestedLayerState::Changes::Created; |
| 60 | metadata.merge(args.metadata); |
| 61 | changes |= RequestedLayerState::Changes::Metadata; |
| 62 | handleAlive = true; |
| 63 | parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 64 | if (args.parentHandle != nullptr) { |
| 65 | canBeRoot = false; |
| 66 | } |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 67 | mirrorId = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
| 68 | if (mirrorId != UNASSIGNED_LAYER_ID) { |
| 69 | 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 Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 91 | LLOGV(layerId, "Created %s flags=%d", getDebugString().c_str(), flags); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 92 | 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; |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame^] | 99 | desiredSdrHdrRatio = 1.f; |
| 100 | currentSdrHdrRatio = 1.f; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 101 | 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 Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 125 | gameMode = gui::GameMode::Unsupported; |
| 126 | requestedFrameRate = {}; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerState) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 130 | const uint32_t oldFlags = flags; |
| 131 | const half oldAlpha = color.a; |
| 132 | const bool hadBufferOrSideStream = hasValidBuffer() || sidebandStream != nullptr; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 133 | const layer_state_t& clientState = resolvedComposerState.state; |
| 134 | |
| 135 | uint64_t clientChanges = what | layer_state_t::diff(clientState); |
| 136 | layer_state_t::merge(clientState); |
| 137 | what = clientChanges; |
| 138 | |
| 139 | if (clientState.what & layer_state_t::eFlagsChanged) { |
| 140 | if ((oldFlags ^ flags) & layer_state_t::eLayerHidden) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 141 | changes |= RequestedLayerState::Changes::Visibility | |
| 142 | RequestedLayerState::Changes::VisibleRegion; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 143 | } |
| 144 | if ((oldFlags ^ flags) & layer_state_t::eIgnoreDestinationFrame) { |
| 145 | changes |= RequestedLayerState::Changes::Geometry; |
| 146 | } |
| 147 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 148 | if (clientState.what & |
| 149 | (layer_state_t::eBufferChanged | layer_state_t::eSidebandStreamChanged)) { |
| 150 | const bool hasBufferOrSideStream = hasValidBuffer() || sidebandStream != nullptr; |
| 151 | if (hadBufferOrSideStream != hasBufferOrSideStream) { |
| 152 | changes |= RequestedLayerState::Changes::Geometry | |
| 153 | RequestedLayerState::Changes::VisibleRegion | |
| 154 | RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Input | |
| 155 | RequestedLayerState::Changes::Buffer; |
| 156 | } |
| 157 | } |
| 158 | if (what & (layer_state_t::eAlphaChanged)) { |
| 159 | if (oldAlpha == 0 || color.a == 0) { |
| 160 | changes |= RequestedLayerState::Changes::Visibility | |
| 161 | RequestedLayerState::Changes::VisibleRegion; |
| 162 | } |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 163 | } |
| 164 | if (clientChanges & layer_state_t::HIERARCHY_CHANGES) |
| 165 | changes |= RequestedLayerState::Changes::Hierarchy; |
| 166 | if (clientChanges & layer_state_t::CONTENT_CHANGES) |
| 167 | changes |= RequestedLayerState::Changes::Content; |
| 168 | if (clientChanges & layer_state_t::GEOMETRY_CHANGES) |
| 169 | changes |= RequestedLayerState::Changes::Geometry; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 170 | if (clientChanges & layer_state_t::AFFECTS_CHILDREN) |
| 171 | changes |= RequestedLayerState::Changes::AffectsChildren; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 172 | if (clientChanges & layer_state_t::INPUT_CHANGES) |
| 173 | changes |= RequestedLayerState::Changes::Input; |
| 174 | if (clientChanges & layer_state_t::VISIBLE_REGION_CHANGES) |
| 175 | changes |= RequestedLayerState::Changes::VisibleRegion; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 176 | if (clientState.what & layer_state_t::eColorTransformChanged) { |
| 177 | static const mat4 identityMatrix = mat4(); |
| 178 | hasColorTransform = colorTransform != identityMatrix; |
| 179 | } |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 180 | if (clientState.what & (layer_state_t::eLayerChanged | layer_state_t::eRelativeLayerChanged)) { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 181 | changes |= RequestedLayerState::Changes::Z; |
| 182 | } |
| 183 | if (clientState.what & layer_state_t::eReparent) { |
| 184 | changes |= RequestedLayerState::Changes::Parent; |
| 185 | parentId = getLayerIdFromSurfaceControl(clientState.parentSurfaceControlForChild); |
| 186 | parentSurfaceControlForChild = nullptr; |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 187 | // Once a layer has be reparented, it cannot be placed at the root. It sounds odd |
| 188 | // but thats the existing logic and until we make this behavior more explicit, we need |
| 189 | // to maintain this logic. |
| 190 | canBeRoot = false; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 191 | } |
| 192 | if (clientState.what & layer_state_t::eRelativeLayerChanged) { |
| 193 | changes |= RequestedLayerState::Changes::RelativeParent; |
| 194 | relativeParentId = getLayerIdFromSurfaceControl(clientState.relativeLayerSurfaceControl); |
| 195 | isRelativeOf = true; |
| 196 | relativeLayerSurfaceControl = nullptr; |
| 197 | } |
| 198 | if ((clientState.what & layer_state_t::eLayerChanged || |
| 199 | (clientState.what & layer_state_t::eReparent && parentId == UNASSIGNED_LAYER_ID)) && |
| 200 | isRelativeOf) { |
| 201 | // clear out relz data |
| 202 | relativeParentId = UNASSIGNED_LAYER_ID; |
| 203 | isRelativeOf = false; |
| 204 | changes |= RequestedLayerState::Changes::RelativeParent; |
| 205 | } |
| 206 | if (clientState.what & layer_state_t::eReparent && parentId == relativeParentId) { |
| 207 | // provide a hint that we are are now a direct child and not a relative child. |
| 208 | changes |= RequestedLayerState::Changes::RelativeParent; |
| 209 | } |
| 210 | if (clientState.what & layer_state_t::eInputInfoChanged) { |
| 211 | wp<IBinder>& touchableRegionCropHandle = |
| 212 | windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 213 | touchCropId = LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 214 | touchableRegionCropHandle.clear(); |
| 215 | } |
| 216 | if (clientState.what & layer_state_t::eStretchChanged) { |
| 217 | stretchEffect.sanitize(); |
| 218 | } |
| 219 | |
| 220 | if (clientState.what & layer_state_t::eHasListenerCallbacksChanged) { |
| 221 | // TODO(b/238781169) handle callbacks |
| 222 | } |
| 223 | |
| 224 | if (clientState.what & layer_state_t::eBufferChanged) { |
| 225 | externalTexture = resolvedComposerState.externalTexture; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | if (clientState.what & layer_state_t::ePositionChanged) { |
| 229 | requestedTransform.set(x, y); |
| 230 | } |
| 231 | |
| 232 | if (clientState.what & layer_state_t::eMatrixChanged) { |
| 233 | requestedTransform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); |
| 234 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 235 | if (clientState.what & layer_state_t::eMetadataChanged) { |
| 236 | const int32_t requestedGameMode = |
| 237 | clientState.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 238 | if (requestedGameMode != -1) { |
| 239 | // The transaction will be received on the Task layer and needs to be applied to all |
| 240 | // child layers. |
| 241 | if (static_cast<int32_t>(gameMode) != requestedGameMode) { |
| 242 | gameMode = static_cast<gui::GameMode>(requestedGameMode); |
| 243 | changes |= RequestedLayerState::Changes::AffectsChildren; |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | if (clientState.what & layer_state_t::eFrameRateChanged) { |
| 248 | const auto compatibility = |
| 249 | Layer::FrameRate::convertCompatibility(clientState.frameRateCompatibility); |
| 250 | const auto strategy = Layer::FrameRate::convertChangeFrameRateStrategy( |
| 251 | clientState.changeFrameRateStrategy); |
| 252 | requestedFrameRate = |
| 253 | Layer::FrameRate(Fps::fromValue(clientState.frameRate), compatibility, strategy); |
| 254 | changes |= RequestedLayerState::Changes::FrameRate; |
| 255 | } |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 258 | ui::Size RequestedLayerState::getUnrotatedBufferSize(uint32_t displayRotationFlags) const { |
| 259 | uint32_t bufferWidth = externalTexture->getWidth(); |
| 260 | uint32_t bufferHeight = externalTexture->getHeight(); |
| 261 | // Undo any transformations on the buffer. |
| 262 | if (bufferTransform & ui::Transform::ROT_90) { |
| 263 | std::swap(bufferWidth, bufferHeight); |
| 264 | } |
| 265 | if (transformToDisplayInverse) { |
| 266 | if (displayRotationFlags & ui::Transform::ROT_90) { |
| 267 | std::swap(bufferWidth, bufferHeight); |
| 268 | } |
| 269 | } |
| 270 | return {bufferWidth, bufferHeight}; |
| 271 | } |
| 272 | |
| 273 | ui::Transform RequestedLayerState::getTransform(uint32_t displayRotationFlags) const { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 274 | if ((flags & layer_state_t::eIgnoreDestinationFrame) || destinationFrame.isEmpty()) { |
| 275 | // If destination frame is not set, use the requested transform set via |
| 276 | // Transaction::setPosition and Transaction::setMatrix. |
| 277 | return requestedTransform; |
| 278 | } |
| 279 | |
| 280 | Rect destRect = destinationFrame; |
| 281 | int32_t destW = destRect.width(); |
| 282 | int32_t destH = destRect.height(); |
| 283 | if (destRect.left < 0) { |
| 284 | destRect.left = 0; |
| 285 | destRect.right = destW; |
| 286 | } |
| 287 | if (destRect.top < 0) { |
| 288 | destRect.top = 0; |
| 289 | destRect.bottom = destH; |
| 290 | } |
| 291 | |
| 292 | if (!externalTexture) { |
| 293 | ui::Transform transform; |
| 294 | transform.set(static_cast<float>(destRect.left), static_cast<float>(destRect.top)); |
| 295 | return transform; |
| 296 | } |
| 297 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 298 | ui::Size bufferSize = getUnrotatedBufferSize(displayRotationFlags); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 299 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 300 | float sx = static_cast<float>(destW) / static_cast<float>(bufferSize.width); |
| 301 | float sy = static_cast<float>(destH) / static_cast<float>(bufferSize.height); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 302 | ui::Transform transform; |
| 303 | transform.set(sx, 0, 0, sy); |
| 304 | transform.set(static_cast<float>(destRect.left), static_cast<float>(destRect.top)); |
| 305 | return transform; |
| 306 | } |
| 307 | |
| 308 | std::string RequestedLayerState::getDebugString() const { |
| 309 | return "[" + std::to_string(id) + "]" + name + ",parent=" + layerIdToString(parentId) + |
| 310 | ",relativeParent=" + layerIdToString(relativeParentId) + |
| 311 | ",isRelativeOf=" + std::to_string(isRelativeOf) + |
| 312 | ",mirrorId=" + layerIdToString(mirrorId) + |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 313 | ",handleAlive=" + std::to_string(handleAlive) + ",z=" + std::to_string(z); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | std::string RequestedLayerState::getDebugStringShort() const { |
| 317 | return "[" + std::to_string(id) + "]" + name; |
| 318 | } |
| 319 | |
| 320 | bool RequestedLayerState::canBeDestroyed() const { |
| 321 | return !handleAlive && parentId == UNASSIGNED_LAYER_ID; |
| 322 | } |
| 323 | bool RequestedLayerState::isRoot() const { |
| 324 | return canBeRoot && parentId == UNASSIGNED_LAYER_ID; |
| 325 | } |
| 326 | bool RequestedLayerState::isHiddenByPolicy() const { |
| 327 | return (flags & layer_state_t::eLayerHidden) == layer_state_t::eLayerHidden; |
| 328 | }; |
| 329 | half4 RequestedLayerState::getColor() const { |
| 330 | if ((sidebandStream != nullptr) || (externalTexture != nullptr)) { |
| 331 | return {0._hf, 0._hf, 0._hf, color.a}; |
| 332 | } |
| 333 | return color; |
| 334 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 335 | Rect RequestedLayerState::getBufferSize(uint32_t displayRotationFlags) const { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 336 | // for buffer state layers we use the display frame size as the buffer size. |
| 337 | if (!externalTexture) { |
| 338 | return Rect::INVALID_RECT; |
| 339 | } |
| 340 | |
| 341 | uint32_t bufWidth = externalTexture->getWidth(); |
| 342 | uint32_t bufHeight = externalTexture->getHeight(); |
| 343 | |
| 344 | // Undo any transformations on the buffer and return the result. |
| 345 | if (bufferTransform & ui::Transform::ROT_90) { |
| 346 | std::swap(bufWidth, bufHeight); |
| 347 | } |
| 348 | |
| 349 | if (transformToDisplayInverse) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 350 | uint32_t invTransform = displayRotationFlags; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 351 | if (invTransform & ui::Transform::ROT_90) { |
| 352 | std::swap(bufWidth, bufHeight); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | return Rect(0, 0, static_cast<int32_t>(bufWidth), static_cast<int32_t>(bufHeight)); |
| 357 | } |
| 358 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 359 | Rect RequestedLayerState::getCroppedBufferSize(const Rect& bufferSize) const { |
| 360 | Rect size = bufferSize; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 361 | if (!crop.isEmpty() && size.isValid()) { |
| 362 | size.intersect(crop, &size); |
| 363 | } else if (!crop.isEmpty()) { |
| 364 | size = crop; |
| 365 | } |
| 366 | return size; |
| 367 | } |
| 368 | |
| 369 | Rect RequestedLayerState::getBufferCrop() const { |
| 370 | // this is the crop rectangle that applies to the buffer |
| 371 | // itself (as opposed to the window) |
| 372 | if (!bufferCrop.isEmpty()) { |
| 373 | // if the buffer crop is defined, we use that |
| 374 | return bufferCrop; |
| 375 | } else if (externalTexture != nullptr) { |
| 376 | // otherwise we use the whole buffer |
| 377 | return externalTexture->getBounds(); |
| 378 | } else { |
| 379 | // if we don't have a buffer yet, we use an empty/invalid crop |
| 380 | return Rect(); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | aidl::android::hardware::graphics::composer3::Composition RequestedLayerState::getCompositionType() |
| 385 | const { |
| 386 | using aidl::android::hardware::graphics::composer3::Composition; |
| 387 | // TODO(b/238781169) check about sidestream ready flag |
| 388 | if (sidebandStream.get()) { |
| 389 | return Composition::SIDEBAND; |
| 390 | } |
| 391 | if (!externalTexture) { |
| 392 | return Composition::SOLID_COLOR; |
| 393 | } |
| 394 | if (flags & layer_state_t::eLayerIsDisplayDecoration) { |
| 395 | return Composition::DISPLAY_DECORATION; |
| 396 | } |
| 397 | if (potentialCursor) { |
| 398 | return Composition::CURSOR; |
| 399 | } |
| 400 | return Composition::DEVICE; |
| 401 | } |
| 402 | |
| 403 | Rect RequestedLayerState::reduce(const Rect& win, const Region& exclude) { |
| 404 | if (CC_LIKELY(exclude.isEmpty())) { |
| 405 | return win; |
| 406 | } |
| 407 | if (exclude.isRect()) { |
| 408 | return win.reduce(exclude.getBounds()); |
| 409 | } |
| 410 | return Region(win).subtract(exclude).getBounds(); |
| 411 | } |
| 412 | |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 413 | // Returns true if the layer has a relative parent that is not its own parent. This is an input |
| 414 | // error from the client, and this check allows us to handle it gracefully. If both parentId and |
| 415 | // relativeParentId is unassigned then the layer does not have a valid relative parent. |
| 416 | // If the relative parentid is unassigned, the layer will be considered relative but won't be |
| 417 | // reachable. |
| 418 | bool RequestedLayerState::hasValidRelativeParent() const { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 419 | return isRelativeOf && |
| 420 | (parentId != relativeParentId || relativeParentId == UNASSIGNED_LAYER_ID); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 423 | bool RequestedLayerState::hasInputInfo() const { |
| 424 | if (!windowInfoHandle) { |
| 425 | return false; |
| 426 | } |
| 427 | const auto windowInfo = windowInfoHandle->getInfo(); |
| 428 | return windowInfo->token != nullptr || |
| 429 | windowInfo->inputConfig.test(gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL); |
| 430 | } |
| 431 | |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 432 | } // namespace android::surfaceflinger::frontend |