blob: c736d0550687e1c9d6509d3b1fc8a2c772cc089b [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();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800186 windowInfoProto->set_layout_params_flags(inputInfo->layoutParamsFlags.get());
187 windowInfoProto->set_layout_params_type(
188 static_cast<int32_t>(inputInfo->layoutParamsType));
Vishnu Nair6b591152021-10-08 11:45:14 -0700189 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
190 windowInfoProto->mutable_touchable_region());
191 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800192 windowInfoProto->set_focusable(
193 !inputInfo->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE));
194 windowInfoProto->set_has_wallpaper(inputInfo->inputConfig.test(
195 gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER));
Vishnu Nair6b591152021-10-08 11:45:14 -0700196 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
197 proto::LayerState_Transform* transformProto = windowInfoProto->mutable_transform();
198 transformProto->set_dsdx(inputInfo->transform.dsdx());
199 transformProto->set_dtdx(inputInfo->transform.dtdx());
200 transformProto->set_dtdy(inputInfo->transform.dtdy());
201 transformProto->set_dsdy(inputInfo->transform.dsdy());
202 transformProto->set_tx(inputInfo->transform.tx());
203 transformProto->set_ty(inputInfo->transform.ty());
204 windowInfoProto->set_replace_touchable_region_with_crop(
205 inputInfo->replaceTouchableRegionWithCrop);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800206 if (getLayerId != nullptr) {
207 windowInfoProto->set_crop_layer_id(
208 getLayerId(inputInfo->touchableRegionCropHandle.promote()));
209 } else {
210 windowInfoProto->set_crop_layer_id(-1);
211 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700212 }
213 }
214 if (layer.what & layer_state_t::eBackgroundColorChanged) {
215 proto.set_bg_color_alpha(layer.bgColorAlpha);
216 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
217 proto::LayerState_Color3* colorProto = proto.mutable_color();
218 colorProto->set_r(layer.color.r);
219 colorProto->set_g(layer.color.g);
220 colorProto->set_b(layer.color.b);
221 }
222 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
223 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
224 }
225 if (layer.what & layer_state_t::eShadowRadiusChanged) {
226 proto.set_shadow_radius(layer.shadowRadius);
227 }
228 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
229 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
230 }
231 if (layer.what & layer_state_t::eFrameRateChanged) {
232 proto.set_frame_rate(layer.frameRate);
233 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
234 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
235 }
236 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
237 proto.set_fixed_transform_hint(layer.fixedTransformHint);
238 }
239 if (layer.what & layer_state_t::eAutoRefreshChanged) {
240 proto.set_auto_refresh(layer.autoRefresh);
241 }
242 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
243 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
244 }
245 if (layer.what & layer_state_t::eBufferCropChanged) {
246 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
247 }
248 if (layer.what & layer_state_t::eDestinationFrameChanged) {
249 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
250 }
251 if (layer.what & layer_state_t::eDropInputModeChanged) {
252 proto.set_drop_input_mode(
253 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
254 }
255 return proto;
256}
257
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800258proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display,
259 DisplayHandleToIdFn getDisplayId) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700260 proto::DisplayState proto;
261 proto.set_what(display.what);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800262 if (getDisplayId != nullptr) {
263 proto.set_id(getDisplayId(display.token));
264 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700265
266 if (display.what & DisplayState::eLayerStackChanged) {
267 proto.set_layer_stack(display.layerStack.id);
268 }
269 if (display.what & DisplayState::eDisplayProjectionChanged) {
270 proto.set_orientation(static_cast<uint32_t>(display.orientation));
271 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
272 proto.mutable_oriented_display_space_rect());
273 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
274 proto.mutable_layer_stack_space_rect());
275 }
276 if (display.what & DisplayState::eDisplaySizeChanged) {
277 proto.set_width(display.width);
278 proto.set_height(display.height);
279 }
280 if (display.what & DisplayState::eFlagsChanged) {
281 proto.set_flags(display.flags);
282 }
283 return proto;
284}
285
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800286proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) {
287 proto::LayerCreationArgs proto;
288 proto.set_layer_id(args.layerId);
289 proto.set_name(args.name);
290 proto.set_flags(args.flags);
291 proto.set_parent_id(args.parentId);
Vishnu Nair84125ac2021-12-02 08:47:48 -0800292 proto.set_mirror_from_id(args.mirrorFromId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800293 return proto;
294}
295
296TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto,
297 LayerIdToHandleFn getLayerHandle,
298 DisplayIdToHandleFn getDisplayHandle) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700299 TransactionState t;
300 t.originPid = proto.pid();
301 t.originUid = proto.uid();
302 t.frameTimelineInfo.vsyncId = proto.vsync_id();
303 t.frameTimelineInfo.inputEventId = proto.input_event_id();
304 t.postTime = proto.post_time();
Vishnu Naird37343b2022-01-12 16:18:56 -0800305 t.id = proto.transaction_id();
306
Vishnu Nair6b591152021-10-08 11:45:14 -0700307 int32_t layerCount = proto.layer_changes_size();
308 t.states.reserve(static_cast<size_t>(layerCount));
309 for (int i = 0; i < layerCount; i++) {
310 ComposerState s;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800311 s.state.what = 0;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800312 fromProto(proto.layer_changes(i), getLayerHandle, s.state);
Vishnu Nair6b591152021-10-08 11:45:14 -0700313 t.states.add(s);
314 }
315
316 int32_t displayCount = proto.display_changes_size();
317 t.displays.reserve(static_cast<size_t>(displayCount));
318 for (int i = 0; i < displayCount; i++) {
319 t.displays.add(fromProto(proto.display_changes(i), getDisplayHandle));
320 }
321 return t;
322}
323
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800324void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
325 TracingLayerCreationArgs& outArgs) {
326 outArgs.layerId = proto.layer_id();
327 outArgs.name = proto.name();
328 outArgs.flags = proto.flags();
329 outArgs.parentId = proto.parent_id();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800330 outArgs.mirrorFromId = proto.mirror_from_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800331}
Vishnu Nair6b591152021-10-08 11:45:14 -0700332
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800333void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto,
334 LayerIdToHandleFn getLayerHandle,
335 TracingLayerState& outState) {
336 layer_state_t state;
337 fromProto(proto, getLayerHandle, state);
338 outState.merge(state);
339
340 if (state.what & layer_state_t::eReparent) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800341 outState.parentId = proto.parent_id();
342 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800343 if (state.what & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800344 outState.relativeParentId = proto.relative_parent_id();
345 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800346 if (state.what & layer_state_t::eInputInfoChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800347 outState.inputCropId = proto.window_info_handle().crop_layer_id();
348 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800349 if (state.what & layer_state_t::eBufferChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800350 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
351 outState.bufferId = bufferProto.buffer_id();
352 outState.bufferWidth = bufferProto.width();
353 outState.bufferHeight = bufferProto.height();
Vishnu Naird37343b2022-01-12 16:18:56 -0800354 outState.pixelFormat = bufferProto.pixel_format();
355 outState.bufferUsage = bufferProto.usage();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800356 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800357 if (state.what & layer_state_t::eSidebandStreamChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800358 outState.hasSidebandStream = proto.has_sideband_stream();
359 }
360}
361
362void TransactionProtoParser::fromProto(const proto::LayerState& proto,
363 LayerIdToHandleFn getLayerHandle, layer_state_t& layer) {
364 layer.layerId = proto.layer_id();
365 layer.what |= proto.what();
366
367 if (getLayerHandle != nullptr) {
368 layer.surface = getLayerHandle(layer.layerId);
369 }
370
371 if (proto.what() & layer_state_t::ePositionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700372 layer.x = proto.x();
373 layer.y = proto.y();
374 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800375 if (proto.what() & layer_state_t::eLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700376 layer.z = proto.z();
377 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800378 if (proto.what() & layer_state_t::eSizeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700379 layer.w = proto.w();
380 layer.h = proto.h();
381 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800382 if (proto.what() & layer_state_t::eLayerStackChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700383 layer.layerStack.id = proto.layer_stack();
384 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800385 if (proto.what() & layer_state_t::eFlagsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700386 layer.flags = proto.flags();
387 layer.mask = proto.mask();
388 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800389 if (proto.what() & layer_state_t::eMatrixChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700390 const proto::LayerState_Matrix22& matrixProto = proto.matrix();
391 layer.matrix.dsdx = matrixProto.dsdx();
392 layer.matrix.dsdy = matrixProto.dsdy();
393 layer.matrix.dtdx = matrixProto.dtdx();
394 layer.matrix.dtdy = matrixProto.dtdy();
395 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800396 if (proto.what() & layer_state_t::eCornerRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700397 layer.cornerRadius = proto.corner_radius();
398 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800399 if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700400 layer.backgroundBlurRadius = proto.background_blur_radius();
401 }
402
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800403 if (proto.what() & layer_state_t::eAlphaChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700404 layer.alpha = proto.alpha();
405 }
406
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800407 if (proto.what() & layer_state_t::eColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700408 const proto::LayerState_Color3& colorProto = proto.color();
409 layer.color.r = colorProto.r();
410 layer.color.g = colorProto.g();
411 layer.color.b = colorProto.b();
412 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800413 if (proto.what() & layer_state_t::eTransparentRegionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700414 LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
415 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800416 if (proto.what() & layer_state_t::eTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700417 layer.transform = proto.transform();
418 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800419 if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700420 layer.transformToDisplayInverse = proto.transform_to_display_inverse();
421 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800422 if (proto.what() & layer_state_t::eCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700423 LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
424 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800425 if (proto.what() & layer_state_t::eBufferChanged) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800426 if (!layer.bufferData) {
427 layer.bufferData = std::make_shared<BufferData>();
428 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700429 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800430 layer.bufferData->frameNumber = bufferProto.frame_number();
431 layer.bufferData->flags = Flags<BufferData::BufferDataChange>(bufferProto.flags());
432 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
Vishnu Nair6b591152021-10-08 11:45:14 -0700433 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700434
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800435 if (proto.what() & layer_state_t::eApiChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700436 layer.api = proto.api();
437 }
438
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800439 if (proto.what() & layer_state_t::eColorTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700440 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
441 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800442 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700443 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
444 for (int i = 0; i < proto.blur_regions_size(); i++) {
445 android::BlurRegion region;
446 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
447 layer.blurRegions.push_back(region);
448 }
449 }
450
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800451 if ((proto.what() & layer_state_t::eReparent) && (getLayerHandle != nullptr)) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700452 int32_t layerId = proto.parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800453 if (layerId == -1) {
454 layer.parentSurfaceControlForChild = nullptr;
455 } else {
456 layer.parentSurfaceControlForChild =
457 new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId),
458 nullptr, layerId);
459 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700460 }
Vishnu Naird37343b2022-01-12 16:18:56 -0800461 if (proto.what() & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700462 int32_t layerId = proto.relative_parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800463 if (layerId == -1) {
464 layer.relativeLayerSurfaceControl = nullptr;
465 } else if (getLayerHandle != nullptr) {
466 layer.relativeLayerSurfaceControl =
467 new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId),
468 nullptr, layerId);
469 }
470 layer.z = proto.z();
Vishnu Nair6b591152021-10-08 11:45:14 -0700471 }
472
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800473 if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700474 gui::WindowInfo inputInfo;
475 const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
476
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800477 inputInfo.layoutParamsFlags =
478 static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
479 inputInfo.layoutParamsType =
480 static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
Vishnu Nair6b591152021-10-08 11:45:14 -0700481 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
482 inputInfo.touchableRegion);
483 inputInfo.surfaceInset = windowInfoProto.surface_inset();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800484 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_FOCUSABLE,
485 !windowInfoProto.focusable());
486 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER,
487 windowInfoProto.has_wallpaper());
Vishnu Nair6b591152021-10-08 11:45:14 -0700488 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
489 const proto::LayerState_Transform& transformProto = windowInfoProto.transform();
490 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
491 transformProto.dsdy());
492 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
493 inputInfo.replaceTouchableRegionWithCrop =
494 windowInfoProto.replace_touchable_region_with_crop();
495 int32_t layerId = windowInfoProto.crop_layer_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800496 if (getLayerHandle != nullptr) {
497 inputInfo.touchableRegionCropHandle = getLayerHandle(layerId);
498 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700499 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
500 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800501 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700502 layer.bgColorAlpha = proto.bg_color_alpha();
503 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
504 const proto::LayerState_Color3& colorProto = proto.color();
505 layer.color.r = colorProto.r();
506 layer.color.g = colorProto.g();
507 layer.color.b = colorProto.b();
508 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800509 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700510 layer.colorSpaceAgnostic = proto.color_space_agnostic();
511 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800512 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700513 layer.shadowRadius = proto.shadow_radius();
514 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800515 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700516 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
517 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800518 if (proto.what() & layer_state_t::eFrameRateChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700519 layer.frameRate = proto.frame_rate();
520 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
521 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
522 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800523 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700524 layer.fixedTransformHint =
525 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
526 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800527 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700528 layer.autoRefresh = proto.auto_refresh();
529 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800530 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700531 layer.isTrustedOverlay = proto.is_trusted_overlay();
532 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800533 if (proto.what() & layer_state_t::eBufferCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700534 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
535 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800536 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700537 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
538 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800539 if (proto.what() & layer_state_t::eDropInputModeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700540 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
541 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700542}
543
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800544DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto,
545 DisplayIdToHandleFn getDisplayHandle) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700546 DisplayState display;
547 display.what = proto.what();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800548 if (getDisplayHandle != nullptr) {
549 display.token = getDisplayHandle(proto.id());
550 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700551
552 if (display.what & DisplayState::eLayerStackChanged) {
553 display.layerStack.id = proto.layer_stack();
554 }
555 if (display.what & DisplayState::eDisplayProjectionChanged) {
556 display.orientation = static_cast<ui::Rotation>(proto.orientation());
557 LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
558 display.orientedDisplaySpaceRect);
559 LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
560 display.layerStackSpaceRect);
561 }
562 if (display.what & DisplayState::eDisplaySizeChanged) {
563 display.width = proto.width();
564 display.height = proto.height();
565 }
566 if (display.what & DisplayState::eFlagsChanged) {
567 display.flags = proto.flags();
568 }
569 return display;
570}
571
572} // namespace android::surfaceflinger