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 
17 // TODO(b/129481165): remove the #pragma below and fix conversion issues
18 #include "FrontEnd/LayerCreationArgs.h"
19 #include "FrontEnd/LayerSnapshot.h"
20 #pragma clang diagnostic push
21 #pragma clang diagnostic ignored "-Wconversion"
22 #pragma clang diagnostic ignored "-Wextra"
23 
24 #include "LayerProtoHelper.h"
25 
26 namespace android {
27 
28 using gui::WindowInfo;
29 
30 namespace surfaceflinger {
31 
writePositionToProto(const float x,const float y,std::function<perfetto::protos::PositionProto * ()> getPositionProto)32 void LayerProtoHelper::writePositionToProto(
33         const float x, const float y,
34         std::function<perfetto::protos::PositionProto*()> getPositionProto) {
35     if (x != 0 || y != 0) {
36         // Use a lambda do avoid writing the object header when the object is empty
37         perfetto::protos::PositionProto* position = getPositionProto();
38         position->set_x(x);
39         position->set_y(y);
40     }
41 }
42 
writeSizeToProto(const uint32_t w,const uint32_t h,std::function<perfetto::protos::SizeProto * ()> getSizeProto)43 void LayerProtoHelper::writeSizeToProto(
44         const uint32_t w, const uint32_t h,
45         std::function<perfetto::protos::SizeProto*()> getSizeProto) {
46     if (w != 0 || h != 0) {
47         // Use a lambda do avoid writing the object header when the object is empty
48         perfetto::protos::SizeProto* size = getSizeProto();
49         size->set_w(w);
50         size->set_h(h);
51     }
52 }
53 
writeToProto(const Region & region,std::function<perfetto::protos::RegionProto * ()> getRegionProto)54 void LayerProtoHelper::writeToProto(
55         const Region& region, std::function<perfetto::protos::RegionProto*()> getRegionProto) {
56     if (region.isEmpty()) {
57         return;
58     }
59 
60     writeToProto(region, getRegionProto());
61 }
62 
writeToProto(const Region & region,perfetto::protos::RegionProto * regionProto)63 void LayerProtoHelper::writeToProto(const Region& region,
64                                     perfetto::protos::RegionProto* regionProto) {
65     if (region.isEmpty()) {
66         return;
67     }
68 
69     Region::const_iterator head = region.begin();
70     Region::const_iterator const tail = region.end();
71     // Use a lambda do avoid writing the object header when the object is empty
72     while (head != tail) {
73         writeToProto(*head, regionProto->add_rect());
74         head++;
75     }
76 }
77 
readFromProto(const perfetto::protos::RegionProto & regionProto,Region & outRegion)78 void LayerProtoHelper::readFromProto(const perfetto::protos::RegionProto& regionProto,
79                                      Region& outRegion) {
80     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 
writeToProto(const Rect & rect,std::function<perfetto::protos::RectProto * ()> getRectProto)87 void LayerProtoHelper::writeToProto(const Rect& rect,
88                                     std::function<perfetto::protos::RectProto*()> getRectProto) {
89     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
91         writeToProto(rect, getRectProto());
92     }
93 }
94 
writeToProto(const Rect & rect,perfetto::protos::RectProto * rectProto)95 void LayerProtoHelper::writeToProto(const Rect& rect, perfetto::protos::RectProto* rectProto) {
96     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 
readFromProto(const perfetto::protos::RectProto & proto,Rect & outRect)102 void LayerProtoHelper::readFromProto(const perfetto::protos::RectProto& proto, Rect& outRect) {
103     outRect.left = proto.left();
104     outRect.top = proto.top();
105     outRect.bottom = proto.bottom();
106     outRect.right = proto.right();
107 }
108 
writeToProto(const FloatRect & rect,std::function<perfetto::protos::FloatRectProto * ()> getFloatRectProto)109 void LayerProtoHelper::writeToProto(
110         const FloatRect& rect,
111         std::function<perfetto::protos::FloatRectProto*()> getFloatRectProto) {
112     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
114         perfetto::protos::FloatRectProto* rectProto = getFloatRectProto();
115         rectProto->set_left(rect.left);
116         rectProto->set_top(rect.top);
117         rectProto->set_bottom(rect.bottom);
118         rectProto->set_right(rect.right);
119     }
120 }
121 
writeToProto(const half4 color,std::function<perfetto::protos::ColorProto * ()> getColorProto)122 void LayerProtoHelper::writeToProto(const half4 color,
123                                     std::function<perfetto::protos::ColorProto*()> getColorProto) {
124     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
126         perfetto::protos::ColorProto* colorProto = getColorProto();
127         colorProto->set_r(color.r);
128         colorProto->set_g(color.g);
129         colorProto->set_b(color.b);
130         colorProto->set_a(color.a);
131     }
132 }
133 
writeToProtoDeprecated(const ui::Transform & transform,perfetto::protos::TransformProto * transformProto)134 void LayerProtoHelper::writeToProtoDeprecated(const ui::Transform& transform,
135                                               perfetto::protos::TransformProto* transformProto) {
136     const uint32_t type = transform.getType() | (transform.getOrientation() << 8);
137     transformProto->set_type(type);
138 
139     // 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.
142     if (type & (ui::Transform::SCALE | ui::Transform::UNKNOWN)) {
143         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     }
148 }
149 
writeTransformToProto(const ui::Transform & transform,perfetto::protos::TransformProto * transformProto)150 void LayerProtoHelper::writeTransformToProto(const ui::Transform& transform,
151                                              perfetto::protos::TransformProto* transformProto) {
152     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 
writeToProto(const renderengine::ExternalTexture & buffer,std::function<perfetto::protos::ActiveBufferProto * ()> getActiveBufferProto)166 void LayerProtoHelper::writeToProto(
167         const renderengine::ExternalTexture& buffer,
168         std::function<perfetto::protos::ActiveBufferProto*()> getActiveBufferProto) {
169     if (buffer.getWidth() != 0 || buffer.getHeight() != 0 || buffer.getUsage() != 0 ||
170         buffer.getPixelFormat() != 0) {
171         // Use a lambda do avoid writing the object header when the object is empty
172         auto* activeBufferProto = getActiveBufferProto();
173         activeBufferProto->set_width(buffer.getWidth());
174         activeBufferProto->set_height(buffer.getHeight());
175         activeBufferProto->set_stride(buffer.getUsage());
176         activeBufferProto->set_format(buffer.getPixelFormat());
177     }
178 }
179 
writeToProto(const WindowInfo & inputInfo,const wp<Layer> & touchableRegionBounds,std::function<perfetto::protos::InputWindowInfoProto * ()> getInputWindowInfoProto)180 void LayerProtoHelper::writeToProto(
181         const WindowInfo& inputInfo, const wp<Layer>& touchableRegionBounds,
182         std::function<perfetto::protos::InputWindowInfoProto*()> getInputWindowInfoProto) {
183     if (inputInfo.token == nullptr) {
184         return;
185     }
186 
187     perfetto::protos::InputWindowInfoProto* proto = getInputWindowInfoProto();
188     proto->set_layout_params_flags(inputInfo.layoutParamsFlags.get());
189     proto->set_input_config(inputInfo.inputConfig.get());
190     using U = std::underlying_type_t<WindowInfo::Type>;
191     // 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>);
194     proto->set_layout_params_type(static_cast<U>(inputInfo.layoutParamsType));
195 
196     LayerProtoHelper::writeToProto({inputInfo.frame.left, inputInfo.frame.top,
197                                     inputInfo.frame.right, inputInfo.frame.bottom},
198                                    [&]() { return proto->mutable_frame(); });
199     LayerProtoHelper::writeToProto(inputInfo.touchableRegion,
200                                    [&]() { return proto->mutable_touchable_region(); });
201 
202     proto->set_surface_inset(inputInfo.surfaceInset);
203     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));
207 
208     proto->set_global_scale_factor(inputInfo.globalScaleFactor);
209     LayerProtoHelper::writeToProtoDeprecated(inputInfo.transform, proto->mutable_transform());
210     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 
writeToProto(const mat4 matrix,perfetto::protos::ColorTransformProto * colorTransformProto)220 void LayerProtoHelper::writeToProto(const mat4 matrix,
221                                     perfetto::protos::ColorTransformProto* colorTransformProto) {
222     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 
readFromProto(const perfetto::protos::ColorTransformProto & colorTransformProto,mat4 & matrix)229 void LayerProtoHelper::readFromProto(
230         const perfetto::protos::ColorTransformProto& colorTransformProto, mat4& matrix) {
231     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 
writeToProto(const android::BlurRegion region,perfetto::protos::BlurRegion * proto)238 void LayerProtoHelper::writeToProto(const android::BlurRegion region,
239                                     perfetto::protos::BlurRegion* proto) {
240     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 
readFromProto(const perfetto::protos::BlurRegion & proto,android::BlurRegion & outRegion)252 void LayerProtoHelper::readFromProto(const perfetto::protos::BlurRegion& proto,
253                                      android::BlurRegion& outRegion) {
254     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 }
265 
generate(const frontend::LayerHierarchy & root)266 perfetto::protos::LayersProto LayerProtoFromSnapshotGenerator::generate(
267         const frontend::LayerHierarchy& root) {
268     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             }
275         }
276     }
277 
278     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);
288     }
289 
290     // 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         }
305     }
306 
307     mDefaultSnapshots.clear();
308     mChildToRelativeParent.clear();
309     return std::move(mLayersProto);
310 }
311 
getSnapshot(frontend::LayerHierarchy::TraversalPath & path,const frontend::RequestedLayerState & layer)312 frontend::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 
writeHierarchyToProto(const frontend::LayerHierarchy & root,frontend::LayerHierarchy::TraversalPath & path)323 void LayerProtoFromSnapshotGenerator::writeHierarchyToProto(
324         const frontend::LayerHierarchy& root, frontend::LayerHierarchy::TraversalPath& path) {
325     using Variant = frontend::LayerHierarchy::Variant;
326     perfetto::protos::LayerProto* layerProto = mLayersProto.add_layers();
327     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 ||
337             frontend::LayerHierarchy::isMirror(variant)) {
338             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()) {
349             it->second->writeCompositionStateToProto(layerProto, snapshot->outputFilter.layerStack);
350         }
351     }
352 
353     for (const auto& [child, variant] : root.mChildren) {
354         // avoid visiting relative layers twice
355         if (variant == Variant::Detached) {
356             continue;
357         }
358         frontend::LayerHierarchy::ScopedAddToTraversalPath addChildToPath(path,
359                                                                           child->getLayer()->id,
360                                                                           variant);
361         writeHierarchyToProto(*child, path);
362     }
363 }
364 
writeSnapshotToProto(perfetto::protos::LayerProto * layerInfo,const frontend::RequestedLayerState & requestedState,const frontend::LayerSnapshot & snapshot,uint32_t traceFlags)365 void LayerProtoHelper::writeSnapshotToProto(perfetto::protos::LayerProto* layerInfo,
366                                             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.trustedOverlay == gui::TrustedOverlay::ENABLED);
386     // TODO(b/339701674) update protos
387     LayerProtoHelper::writeToProtoDeprecated(transform, layerInfo->mutable_transform());
388     LayerProtoHelper::writePositionToProto(transform.tx(), transform.ty(),
389                                            [&]() { return layerInfo->mutable_position(); });
390     LayerProtoHelper::writeToProto(snapshot.geomLayerBounds,
391                                    [&]() { return layerInfo->mutable_bounds(); });
392     LayerProtoHelper::writeToProto(snapshot.surfaceDamage,
393                                    [&]() { return layerInfo->mutable_damage_region(); });
394 
395     if (requestedState.hasColorTransform) {
396         LayerProtoHelper::writeToProto(snapshot.colorTransform,
397                                        layerInfo->mutable_color_transform());
398     }
399 
400     LayerProtoHelper::writeToProto(snapshot.croppedBufferSize.toFloatRect(),
401                                    [&]() { return layerInfo->mutable_source_bounds(); });
402     LayerProtoHelper::writeToProto(snapshot.transformedBounds,
403                                    [&]() { return layerInfo->mutable_screen_bounds(); });
404     LayerProtoHelper::writeToProto(snapshot.roundedCorner.cropRect,
405                                    [&]() { return layerInfo->mutable_corner_radius_crop(); });
406     layerInfo->set_shadow_radius(snapshot.shadowSettings.length);
407 
408     layerInfo->set_id(snapshot.uniqueSequence);
409     layerInfo->set_original_id(snapshot.sequence);
410     if (!snapshot.path.isClone()) {
411         layerInfo->set_name(requestedState.name);
412     } else {
413         layerInfo->set_name(requestedState.name + "(Mirror)");
414     }
415     layerInfo->set_type("Layer");
416 
417     LayerProtoHelper::writeToProto(requestedState.transparentRegion,
418                                    [&]() { return layerInfo->mutable_transparent_region(); });
419 
420     layerInfo->set_layer_stack(snapshot.outputFilter.layerStack.id);
421     layerInfo->set_z(requestedState.z);
422 
423     ui::Transform requestedTransform = requestedState.getTransform(0);
424     LayerProtoHelper::writePositionToProto(requestedTransform.tx(), requestedTransform.ty(), [&]() {
425         return layerInfo->mutable_requested_position();
426     });
427 
428     LayerProtoHelper::writeToProto(requestedState.crop,
429                                    [&]() { return layerInfo->mutable_crop(); });
430 
431     layerInfo->set_is_opaque(snapshot.contentOpaque);
432     if (requestedState.externalTexture)
433         layerInfo->set_pixel_format(
434                 decodePixelFormat(requestedState.externalTexture->getPixelFormat()));
435     LayerProtoHelper::writeToProto(snapshot.color, [&]() { return layerInfo->mutable_color(); });
436     LayerProtoHelper::writeToProto(requestedState.color,
437                                    [&]() { return layerInfo->mutable_requested_color(); });
438     layerInfo->set_flags(requestedState.flags);
439 
440     LayerProtoHelper::writeToProtoDeprecated(requestedTransform,
441                                              layerInfo->mutable_requested_transform());
442 
443     layerInfo->set_is_relative_of(requestedState.isRelativeOf);
444 
445     layerInfo->set_owner_uid(requestedState.ownerUid.val());
446 
447     if ((traceFlags & LayerTracing::TRACE_INPUT) && snapshot.hasInputInfo()) {
448         LayerProtoHelper::writeToProto(snapshot.inputInfo, {},
449                                        [&]() { return layerInfo->mutable_input_window_info(); });
450     }
451 
452     if (traceFlags & LayerTracing::TRACE_EXTRA) {
453         auto protoMap = layerInfo->mutable_metadata();
454         for (const auto& entry : requestedState.metadata.mMap) {
455             (*protoMap)[entry.first] = std::string(entry.second.cbegin(), entry.second.cend());
456         }
457     }
458 
459     LayerProtoHelper::writeToProto(requestedState.destinationFrame,
460                                    [&]() { return layerInfo->mutable_destination_frame(); });
461 }
462 
463 google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto>
writeDisplayInfoToProto(const frontend::DisplayInfos & displayInfos)464 LayerProtoHelper::writeDisplayInfoToProto(const frontend::DisplayInfos& displayInfos) {
465     google::protobuf::RepeatedPtrField<perfetto::protos::DisplayProto> displays;
466     displays.Reserve(displayInfos.size());
467     for (const auto& [layerStack, displayInfo] : displayInfos) {
468         auto displayProto = displays.Add();
469         displayProto->set_id(displayInfo.info.displayId.val());
470         displayProto->set_layer_stack(layerStack.id);
471         displayProto->mutable_size()->set_w(displayInfo.info.logicalWidth);
472         displayProto->mutable_size()->set_h(displayInfo.info.logicalHeight);
473         writeTransformToProto(displayInfo.transform, displayProto->mutable_transform());
474         displayProto->set_is_virtual(displayInfo.isVirtual);
475     }
476     return displays;
477 }
478 
479 } // namespace surfaceflinger
480 } // namespace android
481 
482 // TODO(b/129481165): remove the #pragma below and fix conversion issues
483 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
484