blob: 513c943f6184ee6796324c131bfaa15b982a9e02 [file] [log] [blame]
chaviw1d044282017-09-27 12:19:28 -07001/*
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 Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
Vishnu Naird0183602023-03-16 18:52:15 +000018#include "FrontEnd/LayerCreationArgs.h"
19#include "FrontEnd/LayerSnapshot.h"
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080020#pragma clang diagnostic push
21#pragma clang diagnostic ignored "-Wconversion"
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010022#pragma clang diagnostic ignored "-Wextra"
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080023
chaviw1d044282017-09-27 12:19:28 -070024#include "LayerProtoHelper.h"
25
26namespace android {
chaviw98318de2021-05-19 16:45:23 -050027
28using gui::WindowInfo;
29
chaviw1d044282017-09-27 12:19:28 -070030namespace surfaceflinger {
Nataniel Borges797b0e42019-02-15 14:11:58 -080031
Kean Mariotti4ba343c2023-04-19 13:31:02 +000032void LayerProtoHelper::writePositionToProto(
33 const float x, const float y,
34 std::function<perfetto::protos::PositionProto*()> getPositionProto) {
Nataniel Borges797b0e42019-02-15 14:11:58 -080035 if (x != 0 || y != 0) {
36 // Use a lambda do avoid writing the object header when the object is empty
Kean Mariotti4ba343c2023-04-19 13:31:02 +000037 perfetto::protos::PositionProto* position = getPositionProto();
Nataniel Borges797b0e42019-02-15 14:11:58 -080038 position->set_x(x);
39 position->set_y(y);
40 }
41}
42
Kean Mariotti4ba343c2023-04-19 13:31:02 +000043void LayerProtoHelper::writeSizeToProto(
44 const uint32_t w, const uint32_t h,
45 std::function<perfetto::protos::SizeProto*()> getSizeProto) {
Nataniel Borges797b0e42019-02-15 14:11:58 -080046 if (w != 0 || h != 0) {
47 // Use a lambda do avoid writing the object header when the object is empty
Kean Mariotti4ba343c2023-04-19 13:31:02 +000048 perfetto::protos::SizeProto* size = getSizeProto();
Nataniel Borges797b0e42019-02-15 14:11:58 -080049 size->set_w(w);
50 size->set_h(h);
51 }
52}
53
Kean Mariotti4ba343c2023-04-19 13:31:02 +000054void LayerProtoHelper::writeToProto(
55 const Region& region, std::function<perfetto::protos::RegionProto*()> getRegionProto) {
Nataniel Borges797b0e42019-02-15 14:11:58 -080056 if (region.isEmpty()) {
57 return;
58 }
59
Vishnu Nair6b591152021-10-08 11:45:14 -070060 writeToProto(region, getRegionProto());
61}
62
Kean Mariotti4ba343c2023-04-19 13:31:02 +000063void LayerProtoHelper::writeToProto(const Region& region,
64 perfetto::protos::RegionProto* regionProto) {
Vishnu Nair6b591152021-10-08 11:45:14 -070065 if (region.isEmpty()) {
66 return;
67 }
68
chaviw1d044282017-09-27 12:19:28 -070069 Region::const_iterator head = region.begin();
70 Region::const_iterator const tail = region.end();
Nataniel Borges797b0e42019-02-15 14:11:58 -080071 // Use a lambda do avoid writing the object header when the object is empty
chaviw1d044282017-09-27 12:19:28 -070072 while (head != tail) {
Vishnu Nair6b591152021-10-08 11:45:14 -070073 writeToProto(*head, regionProto->add_rect());
chaviw1d044282017-09-27 12:19:28 -070074 head++;
75 }
76}
77
Kean Mariotti4ba343c2023-04-19 13:31:02 +000078void LayerProtoHelper::readFromProto(const perfetto::protos::RegionProto& regionProto,
79 Region& outRegion) {
Vishnu Nair6b591152021-10-08 11:45:14 -070080 for (int i = 0; i < regionProto.rect_size(); i++) {
81 Rect rect;
82 readFromProto(regionProto.rect(i), rect);
83 outRegion.orSelf(rect);
84 }
85}
86
Kean Mariotti4ba343c2023-04-19 13:31:02 +000087void LayerProtoHelper::writeToProto(const Rect& rect,
88 std::function<perfetto::protos::RectProto*()> getRectProto) {
Nataniel Borges797b0e42019-02-15 14:11:58 -080089 if (rect.left != 0 || rect.right != 0 || rect.top != 0 || rect.bottom != 0) {
90 // Use a lambda do avoid writing the object header when the object is empty
Vishnu Nair6b591152021-10-08 11:45:14 -070091 writeToProto(rect, getRectProto());
Nataniel Borges797b0e42019-02-15 14:11:58 -080092 }
chaviw1d044282017-09-27 12:19:28 -070093}
94
Kean Mariotti4ba343c2023-04-19 13:31:02 +000095void LayerProtoHelper::writeToProto(const Rect& rect, perfetto::protos::RectProto* rectProto) {
Vishnu Nair6b591152021-10-08 11:45:14 -070096 rectProto->set_left(rect.left);
97 rectProto->set_top(rect.top);
98 rectProto->set_bottom(rect.bottom);
99 rectProto->set_right(rect.right);
100}
101
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000102void LayerProtoHelper::readFromProto(const perfetto::protos::RectProto& proto, Rect& outRect) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700103 outRect.left = proto.left();
104 outRect.top = proto.top();
105 outRect.bottom = proto.bottom();
106 outRect.right = proto.right();
107}
108
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000109void LayerProtoHelper::writeToProto(
110 const FloatRect& rect,
111 std::function<perfetto::protos::FloatRectProto*()> getFloatRectProto) {
Nataniel Borges797b0e42019-02-15 14:11:58 -0800112 if (rect.left != 0 || rect.right != 0 || rect.top != 0 || rect.bottom != 0) {
113 // Use a lambda do avoid writing the object header when the object is empty
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000114 perfetto::protos::FloatRectProto* rectProto = getFloatRectProto();
Nataniel Borges797b0e42019-02-15 14:11:58 -0800115 rectProto->set_left(rect.left);
116 rectProto->set_top(rect.top);
117 rectProto->set_bottom(rect.bottom);
118 rectProto->set_right(rect.right);
119 }
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800120}
121
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000122void LayerProtoHelper::writeToProto(const half4 color,
123 std::function<perfetto::protos::ColorProto*()> getColorProto) {
Nataniel Borges797b0e42019-02-15 14:11:58 -0800124 if (color.r != 0 || color.g != 0 || color.b != 0 || color.a != 0) {
125 // Use a lambda do avoid writing the object header when the object is empty
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000126 perfetto::protos::ColorProto* colorProto = getColorProto();
Nataniel Borges797b0e42019-02-15 14:11:58 -0800127 colorProto->set_r(color.r);
128 colorProto->set_g(color.g);
129 colorProto->set_b(color.b);
130 colorProto->set_a(color.a);
131 }
chaviw1d044282017-09-27 12:19:28 -0700132}
133
chaviw0a398992021-08-13 10:13:01 -0500134void LayerProtoHelper::writeToProtoDeprecated(const ui::Transform& transform,
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000135 perfetto::protos::TransformProto* transformProto) {
Nataniel Borges84a46182019-02-26 15:36:32 -0800136 const uint32_t type = transform.getType() | (transform.getOrientation() << 8);
Nataniel Borges797b0e42019-02-15 14:11:58 -0800137 transformProto->set_type(type);
138
Nataniel Borges9a2433c2019-03-13 15:02:45 -0700139 // Rotations that are 90/180/270 have their own type so the transform matrix can be
140 // reconstructed later. All other rotation have the type UKNOWN so we need to save the transform
141 // values in that case.
Nataniel Borges84a46182019-02-26 15:36:32 -0800142 if (type & (ui::Transform::SCALE | ui::Transform::UNKNOWN)) {
Nataniel Borges797b0e42019-02-15 14:11:58 -0800143 transformProto->set_dsdx(transform[0][0]);
144 transformProto->set_dtdx(transform[0][1]);
145 transformProto->set_dsdy(transform[1][0]);
146 transformProto->set_dtdy(transform[1][1]);
147 }
chaviw1d044282017-09-27 12:19:28 -0700148}
149
chaviw0a398992021-08-13 10:13:01 -0500150void LayerProtoHelper::writeTransformToProto(const ui::Transform& transform,
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000151 perfetto::protos::TransformProto* transformProto) {
chaviw0a398992021-08-13 10:13:01 -0500152 const uint32_t type = transform.getType() | (transform.getOrientation() << 8);
153 transformProto->set_type(type);
154
155 // Rotations that are 90/180/270 have their own type so the transform matrix can be
156 // reconstructed later. All other rotation have the type UNKNOWN so we need to save the
157 // transform values in that case.
158 if (type & (ui::Transform::SCALE | ui::Transform::UNKNOWN)) {
159 transformProto->set_dsdx(transform.dsdx());
160 transformProto->set_dtdx(transform.dtdx());
161 transformProto->set_dtdy(transform.dtdy());
162 transformProto->set_dsdy(transform.dsdy());
163 }
164}
165
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000166void LayerProtoHelper::writeToProto(
167 const renderengine::ExternalTexture& buffer,
168 std::function<perfetto::protos::ActiveBufferProto*()> getActiveBufferProto) {
Vishnu Naird8f5e9f2022-02-03 10:23:28 -0800169 if (buffer.getWidth() != 0 || buffer.getHeight() != 0 || buffer.getUsage() != 0 ||
170 buffer.getPixelFormat() != 0) {
Nataniel Borges797b0e42019-02-15 14:11:58 -0800171 // Use a lambda do avoid writing the object header when the object is empty
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000172 auto* activeBufferProto = getActiveBufferProto();
Vishnu Naird8f5e9f2022-02-03 10:23:28 -0800173 activeBufferProto->set_width(buffer.getWidth());
174 activeBufferProto->set_height(buffer.getHeight());
175 activeBufferProto->set_stride(buffer.getUsage());
176 activeBufferProto->set_format(buffer.getPixelFormat());
Nataniel Borges797b0e42019-02-15 14:11:58 -0800177 }
chaviw1d044282017-09-27 12:19:28 -0700178}
179
Vishnu Nair9245d3b2019-03-22 13:38:56 -0700180void LayerProtoHelper::writeToProto(
chaviw98318de2021-05-19 16:45:23 -0500181 const WindowInfo& inputInfo, const wp<Layer>& touchableRegionBounds,
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000182 std::function<perfetto::protos::InputWindowInfoProto*()> getInputWindowInfoProto) {
Vishnu Nair9245d3b2019-03-22 13:38:56 -0700183 if (inputInfo.token == nullptr) {
184 return;
185 }
186
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000187 perfetto::protos::InputWindowInfoProto* proto = getInputWindowInfoProto();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800188 proto->set_layout_params_flags(inputInfo.layoutParamsFlags.get());
Siarhei Vishniakoue2eff112023-06-21 14:20:39 -0700189 proto->set_input_config(inputInfo.inputConfig.get());
chaviw98318de2021-05-19 16:45:23 -0500190 using U = std::underlying_type_t<WindowInfo::Type>;
Michael Wright44753b12020-07-08 13:48:11 +0100191 // TODO(b/129481165): This static assert can be safely removed once conversion warnings
192 // are re-enabled.
193 static_assert(std::is_same_v<U, int32_t>);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800194 proto->set_layout_params_type(static_cast<U>(inputInfo.layoutParamsType));
Vishnu Nair9245d3b2019-03-22 13:38:56 -0700195
Chavi Weingarten7f019192023-08-08 20:39:01 +0000196 LayerProtoHelper::writeToProto({inputInfo.frame.left, inputInfo.frame.top,
197 inputInfo.frame.right, inputInfo.frame.bottom},
Vishnu Nair9245d3b2019-03-22 13:38:56 -0700198 [&]() { return proto->mutable_frame(); });
199 LayerProtoHelper::writeToProto(inputInfo.touchableRegion,
200 [&]() { return proto->mutable_touchable_region(); });
201
202 proto->set_surface_inset(inputInfo.surfaceInset);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800203 using InputConfig = gui::WindowInfo::InputConfig;
204 proto->set_visible(!inputInfo.inputConfig.test(InputConfig::NOT_VISIBLE));
205 proto->set_focusable(!inputInfo.inputConfig.test(InputConfig::NOT_FOCUSABLE));
206 proto->set_has_wallpaper(inputInfo.inputConfig.test(InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER));
Vishnu Nair9245d3b2019-03-22 13:38:56 -0700207
208 proto->set_global_scale_factor(inputInfo.globalScaleFactor);
chaviw0a398992021-08-13 10:13:01 -0500209 LayerProtoHelper::writeToProtoDeprecated(inputInfo.transform, proto->mutable_transform());
Vishnu Nair9245d3b2019-03-22 13:38:56 -0700210 proto->set_replace_touchable_region_with_crop(inputInfo.replaceTouchableRegionWithCrop);
211 auto cropLayer = touchableRegionBounds.promote();
212 if (cropLayer != nullptr) {
213 proto->set_crop_layer_id(cropLayer->sequence);
214 LayerProtoHelper::writeToProto(cropLayer->getScreenBounds(
215 false /* reduceTransparentRegion */),
216 [&]() { return proto->mutable_touchable_region_crop(); });
217 }
218}
219
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000220void LayerProtoHelper::writeToProto(const mat4 matrix,
221 perfetto::protos::ColorTransformProto* colorTransformProto) {
chaviwddeae262020-01-06 10:31:23 -0800222 for (int i = 0; i < mat4::ROW_SIZE; i++) {
223 for (int j = 0; j < mat4::COL_SIZE; j++) {
224 colorTransformProto->add_val(matrix[i][j]);
225 }
226 }
227}
228
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000229void LayerProtoHelper::readFromProto(
230 const perfetto::protos::ColorTransformProto& colorTransformProto, mat4& matrix) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700231 for (int i = 0; i < mat4::ROW_SIZE; i++) {
232 for (int j = 0; j < mat4::COL_SIZE; j++) {
233 matrix[i][j] = colorTransformProto.val(i * mat4::COL_SIZE + j);
234 }
235 }
236}
237
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000238void LayerProtoHelper::writeToProto(const android::BlurRegion region,
239 perfetto::protos::BlurRegion* proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700240 proto->set_blur_radius(region.blurRadius);
241 proto->set_corner_radius_tl(region.cornerRadiusTL);
242 proto->set_corner_radius_tr(region.cornerRadiusTR);
243 proto->set_corner_radius_bl(region.cornerRadiusBL);
244 proto->set_corner_radius_br(region.cornerRadiusBR);
245 proto->set_alpha(region.alpha);
246 proto->set_left(region.left);
247 proto->set_top(region.top);
248 proto->set_right(region.right);
249 proto->set_bottom(region.bottom);
250}
251
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000252void LayerProtoHelper::readFromProto(const perfetto::protos::BlurRegion& proto,
253 android::BlurRegion& outRegion) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700254 outRegion.blurRadius = proto.blur_radius();
255 outRegion.cornerRadiusTL = proto.corner_radius_tl();
256 outRegion.cornerRadiusTR = proto.corner_radius_tr();
257 outRegion.cornerRadiusBL = proto.corner_radius_bl();
258 outRegion.cornerRadiusBR = proto.corner_radius_br();
259 outRegion.alpha = proto.alpha();
260 outRegion.left = proto.left();
261 outRegion.top = proto.top();
262 outRegion.right = proto.right();
263 outRegion.bottom = proto.bottom();
264}
Vishnu Nairea6ff812023-02-27 17:41:39 +0000265
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000266perfetto::protos::LayersProto LayerProtoFromSnapshotGenerator::generate(
267 const frontend::LayerHierarchy& root) {
Vishnu Naird0183602023-03-16 18:52:15 +0000268 mLayersProto.clear_layers();
269 std::unordered_set<uint64_t> stackIdsToSkip;
270 if ((mTraceFlags & LayerTracing::TRACE_VIRTUAL_DISPLAYS) == 0) {
271 for (const auto& [layerStack, displayInfo] : mDisplayInfos) {
272 if (displayInfo.isVirtual) {
273 stackIdsToSkip.insert(layerStack.id);
274 }
Vishnu Nair39872bc2023-03-11 12:48:31 -0800275 }
276 }
277
Vishnu Naird0183602023-03-16 18:52:15 +0000278 frontend::LayerHierarchy::TraversalPath path = frontend::LayerHierarchy::TraversalPath::ROOT;
279 for (auto& [child, variant] : root.mChildren) {
280 if (variant != frontend::LayerHierarchy::Variant::Attached ||
281 stackIdsToSkip.find(child->getLayer()->layerStack.id) != stackIdsToSkip.end()) {
282 continue;
283 }
284 frontend::LayerHierarchy::ScopedAddToTraversalPath addChildToPath(path,
285 child->getLayer()->id,
286 variant);
287 LayerProtoFromSnapshotGenerator::writeHierarchyToProto(*child, path);
Vishnu Naird19848f2023-03-15 18:24:28 +0000288 }
289
Vishnu Naird0183602023-03-16 18:52:15 +0000290 // fill in relative and parent info
291 for (int i = 0; i < mLayersProto.layers_size(); i++) {
292 auto layerProto = mLayersProto.mutable_layers()->Mutable(i);
293 auto it = mChildToRelativeParent.find(layerProto->id());
294 if (it == mChildToRelativeParent.end()) {
295 layerProto->set_z_order_relative_of(-1);
296 } else {
297 layerProto->set_z_order_relative_of(it->second);
298 }
299 it = mChildToParent.find(layerProto->id());
300 if (it == mChildToParent.end()) {
301 layerProto->set_parent(-1);
302 } else {
303 layerProto->set_parent(it->second);
304 }
Vishnu Naird19848f2023-03-15 18:24:28 +0000305 }
306
Vishnu Naird0183602023-03-16 18:52:15 +0000307 mDefaultSnapshots.clear();
308 mChildToRelativeParent.clear();
309 return std::move(mLayersProto);
310}
311
312frontend::LayerSnapshot* LayerProtoFromSnapshotGenerator::getSnapshot(
313 frontend::LayerHierarchy::TraversalPath& path, const frontend::RequestedLayerState& layer) {
314 frontend::LayerSnapshot* snapshot = mSnapshotBuilder.getSnapshot(path);
315 if (snapshot) {
316 return snapshot;
317 } else {
318 mDefaultSnapshots[path] = frontend::LayerSnapshot(layer, path);
319 return &mDefaultSnapshots[path];
320 }
321}
322
323void LayerProtoFromSnapshotGenerator::writeHierarchyToProto(
324 const frontend::LayerHierarchy& root, frontend::LayerHierarchy::TraversalPath& path) {
325 using Variant = frontend::LayerHierarchy::Variant;
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000326 perfetto::protos::LayerProto* layerProto = mLayersProto.add_layers();
Vishnu Naird0183602023-03-16 18:52:15 +0000327 const frontend::RequestedLayerState& layer = *root.getLayer();
328 frontend::LayerSnapshot* snapshot = getSnapshot(path, layer);
329 LayerProtoHelper::writeSnapshotToProto(layerProto, layer, *snapshot, mTraceFlags);
330
331 for (const auto& [child, variant] : root.mChildren) {
332 frontend::LayerHierarchy::ScopedAddToTraversalPath addChildToPath(path,
333 child->getLayer()->id,
334 variant);
335 frontend::LayerSnapshot* childSnapshot = getSnapshot(path, layer);
336 if (variant == Variant::Attached || variant == Variant::Detached ||
Vishnu Nair491827d2024-04-29 23:43:26 +0000337 frontend::LayerHierarchy::isMirror(variant)) {
Vishnu Naird0183602023-03-16 18:52:15 +0000338 mChildToParent[childSnapshot->uniqueSequence] = snapshot->uniqueSequence;
339 layerProto->add_children(childSnapshot->uniqueSequence);
340 } else if (variant == Variant::Relative) {
341 mChildToRelativeParent[childSnapshot->uniqueSequence] = snapshot->uniqueSequence;
342 layerProto->add_relatives(childSnapshot->uniqueSequence);
343 }
344 }
345
346 if (mTraceFlags & LayerTracing::TRACE_COMPOSITION) {
347 auto it = mLegacyLayers.find(layer.id);
348 if (it != mLegacyLayers.end()) {
Vishnu Nair2f65e972023-04-04 16:36:28 +0000349 it->second->writeCompositionStateToProto(layerProto, snapshot->outputFilter.layerStack);
Vishnu Nairea6ff812023-02-27 17:41:39 +0000350 }
351 }
352
353 for (const auto& [child, variant] : root.mChildren) {
354 // avoid visiting relative layers twice
355 if (variant == Variant::Detached) {
356 continue;
357 }
Vishnu Naird0183602023-03-16 18:52:15 +0000358 frontend::LayerHierarchy::ScopedAddToTraversalPath addChildToPath(path,
359 child->getLayer()->id,
360 variant);
361 writeHierarchyToProto(*child, path);
Vishnu Nairea6ff812023-02-27 17:41:39 +0000362 }
363}
364
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000365void LayerProtoHelper::writeSnapshotToProto(perfetto::protos::LayerProto* layerInfo,
Vishnu Nairea6ff812023-02-27 17:41:39 +0000366 const frontend::RequestedLayerState& requestedState,
367 const frontend::LayerSnapshot& snapshot,
368 uint32_t traceFlags) {
369 const ui::Transform transform = snapshot.geomLayerTransform;
370 auto buffer = requestedState.externalTexture;
371 if (buffer != nullptr) {
372 LayerProtoHelper::writeToProto(*buffer,
373 [&]() { return layerInfo->mutable_active_buffer(); });
374 LayerProtoHelper::writeToProtoDeprecated(ui::Transform(requestedState.bufferTransform),
375 layerInfo->mutable_buffer_transform());
376 }
377 layerInfo->set_invalidate(snapshot.contentDirty);
378 layerInfo->set_is_protected(snapshot.hasProtectedContent);
379 layerInfo->set_dataspace(dataspaceDetails(static_cast<android_dataspace>(snapshot.dataspace)));
380 layerInfo->set_curr_frame(requestedState.bufferData->frameNumber);
381 layerInfo->set_requested_corner_radius(requestedState.cornerRadius);
382 layerInfo->set_corner_radius(
383 (snapshot.roundedCorner.radius.x + snapshot.roundedCorner.radius.y) / 2.0);
384 layerInfo->set_background_blur_radius(snapshot.backgroundBlurRadius);
385 layerInfo->set_is_trusted_overlay(snapshot.isTrustedOverlay);
386 LayerProtoHelper::writeToProtoDeprecated(transform, layerInfo->mutable_transform());
387 LayerProtoHelper::writePositionToProto(transform.tx(), transform.ty(),
388 [&]() { return layerInfo->mutable_position(); });
389 LayerProtoHelper::writeToProto(snapshot.geomLayerBounds,
390 [&]() { return layerInfo->mutable_bounds(); });
391 LayerProtoHelper::writeToProto(snapshot.surfaceDamage,
392 [&]() { return layerInfo->mutable_damage_region(); });
393
394 if (requestedState.hasColorTransform) {
395 LayerProtoHelper::writeToProto(snapshot.colorTransform,
396 layerInfo->mutable_color_transform());
397 }
398
399 LayerProtoHelper::writeToProto(snapshot.croppedBufferSize.toFloatRect(),
400 [&]() { return layerInfo->mutable_source_bounds(); });
401 LayerProtoHelper::writeToProto(snapshot.transformedBounds,
402 [&]() { return layerInfo->mutable_screen_bounds(); });
403 LayerProtoHelper::writeToProto(snapshot.roundedCorner.cropRect,
404 [&]() { return layerInfo->mutable_corner_radius_crop(); });
Vishnu Naird9e4f462023-10-06 04:05:45 +0000405 layerInfo->set_shadow_radius(snapshot.shadowSettings.length);
Vishnu Nairea6ff812023-02-27 17:41:39 +0000406
Vishnu Nair93b8b792023-02-27 19:40:24 +0000407 layerInfo->set_id(snapshot.uniqueSequence);
Vishnu Naird0183602023-03-16 18:52:15 +0000408 layerInfo->set_original_id(snapshot.sequence);
Vishnu Nair150065b2023-04-17 19:14:11 -0700409 if (!snapshot.path.isClone()) {
410 layerInfo->set_name(requestedState.name);
411 } else {
412 layerInfo->set_name(requestedState.name + "(Mirror)");
413 }
Vishnu Nairea6ff812023-02-27 17:41:39 +0000414 layerInfo->set_type("Layer");
415
416 LayerProtoHelper::writeToProto(requestedState.transparentRegion,
417 [&]() { return layerInfo->mutable_transparent_region(); });
418
419 layerInfo->set_layer_stack(snapshot.outputFilter.layerStack.id);
420 layerInfo->set_z(requestedState.z);
421
422 ui::Transform requestedTransform = requestedState.getTransform(0);
423 LayerProtoHelper::writePositionToProto(requestedTransform.tx(), requestedTransform.ty(), [&]() {
424 return layerInfo->mutable_requested_position();
425 });
426
427 LayerProtoHelper::writeToProto(requestedState.crop,
428 [&]() { return layerInfo->mutable_crop(); });
429
430 layerInfo->set_is_opaque(snapshot.contentOpaque);
431 if (requestedState.externalTexture)
432 layerInfo->set_pixel_format(
433 decodePixelFormat(requestedState.externalTexture->getPixelFormat()));
434 LayerProtoHelper::writeToProto(snapshot.color, [&]() { return layerInfo->mutable_color(); });
435 LayerProtoHelper::writeToProto(requestedState.color,
436 [&]() { return layerInfo->mutable_requested_color(); });
437 layerInfo->set_flags(requestedState.flags);
438
439 LayerProtoHelper::writeToProtoDeprecated(requestedTransform,
440 layerInfo->mutable_requested_transform());
441
442 layerInfo->set_is_relative_of(requestedState.isRelativeOf);
443
Vishnu Naira02943f2023-06-03 13:44:46 -0700444 layerInfo->set_owner_uid(requestedState.ownerUid.val());
Vishnu Nairea6ff812023-02-27 17:41:39 +0000445
446 if ((traceFlags & LayerTracing::TRACE_INPUT) && snapshot.hasInputInfo()) {
447 LayerProtoHelper::writeToProto(snapshot.inputInfo, {},
448 [&]() { return layerInfo->mutable_input_window_info(); });
449 }
450
451 if (traceFlags & LayerTracing::TRACE_EXTRA) {
452 auto protoMap = layerInfo->mutable_metadata();
453 for (const auto& entry : requestedState.metadata.mMap) {
454 (*protoMap)[entry.first] = std::string(entry.second.cbegin(), entry.second.cend());
455 }
456 }
457
458 LayerProtoHelper::writeToProto(requestedState.destinationFrame,
459 [&]() { return layerInfo->mutable_destination_frame(); });
460}
461
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000462google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto>
463LayerProtoHelper::writeDisplayInfoToProto(const frontend::DisplayInfos& displayInfos) {
464 google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays;
Vishnu Nair81750622023-03-08 15:02:06 -0800465 displays.Reserve(displayInfos.size());
466 for (const auto& [layerStack, displayInfo] : displayInfos) {
467 auto displayProto = displays.Add();
468 displayProto->set_id(displayInfo.info.displayId);
469 displayProto->set_layer_stack(layerStack.id);
470 displayProto->mutable_size()->set_w(displayInfo.info.logicalWidth);
471 displayProto->mutable_size()->set_h(displayInfo.info.logicalHeight);
472 writeTransformToProto(displayInfo.transform, displayProto->mutable_transform());
473 displayProto->set_is_virtual(displayInfo.isVirtual);
474 }
475 return displays;
476}
477
chaviw1d044282017-09-27 12:19:28 -0700478} // namespace surfaceflinger
479} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800480
481// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +0100482#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"