blob: a91698fb79a481164e7a71dd70c739507c8213a9 [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);
Vishnu Naird37343b2022-01-12 16:18:56 -080034 proto.set_transaction_id(t.id);
Vishnu Nair6b591152021-10-08 11:45:14 -070035
36 for (auto& layerState : t.states) {
37 proto.mutable_layer_changes()->Add(std::move(toProto(layerState.state, getLayerId)));
38 }
39
40 for (auto& displayState : t.displays) {
41 proto.mutable_display_changes()->Add(std::move(toProto(displayState, getDisplayId)));
42 }
43 return proto;
44}
45
Vishnu Nair68dee2b2021-11-08 18:52:12 -080046proto::TransactionState TransactionProtoParser::toProto(
Greg Kaiser2c909852021-12-07 09:45:29 -080047 const std::map<int32_t /* layerId */, TracingLayerState>& states) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -080048 proto::TransactionState proto;
49 for (auto& [layerId, state] : states) {
50 proto::LayerState layerProto = toProto(state, nullptr);
51 if (layerProto.has_buffer_data()) {
52 proto::LayerState_BufferData* bufferProto = layerProto.mutable_buffer_data();
53 bufferProto->set_buffer_id(state.bufferId);
54 bufferProto->set_width(state.bufferWidth);
55 bufferProto->set_height(state.bufferHeight);
Vishnu Naird37343b2022-01-12 16:18:56 -080056 bufferProto->set_pixel_format(
57 static_cast<proto::LayerState_BufferData_PixelFormat>(state.pixelFormat));
58 bufferProto->set_usage(state.bufferUsage);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080059 }
60 layerProto.set_has_sideband_stream(state.hasSidebandStream);
61 layerProto.set_layer_id(state.layerId);
62 layerProto.set_parent_id(state.parentId);
63 layerProto.set_relative_parent_id(state.relativeParentId);
64 if (layerProto.has_window_info_handle()) {
65 layerProto.mutable_window_info_handle()->set_crop_layer_id(state.inputCropId);
66 }
67 proto.mutable_layer_changes()->Add(std::move(layerProto));
68 }
69 return proto;
70}
71
72proto::LayerState TransactionProtoParser::toProto(const layer_state_t& layer,
73 LayerHandleToIdFn getLayerId) {
Vishnu Nair6b591152021-10-08 11:45:14 -070074 proto::LayerState proto;
Vishnu Nair68dee2b2021-11-08 18:52:12 -080075 if (getLayerId != nullptr) {
76 proto.set_layer_id(getLayerId(layer.surface));
77 } else {
78 proto.set_layer_id(layer.layerId);
79 }
80
Vishnu Nair6b591152021-10-08 11:45:14 -070081 proto.set_what(layer.what);
82
83 if (layer.what & layer_state_t::ePositionChanged) {
84 proto.set_x(layer.x);
85 proto.set_y(layer.y);
86 }
87 if (layer.what & layer_state_t::eLayerChanged) {
88 proto.set_z(layer.z);
89 }
90 if (layer.what & layer_state_t::eSizeChanged) {
91 proto.set_w(layer.w);
92 proto.set_h(layer.h);
93 }
94 if (layer.what & layer_state_t::eLayerStackChanged) {
95 proto.set_layer_stack(layer.layerStack.id);
96 }
97 if (layer.what & layer_state_t::eFlagsChanged) {
98 proto.set_flags(layer.flags);
99 proto.set_mask(layer.mask);
100 }
101 if (layer.what & layer_state_t::eMatrixChanged) {
102 proto::LayerState_Matrix22* matrixProto = proto.mutable_matrix();
103 matrixProto->set_dsdx(layer.matrix.dsdx);
104 matrixProto->set_dsdy(layer.matrix.dsdy);
105 matrixProto->set_dtdx(layer.matrix.dtdx);
106 matrixProto->set_dtdy(layer.matrix.dtdy);
107 }
108 if (layer.what & layer_state_t::eCornerRadiusChanged) {
109 proto.set_corner_radius(layer.cornerRadius);
110 }
111 if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) {
112 proto.set_background_blur_radius(layer.backgroundBlurRadius);
113 }
114
115 if (layer.what & layer_state_t::eAlphaChanged) {
116 proto.set_alpha(layer.alpha);
117 }
118
119 if (layer.what & layer_state_t::eColorChanged) {
120 proto::LayerState_Color3* colorProto = proto.mutable_color();
121 colorProto->set_r(layer.color.r);
122 colorProto->set_g(layer.color.g);
123 colorProto->set_b(layer.color.b);
124 }
125 if (layer.what & layer_state_t::eTransparentRegionChanged) {
126 LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region());
127 }
128 if (layer.what & layer_state_t::eTransformChanged) {
129 proto.set_transform(layer.transform);
130 }
131 if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
132 proto.set_transform_to_display_inverse(layer.transformToDisplayInverse);
133 }
134 if (layer.what & layer_state_t::eCropChanged) {
135 LayerProtoHelper::writeToProto(layer.crop, proto.mutable_crop());
136 }
137 if (layer.what & layer_state_t::eBufferChanged) {
138 proto::LayerState_BufferData* bufferProto = proto.mutable_buffer_data();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800139 if (layer.bufferData->buffer) {
140 bufferProto->set_buffer_id(layer.bufferData->getId());
141 bufferProto->set_width(layer.bufferData->getWidth());
142 bufferProto->set_height(layer.bufferData->getHeight());
Vishnu Naird37343b2022-01-12 16:18:56 -0800143 bufferProto->set_pixel_format(static_cast<proto::LayerState_BufferData_PixelFormat>(
144 layer.bufferData->getPixelFormat()));
145 bufferProto->set_usage(layer.bufferData->getUsage());
Vishnu Nair6b591152021-10-08 11:45:14 -0700146 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800147 bufferProto->set_frame_number(layer.bufferData->frameNumber);
148 bufferProto->set_flags(layer.bufferData->flags.get());
149 bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id);
Vishnu Nair6b591152021-10-08 11:45:14 -0700150 }
151 if (layer.what & layer_state_t::eSidebandStreamChanged) {
152 proto.set_has_sideband_stream(layer.sidebandStream != nullptr);
153 }
154
155 if (layer.what & layer_state_t::eApiChanged) {
156 proto.set_api(layer.api);
157 }
158
159 if (layer.what & layer_state_t::eColorTransformChanged) {
160 LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform());
161 }
162 if (layer.what & layer_state_t::eBlurRegionsChanged) {
163 for (auto& region : layer.blurRegions) {
164 LayerProtoHelper::writeToProto(region, proto.add_blur_regions());
165 }
166 }
167
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800168 if ((layer.what & layer_state_t::eReparent) && getLayerId != nullptr) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700169 int32_t layerId = layer.parentSurfaceControlForChild
170 ? getLayerId(layer.parentSurfaceControlForChild->getHandle())
171 : -1;
172 proto.set_parent_id(layerId);
173 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800174 if ((layer.what & layer_state_t::eRelativeLayerChanged) && getLayerId != nullptr) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700175 int32_t layerId = layer.relativeLayerSurfaceControl
176 ? getLayerId(layer.relativeLayerSurfaceControl->getHandle())
177 : -1;
178 proto.set_relative_parent_id(layerId);
Vishnu Naird37343b2022-01-12 16:18:56 -0800179 proto.set_z(layer.z);
Vishnu Nair6b591152021-10-08 11:45:14 -0700180 }
181
182 if (layer.what & layer_state_t::eInputInfoChanged) {
183 if (layer.windowInfoHandle) {
184 const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo();
185 proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle();
186 windowInfoProto->set_layout_params_flags(inputInfo->flags.get());
187 windowInfoProto->set_layout_params_type(static_cast<int32_t>(inputInfo->type));
188 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
189 windowInfoProto->mutable_touchable_region());
190 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
191 windowInfoProto->set_focusable(inputInfo->focusable);
192 windowInfoProto->set_has_wallpaper(inputInfo->hasWallpaper);
193 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
194 proto::LayerState_Transform* transformProto = windowInfoProto->mutable_transform();
195 transformProto->set_dsdx(inputInfo->transform.dsdx());
196 transformProto->set_dtdx(inputInfo->transform.dtdx());
197 transformProto->set_dtdy(inputInfo->transform.dtdy());
198 transformProto->set_dsdy(inputInfo->transform.dsdy());
199 transformProto->set_tx(inputInfo->transform.tx());
200 transformProto->set_ty(inputInfo->transform.ty());
201 windowInfoProto->set_replace_touchable_region_with_crop(
202 inputInfo->replaceTouchableRegionWithCrop);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800203 if (getLayerId != nullptr) {
204 windowInfoProto->set_crop_layer_id(
205 getLayerId(inputInfo->touchableRegionCropHandle.promote()));
206 } else {
207 windowInfoProto->set_crop_layer_id(-1);
208 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700209 }
210 }
211 if (layer.what & layer_state_t::eBackgroundColorChanged) {
212 proto.set_bg_color_alpha(layer.bgColorAlpha);
213 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
214 proto::LayerState_Color3* colorProto = proto.mutable_color();
215 colorProto->set_r(layer.color.r);
216 colorProto->set_g(layer.color.g);
217 colorProto->set_b(layer.color.b);
218 }
219 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
220 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
221 }
222 if (layer.what & layer_state_t::eShadowRadiusChanged) {
223 proto.set_shadow_radius(layer.shadowRadius);
224 }
225 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
226 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
227 }
228 if (layer.what & layer_state_t::eFrameRateChanged) {
229 proto.set_frame_rate(layer.frameRate);
230 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
231 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
232 }
233 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
234 proto.set_fixed_transform_hint(layer.fixedTransformHint);
235 }
236 if (layer.what & layer_state_t::eAutoRefreshChanged) {
237 proto.set_auto_refresh(layer.autoRefresh);
238 }
239 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
240 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
241 }
242 if (layer.what & layer_state_t::eBufferCropChanged) {
243 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
244 }
245 if (layer.what & layer_state_t::eDestinationFrameChanged) {
246 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
247 }
248 if (layer.what & layer_state_t::eDropInputModeChanged) {
249 proto.set_drop_input_mode(
250 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
251 }
252 return proto;
253}
254
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800255proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display,
256 DisplayHandleToIdFn getDisplayId) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700257 proto::DisplayState proto;
258 proto.set_what(display.what);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800259 if (getDisplayId != nullptr) {
260 proto.set_id(getDisplayId(display.token));
261 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700262
263 if (display.what & DisplayState::eLayerStackChanged) {
264 proto.set_layer_stack(display.layerStack.id);
265 }
266 if (display.what & DisplayState::eDisplayProjectionChanged) {
267 proto.set_orientation(static_cast<uint32_t>(display.orientation));
268 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
269 proto.mutable_oriented_display_space_rect());
270 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
271 proto.mutable_layer_stack_space_rect());
272 }
273 if (display.what & DisplayState::eDisplaySizeChanged) {
274 proto.set_width(display.width);
275 proto.set_height(display.height);
276 }
277 if (display.what & DisplayState::eFlagsChanged) {
278 proto.set_flags(display.flags);
279 }
280 return proto;
281}
282
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800283proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) {
284 proto::LayerCreationArgs proto;
285 proto.set_layer_id(args.layerId);
286 proto.set_name(args.name);
287 proto.set_flags(args.flags);
288 proto.set_parent_id(args.parentId);
Vishnu Nair84125ac2021-12-02 08:47:48 -0800289 proto.set_mirror_from_id(args.mirrorFromId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800290 return proto;
291}
292
293TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto,
294 LayerIdToHandleFn getLayerHandle,
295 DisplayIdToHandleFn getDisplayHandle) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700296 TransactionState t;
297 t.originPid = proto.pid();
298 t.originUid = proto.uid();
299 t.frameTimelineInfo.vsyncId = proto.vsync_id();
300 t.frameTimelineInfo.inputEventId = proto.input_event_id();
301 t.postTime = proto.post_time();
Vishnu Naird37343b2022-01-12 16:18:56 -0800302 t.id = proto.transaction_id();
303
Vishnu Nair6b591152021-10-08 11:45:14 -0700304 int32_t layerCount = proto.layer_changes_size();
305 t.states.reserve(static_cast<size_t>(layerCount));
306 for (int i = 0; i < layerCount; i++) {
307 ComposerState s;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800308 s.state.what = 0;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800309 fromProto(proto.layer_changes(i), getLayerHandle, s.state);
Vishnu Nair6b591152021-10-08 11:45:14 -0700310 t.states.add(s);
311 }
312
313 int32_t displayCount = proto.display_changes_size();
314 t.displays.reserve(static_cast<size_t>(displayCount));
315 for (int i = 0; i < displayCount; i++) {
316 t.displays.add(fromProto(proto.display_changes(i), getDisplayHandle));
317 }
318 return t;
319}
320
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800321void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
322 TracingLayerCreationArgs& outArgs) {
323 outArgs.layerId = proto.layer_id();
324 outArgs.name = proto.name();
325 outArgs.flags = proto.flags();
326 outArgs.parentId = proto.parent_id();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800327 outArgs.mirrorFromId = proto.mirror_from_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800328}
Vishnu Nair6b591152021-10-08 11:45:14 -0700329
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800330void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto,
331 LayerIdToHandleFn getLayerHandle,
332 TracingLayerState& outState) {
333 layer_state_t state;
334 fromProto(proto, getLayerHandle, state);
335 outState.merge(state);
336
337 if (state.what & layer_state_t::eReparent) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800338 outState.parentId = proto.parent_id();
339 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800340 if (state.what & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800341 outState.relativeParentId = proto.relative_parent_id();
342 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800343 if (state.what & layer_state_t::eInputInfoChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800344 outState.inputCropId = proto.window_info_handle().crop_layer_id();
345 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800346 if (state.what & layer_state_t::eBufferChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800347 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
348 outState.bufferId = bufferProto.buffer_id();
349 outState.bufferWidth = bufferProto.width();
350 outState.bufferHeight = bufferProto.height();
Vishnu Naird37343b2022-01-12 16:18:56 -0800351 outState.pixelFormat = bufferProto.pixel_format();
352 outState.bufferUsage = bufferProto.usage();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800353 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800354 if (state.what & layer_state_t::eSidebandStreamChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800355 outState.hasSidebandStream = proto.has_sideband_stream();
356 }
357}
358
359void TransactionProtoParser::fromProto(const proto::LayerState& proto,
360 LayerIdToHandleFn getLayerHandle, layer_state_t& layer) {
361 layer.layerId = proto.layer_id();
362 layer.what |= proto.what();
363
364 if (getLayerHandle != nullptr) {
365 layer.surface = getLayerHandle(layer.layerId);
366 }
367
368 if (proto.what() & layer_state_t::ePositionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700369 layer.x = proto.x();
370 layer.y = proto.y();
371 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800372 if (proto.what() & layer_state_t::eLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700373 layer.z = proto.z();
374 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800375 if (proto.what() & layer_state_t::eSizeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700376 layer.w = proto.w();
377 layer.h = proto.h();
378 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800379 if (proto.what() & layer_state_t::eLayerStackChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700380 layer.layerStack.id = proto.layer_stack();
381 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800382 if (proto.what() & layer_state_t::eFlagsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700383 layer.flags = proto.flags();
384 layer.mask = proto.mask();
385 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800386 if (proto.what() & layer_state_t::eMatrixChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700387 const proto::LayerState_Matrix22& matrixProto = proto.matrix();
388 layer.matrix.dsdx = matrixProto.dsdx();
389 layer.matrix.dsdy = matrixProto.dsdy();
390 layer.matrix.dtdx = matrixProto.dtdx();
391 layer.matrix.dtdy = matrixProto.dtdy();
392 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800393 if (proto.what() & layer_state_t::eCornerRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700394 layer.cornerRadius = proto.corner_radius();
395 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800396 if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700397 layer.backgroundBlurRadius = proto.background_blur_radius();
398 }
399
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800400 if (proto.what() & layer_state_t::eAlphaChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700401 layer.alpha = proto.alpha();
402 }
403
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800404 if (proto.what() & layer_state_t::eColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700405 const proto::LayerState_Color3& colorProto = proto.color();
406 layer.color.r = colorProto.r();
407 layer.color.g = colorProto.g();
408 layer.color.b = colorProto.b();
409 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800410 if (proto.what() & layer_state_t::eTransparentRegionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700411 LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
412 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800413 if (proto.what() & layer_state_t::eTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700414 layer.transform = proto.transform();
415 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800416 if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700417 layer.transformToDisplayInverse = proto.transform_to_display_inverse();
418 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800419 if (proto.what() & layer_state_t::eCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700420 LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
421 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800422 if (proto.what() & layer_state_t::eBufferChanged) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800423 if (!layer.bufferData) {
424 layer.bufferData = std::make_shared<BufferData>();
425 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700426 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800427 layer.bufferData->frameNumber = bufferProto.frame_number();
428 layer.bufferData->flags = Flags<BufferData::BufferDataChange>(bufferProto.flags());
429 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
Vishnu Nair6b591152021-10-08 11:45:14 -0700430 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700431
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800432 if (proto.what() & layer_state_t::eApiChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700433 layer.api = proto.api();
434 }
435
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800436 if (proto.what() & layer_state_t::eColorTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700437 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
438 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800439 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700440 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
441 for (int i = 0; i < proto.blur_regions_size(); i++) {
442 android::BlurRegion region;
443 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
444 layer.blurRegions.push_back(region);
445 }
446 }
447
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800448 if ((proto.what() & layer_state_t::eReparent) && (getLayerHandle != nullptr)) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700449 int32_t layerId = proto.parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800450 if (layerId == -1) {
451 layer.parentSurfaceControlForChild = nullptr;
452 } else {
453 layer.parentSurfaceControlForChild =
454 new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId),
455 nullptr, layerId);
456 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700457 }
Vishnu Naird37343b2022-01-12 16:18:56 -0800458 if (proto.what() & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700459 int32_t layerId = proto.relative_parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800460 if (layerId == -1) {
461 layer.relativeLayerSurfaceControl = nullptr;
462 } else if (getLayerHandle != nullptr) {
463 layer.relativeLayerSurfaceControl =
464 new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId),
465 nullptr, layerId);
466 }
467 layer.z = proto.z();
Vishnu Nair6b591152021-10-08 11:45:14 -0700468 }
469
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800470 if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700471 gui::WindowInfo inputInfo;
472 const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
473
474 inputInfo.flags = static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
475 inputInfo.type = static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
476 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
477 inputInfo.touchableRegion);
478 inputInfo.surfaceInset = windowInfoProto.surface_inset();
479 inputInfo.focusable = windowInfoProto.focusable();
480 inputInfo.hasWallpaper = windowInfoProto.has_wallpaper();
481 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
482 const proto::LayerState_Transform& transformProto = windowInfoProto.transform();
483 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
484 transformProto.dsdy());
485 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
486 inputInfo.replaceTouchableRegionWithCrop =
487 windowInfoProto.replace_touchable_region_with_crop();
488 int32_t layerId = windowInfoProto.crop_layer_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800489 if (getLayerHandle != nullptr) {
490 inputInfo.touchableRegionCropHandle = getLayerHandle(layerId);
491 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700492 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
493 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800494 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700495 layer.bgColorAlpha = proto.bg_color_alpha();
496 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
497 const proto::LayerState_Color3& colorProto = proto.color();
498 layer.color.r = colorProto.r();
499 layer.color.g = colorProto.g();
500 layer.color.b = colorProto.b();
501 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800502 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700503 layer.colorSpaceAgnostic = proto.color_space_agnostic();
504 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800505 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700506 layer.shadowRadius = proto.shadow_radius();
507 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800508 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700509 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
510 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800511 if (proto.what() & layer_state_t::eFrameRateChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700512 layer.frameRate = proto.frame_rate();
513 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
514 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
515 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800516 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700517 layer.fixedTransformHint =
518 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
519 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800520 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700521 layer.autoRefresh = proto.auto_refresh();
522 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800523 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700524 layer.isTrustedOverlay = proto.is_trusted_overlay();
525 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800526 if (proto.what() & layer_state_t::eBufferCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700527 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
528 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800529 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700530 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
531 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800532 if (proto.what() & layer_state_t::eDropInputModeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700533 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
534 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700535}
536
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800537DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto,
538 DisplayIdToHandleFn getDisplayHandle) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700539 DisplayState display;
540 display.what = proto.what();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800541 if (getDisplayHandle != nullptr) {
542 display.token = getDisplayHandle(proto.id());
543 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700544
545 if (display.what & DisplayState::eLayerStackChanged) {
546 display.layerStack.id = proto.layer_stack();
547 }
548 if (display.what & DisplayState::eDisplayProjectionChanged) {
549 display.orientation = static_cast<ui::Rotation>(proto.orientation());
550 LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
551 display.orientedDisplaySpaceRect);
552 LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
553 display.layerStackSpaceRect);
554 }
555 if (display.what & DisplayState::eDisplaySizeChanged) {
556 display.width = proto.width();
557 display.height = proto.height();
558 }
559 if (display.what & DisplayState::eFlagsChanged) {
560 display.flags = proto.flags();
561 }
562 return display;
563}
564
565} // namespace android::surfaceflinger