blob: 849de22a41a132282d6bf21fbed59887374d7dc4 [file] [log] [blame]
Vishnu Nair6b591152021-10-08 11:45:14 -07001/*
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/Rect.h>
19
20#include "LayerProtoHelper.h"
21#include "TransactionProtoParser.h"
22
23namespace android::surfaceflinger {
24
Vishnu Nair68dee2b2021-11-08 18:52:12 -080025proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t,
26 LayerHandleToIdFn getLayerId,
27 DisplayHandleToIdFn getDisplayId) {
Vishnu Nair6b591152021-10-08 11:45:14 -070028 proto::TransactionState proto;
29 proto.set_pid(t.originPid);
30 proto.set_uid(t.originUid);
31 proto.set_vsync_id(t.frameTimelineInfo.vsyncId);
32 proto.set_input_event_id(t.frameTimelineInfo.inputEventId);
33 proto.set_post_time(t.postTime);
34
35 for (auto& layerState : t.states) {
36 proto.mutable_layer_changes()->Add(std::move(toProto(layerState.state, getLayerId)));
37 }
38
39 for (auto& displayState : t.displays) {
40 proto.mutable_display_changes()->Add(std::move(toProto(displayState, getDisplayId)));
41 }
42 return proto;
43}
44
Vishnu Nair68dee2b2021-11-08 18:52:12 -080045proto::TransactionState TransactionProtoParser::toProto(
Greg Kaiser2c909852021-12-07 09:45:29 -080046 const std::map<int32_t /* layerId */, TracingLayerState>& states) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -080047 proto::TransactionState proto;
48 for (auto& [layerId, state] : states) {
49 proto::LayerState layerProto = toProto(state, nullptr);
50 if (layerProto.has_buffer_data()) {
51 proto::LayerState_BufferData* bufferProto = layerProto.mutable_buffer_data();
52 bufferProto->set_buffer_id(state.bufferId);
53 bufferProto->set_width(state.bufferWidth);
54 bufferProto->set_height(state.bufferHeight);
55 }
56 layerProto.set_has_sideband_stream(state.hasSidebandStream);
57 layerProto.set_layer_id(state.layerId);
58 layerProto.set_parent_id(state.parentId);
59 layerProto.set_relative_parent_id(state.relativeParentId);
60 if (layerProto.has_window_info_handle()) {
61 layerProto.mutable_window_info_handle()->set_crop_layer_id(state.inputCropId);
62 }
63 proto.mutable_layer_changes()->Add(std::move(layerProto));
64 }
65 return proto;
66}
67
68proto::LayerState TransactionProtoParser::toProto(const layer_state_t& layer,
69 LayerHandleToIdFn getLayerId) {
Vishnu Nair6b591152021-10-08 11:45:14 -070070 proto::LayerState proto;
Vishnu Nair68dee2b2021-11-08 18:52:12 -080071 if (getLayerId != nullptr) {
72 proto.set_layer_id(getLayerId(layer.surface));
73 } else {
74 proto.set_layer_id(layer.layerId);
75 }
76
Vishnu Nair6b591152021-10-08 11:45:14 -070077 proto.set_what(layer.what);
78
79 if (layer.what & layer_state_t::ePositionChanged) {
80 proto.set_x(layer.x);
81 proto.set_y(layer.y);
82 }
83 if (layer.what & layer_state_t::eLayerChanged) {
84 proto.set_z(layer.z);
85 }
86 if (layer.what & layer_state_t::eSizeChanged) {
87 proto.set_w(layer.w);
88 proto.set_h(layer.h);
89 }
90 if (layer.what & layer_state_t::eLayerStackChanged) {
91 proto.set_layer_stack(layer.layerStack.id);
92 }
93 if (layer.what & layer_state_t::eFlagsChanged) {
94 proto.set_flags(layer.flags);
95 proto.set_mask(layer.mask);
96 }
97 if (layer.what & layer_state_t::eMatrixChanged) {
98 proto::LayerState_Matrix22* matrixProto = proto.mutable_matrix();
99 matrixProto->set_dsdx(layer.matrix.dsdx);
100 matrixProto->set_dsdy(layer.matrix.dsdy);
101 matrixProto->set_dtdx(layer.matrix.dtdx);
102 matrixProto->set_dtdy(layer.matrix.dtdy);
103 }
104 if (layer.what & layer_state_t::eCornerRadiusChanged) {
105 proto.set_corner_radius(layer.cornerRadius);
106 }
107 if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) {
108 proto.set_background_blur_radius(layer.backgroundBlurRadius);
109 }
110
111 if (layer.what & layer_state_t::eAlphaChanged) {
112 proto.set_alpha(layer.alpha);
113 }
114
115 if (layer.what & layer_state_t::eColorChanged) {
116 proto::LayerState_Color3* colorProto = proto.mutable_color();
117 colorProto->set_r(layer.color.r);
118 colorProto->set_g(layer.color.g);
119 colorProto->set_b(layer.color.b);
120 }
121 if (layer.what & layer_state_t::eTransparentRegionChanged) {
122 LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region());
123 }
124 if (layer.what & layer_state_t::eTransformChanged) {
125 proto.set_transform(layer.transform);
126 }
127 if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
128 proto.set_transform_to_display_inverse(layer.transformToDisplayInverse);
129 }
130 if (layer.what & layer_state_t::eCropChanged) {
131 LayerProtoHelper::writeToProto(layer.crop, proto.mutable_crop());
132 }
133 if (layer.what & layer_state_t::eBufferChanged) {
134 proto::LayerState_BufferData* bufferProto = proto.mutable_buffer_data();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800135 if (layer.bufferData->buffer) {
136 bufferProto->set_buffer_id(layer.bufferData->getId());
137 bufferProto->set_width(layer.bufferData->getWidth());
138 bufferProto->set_height(layer.bufferData->getHeight());
Vishnu Nair6b591152021-10-08 11:45:14 -0700139 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800140 bufferProto->set_frame_number(layer.bufferData->frameNumber);
141 bufferProto->set_flags(layer.bufferData->flags.get());
142 bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id);
Vishnu Nair6b591152021-10-08 11:45:14 -0700143 }
144 if (layer.what & layer_state_t::eSidebandStreamChanged) {
145 proto.set_has_sideband_stream(layer.sidebandStream != nullptr);
146 }
147
148 if (layer.what & layer_state_t::eApiChanged) {
149 proto.set_api(layer.api);
150 }
151
152 if (layer.what & layer_state_t::eColorTransformChanged) {
153 LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform());
154 }
155 if (layer.what & layer_state_t::eBlurRegionsChanged) {
156 for (auto& region : layer.blurRegions) {
157 LayerProtoHelper::writeToProto(region, proto.add_blur_regions());
158 }
159 }
160
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800161 if ((layer.what & layer_state_t::eReparent) && getLayerId != nullptr) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700162 int32_t layerId = layer.parentSurfaceControlForChild
163 ? getLayerId(layer.parentSurfaceControlForChild->getHandle())
164 : -1;
165 proto.set_parent_id(layerId);
166 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800167 if ((layer.what & layer_state_t::eRelativeLayerChanged) && getLayerId != nullptr) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700168 int32_t layerId = layer.relativeLayerSurfaceControl
169 ? getLayerId(layer.relativeLayerSurfaceControl->getHandle())
170 : -1;
171 proto.set_relative_parent_id(layerId);
172 }
173
174 if (layer.what & layer_state_t::eInputInfoChanged) {
175 if (layer.windowInfoHandle) {
176 const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo();
177 proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle();
178 windowInfoProto->set_layout_params_flags(inputInfo->flags.get());
179 windowInfoProto->set_layout_params_type(static_cast<int32_t>(inputInfo->type));
180 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
181 windowInfoProto->mutable_touchable_region());
182 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
183 windowInfoProto->set_focusable(inputInfo->focusable);
184 windowInfoProto->set_has_wallpaper(inputInfo->hasWallpaper);
185 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
186 proto::LayerState_Transform* transformProto = windowInfoProto->mutable_transform();
187 transformProto->set_dsdx(inputInfo->transform.dsdx());
188 transformProto->set_dtdx(inputInfo->transform.dtdx());
189 transformProto->set_dtdy(inputInfo->transform.dtdy());
190 transformProto->set_dsdy(inputInfo->transform.dsdy());
191 transformProto->set_tx(inputInfo->transform.tx());
192 transformProto->set_ty(inputInfo->transform.ty());
193 windowInfoProto->set_replace_touchable_region_with_crop(
194 inputInfo->replaceTouchableRegionWithCrop);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800195 if (getLayerId != nullptr) {
196 windowInfoProto->set_crop_layer_id(
197 getLayerId(inputInfo->touchableRegionCropHandle.promote()));
198 } else {
199 windowInfoProto->set_crop_layer_id(-1);
200 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700201 }
202 }
203 if (layer.what & layer_state_t::eBackgroundColorChanged) {
204 proto.set_bg_color_alpha(layer.bgColorAlpha);
205 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
206 proto::LayerState_Color3* colorProto = proto.mutable_color();
207 colorProto->set_r(layer.color.r);
208 colorProto->set_g(layer.color.g);
209 colorProto->set_b(layer.color.b);
210 }
211 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
212 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
213 }
214 if (layer.what & layer_state_t::eShadowRadiusChanged) {
215 proto.set_shadow_radius(layer.shadowRadius);
216 }
217 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
218 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
219 }
220 if (layer.what & layer_state_t::eFrameRateChanged) {
221 proto.set_frame_rate(layer.frameRate);
222 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
223 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
224 }
225 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
226 proto.set_fixed_transform_hint(layer.fixedTransformHint);
227 }
228 if (layer.what & layer_state_t::eAutoRefreshChanged) {
229 proto.set_auto_refresh(layer.autoRefresh);
230 }
231 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
232 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
233 }
234 if (layer.what & layer_state_t::eBufferCropChanged) {
235 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
236 }
237 if (layer.what & layer_state_t::eDestinationFrameChanged) {
238 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
239 }
240 if (layer.what & layer_state_t::eDropInputModeChanged) {
241 proto.set_drop_input_mode(
242 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
243 }
244 return proto;
245}
246
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800247proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display,
248 DisplayHandleToIdFn getDisplayId) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700249 proto::DisplayState proto;
250 proto.set_what(display.what);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800251 if (getDisplayId != nullptr) {
252 proto.set_id(getDisplayId(display.token));
253 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700254
255 if (display.what & DisplayState::eLayerStackChanged) {
256 proto.set_layer_stack(display.layerStack.id);
257 }
258 if (display.what & DisplayState::eDisplayProjectionChanged) {
259 proto.set_orientation(static_cast<uint32_t>(display.orientation));
260 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
261 proto.mutable_oriented_display_space_rect());
262 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
263 proto.mutable_layer_stack_space_rect());
264 }
265 if (display.what & DisplayState::eDisplaySizeChanged) {
266 proto.set_width(display.width);
267 proto.set_height(display.height);
268 }
269 if (display.what & DisplayState::eFlagsChanged) {
270 proto.set_flags(display.flags);
271 }
272 return proto;
273}
274
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800275proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) {
276 proto::LayerCreationArgs proto;
277 proto.set_layer_id(args.layerId);
278 proto.set_name(args.name);
279 proto.set_flags(args.flags);
280 proto.set_parent_id(args.parentId);
Vishnu Nair84125ac2021-12-02 08:47:48 -0800281 proto.set_mirror_from_id(args.mirrorFromId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800282 return proto;
283}
284
285TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto,
286 LayerIdToHandleFn getLayerHandle,
287 DisplayIdToHandleFn getDisplayHandle) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700288 TransactionState t;
289 t.originPid = proto.pid();
290 t.originUid = proto.uid();
291 t.frameTimelineInfo.vsyncId = proto.vsync_id();
292 t.frameTimelineInfo.inputEventId = proto.input_event_id();
293 t.postTime = proto.post_time();
294 int32_t layerCount = proto.layer_changes_size();
295 t.states.reserve(static_cast<size_t>(layerCount));
296 for (int i = 0; i < layerCount; i++) {
297 ComposerState s;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800298 fromProto(proto.layer_changes(i), getLayerHandle, s.state);
Vishnu Nair6b591152021-10-08 11:45:14 -0700299 t.states.add(s);
300 }
301
302 int32_t displayCount = proto.display_changes_size();
303 t.displays.reserve(static_cast<size_t>(displayCount));
304 for (int i = 0; i < displayCount; i++) {
305 t.displays.add(fromProto(proto.display_changes(i), getDisplayHandle));
306 }
307 return t;
308}
309
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800310void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
311 TracingLayerCreationArgs& outArgs) {
312 outArgs.layerId = proto.layer_id();
313 outArgs.name = proto.name();
314 outArgs.flags = proto.flags();
315 outArgs.parentId = proto.parent_id();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800316 outArgs.mirrorFromId = proto.mirror_from_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800317}
Vishnu Nair6b591152021-10-08 11:45:14 -0700318
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800319void TransactionProtoParser::fromProto(const proto::LayerState& proto,
320 LayerIdToHandleFn getLayerHandle,
321 TracingLayerState& outState) {
322 fromProto(proto, getLayerHandle, static_cast<layer_state_t&>(outState));
323 if (proto.what() & layer_state_t::eReparent) {
324 outState.parentId = proto.parent_id();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800325 outState.args.parentId = outState.parentId;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800326 }
327 if (proto.what() & layer_state_t::eRelativeLayerChanged) {
328 outState.relativeParentId = proto.relative_parent_id();
329 }
330 if (proto.what() & layer_state_t::eInputInfoChanged) {
331 outState.inputCropId = proto.window_info_handle().crop_layer_id();
332 }
333 if (proto.what() & layer_state_t::eBufferChanged) {
334 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
335 outState.bufferId = bufferProto.buffer_id();
336 outState.bufferWidth = bufferProto.width();
337 outState.bufferHeight = bufferProto.height();
338 }
339 if (proto.what() & layer_state_t::eSidebandStreamChanged) {
340 outState.hasSidebandStream = proto.has_sideband_stream();
341 }
342}
343
344void TransactionProtoParser::fromProto(const proto::LayerState& proto,
345 LayerIdToHandleFn getLayerHandle, layer_state_t& layer) {
346 layer.layerId = proto.layer_id();
347 layer.what |= proto.what();
348
349 if (getLayerHandle != nullptr) {
350 layer.surface = getLayerHandle(layer.layerId);
351 }
352
353 if (proto.what() & layer_state_t::ePositionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700354 layer.x = proto.x();
355 layer.y = proto.y();
356 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800357 if (proto.what() & layer_state_t::eLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700358 layer.z = proto.z();
359 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800360 if (proto.what() & layer_state_t::eSizeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700361 layer.w = proto.w();
362 layer.h = proto.h();
363 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800364 if (proto.what() & layer_state_t::eLayerStackChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700365 layer.layerStack.id = proto.layer_stack();
366 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800367 if (proto.what() & layer_state_t::eFlagsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700368 layer.flags = proto.flags();
369 layer.mask = proto.mask();
370 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800371 if (proto.what() & layer_state_t::eMatrixChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700372 const proto::LayerState_Matrix22& matrixProto = proto.matrix();
373 layer.matrix.dsdx = matrixProto.dsdx();
374 layer.matrix.dsdy = matrixProto.dsdy();
375 layer.matrix.dtdx = matrixProto.dtdx();
376 layer.matrix.dtdy = matrixProto.dtdy();
377 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800378 if (proto.what() & layer_state_t::eCornerRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700379 layer.cornerRadius = proto.corner_radius();
380 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800381 if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700382 layer.backgroundBlurRadius = proto.background_blur_radius();
383 }
384
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800385 if (proto.what() & layer_state_t::eAlphaChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700386 layer.alpha = proto.alpha();
387 }
388
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800389 if (proto.what() & layer_state_t::eColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700390 const proto::LayerState_Color3& colorProto = proto.color();
391 layer.color.r = colorProto.r();
392 layer.color.g = colorProto.g();
393 layer.color.b = colorProto.b();
394 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800395 if (proto.what() & layer_state_t::eTransparentRegionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700396 LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
397 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800398 if (proto.what() & layer_state_t::eTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700399 layer.transform = proto.transform();
400 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800401 if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700402 layer.transformToDisplayInverse = proto.transform_to_display_inverse();
403 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800404 if (proto.what() & layer_state_t::eCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700405 LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
406 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800407 if (proto.what() & layer_state_t::eBufferChanged) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800408 if (!layer.bufferData) {
409 layer.bufferData = std::make_shared<BufferData>();
410 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700411 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800412 layer.bufferData->frameNumber = bufferProto.frame_number();
413 layer.bufferData->flags = Flags<BufferData::BufferDataChange>(bufferProto.flags());
414 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
Vishnu Nair6b591152021-10-08 11:45:14 -0700415 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700416
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800417 if (proto.what() & layer_state_t::eApiChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700418 layer.api = proto.api();
419 }
420
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800421 if (proto.what() & layer_state_t::eColorTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700422 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
423 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800424 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700425 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
426 for (int i = 0; i < proto.blur_regions_size(); i++) {
427 android::BlurRegion region;
428 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
429 layer.blurRegions.push_back(region);
430 }
431 }
432
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800433 if ((proto.what() & layer_state_t::eReparent) && (getLayerHandle != nullptr)) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700434 int32_t layerId = proto.parent_id();
435 layer.parentSurfaceControlForChild =
436 new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId),
437 nullptr, layerId);
438 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800439 if ((proto.what() & layer_state_t::eRelativeLayerChanged) && (getLayerHandle != nullptr)) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700440 int32_t layerId = proto.relative_parent_id();
441 layer.relativeLayerSurfaceControl =
442 new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId),
443 nullptr, layerId);
444 }
445
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800446 if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700447 gui::WindowInfo inputInfo;
448 const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
449
450 inputInfo.flags = static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
451 inputInfo.type = static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
452 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
453 inputInfo.touchableRegion);
454 inputInfo.surfaceInset = windowInfoProto.surface_inset();
455 inputInfo.focusable = windowInfoProto.focusable();
456 inputInfo.hasWallpaper = windowInfoProto.has_wallpaper();
457 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
458 const proto::LayerState_Transform& transformProto = windowInfoProto.transform();
459 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
460 transformProto.dsdy());
461 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
462 inputInfo.replaceTouchableRegionWithCrop =
463 windowInfoProto.replace_touchable_region_with_crop();
464 int32_t layerId = windowInfoProto.crop_layer_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800465 if (getLayerHandle != nullptr) {
466 inputInfo.touchableRegionCropHandle = getLayerHandle(layerId);
467 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700468 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
469 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800470 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700471 layer.bgColorAlpha = proto.bg_color_alpha();
472 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
473 const proto::LayerState_Color3& colorProto = proto.color();
474 layer.color.r = colorProto.r();
475 layer.color.g = colorProto.g();
476 layer.color.b = colorProto.b();
477 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800478 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700479 layer.colorSpaceAgnostic = proto.color_space_agnostic();
480 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800481 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700482 layer.shadowRadius = proto.shadow_radius();
483 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800484 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700485 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
486 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800487 if (proto.what() & layer_state_t::eFrameRateChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700488 layer.frameRate = proto.frame_rate();
489 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
490 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
491 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800492 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700493 layer.fixedTransformHint =
494 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
495 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800496 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700497 layer.autoRefresh = proto.auto_refresh();
498 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800499 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700500 layer.isTrustedOverlay = proto.is_trusted_overlay();
501 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800502 if (proto.what() & layer_state_t::eBufferCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700503 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
504 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800505 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700506 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
507 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800508 if (proto.what() & layer_state_t::eDropInputModeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700509 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
510 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700511}
512
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800513DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto,
514 DisplayIdToHandleFn getDisplayHandle) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700515 DisplayState display;
516 display.what = proto.what();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800517 if (getDisplayHandle != nullptr) {
518 display.token = getDisplayHandle(proto.id());
519 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700520
521 if (display.what & DisplayState::eLayerStackChanged) {
522 display.layerStack.id = proto.layer_stack();
523 }
524 if (display.what & DisplayState::eDisplayProjectionChanged) {
525 display.orientation = static_cast<ui::Rotation>(proto.orientation());
526 LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
527 display.orientedDisplaySpaceRect);
528 LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
529 display.layerStackSpaceRect);
530 }
531 if (display.what & DisplayState::eDisplaySizeChanged) {
532 display.width = proto.width();
533 display.height = proto.height();
534 }
535 if (display.what & DisplayState::eFlagsChanged) {
536 display.flags = proto.flags();
537 }
538 return display;
539}
540
541} // namespace android::surfaceflinger