blob: b5ae1a7f5a1d9ef5e0ff7a5c7f799e8f42ed2a71 [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 Nair39872bc2023-03-11 12:48:31 -080018#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
32void 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
42void 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
52void LayerProtoHelper::writeToProto(const Region& region,
53 std::function<RegionProto*()> getRegionProto) {
54 if (region.isEmpty()) {
55 return;
56 }
57
Vishnu Nair6b591152021-10-08 11:45:14 -070058 writeToProto(region, getRegionProto());
59}
60
61void LayerProtoHelper::writeToProto(const Region& region, RegionProto* regionProto) {
62 if (region.isEmpty()) {
63 return;
64 }
65
chaviw1d044282017-09-27 12:19:28 -070066 Region::const_iterator head = region.begin();
67 Region::const_iterator const tail = region.end();
Nataniel Borges797b0e42019-02-15 14:11:58 -080068 // Use a lambda do avoid writing the object header when the object is empty
chaviw1d044282017-09-27 12:19:28 -070069 while (head != tail) {
Vishnu Nair6b591152021-10-08 11:45:14 -070070 writeToProto(*head, regionProto->add_rect());
chaviw1d044282017-09-27 12:19:28 -070071 head++;
72 }
73}
74
Vishnu Nair6b591152021-10-08 11:45:14 -070075void 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 Borges797b0e42019-02-15 14:11:58 -080083void 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 Nair6b591152021-10-08 11:45:14 -070086 writeToProto(rect, getRectProto());
Nataniel Borges797b0e42019-02-15 14:11:58 -080087 }
chaviw1d044282017-09-27 12:19:28 -070088}
89
Vishnu Nair6b591152021-10-08 11:45:14 -070090void 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
97void 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 Borges797b0e42019-02-15 14:11:58 -0800104void 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 Zhang7124ad32018-02-21 13:02:45 -0800114}
115
Nataniel Borges797b0e42019-02-15 14:11:58 -0800116void 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 }
chaviw1d044282017-09-27 12:19:28 -0700125}
126
chaviw0a398992021-08-13 10:13:01 -0500127void LayerProtoHelper::writeToProtoDeprecated(const ui::Transform& transform,
128 TransformProto* transformProto) {
Nataniel Borges84a46182019-02-26 15:36:32 -0800129 const uint32_t type = transform.getType() | (transform.getOrientation() << 8);
Nataniel Borges797b0e42019-02-15 14:11:58 -0800130 transformProto->set_type(type);
131
Nataniel Borges9a2433c2019-03-13 15:02:45 -0700132 // 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 Borges84a46182019-02-26 15:36:32 -0800135 if (type & (ui::Transform::SCALE | ui::Transform::UNKNOWN)) {
Nataniel Borges797b0e42019-02-15 14:11:58 -0800136 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 }
chaviw1d044282017-09-27 12:19:28 -0700141}
142
chaviw0a398992021-08-13 10:13:01 -0500143void 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 Naird37343b2022-01-12 16:18:56 -0800159void LayerProtoHelper::writeToProto(const renderengine::ExternalTexture& buffer,
Nataniel Borges797b0e42019-02-15 14:11:58 -0800160 std::function<ActiveBufferProto*()> getActiveBufferProto) {
Vishnu Naird8f5e9f2022-02-03 10:23:28 -0800161 if (buffer.getWidth() != 0 || buffer.getHeight() != 0 || buffer.getUsage() != 0 ||
162 buffer.getPixelFormat() != 0) {
Nataniel Borges797b0e42019-02-15 14:11:58 -0800163 // Use a lambda do avoid writing the object header when the object is empty
164 ActiveBufferProto* activeBufferProto = getActiveBufferProto();
Vishnu Naird8f5e9f2022-02-03 10:23:28 -0800165 activeBufferProto->set_width(buffer.getWidth());
166 activeBufferProto->set_height(buffer.getHeight());
167 activeBufferProto->set_stride(buffer.getUsage());
168 activeBufferProto->set_format(buffer.getPixelFormat());
Nataniel Borges797b0e42019-02-15 14:11:58 -0800169 }
chaviw1d044282017-09-27 12:19:28 -0700170}
171
Vishnu Nair9245d3b2019-03-22 13:38:56 -0700172void LayerProtoHelper::writeToProto(
chaviw98318de2021-05-19 16:45:23 -0500173 const WindowInfo& inputInfo, const wp<Layer>& touchableRegionBounds,
Vishnu Nair9245d3b2019-03-22 13:38:56 -0700174 std::function<InputWindowInfoProto*()> getInputWindowInfoProto) {
175 if (inputInfo.token == nullptr) {
176 return;
177 }
178
179 InputWindowInfoProto* proto = getInputWindowInfoProto();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800180 proto->set_layout_params_flags(inputInfo.layoutParamsFlags.get());
chaviw98318de2021-05-19 16:45:23 -0500181 using U = std::underlying_type_t<WindowInfo::Type>;
Michael Wright44753b12020-07-08 13:48:11 +0100182 // 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 Pradhan4d5c52f2022-01-31 08:52:10 -0800185 proto->set_layout_params_type(static_cast<U>(inputInfo.layoutParamsType));
Vishnu Nair9245d3b2019-03-22 13:38:56 -0700186
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 Pradhan4d5c52f2022-01-31 08:52:10 -0800194 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 Nair9245d3b2019-03-22 13:38:56 -0700198
199 proto->set_global_scale_factor(inputInfo.globalScaleFactor);
chaviw0a398992021-08-13 10:13:01 -0500200 LayerProtoHelper::writeToProtoDeprecated(inputInfo.transform, proto->mutable_transform());
Vishnu Nair9245d3b2019-03-22 13:38:56 -0700201 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
chaviwddeae262020-01-06 10:31:23 -0800211void 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 Nair6b591152021-10-08 11:45:14 -0700219void 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
227void 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
240void 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 Nairea6ff812023-02-27 17:41:39 +0000252
Vishnu Nair39872bc2023-03-11 12:48:31 -0800253LayersProto 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 Nairea6ff812023-02-27 17:41:39 +0000261 }
262 }
263
Vishnu Nair39872bc2023-03-11 12:48:31 -0800264 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 Nairea6ff812023-02-27 17:41:39 +0000274 }
275
Vishnu Nair39872bc2023-03-11 12:48:31 -0800276 // 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 Nairea6ff812023-02-27 17:41:39 +0000291 }
292
Vishnu Nair39872bc2023-03-11 12:48:31 -0800293 mDefaultSnapshots.clear();
294 mChildToRelativeParent.clear();
295 return std::move(mLayersProto);
296}
297
298frontend::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
309void 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 Nairea6ff812023-02-27 17:41:39 +0000335 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 Nair39872bc2023-03-11 12:48:31 -0800344 frontend::LayerHierarchy::ScopedAddToTraversalPath addChildToPath(path,
345 child->getLayer()->id,
346 variant);
347 writeHierarchyToProto(*child, path);
Vishnu Nairea6ff812023-02-27 17:41:39 +0000348 }
349}
350
351void 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 Nair93b8b792023-02-27 19:40:24 +0000393 layerInfo->set_id(snapshot.uniqueSequence);
Vishnu Nair39872bc2023-03-11 12:48:31 -0800394 layerInfo->set_original_id(snapshot.sequence);
Vishnu Nairea6ff812023-02-27 17:41:39 +0000395 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 Nair81750622023-03-08 15:02:06 -0800444google::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
chaviw1d044282017-09-27 12:19:28 -0700460} // namespace surfaceflinger
461} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800462
463// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +0100464#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"