1 /*
2 * Copyright (C) 2021 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 #include <gui/SurfaceComposerClient.h>
18 #include <ui/Fence.h>
19 #include <ui/Rect.h>
20
21 #include "FrontEnd/LayerCreationArgs.h"
22 #include "LayerProtoHelper.h"
23 #include "TransactionProtoParser.h"
24 #include "TransactionState.h"
25 #include "gui/LayerState.h"
26
27 namespace android::surfaceflinger {
28
29 class FakeExternalTexture : public renderengine::ExternalTexture {
30 const sp<GraphicBuffer> mEmptyBuffer = nullptr;
31 uint32_t mWidth;
32 uint32_t mHeight;
33 uint64_t mId;
34 PixelFormat mPixelFormat;
35 uint64_t mUsage;
36
37 public:
FakeExternalTexture(uint32_t width,uint32_t height,uint64_t id,PixelFormat pixelFormat,uint64_t usage)38 FakeExternalTexture(uint32_t width, uint32_t height, uint64_t id, PixelFormat pixelFormat,
39 uint64_t usage)
40 : mWidth(width), mHeight(height), mId(id), mPixelFormat(pixelFormat), mUsage(usage) {}
getBuffer() const41 const sp<GraphicBuffer>& getBuffer() const { return mEmptyBuffer; }
hasSameBuffer(const renderengine::ExternalTexture & other) const42 bool hasSameBuffer(const renderengine::ExternalTexture& other) const override {
43 return getId() == other.getId();
44 }
getWidth() const45 uint32_t getWidth() const override { return mWidth; }
getHeight() const46 uint32_t getHeight() const override { return mHeight; }
getId() const47 uint64_t getId() const override { return mId; }
getPixelFormat() const48 PixelFormat getPixelFormat() const override { return mPixelFormat; }
getUsage() const49 uint64_t getUsage() const override { return mUsage; }
remapBuffer()50 void remapBuffer() override {}
51 ~FakeExternalTexture() = default;
52 };
53
toProto(const TransactionState & t)54 proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t) {
55 proto::TransactionState proto;
56 proto.set_pid(t.originPid);
57 proto.set_uid(t.originUid);
58 proto.set_vsync_id(t.frameTimelineInfo.vsyncId);
59 proto.set_input_event_id(t.frameTimelineInfo.inputEventId);
60 proto.set_post_time(t.postTime);
61 proto.set_transaction_id(t.id);
62
63 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(t.states.size()));
64 for (auto& layerState : t.states) {
65 proto.mutable_layer_changes()->Add(std::move(toProto(layerState)));
66 }
67
68 proto.mutable_display_changes()->Reserve(static_cast<int32_t>(t.displays.size()));
69 for (auto& displayState : t.displays) {
70 proto.mutable_display_changes()->Add(std::move(toProto(displayState)));
71 }
72
73 proto.mutable_merged_transaction_ids()->Reserve(
74 static_cast<int32_t>(t.mergedTransactionIds.size()));
75 for (auto& mergedTransactionId : t.mergedTransactionIds) {
76 proto.mutable_merged_transaction_ids()->Add(mergedTransactionId);
77 }
78
79 return proto;
80 }
81
toProto(const std::map<uint32_t,TracingLayerState> & states)82 proto::TransactionState TransactionProtoParser::toProto(
83 const std::map<uint32_t /* layerId */, TracingLayerState>& states) {
84 proto::TransactionState proto;
85 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(states.size()));
86 for (auto& [layerId, state] : states) {
87 proto::LayerState layerProto = toProto(state);
88 layerProto.set_has_sideband_stream(state.hasSidebandStream);
89 proto.mutable_layer_changes()->Add(std::move(layerProto));
90 }
91 return proto;
92 }
93
toProto(const ResolvedComposerState & resolvedComposerState)94 proto::LayerState TransactionProtoParser::toProto(
95 const ResolvedComposerState& resolvedComposerState) {
96 proto::LayerState proto;
97 auto& layer = resolvedComposerState.state;
98 proto.set_layer_id(resolvedComposerState.layerId);
99 proto.set_what(layer.what);
100
101 if (layer.what & layer_state_t::ePositionChanged) {
102 proto.set_x(layer.x);
103 proto.set_y(layer.y);
104 }
105 if (layer.what & layer_state_t::eLayerChanged) {
106 proto.set_z(layer.z);
107 }
108
109 if (layer.what & layer_state_t::eLayerStackChanged) {
110 proto.set_layer_stack(layer.layerStack.id);
111 }
112 if (layer.what & layer_state_t::eFlagsChanged) {
113 proto.set_flags(layer.flags);
114 proto.set_mask(layer.mask);
115 }
116 if (layer.what & layer_state_t::eMatrixChanged) {
117 proto::LayerState_Matrix22* matrixProto = proto.mutable_matrix();
118 matrixProto->set_dsdx(layer.matrix.dsdx);
119 matrixProto->set_dsdy(layer.matrix.dsdy);
120 matrixProto->set_dtdx(layer.matrix.dtdx);
121 matrixProto->set_dtdy(layer.matrix.dtdy);
122 }
123 if (layer.what & layer_state_t::eCornerRadiusChanged) {
124 proto.set_corner_radius(layer.cornerRadius);
125 }
126 if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) {
127 proto.set_background_blur_radius(layer.backgroundBlurRadius);
128 }
129
130 if (layer.what & layer_state_t::eAlphaChanged) {
131 proto.set_alpha(layer.color.a);
132 }
133
134 if (layer.what & layer_state_t::eColorChanged) {
135 proto::LayerState_Color3* colorProto = proto.mutable_color();
136 colorProto->set_r(layer.color.r);
137 colorProto->set_g(layer.color.g);
138 colorProto->set_b(layer.color.b);
139 }
140 if (layer.what & layer_state_t::eTransparentRegionChanged) {
141 LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region());
142 }
143 if (layer.what & layer_state_t::eBufferTransformChanged) {
144 proto.set_transform(layer.bufferTransform);
145 }
146 if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
147 proto.set_transform_to_display_inverse(layer.transformToDisplayInverse);
148 }
149 if (layer.what & layer_state_t::eCropChanged) {
150 LayerProtoHelper::writeToProto(layer.crop, proto.mutable_crop());
151 }
152 if (layer.what & layer_state_t::eBufferChanged) {
153 proto::LayerState_BufferData* bufferProto = proto.mutable_buffer_data();
154 if (resolvedComposerState.externalTexture) {
155 bufferProto->set_buffer_id(resolvedComposerState.externalTexture->getId());
156 bufferProto->set_width(resolvedComposerState.externalTexture->getWidth());
157 bufferProto->set_height(resolvedComposerState.externalTexture->getHeight());
158 bufferProto->set_pixel_format(static_cast<proto::LayerState_BufferData_PixelFormat>(
159 resolvedComposerState.externalTexture->getPixelFormat()));
160 bufferProto->set_usage(resolvedComposerState.externalTexture->getUsage());
161 }
162 bufferProto->set_frame_number(layer.bufferData->frameNumber);
163 bufferProto->set_flags(layer.bufferData->flags.get());
164 bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id);
165 }
166 if (layer.what & layer_state_t::eSidebandStreamChanged) {
167 proto.set_has_sideband_stream(layer.sidebandStream != nullptr);
168 }
169
170 if (layer.what & layer_state_t::eApiChanged) {
171 proto.set_api(layer.api);
172 }
173
174 if (layer.what & layer_state_t::eColorTransformChanged) {
175 LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform());
176 }
177 if (layer.what & layer_state_t::eBlurRegionsChanged) {
178 for (auto& region : layer.blurRegions) {
179 LayerProtoHelper::writeToProto(region, proto.add_blur_regions());
180 }
181 }
182
183 if (layer.what & layer_state_t::eReparent) {
184 proto.set_parent_id(resolvedComposerState.parentId);
185 }
186 if (layer.what & layer_state_t::eRelativeLayerChanged) {
187 proto.set_relative_parent_id(resolvedComposerState.relativeParentId);
188 proto.set_z(layer.z);
189 }
190
191 if (layer.what & layer_state_t::eInputInfoChanged) {
192 if (layer.windowInfoHandle) {
193 const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo();
194 proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle();
195 windowInfoProto->set_layout_params_flags(inputInfo->layoutParamsFlags.get());
196 windowInfoProto->set_layout_params_type(
197 static_cast<int32_t>(inputInfo->layoutParamsType));
198 windowInfoProto->set_input_config(inputInfo->inputConfig.get());
199 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
200 windowInfoProto->mutable_touchable_region());
201 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
202 windowInfoProto->set_focusable(
203 !inputInfo->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE));
204 windowInfoProto->set_has_wallpaper(inputInfo->inputConfig.test(
205 gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER));
206 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
207 proto::Transform* transformProto = windowInfoProto->mutable_transform();
208 transformProto->set_dsdx(inputInfo->transform.dsdx());
209 transformProto->set_dtdx(inputInfo->transform.dtdx());
210 transformProto->set_dtdy(inputInfo->transform.dtdy());
211 transformProto->set_dsdy(inputInfo->transform.dsdy());
212 transformProto->set_tx(inputInfo->transform.tx());
213 transformProto->set_ty(inputInfo->transform.ty());
214 windowInfoProto->set_replace_touchable_region_with_crop(
215 inputInfo->replaceTouchableRegionWithCrop);
216 windowInfoProto->set_crop_layer_id(resolvedComposerState.touchCropId);
217 }
218 }
219 if (layer.what & layer_state_t::eBackgroundColorChanged) {
220 proto.set_bg_color_alpha(layer.bgColor.a);
221 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
222 proto::LayerState_Color3* colorProto = proto.mutable_color();
223 colorProto->set_r(layer.bgColor.r);
224 colorProto->set_g(layer.bgColor.g);
225 colorProto->set_b(layer.bgColor.b);
226 }
227 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
228 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
229 }
230 if (layer.what & layer_state_t::eShadowRadiusChanged) {
231 proto.set_shadow_radius(layer.shadowRadius);
232 }
233 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
234 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
235 }
236 if (layer.what & layer_state_t::eFrameRateChanged) {
237 proto.set_frame_rate(layer.frameRate);
238 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
239 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
240 }
241 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
242 proto.set_fixed_transform_hint(layer.fixedTransformHint);
243 }
244 if (layer.what & layer_state_t::eAutoRefreshChanged) {
245 proto.set_auto_refresh(layer.autoRefresh);
246 }
247 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
248 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
249 }
250 if (layer.what & layer_state_t::eBufferCropChanged) {
251 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
252 }
253 if (layer.what & layer_state_t::eDestinationFrameChanged) {
254 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
255 }
256 if (layer.what & layer_state_t::eDropInputModeChanged) {
257 proto.set_drop_input_mode(
258 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
259 }
260 return proto;
261 }
262
toProto(const DisplayState & display)263 proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display) {
264 proto::DisplayState proto;
265 proto.set_what(display.what);
266 proto.set_id(mMapper->getDisplayId(display.token));
267
268 if (display.what & DisplayState::eLayerStackChanged) {
269 proto.set_layer_stack(display.layerStack.id);
270 }
271 if (display.what & DisplayState::eDisplayProjectionChanged) {
272 proto.set_orientation(static_cast<uint32_t>(display.orientation));
273 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
274 proto.mutable_oriented_display_space_rect());
275 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
276 proto.mutable_layer_stack_space_rect());
277 }
278 if (display.what & DisplayState::eDisplaySizeChanged) {
279 proto.set_width(display.width);
280 proto.set_height(display.height);
281 }
282 if (display.what & DisplayState::eFlagsChanged) {
283 proto.set_flags(display.flags);
284 }
285 return proto;
286 }
287
toProto(const LayerCreationArgs & args)288 proto::LayerCreationArgs TransactionProtoParser::toProto(const LayerCreationArgs& args) {
289 proto::LayerCreationArgs proto;
290 proto.set_layer_id(args.sequence);
291 proto.set_name(args.name);
292 proto.set_flags(args.flags);
293 proto.set_parent_id(args.parentId);
294 proto.set_mirror_from_id(args.layerIdToMirror);
295 proto.set_add_to_root(args.addToRoot);
296 proto.set_layer_stack_to_mirror(args.layerStackToMirror.id);
297 return proto;
298 }
299
fromProto(const proto::TransactionState & proto)300 TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto) {
301 TransactionState t;
302 t.originPid = proto.pid();
303 t.originUid = proto.uid();
304 t.frameTimelineInfo.vsyncId = proto.vsync_id();
305 t.frameTimelineInfo.inputEventId = proto.input_event_id();
306 t.postTime = proto.post_time();
307 t.id = proto.transaction_id();
308
309 int32_t layerCount = proto.layer_changes_size();
310 t.states.reserve(static_cast<size_t>(layerCount));
311 for (int i = 0; i < layerCount; i++) {
312 ResolvedComposerState s;
313 s.state.what = 0;
314 fromProto(proto.layer_changes(i), s);
315 t.states.emplace_back(s);
316 }
317
318 int32_t displayCount = proto.display_changes_size();
319 t.displays.reserve(static_cast<size_t>(displayCount));
320 for (int i = 0; i < displayCount; i++) {
321 t.displays.add(fromProto(proto.display_changes(i)));
322 }
323 return t;
324 }
325
fromProto(const proto::LayerCreationArgs & proto,LayerCreationArgs & outArgs)326 void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
327 LayerCreationArgs& outArgs) {
328 outArgs.sequence = proto.layer_id();
329
330 outArgs.name = proto.name();
331 outArgs.flags = proto.flags();
332 outArgs.parentId = proto.parent_id();
333 outArgs.layerIdToMirror = proto.mirror_from_id();
334 outArgs.addToRoot = proto.add_to_root();
335 outArgs.layerStackToMirror.id = proto.layer_stack_to_mirror();
336 }
337
mergeFromProto(const proto::LayerState & proto,TracingLayerState & outState)338 void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto,
339 TracingLayerState& outState) {
340 ResolvedComposerState resolvedComposerState;
341 fromProto(proto, resolvedComposerState);
342 layer_state_t& state = resolvedComposerState.state;
343 outState.state.merge(state);
344 outState.layerId = resolvedComposerState.layerId;
345
346 if (state.what & layer_state_t::eReparent) {
347 outState.parentId = resolvedComposerState.parentId;
348 }
349 if (state.what & layer_state_t::eRelativeLayerChanged) {
350 outState.relativeParentId = resolvedComposerState.relativeParentId;
351 }
352 if (state.what & layer_state_t::eInputInfoChanged) {
353 outState.touchCropId = resolvedComposerState.touchCropId;
354 }
355 if (state.what & layer_state_t::eBufferChanged) {
356 outState.externalTexture = resolvedComposerState.externalTexture;
357 }
358 if (state.what & layer_state_t::eSidebandStreamChanged) {
359 outState.hasSidebandStream = proto.has_sideband_stream();
360 }
361 }
362
fromProto(const proto::LayerState & proto,ResolvedComposerState & resolvedComposerState)363 void TransactionProtoParser::fromProto(const proto::LayerState& proto,
364 ResolvedComposerState& resolvedComposerState) {
365 auto& layer = resolvedComposerState.state;
366 resolvedComposerState.layerId = proto.layer_id();
367 layer.what |= proto.what();
368
369 if (proto.what() & layer_state_t::ePositionChanged) {
370 layer.x = proto.x();
371 layer.y = proto.y();
372 }
373 if (proto.what() & layer_state_t::eLayerChanged) {
374 layer.z = proto.z();
375 }
376 if (proto.what() & layer_state_t::eLayerStackChanged) {
377 layer.layerStack.id = proto.layer_stack();
378 }
379 if (proto.what() & layer_state_t::eFlagsChanged) {
380 layer.flags = proto.flags();
381 layer.mask = proto.mask();
382 }
383 if (proto.what() & layer_state_t::eMatrixChanged) {
384 const proto::LayerState_Matrix22& matrixProto = proto.matrix();
385 layer.matrix.dsdx = matrixProto.dsdx();
386 layer.matrix.dsdy = matrixProto.dsdy();
387 layer.matrix.dtdx = matrixProto.dtdx();
388 layer.matrix.dtdy = matrixProto.dtdy();
389 }
390 if (proto.what() & layer_state_t::eCornerRadiusChanged) {
391 layer.cornerRadius = proto.corner_radius();
392 }
393 if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
394 layer.backgroundBlurRadius = proto.background_blur_radius();
395 }
396
397 if (proto.what() & layer_state_t::eAlphaChanged) {
398 layer.color.a = proto.alpha();
399 }
400
401 if (proto.what() & layer_state_t::eColorChanged) {
402 const proto::LayerState_Color3& colorProto = proto.color();
403 layer.color.r = colorProto.r();
404 layer.color.g = colorProto.g();
405 layer.color.b = colorProto.b();
406 }
407 if (proto.what() & layer_state_t::eTransparentRegionChanged) {
408 LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
409 }
410 if (proto.what() & layer_state_t::eBufferTransformChanged) {
411 layer.bufferTransform = proto.transform();
412 }
413 if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
414 layer.transformToDisplayInverse = proto.transform_to_display_inverse();
415 }
416 if (proto.what() & layer_state_t::eCropChanged) {
417 LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
418 }
419 if (proto.what() & layer_state_t::eBufferChanged) {
420 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
421 layer.bufferData =
422 std::make_shared<fake::BufferData>(bufferProto.buffer_id(), bufferProto.width(),
423 bufferProto.height(), bufferProto.pixel_format(),
424 bufferProto.usage());
425 resolvedComposerState.externalTexture =
426 std::make_shared<FakeExternalTexture>(layer.bufferData->getWidth(),
427 layer.bufferData->getHeight(),
428 layer.bufferData->getId(),
429 layer.bufferData->getPixelFormat(),
430 layer.bufferData->getUsage());
431 layer.bufferData->frameNumber = bufferProto.frame_number();
432 layer.bufferData->flags = ftl::Flags<BufferData::BufferDataChange>(bufferProto.flags());
433 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
434 layer.bufferData->acquireFence = Fence::NO_FENCE;
435 }
436
437 if (proto.what() & layer_state_t::eApiChanged) {
438 layer.api = proto.api();
439 }
440
441 if (proto.what() & layer_state_t::eColorTransformChanged) {
442 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
443 }
444 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
445 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
446 for (int i = 0; i < proto.blur_regions_size(); i++) {
447 android::BlurRegion region;
448 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
449 layer.blurRegions.push_back(region);
450 }
451 }
452
453 if (proto.what() & layer_state_t::eReparent) {
454 resolvedComposerState.parentId = proto.parent_id();
455 }
456 if (proto.what() & layer_state_t::eRelativeLayerChanged) {
457 resolvedComposerState.relativeParentId = proto.relative_parent_id();
458 layer.z = proto.z();
459 }
460
461 if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
462 gui::WindowInfo inputInfo;
463 const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
464
465 inputInfo.layoutParamsFlags =
466 static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
467 inputInfo.layoutParamsType =
468 static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
469 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
470 inputInfo.touchableRegion);
471 inputInfo.inputConfig =
472 ftl::Flags<gui::WindowInfo::InputConfig>(windowInfoProto.input_config());
473 inputInfo.surfaceInset = windowInfoProto.surface_inset();
474 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
475 const proto::Transform& transformProto = windowInfoProto.transform();
476 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
477 transformProto.dsdy());
478 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
479 inputInfo.replaceTouchableRegionWithCrop =
480 windowInfoProto.replace_touchable_region_with_crop();
481 resolvedComposerState.touchCropId = windowInfoProto.crop_layer_id();
482
483 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
484 }
485 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
486 layer.bgColor.a = proto.bg_color_alpha();
487 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
488 const proto::LayerState_Color3& colorProto = proto.color();
489 layer.bgColor.r = colorProto.r();
490 layer.bgColor.g = colorProto.g();
491 layer.bgColor.b = colorProto.b();
492 }
493 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
494 layer.colorSpaceAgnostic = proto.color_space_agnostic();
495 }
496 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
497 layer.shadowRadius = proto.shadow_radius();
498 }
499 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
500 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
501 }
502 if (proto.what() & layer_state_t::eFrameRateChanged) {
503 layer.frameRate = proto.frame_rate();
504 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
505 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
506 }
507 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
508 layer.fixedTransformHint =
509 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
510 }
511 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
512 layer.autoRefresh = proto.auto_refresh();
513 }
514 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
515 layer.isTrustedOverlay = proto.is_trusted_overlay();
516 }
517 if (proto.what() & layer_state_t::eBufferCropChanged) {
518 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
519 }
520 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
521 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
522 }
523 if (proto.what() & layer_state_t::eDropInputModeChanged) {
524 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
525 }
526 }
527
fromProto(const proto::DisplayState & proto)528 DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto) {
529 DisplayState display;
530 display.what = proto.what();
531 display.token = mMapper->getDisplayHandle(proto.id());
532
533 if (display.what & DisplayState::eLayerStackChanged) {
534 display.layerStack.id = proto.layer_stack();
535 }
536 if (display.what & DisplayState::eDisplayProjectionChanged) {
537 display.orientation = static_cast<ui::Rotation>(proto.orientation());
538 LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
539 display.orientedDisplaySpaceRect);
540 LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
541 display.layerStackSpaceRect);
542 }
543 if (display.what & DisplayState::eDisplaySizeChanged) {
544 display.width = proto.width();
545 display.height = proto.height();
546 }
547 if (display.what & DisplayState::eFlagsChanged) {
548 display.flags = proto.flags();
549 }
550 return display;
551 }
552
asProto(proto::Transform * proto,const ui::Transform & transform)553 void asProto(proto::Transform* proto, const ui::Transform& transform) {
554 proto->set_dsdx(transform.dsdx());
555 proto->set_dtdx(transform.dtdx());
556 proto->set_dtdy(transform.dtdy());
557 proto->set_dsdy(transform.dsdy());
558 proto->set_tx(transform.tx());
559 proto->set_ty(transform.ty());
560 }
561
toProto(const frontend::DisplayInfo & displayInfo,uint32_t layerStack)562 proto::DisplayInfo TransactionProtoParser::toProto(const frontend::DisplayInfo& displayInfo,
563 uint32_t layerStack) {
564 proto::DisplayInfo proto;
565 proto.set_layer_stack(layerStack);
566 proto.set_display_id(displayInfo.info.displayId);
567 proto.set_logical_width(displayInfo.info.logicalWidth);
568 proto.set_logical_height(displayInfo.info.logicalHeight);
569 asProto(proto.mutable_transform_inverse(), displayInfo.info.transform);
570 asProto(proto.mutable_transform(), displayInfo.transform);
571 proto.set_receives_input(displayInfo.receivesInput);
572 proto.set_is_secure(displayInfo.isSecure);
573 proto.set_is_primary(displayInfo.isPrimary);
574 proto.set_is_virtual(displayInfo.isVirtual);
575 proto.set_rotation_flags((int)displayInfo.rotationFlags);
576 proto.set_transform_hint((int)displayInfo.transformHint);
577 return proto;
578 }
579
fromProto2(ui::Transform & outTransform,const proto::Transform & proto)580 void fromProto2(ui::Transform& outTransform, const proto::Transform& proto) {
581 outTransform.set(proto.dsdx(), proto.dtdx(), proto.dtdy(), proto.dsdy());
582 outTransform.set(proto.tx(), proto.ty());
583 }
584
fromProto(const proto::DisplayInfo & proto)585 frontend::DisplayInfo TransactionProtoParser::fromProto(const proto::DisplayInfo& proto) {
586 frontend::DisplayInfo displayInfo;
587 displayInfo.info.displayId = proto.display_id();
588 displayInfo.info.logicalWidth = proto.logical_width();
589 displayInfo.info.logicalHeight = proto.logical_height();
590 fromProto2(displayInfo.info.transform, proto.transform_inverse());
591 fromProto2(displayInfo.transform, proto.transform());
592 displayInfo.receivesInput = proto.receives_input();
593 displayInfo.isSecure = proto.is_secure();
594 displayInfo.isPrimary = proto.is_primary();
595 displayInfo.isVirtual = proto.is_virtual();
596 displayInfo.rotationFlags = (ui::Transform::RotationFlags)proto.rotation_flags();
597 displayInfo.transformHint = (ui::Transform::RotationFlags)proto.transform_hint();
598 return displayInfo;
599 }
600
fromProto(const google::protobuf::RepeatedPtrField<proto::DisplayInfo> & proto,frontend::DisplayInfos & outDisplayInfos)601 void TransactionProtoParser::fromProto(
602 const google::protobuf::RepeatedPtrField<proto::DisplayInfo>& proto,
603 frontend::DisplayInfos& outDisplayInfos) {
604 outDisplayInfos.clear();
605 for (const proto::DisplayInfo& displayInfo : proto) {
606 outDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(displayInfo.layer_stack()),
607 fromProto(displayInfo));
608 }
609 }
610
611 } // namespace android::surfaceflinger
612