chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame^] | 18 | #include "FrontEnd/LayerCreationArgs.h" |
| 19 | #include "FrontEnd/LayerSnapshot.h" |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 20 | #pragma clang diagnostic push |
| 21 | #pragma clang diagnostic ignored "-Wconversion" |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 22 | #pragma clang diagnostic ignored "-Wextra" |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 23 | |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 24 | #include "LayerProtoHelper.h" |
| 25 | |
| 26 | namespace android { |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 27 | |
| 28 | using gui::WindowInfo; |
| 29 | |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 30 | namespace surfaceflinger { |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 31 | |
| 32 | void LayerProtoHelper::writePositionToProto(const float x, const float y, |
| 33 | std::function<PositionProto*()> getPositionProto) { |
| 34 | if (x != 0 || y != 0) { |
| 35 | // Use a lambda do avoid writing the object header when the object is empty |
| 36 | PositionProto* position = getPositionProto(); |
| 37 | position->set_x(x); |
| 38 | position->set_y(y); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void LayerProtoHelper::writeSizeToProto(const uint32_t w, const uint32_t h, |
| 43 | std::function<SizeProto*()> getSizeProto) { |
| 44 | if (w != 0 || h != 0) { |
| 45 | // Use a lambda do avoid writing the object header when the object is empty |
| 46 | SizeProto* size = getSizeProto(); |
| 47 | size->set_w(w); |
| 48 | size->set_h(h); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void LayerProtoHelper::writeToProto(const Region& region, |
| 53 | std::function<RegionProto*()> getRegionProto) { |
| 54 | if (region.isEmpty()) { |
| 55 | return; |
| 56 | } |
| 57 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 58 | writeToProto(region, getRegionProto()); |
| 59 | } |
| 60 | |
| 61 | void LayerProtoHelper::writeToProto(const Region& region, RegionProto* regionProto) { |
| 62 | if (region.isEmpty()) { |
| 63 | return; |
| 64 | } |
| 65 | |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 66 | Region::const_iterator head = region.begin(); |
| 67 | Region::const_iterator const tail = region.end(); |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 68 | // Use a lambda do avoid writing the object header when the object is empty |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 69 | while (head != tail) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 70 | writeToProto(*head, regionProto->add_rect()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 71 | head++; |
| 72 | } |
| 73 | } |
| 74 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 75 | void LayerProtoHelper::readFromProto(const RegionProto& regionProto, Region& outRegion) { |
| 76 | for (int i = 0; i < regionProto.rect_size(); i++) { |
| 77 | Rect rect; |
| 78 | readFromProto(regionProto.rect(i), rect); |
| 79 | outRegion.orSelf(rect); |
| 80 | } |
| 81 | } |
| 82 | |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 83 | void LayerProtoHelper::writeToProto(const Rect& rect, std::function<RectProto*()> getRectProto) { |
| 84 | if (rect.left != 0 || rect.right != 0 || rect.top != 0 || rect.bottom != 0) { |
| 85 | // Use a lambda do avoid writing the object header when the object is empty |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 86 | writeToProto(rect, getRectProto()); |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 87 | } |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 90 | void LayerProtoHelper::writeToProto(const Rect& rect, RectProto* rectProto) { |
| 91 | rectProto->set_left(rect.left); |
| 92 | rectProto->set_top(rect.top); |
| 93 | rectProto->set_bottom(rect.bottom); |
| 94 | rectProto->set_right(rect.right); |
| 95 | } |
| 96 | |
| 97 | void LayerProtoHelper::readFromProto(const RectProto& proto, Rect& outRect) { |
| 98 | outRect.left = proto.left(); |
| 99 | outRect.top = proto.top(); |
| 100 | outRect.bottom = proto.bottom(); |
| 101 | outRect.right = proto.right(); |
| 102 | } |
| 103 | |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 104 | void LayerProtoHelper::writeToProto(const FloatRect& rect, |
| 105 | std::function<FloatRectProto*()> getFloatRectProto) { |
| 106 | if (rect.left != 0 || rect.right != 0 || rect.top != 0 || rect.bottom != 0) { |
| 107 | // Use a lambda do avoid writing the object header when the object is empty |
| 108 | FloatRectProto* rectProto = getFloatRectProto(); |
| 109 | rectProto->set_left(rect.left); |
| 110 | rectProto->set_top(rect.top); |
| 111 | rectProto->set_bottom(rect.bottom); |
| 112 | rectProto->set_right(rect.right); |
| 113 | } |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 116 | void LayerProtoHelper::writeToProto(const half4 color, std::function<ColorProto*()> getColorProto) { |
| 117 | if (color.r != 0 || color.g != 0 || color.b != 0 || color.a != 0) { |
| 118 | // Use a lambda do avoid writing the object header when the object is empty |
| 119 | ColorProto* colorProto = getColorProto(); |
| 120 | colorProto->set_r(color.r); |
| 121 | colorProto->set_g(color.g); |
| 122 | colorProto->set_b(color.b); |
| 123 | colorProto->set_a(color.a); |
| 124 | } |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 125 | } |
| 126 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 127 | void LayerProtoHelper::writeToProtoDeprecated(const ui::Transform& transform, |
| 128 | TransformProto* transformProto) { |
Nataniel Borges | 84a4618 | 2019-02-26 15:36:32 -0800 | [diff] [blame] | 129 | const uint32_t type = transform.getType() | (transform.getOrientation() << 8); |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 130 | transformProto->set_type(type); |
| 131 | |
Nataniel Borges | 9a2433c | 2019-03-13 15:02:45 -0700 | [diff] [blame] | 132 | // Rotations that are 90/180/270 have their own type so the transform matrix can be |
| 133 | // reconstructed later. All other rotation have the type UKNOWN so we need to save the transform |
| 134 | // values in that case. |
Nataniel Borges | 84a4618 | 2019-02-26 15:36:32 -0800 | [diff] [blame] | 135 | if (type & (ui::Transform::SCALE | ui::Transform::UNKNOWN)) { |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 136 | transformProto->set_dsdx(transform[0][0]); |
| 137 | transformProto->set_dtdx(transform[0][1]); |
| 138 | transformProto->set_dsdy(transform[1][0]); |
| 139 | transformProto->set_dtdy(transform[1][1]); |
| 140 | } |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 141 | } |
| 142 | |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 143 | void LayerProtoHelper::writeTransformToProto(const ui::Transform& transform, |
| 144 | TransformProto* transformProto) { |
| 145 | const uint32_t type = transform.getType() | (transform.getOrientation() << 8); |
| 146 | transformProto->set_type(type); |
| 147 | |
| 148 | // Rotations that are 90/180/270 have their own type so the transform matrix can be |
| 149 | // reconstructed later. All other rotation have the type UNKNOWN so we need to save the |
| 150 | // transform values in that case. |
| 151 | if (type & (ui::Transform::SCALE | ui::Transform::UNKNOWN)) { |
| 152 | transformProto->set_dsdx(transform.dsdx()); |
| 153 | transformProto->set_dtdx(transform.dtdx()); |
| 154 | transformProto->set_dtdy(transform.dtdy()); |
| 155 | transformProto->set_dsdy(transform.dsdy()); |
| 156 | } |
| 157 | } |
| 158 | |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 159 | void LayerProtoHelper::writeToProto(const renderengine::ExternalTexture& buffer, |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 160 | std::function<ActiveBufferProto*()> getActiveBufferProto) { |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 161 | if (buffer.getWidth() != 0 || buffer.getHeight() != 0 || buffer.getUsage() != 0 || |
| 162 | buffer.getPixelFormat() != 0) { |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 163 | // Use a lambda do avoid writing the object header when the object is empty |
| 164 | ActiveBufferProto* activeBufferProto = getActiveBufferProto(); |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 165 | activeBufferProto->set_width(buffer.getWidth()); |
| 166 | activeBufferProto->set_height(buffer.getHeight()); |
| 167 | activeBufferProto->set_stride(buffer.getUsage()); |
| 168 | activeBufferProto->set_format(buffer.getPixelFormat()); |
Nataniel Borges | 797b0e4 | 2019-02-15 14:11:58 -0800 | [diff] [blame] | 169 | } |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 172 | void LayerProtoHelper::writeToProto( |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 173 | const WindowInfo& inputInfo, const wp<Layer>& touchableRegionBounds, |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 174 | std::function<InputWindowInfoProto*()> getInputWindowInfoProto) { |
| 175 | if (inputInfo.token == nullptr) { |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | InputWindowInfoProto* proto = getInputWindowInfoProto(); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 180 | proto->set_layout_params_flags(inputInfo.layoutParamsFlags.get()); |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 181 | using U = std::underlying_type_t<WindowInfo::Type>; |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 182 | // TODO(b/129481165): This static assert can be safely removed once conversion warnings |
| 183 | // are re-enabled. |
| 184 | static_assert(std::is_same_v<U, int32_t>); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 185 | proto->set_layout_params_type(static_cast<U>(inputInfo.layoutParamsType)); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 186 | |
| 187 | LayerProtoHelper::writeToProto({inputInfo.frameLeft, inputInfo.frameTop, inputInfo.frameRight, |
| 188 | inputInfo.frameBottom}, |
| 189 | [&]() { return proto->mutable_frame(); }); |
| 190 | LayerProtoHelper::writeToProto(inputInfo.touchableRegion, |
| 191 | [&]() { return proto->mutable_touchable_region(); }); |
| 192 | |
| 193 | proto->set_surface_inset(inputInfo.surfaceInset); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 194 | using InputConfig = gui::WindowInfo::InputConfig; |
| 195 | proto->set_visible(!inputInfo.inputConfig.test(InputConfig::NOT_VISIBLE)); |
| 196 | proto->set_focusable(!inputInfo.inputConfig.test(InputConfig::NOT_FOCUSABLE)); |
| 197 | proto->set_has_wallpaper(inputInfo.inputConfig.test(InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER)); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 198 | |
| 199 | proto->set_global_scale_factor(inputInfo.globalScaleFactor); |
chaviw | 0a39899 | 2021-08-13 10:13:01 -0500 | [diff] [blame] | 200 | LayerProtoHelper::writeToProtoDeprecated(inputInfo.transform, proto->mutable_transform()); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 201 | proto->set_replace_touchable_region_with_crop(inputInfo.replaceTouchableRegionWithCrop); |
| 202 | auto cropLayer = touchableRegionBounds.promote(); |
| 203 | if (cropLayer != nullptr) { |
| 204 | proto->set_crop_layer_id(cropLayer->sequence); |
| 205 | LayerProtoHelper::writeToProto(cropLayer->getScreenBounds( |
| 206 | false /* reduceTransparentRegion */), |
| 207 | [&]() { return proto->mutable_touchable_region_crop(); }); |
| 208 | } |
| 209 | } |
| 210 | |
chaviw | ddeae26 | 2020-01-06 10:31:23 -0800 | [diff] [blame] | 211 | void LayerProtoHelper::writeToProto(const mat4 matrix, ColorTransformProto* colorTransformProto) { |
| 212 | for (int i = 0; i < mat4::ROW_SIZE; i++) { |
| 213 | for (int j = 0; j < mat4::COL_SIZE; j++) { |
| 214 | colorTransformProto->add_val(matrix[i][j]); |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 219 | void LayerProtoHelper::readFromProto(const ColorTransformProto& colorTransformProto, mat4& matrix) { |
| 220 | for (int i = 0; i < mat4::ROW_SIZE; i++) { |
| 221 | for (int j = 0; j < mat4::COL_SIZE; j++) { |
| 222 | matrix[i][j] = colorTransformProto.val(i * mat4::COL_SIZE + j); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | void LayerProtoHelper::writeToProto(const android::BlurRegion region, BlurRegion* proto) { |
| 228 | proto->set_blur_radius(region.blurRadius); |
| 229 | proto->set_corner_radius_tl(region.cornerRadiusTL); |
| 230 | proto->set_corner_radius_tr(region.cornerRadiusTR); |
| 231 | proto->set_corner_radius_bl(region.cornerRadiusBL); |
| 232 | proto->set_corner_radius_br(region.cornerRadiusBR); |
| 233 | proto->set_alpha(region.alpha); |
| 234 | proto->set_left(region.left); |
| 235 | proto->set_top(region.top); |
| 236 | proto->set_right(region.right); |
| 237 | proto->set_bottom(region.bottom); |
| 238 | } |
| 239 | |
| 240 | void LayerProtoHelper::readFromProto(const BlurRegion& proto, android::BlurRegion& outRegion) { |
| 241 | outRegion.blurRadius = proto.blur_radius(); |
| 242 | outRegion.cornerRadiusTL = proto.corner_radius_tl(); |
| 243 | outRegion.cornerRadiusTR = proto.corner_radius_tr(); |
| 244 | outRegion.cornerRadiusBL = proto.corner_radius_bl(); |
| 245 | outRegion.cornerRadiusBR = proto.corner_radius_br(); |
| 246 | outRegion.alpha = proto.alpha(); |
| 247 | outRegion.left = proto.left(); |
| 248 | outRegion.top = proto.top(); |
| 249 | outRegion.right = proto.right(); |
| 250 | outRegion.bottom = proto.bottom(); |
| 251 | } |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 252 | |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame^] | 253 | LayersProto LayerProtoFromSnapshotGenerator::generate(const frontend::LayerHierarchy& root) { |
| 254 | mLayersProto.clear_layers(); |
| 255 | std::unordered_set<uint64_t> stackIdsToSkip; |
| 256 | if ((mTraceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) { |
| 257 | for (const auto& [layerStack, displayInfo] : mDisplayInfos) { |
| 258 | if (displayInfo.isVirtual) { |
| 259 | stackIdsToSkip.insert(layerStack.id); |
| 260 | } |
Vishnu Nair | 39872bc | 2023-03-11 12:48:31 -0800 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame^] | 264 | frontend::LayerHierarchy::TraversalPath path = frontend::LayerHierarchy::TraversalPath::ROOT; |
| 265 | for (auto& [child, variant] : root.mChildren) { |
| 266 | if (variant != frontend::LayerHierarchy::Variant::Attached || |
| 267 | stackIdsToSkip.find(child->getLayer()->layerStack.id) != stackIdsToSkip.end()) { |
| 268 | continue; |
| 269 | } |
| 270 | frontend::LayerHierarchy::ScopedAddToTraversalPath addChildToPath(path, |
| 271 | child->getLayer()->id, |
| 272 | variant); |
| 273 | LayerProtoFromSnapshotGenerator::writeHierarchyToProto(*child, path); |
Vishnu Nair | d19848f | 2023-03-15 18:24:28 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame^] | 276 | // fill in relative and parent info |
| 277 | for (int i = 0; i < mLayersProto.layers_size(); i++) { |
| 278 | auto layerProto = mLayersProto.mutable_layers()->Mutable(i); |
| 279 | auto it = mChildToRelativeParent.find(layerProto->id()); |
| 280 | if (it == mChildToRelativeParent.end()) { |
| 281 | layerProto->set_z_order_relative_of(-1); |
| 282 | } else { |
| 283 | layerProto->set_z_order_relative_of(it->second); |
| 284 | } |
| 285 | it = mChildToParent.find(layerProto->id()); |
| 286 | if (it == mChildToParent.end()) { |
| 287 | layerProto->set_parent(-1); |
| 288 | } else { |
| 289 | layerProto->set_parent(it->second); |
| 290 | } |
Vishnu Nair | d19848f | 2023-03-15 18:24:28 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame^] | 293 | mDefaultSnapshots.clear(); |
| 294 | mChildToRelativeParent.clear(); |
| 295 | return std::move(mLayersProto); |
| 296 | } |
| 297 | |
| 298 | frontend::LayerSnapshot* LayerProtoFromSnapshotGenerator::getSnapshot( |
| 299 | frontend::LayerHierarchy::TraversalPath& path, const frontend::RequestedLayerState& layer) { |
| 300 | frontend::LayerSnapshot* snapshot = mSnapshotBuilder.getSnapshot(path); |
| 301 | if (snapshot) { |
| 302 | return snapshot; |
| 303 | } else { |
| 304 | mDefaultSnapshots[path] = frontend::LayerSnapshot(layer, path); |
| 305 | return &mDefaultSnapshots[path]; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | void LayerProtoFromSnapshotGenerator::writeHierarchyToProto( |
| 310 | const frontend::LayerHierarchy& root, frontend::LayerHierarchy::TraversalPath& path) { |
| 311 | using Variant = frontend::LayerHierarchy::Variant; |
| 312 | LayerProto* layerProto = mLayersProto.add_layers(); |
| 313 | const frontend::RequestedLayerState& layer = *root.getLayer(); |
| 314 | frontend::LayerSnapshot* snapshot = getSnapshot(path, layer); |
| 315 | LayerProtoHelper::writeSnapshotToProto(layerProto, layer, *snapshot, mTraceFlags); |
| 316 | |
| 317 | for (const auto& [child, variant] : root.mChildren) { |
| 318 | frontend::LayerHierarchy::ScopedAddToTraversalPath addChildToPath(path, |
| 319 | child->getLayer()->id, |
| 320 | variant); |
| 321 | frontend::LayerSnapshot* childSnapshot = getSnapshot(path, layer); |
| 322 | if (variant == Variant::Attached || variant == Variant::Detached || |
| 323 | variant == Variant::Mirror) { |
| 324 | mChildToParent[childSnapshot->uniqueSequence] = snapshot->uniqueSequence; |
| 325 | layerProto->add_children(childSnapshot->uniqueSequence); |
| 326 | } else if (variant == Variant::Relative) { |
| 327 | mChildToRelativeParent[childSnapshot->uniqueSequence] = snapshot->uniqueSequence; |
| 328 | layerProto->add_relatives(childSnapshot->uniqueSequence); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | if (mTraceFlags & LayerTracing::TRACE_COMPOSITION) { |
| 333 | auto it = mLegacyLayers.find(layer.id); |
| 334 | if (it != mLegacyLayers.end()) { |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 335 | it->second->writeCompositionStateToProto(layerProto); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | for (const auto& [child, variant] : root.mChildren) { |
| 340 | // avoid visiting relative layers twice |
| 341 | if (variant == Variant::Detached) { |
| 342 | continue; |
| 343 | } |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame^] | 344 | frontend::LayerHierarchy::ScopedAddToTraversalPath addChildToPath(path, |
| 345 | child->getLayer()->id, |
| 346 | variant); |
| 347 | writeHierarchyToProto(*child, path); |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
| 351 | void LayerProtoHelper::writeSnapshotToProto(LayerProto* layerInfo, |
| 352 | const frontend::RequestedLayerState& requestedState, |
| 353 | const frontend::LayerSnapshot& snapshot, |
| 354 | uint32_t traceFlags) { |
| 355 | const ui::Transform transform = snapshot.geomLayerTransform; |
| 356 | auto buffer = requestedState.externalTexture; |
| 357 | if (buffer != nullptr) { |
| 358 | LayerProtoHelper::writeToProto(*buffer, |
| 359 | [&]() { return layerInfo->mutable_active_buffer(); }); |
| 360 | LayerProtoHelper::writeToProtoDeprecated(ui::Transform(requestedState.bufferTransform), |
| 361 | layerInfo->mutable_buffer_transform()); |
| 362 | } |
| 363 | layerInfo->set_invalidate(snapshot.contentDirty); |
| 364 | layerInfo->set_is_protected(snapshot.hasProtectedContent); |
| 365 | layerInfo->set_dataspace(dataspaceDetails(static_cast<android_dataspace>(snapshot.dataspace))); |
| 366 | layerInfo->set_curr_frame(requestedState.bufferData->frameNumber); |
| 367 | layerInfo->set_requested_corner_radius(requestedState.cornerRadius); |
| 368 | layerInfo->set_corner_radius( |
| 369 | (snapshot.roundedCorner.radius.x + snapshot.roundedCorner.radius.y) / 2.0); |
| 370 | layerInfo->set_background_blur_radius(snapshot.backgroundBlurRadius); |
| 371 | layerInfo->set_is_trusted_overlay(snapshot.isTrustedOverlay); |
| 372 | LayerProtoHelper::writeToProtoDeprecated(transform, layerInfo->mutable_transform()); |
| 373 | LayerProtoHelper::writePositionToProto(transform.tx(), transform.ty(), |
| 374 | [&]() { return layerInfo->mutable_position(); }); |
| 375 | LayerProtoHelper::writeToProto(snapshot.geomLayerBounds, |
| 376 | [&]() { return layerInfo->mutable_bounds(); }); |
| 377 | LayerProtoHelper::writeToProto(snapshot.surfaceDamage, |
| 378 | [&]() { return layerInfo->mutable_damage_region(); }); |
| 379 | |
| 380 | if (requestedState.hasColorTransform) { |
| 381 | LayerProtoHelper::writeToProto(snapshot.colorTransform, |
| 382 | layerInfo->mutable_color_transform()); |
| 383 | } |
| 384 | |
| 385 | LayerProtoHelper::writeToProto(snapshot.croppedBufferSize.toFloatRect(), |
| 386 | [&]() { return layerInfo->mutable_source_bounds(); }); |
| 387 | LayerProtoHelper::writeToProto(snapshot.transformedBounds, |
| 388 | [&]() { return layerInfo->mutable_screen_bounds(); }); |
| 389 | LayerProtoHelper::writeToProto(snapshot.roundedCorner.cropRect, |
| 390 | [&]() { return layerInfo->mutable_corner_radius_crop(); }); |
| 391 | layerInfo->set_shadow_radius(snapshot.shadowRadius); |
| 392 | |
Vishnu Nair | 93b8b79 | 2023-02-27 19:40:24 +0000 | [diff] [blame] | 393 | layerInfo->set_id(snapshot.uniqueSequence); |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame^] | 394 | layerInfo->set_original_id(snapshot.sequence); |
Vishnu Nair | ea6ff81 | 2023-02-27 17:41:39 +0000 | [diff] [blame] | 395 | layerInfo->set_name(requestedState.name); |
| 396 | layerInfo->set_type("Layer"); |
| 397 | |
| 398 | LayerProtoHelper::writeToProto(requestedState.transparentRegion, |
| 399 | [&]() { return layerInfo->mutable_transparent_region(); }); |
| 400 | |
| 401 | layerInfo->set_layer_stack(snapshot.outputFilter.layerStack.id); |
| 402 | layerInfo->set_z(requestedState.z); |
| 403 | |
| 404 | ui::Transform requestedTransform = requestedState.getTransform(0); |
| 405 | LayerProtoHelper::writePositionToProto(requestedTransform.tx(), requestedTransform.ty(), [&]() { |
| 406 | return layerInfo->mutable_requested_position(); |
| 407 | }); |
| 408 | |
| 409 | LayerProtoHelper::writeToProto(requestedState.crop, |
| 410 | [&]() { return layerInfo->mutable_crop(); }); |
| 411 | |
| 412 | layerInfo->set_is_opaque(snapshot.contentOpaque); |
| 413 | if (requestedState.externalTexture) |
| 414 | layerInfo->set_pixel_format( |
| 415 | decodePixelFormat(requestedState.externalTexture->getPixelFormat())); |
| 416 | LayerProtoHelper::writeToProto(snapshot.color, [&]() { return layerInfo->mutable_color(); }); |
| 417 | LayerProtoHelper::writeToProto(requestedState.color, |
| 418 | [&]() { return layerInfo->mutable_requested_color(); }); |
| 419 | layerInfo->set_flags(requestedState.flags); |
| 420 | |
| 421 | LayerProtoHelper::writeToProtoDeprecated(requestedTransform, |
| 422 | layerInfo->mutable_requested_transform()); |
| 423 | |
| 424 | layerInfo->set_is_relative_of(requestedState.isRelativeOf); |
| 425 | |
| 426 | layerInfo->set_owner_uid(requestedState.ownerUid); |
| 427 | |
| 428 | if ((traceFlags & LayerTracing::TRACE_INPUT) && snapshot.hasInputInfo()) { |
| 429 | LayerProtoHelper::writeToProto(snapshot.inputInfo, {}, |
| 430 | [&]() { return layerInfo->mutable_input_window_info(); }); |
| 431 | } |
| 432 | |
| 433 | if (traceFlags & LayerTracing::TRACE_EXTRA) { |
| 434 | auto protoMap = layerInfo->mutable_metadata(); |
| 435 | for (const auto& entry : requestedState.metadata.mMap) { |
| 436 | (*protoMap)[entry.first] = std::string(entry.second.cbegin(), entry.second.cend()); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | LayerProtoHelper::writeToProto(requestedState.destinationFrame, |
| 441 | [&]() { return layerInfo->mutable_destination_frame(); }); |
| 442 | } |
| 443 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 444 | google::protobuf::RepeatedPtrField<DisplayProto> LayerProtoHelper::writeDisplayInfoToProto( |
| 445 | const display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& displayInfos) { |
| 446 | google::protobuf::RepeatedPtrField<DisplayProto> displays; |
| 447 | displays.Reserve(displayInfos.size()); |
| 448 | for (const auto& [layerStack, displayInfo] : displayInfos) { |
| 449 | auto displayProto = displays.Add(); |
| 450 | displayProto->set_id(displayInfo.info.displayId); |
| 451 | displayProto->set_layer_stack(layerStack.id); |
| 452 | displayProto->mutable_size()->set_w(displayInfo.info.logicalWidth); |
| 453 | displayProto->mutable_size()->set_h(displayInfo.info.logicalHeight); |
| 454 | writeTransformToProto(displayInfo.transform, displayProto->mutable_transform()); |
| 455 | displayProto->set_is_virtual(displayInfo.isVirtual); |
| 456 | } |
| 457 | return displays; |
| 458 | } |
| 459 | |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 460 | } // namespace surfaceflinger |
| 461 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 462 | |
| 463 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 464 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |