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 | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 35 | std::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 Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 45 | } // namespace |
| 46 | |
| 47 | RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args) |
| 48 | : id(args.sequence), |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 49 | name(args.name + "#" + std::to_string(args.sequence)), |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 50 | canBeRoot(args.addToRoot), |
| 51 | layerCreationFlags(args.flags), |
| 52 | textureName(args.textureName), |
| 53 | ownerUid(args.ownerUid), |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 54 | ownerPid(args.ownerPid), |
| 55 | parentId(args.parentId), |
| 56 | layerIdToMirror(args.layerIdToMirror) { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 57 | 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 Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 62 | if (parentId != UNASSIGNED_LAYER_ID) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 63 | canBeRoot = false; |
| 64 | } |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 65 | if (layerIdToMirror != UNASSIGNED_LAYER_ID) { |
| 66 | changes |= RequestedLayerState::Changes::Mirror; |
| 67 | } else if (args.layerStackToMirror != ui::INVALID_LAYER_STACK) { |
| 68 | layerStackToMirror = args.layerStackToMirror; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 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; |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 99 | desiredHdrSdrRatio = 1.f; |
| 100 | currentHdrSdrRatio = 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 = {}; |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 127 | cachingHint = gui::CachingHint::Enabled; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerState) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 131 | const uint32_t oldFlags = flags; |
| 132 | const half oldAlpha = color.a; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 133 | const bool hadBuffer = externalTexture != nullptr; |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame^] | 134 | uint64_t oldFramenumber = hadBuffer ? bufferData->frameNumber : 0; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 135 | const bool hadSideStream = sidebandStream != nullptr; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 136 | const layer_state_t& clientState = resolvedComposerState.state; |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 137 | const bool hadBlur = hasBlur(); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 138 | 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 Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 144 | changes |= RequestedLayerState::Changes::Visibility | |
| 145 | RequestedLayerState::Changes::VisibleRegion; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 146 | } |
| 147 | if ((oldFlags ^ flags) & layer_state_t::eIgnoreDestinationFrame) { |
| 148 | changes |= RequestedLayerState::Changes::Geometry; |
| 149 | } |
| 150 | } |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame^] | 151 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 152 | if (clientState.what & layer_state_t::eBufferChanged) { |
| 153 | externalTexture = resolvedComposerState.externalTexture; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 154 | const bool hasBuffer = externalTexture != nullptr; |
| 155 | if (hasBuffer || hasBuffer != hadBuffer) { |
| 156 | changes |= RequestedLayerState::Changes::Buffer; |
| 157 | } |
| 158 | |
| 159 | if (hasBuffer != hadBuffer) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 160 | changes |= RequestedLayerState::Changes::Geometry | |
| 161 | RequestedLayerState::Changes::VisibleRegion | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 162 | RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Input; |
| 163 | } |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame^] | 164 | |
| 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 Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 186 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 187 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 188 | if (clientState.what & layer_state_t::eSidebandStreamChanged) { |
| 189 | changes |= RequestedLayerState::Changes::SidebandStream; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 190 | 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 Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 196 | } |
| 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 Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 202 | } |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 203 | 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 Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 209 | 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 Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 215 | if (clientChanges & layer_state_t::AFFECTS_CHILDREN) |
| 216 | changes |= RequestedLayerState::Changes::AffectsChildren; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 217 | 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 Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 221 | if (clientState.what & layer_state_t::eColorTransformChanged) { |
| 222 | static const mat4 identityMatrix = mat4(); |
| 223 | hasColorTransform = colorTransform != identityMatrix; |
| 224 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 225 | if (clientState.what & |
| 226 | (layer_state_t::eLayerChanged | layer_state_t::eRelativeLayerChanged | |
| 227 | layer_state_t::eLayerStackChanged)) { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 228 | changes |= RequestedLayerState::Changes::Z; |
| 229 | } |
| 230 | if (clientState.what & layer_state_t::eReparent) { |
| 231 | changes |= RequestedLayerState::Changes::Parent; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 232 | parentId = resolvedComposerState.parentId; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 233 | parentSurfaceControlForChild = nullptr; |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 234 | // 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 Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 238 | } |
| 239 | if (clientState.what & layer_state_t::eRelativeLayerChanged) { |
| 240 | changes |= RequestedLayerState::Changes::RelativeParent; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 241 | relativeParentId = resolvedComposerState.relativeParentId; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 242 | 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 Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 258 | touchCropId = resolvedComposerState.touchCropId; |
| 259 | windowInfoHandle->editInfo()->touchableRegionCropHandle.clear(); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 260 | } |
| 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 Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 269 | 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 Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 276 | 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 Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 299 | ui::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 | |
| 314 | ui::Transform RequestedLayerState::getTransform(uint32_t displayRotationFlags) const { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 315 | 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 Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 339 | ui::Size bufferSize = getUnrotatedBufferSize(displayRotationFlags); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 340 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 341 | float sx = static_cast<float>(destW) / static_cast<float>(bufferSize.width); |
| 342 | float sy = static_cast<float>(destH) / static_cast<float>(bufferSize.height); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 343 | 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 | |
| 349 | std::string RequestedLayerState::getDebugString() const { |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 350 | std::stringstream debug; |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 351 | 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 Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 358 | return debug.str(); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | std::string RequestedLayerState::getDebugStringShort() const { |
| 362 | return "[" + std::to_string(id) + "]" + name; |
| 363 | } |
| 364 | |
| 365 | bool RequestedLayerState::canBeDestroyed() const { |
| 366 | return !handleAlive && parentId == UNASSIGNED_LAYER_ID; |
| 367 | } |
| 368 | bool RequestedLayerState::isRoot() const { |
| 369 | return canBeRoot && parentId == UNASSIGNED_LAYER_ID; |
| 370 | } |
| 371 | bool RequestedLayerState::isHiddenByPolicy() const { |
| 372 | return (flags & layer_state_t::eLayerHidden) == layer_state_t::eLayerHidden; |
| 373 | }; |
| 374 | half4 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 Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 380 | Rect RequestedLayerState::getBufferSize(uint32_t displayRotationFlags) const { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 381 | // 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 Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 395 | uint32_t invTransform = displayRotationFlags; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 396 | 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 Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 404 | Rect RequestedLayerState::getCroppedBufferSize(const Rect& bufferSize) const { |
| 405 | Rect size = bufferSize; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 406 | if (!crop.isEmpty() && size.isValid()) { |
| 407 | size.intersect(crop, &size); |
| 408 | } else if (!crop.isEmpty()) { |
| 409 | size = crop; |
| 410 | } |
| 411 | return size; |
| 412 | } |
| 413 | |
| 414 | Rect 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 | |
| 429 | aidl::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 | |
| 448 | Rect 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 Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 458 | // 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. |
| 463 | bool RequestedLayerState::hasValidRelativeParent() const { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 464 | return isRelativeOf && |
| 465 | (parentId != relativeParentId || relativeParentId == UNASSIGNED_LAYER_ID); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 468 | bool 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 Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 477 | bool RequestedLayerState::hasBlur() const { |
| 478 | return backgroundBlurRadius > 0 || blurRegions.size() > 0; |
| 479 | } |
| 480 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 481 | bool RequestedLayerState::hasFrameUpdate() const { |
| 482 | return what & layer_state_t::CONTENT_DIRTY && |
| 483 | (externalTexture || bgColorLayerId != UNASSIGNED_LAYER_ID); |
| 484 | } |
| 485 | |
| 486 | bool RequestedLayerState::hasReadyFrame() const { |
| 487 | return hasFrameUpdate() || changes.test(Changes::SidebandStream) || autoRefresh; |
| 488 | } |
| 489 | |
| 490 | bool RequestedLayerState::hasSidebandStreamFrame() const { |
| 491 | return hasFrameUpdate() && sidebandStream.get(); |
| 492 | } |
| 493 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 494 | bool RequestedLayerState::willReleaseBufferOnLatch() const { |
| 495 | return changes.test(Changes::Buffer) && !externalTexture; |
| 496 | } |
| 497 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 498 | void RequestedLayerState::clearChanges() { |
| 499 | what = 0; |
| 500 | changes.clear(); |
| 501 | } |
| 502 | |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 503 | } // namespace android::surfaceflinger::frontend |