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 | */ |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 16 | // #define LOG_NDEBUG 0 |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 17 | |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 19 | #undef LOG_TAG |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 20 | #define LOG_TAG "SurfaceFlinger" |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 21 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 22 | #include <gui/TraceUtils.h> |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 23 | #include <log/log.h> |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 24 | #include <private/android_filesystem_config.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 27 | #include <scheduler/Fps.h> |
| 28 | |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 29 | #include "Layer.h" |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 30 | #include "LayerCreationArgs.h" |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 31 | #include "LayerLog.h" |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 32 | #include "RequestedLayerState.h" |
| 33 | |
| 34 | namespace android::surfaceflinger::frontend { |
| 35 | using ftl::Flags; |
| 36 | using namespace ftl::flag_operators; |
| 37 | |
| 38 | namespace { |
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), |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 56 | ownerUid(args.ownerUid), |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 57 | ownerPid(args.ownerPid), |
| 58 | parentId(args.parentId), |
| 59 | layerIdToMirror(args.layerIdToMirror) { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 60 | layerId = static_cast<int32_t>(args.sequence); |
| 61 | changes |= RequestedLayerState::Changes::Created; |
| 62 | metadata.merge(args.metadata); |
| 63 | changes |= RequestedLayerState::Changes::Metadata; |
| 64 | handleAlive = true; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 65 | if (parentId != UNASSIGNED_LAYER_ID) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 66 | canBeRoot = false; |
| 67 | } |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 68 | if (layerIdToMirror != UNASSIGNED_LAYER_ID) { |
| 69 | changes |= RequestedLayerState::Changes::Mirror; |
| 70 | } else if (args.layerStackToMirror != ui::INVALID_LAYER_STACK) { |
| 71 | layerStackToMirror = args.layerStackToMirror; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 72 | changes |= RequestedLayerState::Changes::Mirror; |
| 73 | } |
| 74 | |
| 75 | flags = 0; |
| 76 | if (args.flags & ISurfaceComposerClient::eHidden) flags |= layer_state_t::eLayerHidden; |
| 77 | if (args.flags & ISurfaceComposerClient::eOpaque) flags |= layer_state_t::eLayerOpaque; |
| 78 | if (args.flags & ISurfaceComposerClient::eSecure) flags |= layer_state_t::eLayerSecure; |
| 79 | if (args.flags & ISurfaceComposerClient::eSkipScreenshot) { |
| 80 | flags |= layer_state_t::eLayerSkipScreenshot; |
| 81 | } |
| 82 | premultipliedAlpha = !(args.flags & ISurfaceComposerClient::eNonPremultiplied); |
| 83 | potentialCursor = args.flags & ISurfaceComposerClient::eCursorWindow; |
| 84 | protectedByApp = args.flags & ISurfaceComposerClient::eProtectedByApp; |
| 85 | if (args.flags & ISurfaceComposerClient::eNoColorFill) { |
| 86 | // Set an invalid color so there is no color fill. |
| 87 | // (b/259981098) use an explicit flag instead of relying on invalid values. |
| 88 | color.r = -1.0_hf; |
| 89 | color.g = -1.0_hf; |
| 90 | color.b = -1.0_hf; |
| 91 | } else { |
| 92 | color.rgb = {0.0_hf, 0.0_hf, 0.0_hf}; |
| 93 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 94 | LLOGV(layerId, "Created %s flags=%d", getDebugString().c_str(), flags); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 95 | color.a = 1.0f; |
| 96 | |
| 97 | crop.makeInvalid(); |
| 98 | z = 0; |
| 99 | layerStack = ui::DEFAULT_LAYER_STACK; |
| 100 | transformToDisplayInverse = false; |
| 101 | dataspace = ui::Dataspace::UNKNOWN; |
Sally Qi | 963049b | 2023-03-23 14:06:21 -0700 | [diff] [blame] | 102 | desiredHdrSdrRatio = 1.f; |
| 103 | currentHdrSdrRatio = 1.f; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 104 | dataspaceRequested = false; |
| 105 | hdrMetadata.validTypes = 0; |
| 106 | surfaceDamageRegion = Region::INVALID_REGION; |
| 107 | cornerRadius = 0.0f; |
| 108 | backgroundBlurRadius = 0; |
| 109 | api = -1; |
| 110 | hasColorTransform = false; |
| 111 | bufferTransform = 0; |
| 112 | requestedTransform.reset(); |
| 113 | bufferData = std::make_shared<BufferData>(); |
| 114 | bufferData->frameNumber = 0; |
| 115 | bufferData->acquireFence = sp<Fence>::make(-1); |
| 116 | acquireFenceTime = std::make_shared<FenceTime>(bufferData->acquireFence); |
| 117 | colorSpaceAgnostic = false; |
| 118 | frameRateSelectionPriority = Layer::PRIORITY_UNSET; |
| 119 | shadowRadius = 0.f; |
| 120 | fixedTransformHint = ui::Transform::ROT_INVALID; |
| 121 | destinationFrame.makeInvalid(); |
| 122 | isTrustedOverlay = false; |
| 123 | dropInputMode = gui::DropInputMode::NONE; |
| 124 | dimmingEnabled = true; |
| 125 | defaultFrameRateCompatibility = |
| 126 | static_cast<int8_t>(scheduler::LayerInfo::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 127 | frameRateCategory = static_cast<int8_t>(FrameRateCategory::Default); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 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 | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 132 | |
| 133 | if (name.length() > 77) { |
| 134 | std::string shortened; |
| 135 | shortened.append(name, 0, 36); |
| 136 | shortened.append("[...]"); |
| 137 | shortened.append(name, name.length() - 36); |
| 138 | debugName = std::move(shortened); |
| 139 | } else { |
| 140 | debugName = name; |
| 141 | } |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerState) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 145 | const uint32_t oldFlags = flags; |
| 146 | const half oldAlpha = color.a; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 147 | const bool hadBuffer = externalTexture != nullptr; |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 148 | uint64_t oldFramenumber = hadBuffer ? bufferData->frameNumber : 0; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 149 | const ui::Size oldBufferSize = hadBuffer |
| 150 | ? ui::Size(externalTexture->getWidth(), externalTexture->getHeight()) |
| 151 | : ui::Size(); |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 152 | const uint64_t oldUsageFlags = hadBuffer ? externalTexture->getUsage() : 0; |
| 153 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 154 | const bool hadSideStream = sidebandStream != nullptr; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 155 | const layer_state_t& clientState = resolvedComposerState.state; |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 156 | const bool hadSomethingToDraw = hasSomethingToDraw(); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 157 | uint64_t clientChanges = what | layer_state_t::diff(clientState); |
| 158 | layer_state_t::merge(clientState); |
| 159 | what = clientChanges; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 160 | LLOGV(layerId, "requested=%" PRIu64 "flags=%" PRIu64, clientState.what, clientChanges); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 161 | |
| 162 | if (clientState.what & layer_state_t::eFlagsChanged) { |
| 163 | if ((oldFlags ^ flags) & layer_state_t::eLayerHidden) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 164 | changes |= RequestedLayerState::Changes::Visibility | |
| 165 | RequestedLayerState::Changes::VisibleRegion; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 166 | } |
| 167 | if ((oldFlags ^ flags) & layer_state_t::eIgnoreDestinationFrame) { |
| 168 | changes |= RequestedLayerState::Changes::Geometry; |
| 169 | } |
| 170 | } |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 171 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 172 | if (clientState.what & layer_state_t::eBufferChanged) { |
| 173 | externalTexture = resolvedComposerState.externalTexture; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 174 | const bool hasBuffer = externalTexture != nullptr; |
| 175 | if (hasBuffer || hasBuffer != hadBuffer) { |
| 176 | changes |= RequestedLayerState::Changes::Buffer; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 177 | const ui::Size newBufferSize = hasBuffer |
| 178 | ? ui::Size(externalTexture->getWidth(), externalTexture->getHeight()) |
| 179 | : ui::Size(); |
| 180 | if (oldBufferSize != newBufferSize) { |
| 181 | changes |= RequestedLayerState::Changes::BufferSize; |
| 182 | changes |= RequestedLayerState::Changes::Geometry; |
| 183 | } |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 184 | const uint64_t usageFlags = hasBuffer ? externalTexture->getUsage() : 0; |
| 185 | if (oldUsageFlags != usageFlags) { |
| 186 | changes |= RequestedLayerState::Changes::BufferUsageFlags; |
| 187 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | if (hasBuffer != hadBuffer) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 191 | changes |= RequestedLayerState::Changes::Geometry | |
| 192 | RequestedLayerState::Changes::VisibleRegion | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 193 | RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Input; |
| 194 | } |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 195 | |
| 196 | if (hasBuffer) { |
| 197 | const bool frameNumberChanged = |
| 198 | bufferData->flags.test(BufferData::BufferDataChange::frameNumberChanged); |
| 199 | const uint64_t frameNumber = |
| 200 | frameNumberChanged ? bufferData->frameNumber : oldFramenumber + 1; |
| 201 | bufferData->frameNumber = frameNumber; |
| 202 | |
| 203 | if ((barrierProducerId > bufferData->producerId) || |
| 204 | ((barrierProducerId == bufferData->producerId) && |
| 205 | (barrierFrameNumber > bufferData->frameNumber))) { |
| 206 | ALOGE("Out of order buffers detected for %s producedId=%d frameNumber=%" PRIu64 |
| 207 | " -> producedId=%d frameNumber=%" PRIu64, |
| 208 | getDebugString().c_str(), bufferData->producerId, bufferData->frameNumber, |
| 209 | bufferData->producerId, frameNumber); |
| 210 | TransactionTraceWriter::getInstance().invoke("out_of_order_buffers_", |
| 211 | /*overwrite=*/false); |
| 212 | } |
| 213 | |
| 214 | barrierProducerId = std::max(bufferData->producerId, barrierProducerId); |
| 215 | barrierFrameNumber = std::max(bufferData->frameNumber, barrierFrameNumber); |
| 216 | } |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 217 | } |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 218 | |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 219 | if (clientState.what & layer_state_t::eSidebandStreamChanged) { |
| 220 | changes |= RequestedLayerState::Changes::SidebandStream; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 221 | const bool hasSideStream = sidebandStream != nullptr; |
| 222 | if (hasSideStream != hadSideStream) { |
| 223 | changes |= RequestedLayerState::Changes::Geometry | |
| 224 | RequestedLayerState::Changes::VisibleRegion | |
| 225 | RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Input; |
| 226 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 227 | } |
| 228 | if (what & (layer_state_t::eAlphaChanged)) { |
| 229 | if (oldAlpha == 0 || color.a == 0) { |
| 230 | changes |= RequestedLayerState::Changes::Visibility | |
| 231 | RequestedLayerState::Changes::VisibleRegion; |
| 232 | } |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 233 | } |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 234 | |
| 235 | if (hadSomethingToDraw != hasSomethingToDraw()) { |
| 236 | changes |= RequestedLayerState::Changes::Visibility | |
| 237 | RequestedLayerState::Changes::VisibleRegion; |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 238 | } |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 239 | if (clientChanges & layer_state_t::HIERARCHY_CHANGES) |
| 240 | changes |= RequestedLayerState::Changes::Hierarchy; |
| 241 | if (clientChanges & layer_state_t::CONTENT_CHANGES) |
| 242 | changes |= RequestedLayerState::Changes::Content; |
| 243 | if (clientChanges & layer_state_t::GEOMETRY_CHANGES) |
| 244 | changes |= RequestedLayerState::Changes::Geometry; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 245 | if (clientChanges & layer_state_t::AFFECTS_CHILDREN) |
| 246 | changes |= RequestedLayerState::Changes::AffectsChildren; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 247 | if (clientChanges & layer_state_t::INPUT_CHANGES) |
| 248 | changes |= RequestedLayerState::Changes::Input; |
| 249 | if (clientChanges & layer_state_t::VISIBLE_REGION_CHANGES) |
| 250 | changes |= RequestedLayerState::Changes::VisibleRegion; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 251 | if (clientState.what & layer_state_t::eColorTransformChanged) { |
| 252 | static const mat4 identityMatrix = mat4(); |
| 253 | hasColorTransform = colorTransform != identityMatrix; |
| 254 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 255 | if (clientState.what & |
| 256 | (layer_state_t::eLayerChanged | layer_state_t::eRelativeLayerChanged | |
| 257 | layer_state_t::eLayerStackChanged)) { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 258 | changes |= RequestedLayerState::Changes::Z; |
| 259 | } |
| 260 | if (clientState.what & layer_state_t::eReparent) { |
| 261 | changes |= RequestedLayerState::Changes::Parent; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 262 | parentId = resolvedComposerState.parentId; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 263 | parentSurfaceControlForChild = nullptr; |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 264 | // Once a layer has be reparented, it cannot be placed at the root. It sounds odd |
| 265 | // but thats the existing logic and until we make this behavior more explicit, we need |
| 266 | // to maintain this logic. |
| 267 | canBeRoot = false; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 268 | } |
| 269 | if (clientState.what & layer_state_t::eRelativeLayerChanged) { |
| 270 | changes |= RequestedLayerState::Changes::RelativeParent; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 271 | relativeParentId = resolvedComposerState.relativeParentId; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 272 | isRelativeOf = true; |
| 273 | relativeLayerSurfaceControl = nullptr; |
| 274 | } |
| 275 | if ((clientState.what & layer_state_t::eLayerChanged || |
| 276 | (clientState.what & layer_state_t::eReparent && parentId == UNASSIGNED_LAYER_ID)) && |
| 277 | isRelativeOf) { |
| 278 | // clear out relz data |
| 279 | relativeParentId = UNASSIGNED_LAYER_ID; |
| 280 | isRelativeOf = false; |
| 281 | changes |= RequestedLayerState::Changes::RelativeParent; |
| 282 | } |
| 283 | if (clientState.what & layer_state_t::eReparent && parentId == relativeParentId) { |
| 284 | // provide a hint that we are are now a direct child and not a relative child. |
| 285 | changes |= RequestedLayerState::Changes::RelativeParent; |
| 286 | } |
| 287 | if (clientState.what & layer_state_t::eInputInfoChanged) { |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 288 | touchCropId = resolvedComposerState.touchCropId; |
| 289 | windowInfoHandle->editInfo()->touchableRegionCropHandle.clear(); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 290 | } |
| 291 | if (clientState.what & layer_state_t::eStretchChanged) { |
| 292 | stretchEffect.sanitize(); |
| 293 | } |
| 294 | |
| 295 | if (clientState.what & layer_state_t::eHasListenerCallbacksChanged) { |
| 296 | // TODO(b/238781169) handle callbacks |
| 297 | } |
| 298 | |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 299 | if (clientState.what & layer_state_t::ePositionChanged) { |
| 300 | requestedTransform.set(x, y); |
| 301 | } |
| 302 | |
| 303 | if (clientState.what & layer_state_t::eMatrixChanged) { |
| 304 | requestedTransform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); |
| 305 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 306 | if (clientState.what & layer_state_t::eMetadataChanged) { |
| 307 | const int32_t requestedGameMode = |
| 308 | clientState.metadata.getInt32(gui::METADATA_GAME_MODE, -1); |
| 309 | if (requestedGameMode != -1) { |
| 310 | // The transaction will be received on the Task layer and needs to be applied to all |
| 311 | // child layers. |
| 312 | if (static_cast<int32_t>(gameMode) != requestedGameMode) { |
| 313 | gameMode = static_cast<gui::GameMode>(requestedGameMode); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 314 | changes |= RequestedLayerState::Changes::GameMode; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | } |
| 318 | if (clientState.what & layer_state_t::eFrameRateChanged) { |
| 319 | const auto compatibility = |
| 320 | Layer::FrameRate::convertCompatibility(clientState.frameRateCompatibility); |
| 321 | const auto strategy = Layer::FrameRate::convertChangeFrameRateStrategy( |
| 322 | clientState.changeFrameRateStrategy); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 323 | requestedFrameRate.vote = |
| 324 | Layer::FrameRate::FrameRateVote(Fps::fromValue(clientState.frameRate), |
| 325 | compatibility, strategy); |
| 326 | changes |= RequestedLayerState::Changes::FrameRate; |
| 327 | } |
| 328 | if (clientState.what & layer_state_t::eFrameRateCategoryChanged) { |
| 329 | const auto category = Layer::FrameRate::convertCategory(clientState.frameRateCategory); |
| 330 | requestedFrameRate.category = category; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 331 | changes |= RequestedLayerState::Changes::FrameRate; |
| 332 | } |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 335 | ui::Size RequestedLayerState::getUnrotatedBufferSize(uint32_t displayRotationFlags) const { |
| 336 | uint32_t bufferWidth = externalTexture->getWidth(); |
| 337 | uint32_t bufferHeight = externalTexture->getHeight(); |
| 338 | // Undo any transformations on the buffer. |
| 339 | if (bufferTransform & ui::Transform::ROT_90) { |
| 340 | std::swap(bufferWidth, bufferHeight); |
| 341 | } |
| 342 | if (transformToDisplayInverse) { |
| 343 | if (displayRotationFlags & ui::Transform::ROT_90) { |
| 344 | std::swap(bufferWidth, bufferHeight); |
| 345 | } |
| 346 | } |
| 347 | return {bufferWidth, bufferHeight}; |
| 348 | } |
| 349 | |
| 350 | ui::Transform RequestedLayerState::getTransform(uint32_t displayRotationFlags) const { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 351 | if ((flags & layer_state_t::eIgnoreDestinationFrame) || destinationFrame.isEmpty()) { |
| 352 | // If destination frame is not set, use the requested transform set via |
| 353 | // Transaction::setPosition and Transaction::setMatrix. |
| 354 | return requestedTransform; |
| 355 | } |
| 356 | |
| 357 | Rect destRect = destinationFrame; |
| 358 | int32_t destW = destRect.width(); |
| 359 | int32_t destH = destRect.height(); |
| 360 | if (destRect.left < 0) { |
| 361 | destRect.left = 0; |
| 362 | destRect.right = destW; |
| 363 | } |
| 364 | if (destRect.top < 0) { |
| 365 | destRect.top = 0; |
| 366 | destRect.bottom = destH; |
| 367 | } |
| 368 | |
| 369 | if (!externalTexture) { |
| 370 | ui::Transform transform; |
| 371 | transform.set(static_cast<float>(destRect.left), static_cast<float>(destRect.top)); |
| 372 | return transform; |
| 373 | } |
| 374 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 375 | ui::Size bufferSize = getUnrotatedBufferSize(displayRotationFlags); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 376 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 377 | float sx = static_cast<float>(destW) / static_cast<float>(bufferSize.width); |
| 378 | float sy = static_cast<float>(destH) / static_cast<float>(bufferSize.height); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 379 | ui::Transform transform; |
| 380 | transform.set(sx, 0, 0, sy); |
| 381 | transform.set(static_cast<float>(destRect.left), static_cast<float>(destRect.top)); |
| 382 | return transform; |
| 383 | } |
| 384 | |
| 385 | std::string RequestedLayerState::getDebugString() const { |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 386 | std::stringstream debug; |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 387 | debug << "RequestedLayerState{" << name; |
| 388 | if (parentId != UNASSIGNED_LAYER_ID) debug << " parentId=" << parentId; |
| 389 | if (relativeParentId != UNASSIGNED_LAYER_ID) debug << " relativeParentId=" << relativeParentId; |
| 390 | if (!mirrorIds.empty()) debug << " mirrorId=" << layerIdsToString(mirrorIds); |
| 391 | if (!handleAlive) debug << " !handle"; |
| 392 | if (z != 0) debug << " z=" << z; |
| 393 | if (layerStack.id != 0) debug << " layerStack=" << layerStack.id; |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 394 | return debug.str(); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 397 | std::ostream& operator<<(std::ostream& out, const RequestedLayerState& obj) { |
| 398 | out << obj.debugName; |
| 399 | if (obj.relativeParentId != UNASSIGNED_LAYER_ID) out << " parent=" << obj.parentId; |
| 400 | if (!obj.handleAlive) out << " handleNotAlive"; |
| 401 | return out; |
| 402 | } |
| 403 | |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 404 | std::string RequestedLayerState::getDebugStringShort() const { |
| 405 | return "[" + std::to_string(id) + "]" + name; |
| 406 | } |
| 407 | |
| 408 | bool RequestedLayerState::canBeDestroyed() const { |
| 409 | return !handleAlive && parentId == UNASSIGNED_LAYER_ID; |
| 410 | } |
| 411 | bool RequestedLayerState::isRoot() const { |
| 412 | return canBeRoot && parentId == UNASSIGNED_LAYER_ID; |
| 413 | } |
| 414 | bool RequestedLayerState::isHiddenByPolicy() const { |
| 415 | return (flags & layer_state_t::eLayerHidden) == layer_state_t::eLayerHidden; |
| 416 | }; |
| 417 | half4 RequestedLayerState::getColor() const { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 418 | if (sidebandStream || externalTexture) { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 419 | return {0._hf, 0._hf, 0._hf, color.a}; |
| 420 | } |
| 421 | return color; |
| 422 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 423 | Rect RequestedLayerState::getBufferSize(uint32_t displayRotationFlags) const { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 424 | // for buffer state layers we use the display frame size as the buffer size. |
| 425 | if (!externalTexture) { |
| 426 | return Rect::INVALID_RECT; |
| 427 | } |
| 428 | |
| 429 | uint32_t bufWidth = externalTexture->getWidth(); |
| 430 | uint32_t bufHeight = externalTexture->getHeight(); |
| 431 | |
| 432 | // Undo any transformations on the buffer and return the result. |
| 433 | if (bufferTransform & ui::Transform::ROT_90) { |
| 434 | std::swap(bufWidth, bufHeight); |
| 435 | } |
| 436 | |
| 437 | if (transformToDisplayInverse) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 438 | uint32_t invTransform = displayRotationFlags; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 439 | if (invTransform & ui::Transform::ROT_90) { |
| 440 | std::swap(bufWidth, bufHeight); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | return Rect(0, 0, static_cast<int32_t>(bufWidth), static_cast<int32_t>(bufHeight)); |
| 445 | } |
| 446 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 447 | Rect RequestedLayerState::getCroppedBufferSize(const Rect& bufferSize) const { |
| 448 | Rect size = bufferSize; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 449 | if (!crop.isEmpty() && size.isValid()) { |
| 450 | size.intersect(crop, &size); |
| 451 | } else if (!crop.isEmpty()) { |
| 452 | size = crop; |
| 453 | } |
| 454 | return size; |
| 455 | } |
| 456 | |
| 457 | Rect RequestedLayerState::getBufferCrop() const { |
| 458 | // this is the crop rectangle that applies to the buffer |
| 459 | // itself (as opposed to the window) |
| 460 | if (!bufferCrop.isEmpty()) { |
| 461 | // if the buffer crop is defined, we use that |
| 462 | return bufferCrop; |
| 463 | } else if (externalTexture != nullptr) { |
| 464 | // otherwise we use the whole buffer |
| 465 | return externalTexture->getBounds(); |
| 466 | } else { |
| 467 | // if we don't have a buffer yet, we use an empty/invalid crop |
| 468 | return Rect(); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | aidl::android::hardware::graphics::composer3::Composition RequestedLayerState::getCompositionType() |
| 473 | const { |
| 474 | using aidl::android::hardware::graphics::composer3::Composition; |
| 475 | // TODO(b/238781169) check about sidestream ready flag |
| 476 | if (sidebandStream.get()) { |
| 477 | return Composition::SIDEBAND; |
| 478 | } |
| 479 | if (!externalTexture) { |
| 480 | return Composition::SOLID_COLOR; |
| 481 | } |
| 482 | if (flags & layer_state_t::eLayerIsDisplayDecoration) { |
| 483 | return Composition::DISPLAY_DECORATION; |
| 484 | } |
| 485 | if (potentialCursor) { |
| 486 | return Composition::CURSOR; |
| 487 | } |
| 488 | return Composition::DEVICE; |
| 489 | } |
| 490 | |
| 491 | Rect RequestedLayerState::reduce(const Rect& win, const Region& exclude) { |
| 492 | if (CC_LIKELY(exclude.isEmpty())) { |
| 493 | return win; |
| 494 | } |
| 495 | if (exclude.isRect()) { |
| 496 | return win.reduce(exclude.getBounds()); |
| 497 | } |
| 498 | return Region(win).subtract(exclude).getBounds(); |
| 499 | } |
| 500 | |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 501 | // Returns true if the layer has a relative parent that is not its own parent. This is an input |
| 502 | // error from the client, and this check allows us to handle it gracefully. If both parentId and |
| 503 | // relativeParentId is unassigned then the layer does not have a valid relative parent. |
| 504 | // If the relative parentid is unassigned, the layer will be considered relative but won't be |
| 505 | // reachable. |
| 506 | bool RequestedLayerState::hasValidRelativeParent() const { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 507 | return isRelativeOf && |
| 508 | (parentId != relativeParentId || relativeParentId == UNASSIGNED_LAYER_ID); |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 511 | bool RequestedLayerState::hasInputInfo() const { |
| 512 | if (!windowInfoHandle) { |
| 513 | return false; |
| 514 | } |
| 515 | const auto windowInfo = windowInfoHandle->getInfo(); |
| 516 | return windowInfo->token != nullptr || |
| 517 | windowInfo->inputConfig.test(gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL); |
| 518 | } |
| 519 | |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 520 | bool RequestedLayerState::hasBlur() const { |
| 521 | return backgroundBlurRadius > 0 || blurRegions.size() > 0; |
| 522 | } |
| 523 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 524 | bool RequestedLayerState::hasFrameUpdate() const { |
| 525 | return what & layer_state_t::CONTENT_DIRTY && |
| 526 | (externalTexture || bgColorLayerId != UNASSIGNED_LAYER_ID); |
| 527 | } |
| 528 | |
| 529 | bool RequestedLayerState::hasReadyFrame() const { |
| 530 | return hasFrameUpdate() || changes.test(Changes::SidebandStream) || autoRefresh; |
| 531 | } |
| 532 | |
| 533 | bool RequestedLayerState::hasSidebandStreamFrame() const { |
| 534 | return hasFrameUpdate() && sidebandStream.get(); |
| 535 | } |
| 536 | |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 537 | bool RequestedLayerState::willReleaseBufferOnLatch() const { |
| 538 | return changes.test(Changes::Buffer) && !externalTexture; |
| 539 | } |
| 540 | |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 541 | bool RequestedLayerState::backpressureEnabled() const { |
| 542 | return flags & layer_state_t::eEnableBackpressure; |
| 543 | } |
| 544 | |
| 545 | bool RequestedLayerState::isSimpleBufferUpdate(const layer_state_t& s) const { |
| 546 | static constexpr uint64_t requiredFlags = layer_state_t::eBufferChanged; |
| 547 | if ((s.what & requiredFlags) != requiredFlags) { |
| 548 | ATRACE_FORMAT_INSTANT("%s: false [missing required flags 0x%" PRIx64 "]", __func__, |
| 549 | (s.what | requiredFlags) & ~s.what); |
| 550 | return false; |
| 551 | } |
| 552 | |
| 553 | static constexpr uint64_t deniedFlags = layer_state_t::eProducerDisconnect | |
| 554 | layer_state_t::eLayerChanged | layer_state_t::eRelativeLayerChanged | |
| 555 | layer_state_t::eTransparentRegionChanged | layer_state_t::eFlagsChanged | |
| 556 | layer_state_t::eBlurRegionsChanged | layer_state_t::eLayerStackChanged | |
| 557 | layer_state_t::eAutoRefreshChanged | layer_state_t::eReparent; |
| 558 | if (s.what & deniedFlags) { |
| 559 | ATRACE_FORMAT_INSTANT("%s: false [has denied flags 0x%" PRIx64 "]", __func__, |
| 560 | s.what & deniedFlags); |
| 561 | return false; |
| 562 | } |
| 563 | |
| 564 | bool changedFlags = diff(s); |
| 565 | static constexpr auto deniedChanges = layer_state_t::ePositionChanged | |
| 566 | layer_state_t::eAlphaChanged | layer_state_t::eColorTransformChanged | |
| 567 | layer_state_t::eBackgroundColorChanged | layer_state_t::eMatrixChanged | |
| 568 | layer_state_t::eCornerRadiusChanged | layer_state_t::eBackgroundBlurRadiusChanged | |
| 569 | layer_state_t::eBufferTransformChanged | |
| 570 | layer_state_t::eTransformToDisplayInverseChanged | layer_state_t::eCropChanged | |
| 571 | layer_state_t::eDataspaceChanged | layer_state_t::eHdrMetadataChanged | |
| 572 | layer_state_t::eSidebandStreamChanged | layer_state_t::eColorSpaceAgnosticChanged | |
| 573 | layer_state_t::eShadowRadiusChanged | layer_state_t::eFixedTransformHintChanged | |
| 574 | layer_state_t::eTrustedOverlayChanged | layer_state_t::eStretchChanged | |
| 575 | layer_state_t::eBufferCropChanged | layer_state_t::eDestinationFrameChanged | |
| 576 | layer_state_t::eDimmingEnabledChanged | layer_state_t::eExtendedRangeBrightnessChanged; |
| 577 | if (changedFlags & deniedChanges) { |
| 578 | ATRACE_FORMAT_INSTANT("%s: false [has denied changes flags 0x%" PRIx64 "]", __func__, |
| 579 | s.what & deniedChanges); |
| 580 | return false; |
| 581 | } |
| 582 | |
| 583 | return true; |
| 584 | } |
| 585 | |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 586 | bool RequestedLayerState::isProtected() const { |
| 587 | return externalTexture && externalTexture->getUsage() & GRALLOC_USAGE_PROTECTED; |
| 588 | } |
| 589 | |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 590 | bool RequestedLayerState::hasSomethingToDraw() const { |
| 591 | return externalTexture != nullptr || sidebandStream != nullptr || shadowRadius > 0.f || |
| 592 | backgroundBlurRadius > 0 || blurRegions.size() > 0 || |
| 593 | (color.r >= 0.0_hf && color.g >= 0.0_hf && color.b >= 0.0_hf); |
| 594 | } |
| 595 | |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 596 | void RequestedLayerState::clearChanges() { |
| 597 | what = 0; |
| 598 | changes.clear(); |
| 599 | } |
| 600 | |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 601 | } // namespace android::surfaceflinger::frontend |