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