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 | |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 48 | std::string layerIdsToString(const std::vector<uint32_t>& layerIds) { |
| 49 | std::stringstream stream; |
| 50 | stream << "{"; |
| 51 | for (auto layerId : layerIds) { |
| 52 | stream << layerId << ","; |
| 53 | } |
| 54 | stream << "}"; |
| 55 | return stream.str(); |
| 56 | } |
| 57 | |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 58 | } // namespace |
| 59 | |
| 60 | RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args) |
| 61 | : id(args.sequence), |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 62 | name(args.name + "#" + std::to_string(args.sequence)), |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 63 | canBeRoot(args.addToRoot), |
| 64 | layerCreationFlags(args.flags), |
| 65 | textureName(args.textureName), |
| 66 | ownerUid(args.ownerUid), |
| 67 | ownerPid(args.ownerPid) { |
| 68 | layerId = static_cast<int32_t>(args.sequence); |
| 69 | changes |= RequestedLayerState::Changes::Created; |
| 70 | metadata.merge(args.metadata); |
| 71 | changes |= RequestedLayerState::Changes::Metadata; |
| 72 | handleAlive = true; |
| 73 | parentId = LayerHandle::getLayerId(args.parentHandle.promote()); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 74 | if (args.parentHandle != nullptr) { |
| 75 | canBeRoot = false; |
| 76 | } |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 77 | layerIdToMirror = LayerHandle::getLayerId(args.mirrorLayerHandle.promote()); |
| 78 | if (layerIdToMirror != UNASSIGNED_LAYER_ID) { |
| 79 | changes |= RequestedLayerState::Changes::Mirror; |
| 80 | } else if (args.layerStackToMirror != ui::INVALID_LAYER_STACK) { |
| 81 | layerStackToMirror = args.layerStackToMirror; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 82 | changes |= RequestedLayerState::Changes::Mirror; |
| 83 | } |
| 84 | |
| 85 | flags = 0; |
| 86 | if (args.flags & ISurfaceComposerClient::eHidden) flags |= layer_state_t::eLayerHidden; |
| 87 | if (args.flags & ISurfaceComposerClient::eOpaque) flags |= layer_state_t::eLayerOpaque; |
| 88 | if (args.flags & ISurfaceComposerClient::eSecure) flags |= layer_state_t::eLayerSecure; |
| 89 | if (args.flags & ISurfaceComposerClient::eSkipScreenshot) { |
| 90 | flags |= layer_state_t::eLayerSkipScreenshot; |
| 91 | } |
| 92 | premultipliedAlpha = !(args.flags & ISurfaceComposerClient::eNonPremultiplied); |
| 93 | potentialCursor = args.flags & ISurfaceComposerClient::eCursorWindow; |
| 94 | protectedByApp = args.flags & ISurfaceComposerClient::eProtectedByApp; |
| 95 | if (args.flags & ISurfaceComposerClient::eNoColorFill) { |
| 96 | // Set an invalid color so there is no color fill. |
| 97 | // (b/259981098) use an explicit flag instead of relying on invalid values. |
| 98 | color.r = -1.0_hf; |
| 99 | color.g = -1.0_hf; |
| 100 | color.b = -1.0_hf; |
| 101 | } else { |
| 102 | color.rgb = {0.0_hf, 0.0_hf, 0.0_hf}; |
| 103 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 104 | LLOGV(layerId, "Created %s flags=%d", getDebugString().c_str(), flags); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 105 | color.a = 1.0f; |
| 106 | |
| 107 | crop.makeInvalid(); |
| 108 | z = 0; |
| 109 | layerStack = ui::DEFAULT_LAYER_STACK; |
| 110 | transformToDisplayInverse = false; |
| 111 | dataspace = ui::Dataspace::UNKNOWN; |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 112 | desiredSdrHdrRatio = 1.f; |
| 113 | currentSdrHdrRatio = 1.f; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 114 | dataspaceRequested = false; |
| 115 | hdrMetadata.validTypes = 0; |
| 116 | surfaceDamageRegion = Region::INVALID_REGION; |
| 117 | cornerRadius = 0.0f; |
| 118 | backgroundBlurRadius = 0; |
| 119 | api = -1; |
| 120 | hasColorTransform = false; |
| 121 | bufferTransform = 0; |
| 122 | requestedTransform.reset(); |
| 123 | bufferData = std::make_shared<BufferData>(); |
| 124 | bufferData->frameNumber = 0; |
| 125 | bufferData->acquireFence = sp<Fence>::make(-1); |
| 126 | acquireFenceTime = std::make_shared<FenceTime>(bufferData->acquireFence); |
| 127 | colorSpaceAgnostic = false; |
| 128 | frameRateSelectionPriority = Layer::PRIORITY_UNSET; |
| 129 | shadowRadius = 0.f; |
| 130 | fixedTransformHint = ui::Transform::ROT_INVALID; |
| 131 | destinationFrame.makeInvalid(); |
| 132 | isTrustedOverlay = false; |
| 133 | dropInputMode = gui::DropInputMode::NONE; |
| 134 | dimmingEnabled = true; |
| 135 | defaultFrameRateCompatibility = |
| 136 | static_cast<int8_t>(scheduler::LayerInfo::FrameRateCompatibility::Default); |
| 137 | dataspace = ui::Dataspace::V0_SRGB; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 138 | gameMode = gui::GameMode::Unsupported; |
| 139 | requestedFrameRate = {}; |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame^] | 140 | cachingHint = gui::CachingHint::Enabled; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerState) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 144 | const uint32_t oldFlags = flags; |
| 145 | const half oldAlpha = color.a; |
| 146 | const bool hadBufferOrSideStream = hasValidBuffer() || sidebandStream != nullptr; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 147 | const layer_state_t& clientState = resolvedComposerState.state; |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 148 | const bool hadBlur = hasBlur(); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 149 | uint64_t clientChanges = what | layer_state_t::diff(clientState); |
| 150 | layer_state_t::merge(clientState); |
| 151 | what = clientChanges; |
| 152 | |
| 153 | if (clientState.what & layer_state_t::eFlagsChanged) { |
| 154 | if ((oldFlags ^ flags) & layer_state_t::eLayerHidden) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 155 | changes |= RequestedLayerState::Changes::Visibility | |
| 156 | RequestedLayerState::Changes::VisibleRegion; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 157 | } |
| 158 | if ((oldFlags ^ flags) & layer_state_t::eIgnoreDestinationFrame) { |
| 159 | changes |= RequestedLayerState::Changes::Geometry; |
| 160 | } |
| 161 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 162 | if (clientState.what & |
| 163 | (layer_state_t::eBufferChanged | layer_state_t::eSidebandStreamChanged)) { |
| 164 | const bool hasBufferOrSideStream = hasValidBuffer() || sidebandStream != nullptr; |
| 165 | if (hadBufferOrSideStream != hasBufferOrSideStream) { |
| 166 | changes |= RequestedLayerState::Changes::Geometry | |
| 167 | RequestedLayerState::Changes::VisibleRegion | |
| 168 | RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Input | |
| 169 | RequestedLayerState::Changes::Buffer; |
| 170 | } |
| 171 | } |
| 172 | if (what & (layer_state_t::eAlphaChanged)) { |
| 173 | if (oldAlpha == 0 || color.a == 0) { |
| 174 | changes |= RequestedLayerState::Changes::Visibility | |
| 175 | RequestedLayerState::Changes::VisibleRegion; |
| 176 | } |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 177 | } |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 178 | if (what & (layer_state_t::eBackgroundBlurRadiusChanged | layer_state_t::eBlurRegionsChanged)) { |
| 179 | if (hadBlur != hasBlur()) { |
| 180 | changes |= RequestedLayerState::Changes::Visibility | |
| 181 | RequestedLayerState::Changes::VisibleRegion; |
| 182 | } |
| 183 | } |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 184 | if (clientChanges & layer_state_t::HIERARCHY_CHANGES) |
| 185 | changes |= RequestedLayerState::Changes::Hierarchy; |
| 186 | if (clientChanges & layer_state_t::CONTENT_CHANGES) |
| 187 | changes |= RequestedLayerState::Changes::Content; |
| 188 | if (clientChanges & layer_state_t::GEOMETRY_CHANGES) |
| 189 | changes |= RequestedLayerState::Changes::Geometry; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 190 | if (clientChanges & layer_state_t::AFFECTS_CHILDREN) |
| 191 | changes |= RequestedLayerState::Changes::AffectsChildren; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 192 | if (clientChanges & layer_state_t::INPUT_CHANGES) |
| 193 | changes |= RequestedLayerState::Changes::Input; |
| 194 | if (clientChanges & layer_state_t::VISIBLE_REGION_CHANGES) |
| 195 | changes |= RequestedLayerState::Changes::VisibleRegion; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 196 | if (clientState.what & layer_state_t::eColorTransformChanged) { |
| 197 | static const mat4 identityMatrix = mat4(); |
| 198 | hasColorTransform = colorTransform != identityMatrix; |
| 199 | } |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 200 | if (clientState.what & (layer_state_t::eLayerChanged | layer_state_t::eRelativeLayerChanged)) { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 201 | changes |= RequestedLayerState::Changes::Z; |
| 202 | } |
| 203 | if (clientState.what & layer_state_t::eReparent) { |
| 204 | changes |= RequestedLayerState::Changes::Parent; |
| 205 | parentId = getLayerIdFromSurfaceControl(clientState.parentSurfaceControlForChild); |
| 206 | parentSurfaceControlForChild = nullptr; |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 207 | // Once a layer has be reparented, it cannot be placed at the root. It sounds odd |
| 208 | // but thats the existing logic and until we make this behavior more explicit, we need |
| 209 | // to maintain this logic. |
| 210 | canBeRoot = false; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 211 | } |
| 212 | if (clientState.what & layer_state_t::eRelativeLayerChanged) { |
| 213 | changes |= RequestedLayerState::Changes::RelativeParent; |
| 214 | relativeParentId = getLayerIdFromSurfaceControl(clientState.relativeLayerSurfaceControl); |
| 215 | isRelativeOf = true; |
| 216 | relativeLayerSurfaceControl = nullptr; |
| 217 | } |
| 218 | if ((clientState.what & layer_state_t::eLayerChanged || |
| 219 | (clientState.what & layer_state_t::eReparent && parentId == UNASSIGNED_LAYER_ID)) && |
| 220 | isRelativeOf) { |
| 221 | // clear out relz data |
| 222 | relativeParentId = UNASSIGNED_LAYER_ID; |
| 223 | isRelativeOf = false; |
| 224 | changes |= RequestedLayerState::Changes::RelativeParent; |
| 225 | } |
| 226 | if (clientState.what & layer_state_t::eReparent && parentId == relativeParentId) { |
| 227 | // provide a hint that we are are now a direct child and not a relative child. |
| 228 | changes |= RequestedLayerState::Changes::RelativeParent; |
| 229 | } |
| 230 | if (clientState.what & layer_state_t::eInputInfoChanged) { |
| 231 | wp<IBinder>& touchableRegionCropHandle = |
| 232 | windowInfoHandle->editInfo()->touchableRegionCropHandle; |
| 233 | touchCropId = LayerHandle::getLayerId(touchableRegionCropHandle.promote()); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 234 | touchableRegionCropHandle.clear(); |
| 235 | } |
| 236 | if (clientState.what & layer_state_t::eStretchChanged) { |
| 237 | stretchEffect.sanitize(); |
| 238 | } |
| 239 | |
| 240 | if (clientState.what & layer_state_t::eHasListenerCallbacksChanged) { |
| 241 | // TODO(b/238781169) handle callbacks |
| 242 | } |
| 243 | |
| 244 | if (clientState.what & layer_state_t::eBufferChanged) { |
| 245 | externalTexture = resolvedComposerState.externalTexture; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | if (clientState.what & layer_state_t::ePositionChanged) { |
| 249 | requestedTransform.set(x, y); |
| 250 | } |
| 251 | |
| 252 | if (clientState.what & layer_state_t::eMatrixChanged) { |
| 253 | requestedTransform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); |
| 254 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 255 | if (clientState.what & layer_state_t::eMetadataChanged) { |
| 256 | const int32_t requestedGameMode = |
| 257 | clientState.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 258 | if (requestedGameMode != -1) { |
| 259 | // The transaction will be received on the Task layer and needs to be applied to all |
| 260 | // child layers. |
| 261 | if (static_cast<int32_t>(gameMode) != requestedGameMode) { |
| 262 | gameMode = static_cast<gui::GameMode>(requestedGameMode); |
| 263 | changes |= RequestedLayerState::Changes::AffectsChildren; |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | if (clientState.what & layer_state_t::eFrameRateChanged) { |
| 268 | const auto compatibility = |
| 269 | Layer::FrameRate::convertCompatibility(clientState.frameRateCompatibility); |
| 270 | const auto strategy = Layer::FrameRate::convertChangeFrameRateStrategy( |
| 271 | clientState.changeFrameRateStrategy); |
| 272 | requestedFrameRate = |
| 273 | Layer::FrameRate(Fps::fromValue(clientState.frameRate), compatibility, strategy); |
| 274 | changes |= RequestedLayerState::Changes::FrameRate; |
| 275 | } |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 278 | ui::Size RequestedLayerState::getUnrotatedBufferSize(uint32_t displayRotationFlags) const { |
| 279 | uint32_t bufferWidth = externalTexture->getWidth(); |
| 280 | uint32_t bufferHeight = externalTexture->getHeight(); |
| 281 | // Undo any transformations on the buffer. |
| 282 | if (bufferTransform & ui::Transform::ROT_90) { |
| 283 | std::swap(bufferWidth, bufferHeight); |
| 284 | } |
| 285 | if (transformToDisplayInverse) { |
| 286 | if (displayRotationFlags & ui::Transform::ROT_90) { |
| 287 | std::swap(bufferWidth, bufferHeight); |
| 288 | } |
| 289 | } |
| 290 | return {bufferWidth, bufferHeight}; |
| 291 | } |
| 292 | |
| 293 | ui::Transform RequestedLayerState::getTransform(uint32_t displayRotationFlags) const { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 294 | if ((flags & layer_state_t::eIgnoreDestinationFrame) || destinationFrame.isEmpty()) { |
| 295 | // If destination frame is not set, use the requested transform set via |
| 296 | // Transaction::setPosition and Transaction::setMatrix. |
| 297 | return requestedTransform; |
| 298 | } |
| 299 | |
| 300 | Rect destRect = destinationFrame; |
| 301 | int32_t destW = destRect.width(); |
| 302 | int32_t destH = destRect.height(); |
| 303 | if (destRect.left < 0) { |
| 304 | destRect.left = 0; |
| 305 | destRect.right = destW; |
| 306 | } |
| 307 | if (destRect.top < 0) { |
| 308 | destRect.top = 0; |
| 309 | destRect.bottom = destH; |
| 310 | } |
| 311 | |
| 312 | if (!externalTexture) { |
| 313 | ui::Transform transform; |
| 314 | transform.set(static_cast<float>(destRect.left), static_cast<float>(destRect.top)); |
| 315 | return transform; |
| 316 | } |
| 317 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 318 | ui::Size bufferSize = getUnrotatedBufferSize(displayRotationFlags); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 319 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 320 | float sx = static_cast<float>(destW) / static_cast<float>(bufferSize.width); |
| 321 | float sy = static_cast<float>(destH) / static_cast<float>(bufferSize.height); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 322 | ui::Transform transform; |
| 323 | transform.set(sx, 0, 0, sy); |
| 324 | transform.set(static_cast<float>(destRect.left), static_cast<float>(destRect.top)); |
| 325 | return transform; |
| 326 | } |
| 327 | |
| 328 | std::string RequestedLayerState::getDebugString() const { |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 329 | std::stringstream debug; |
| 330 | debug << "RequestedLayerState{" << name << " parent=" << layerIdToString(parentId) |
| 331 | << " relativeParent=" << layerIdToString(relativeParentId) |
| 332 | << " mirrorId=" << layerIdsToString(mirrorIds) << " handle=" << handleAlive << " z=" << z; |
| 333 | return debug.str(); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | std::string RequestedLayerState::getDebugStringShort() const { |
| 337 | return "[" + std::to_string(id) + "]" + name; |
| 338 | } |
| 339 | |
| 340 | bool RequestedLayerState::canBeDestroyed() const { |
| 341 | return !handleAlive && parentId == UNASSIGNED_LAYER_ID; |
| 342 | } |
| 343 | bool RequestedLayerState::isRoot() const { |
| 344 | return canBeRoot && parentId == UNASSIGNED_LAYER_ID; |
| 345 | } |
| 346 | bool RequestedLayerState::isHiddenByPolicy() const { |
| 347 | return (flags & layer_state_t::eLayerHidden) == layer_state_t::eLayerHidden; |
| 348 | }; |
| 349 | half4 RequestedLayerState::getColor() const { |
| 350 | if ((sidebandStream != nullptr) || (externalTexture != nullptr)) { |
| 351 | return {0._hf, 0._hf, 0._hf, color.a}; |
| 352 | } |
| 353 | return color; |
| 354 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 355 | Rect RequestedLayerState::getBufferSize(uint32_t displayRotationFlags) const { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 356 | // for buffer state layers we use the display frame size as the buffer size. |
| 357 | if (!externalTexture) { |
| 358 | return Rect::INVALID_RECT; |
| 359 | } |
| 360 | |
| 361 | uint32_t bufWidth = externalTexture->getWidth(); |
| 362 | uint32_t bufHeight = externalTexture->getHeight(); |
| 363 | |
| 364 | // Undo any transformations on the buffer and return the result. |
| 365 | if (bufferTransform & ui::Transform::ROT_90) { |
| 366 | std::swap(bufWidth, bufHeight); |
| 367 | } |
| 368 | |
| 369 | if (transformToDisplayInverse) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 370 | uint32_t invTransform = displayRotationFlags; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 371 | if (invTransform & ui::Transform::ROT_90) { |
| 372 | std::swap(bufWidth, bufHeight); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | return Rect(0, 0, static_cast<int32_t>(bufWidth), static_cast<int32_t>(bufHeight)); |
| 377 | } |
| 378 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 379 | Rect RequestedLayerState::getCroppedBufferSize(const Rect& bufferSize) const { |
| 380 | Rect size = bufferSize; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 381 | if (!crop.isEmpty() && size.isValid()) { |
| 382 | size.intersect(crop, &size); |
| 383 | } else if (!crop.isEmpty()) { |
| 384 | size = crop; |
| 385 | } |
| 386 | return size; |
| 387 | } |
| 388 | |
| 389 | Rect RequestedLayerState::getBufferCrop() const { |
| 390 | // this is the crop rectangle that applies to the buffer |
| 391 | // itself (as opposed to the window) |
| 392 | if (!bufferCrop.isEmpty()) { |
| 393 | // if the buffer crop is defined, we use that |
| 394 | return bufferCrop; |
| 395 | } else if (externalTexture != nullptr) { |
| 396 | // otherwise we use the whole buffer |
| 397 | return externalTexture->getBounds(); |
| 398 | } else { |
| 399 | // if we don't have a buffer yet, we use an empty/invalid crop |
| 400 | return Rect(); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | aidl::android::hardware::graphics::composer3::Composition RequestedLayerState::getCompositionType() |
| 405 | const { |
| 406 | using aidl::android::hardware::graphics::composer3::Composition; |
| 407 | // TODO(b/238781169) check about sidestream ready flag |
| 408 | if (sidebandStream.get()) { |
| 409 | return Composition::SIDEBAND; |
| 410 | } |
| 411 | if (!externalTexture) { |
| 412 | return Composition::SOLID_COLOR; |
| 413 | } |
| 414 | if (flags & layer_state_t::eLayerIsDisplayDecoration) { |
| 415 | return Composition::DISPLAY_DECORATION; |
| 416 | } |
| 417 | if (potentialCursor) { |
| 418 | return Composition::CURSOR; |
| 419 | } |
| 420 | return Composition::DEVICE; |
| 421 | } |
| 422 | |
| 423 | Rect RequestedLayerState::reduce(const Rect& win, const Region& exclude) { |
| 424 | if (CC_LIKELY(exclude.isEmpty())) { |
| 425 | return win; |
| 426 | } |
| 427 | if (exclude.isRect()) { |
| 428 | return win.reduce(exclude.getBounds()); |
| 429 | } |
| 430 | return Region(win).subtract(exclude).getBounds(); |
| 431 | } |
| 432 | |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 433 | // Returns true if the layer has a relative parent that is not its own parent. This is an input |
| 434 | // error from the client, and this check allows us to handle it gracefully. If both parentId and |
| 435 | // relativeParentId is unassigned then the layer does not have a valid relative parent. |
| 436 | // If the relative parentid is unassigned, the layer will be considered relative but won't be |
| 437 | // reachable. |
| 438 | bool RequestedLayerState::hasValidRelativeParent() const { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 439 | return isRelativeOf && |
| 440 | (parentId != relativeParentId || relativeParentId == UNASSIGNED_LAYER_ID); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 443 | bool RequestedLayerState::hasInputInfo() const { |
| 444 | if (!windowInfoHandle) { |
| 445 | return false; |
| 446 | } |
| 447 | const auto windowInfo = windowInfoHandle->getInfo(); |
| 448 | return windowInfo->token != nullptr || |
| 449 | windowInfo->inputConfig.test(gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL); |
| 450 | } |
| 451 | |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 452 | bool RequestedLayerState::hasBlur() const { |
| 453 | return backgroundBlurRadius > 0 || blurRegions.size() > 0; |
| 454 | } |
| 455 | |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 456 | } // namespace android::surfaceflinger::frontend |