blob: fb5a6b3eb78d86129eb309b2532b342c5584d103 [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 Nair685cfef2022-02-02 10:01:25 -080025proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t) {
Vishnu Nair6b591152021-10-08 11:45:14 -070026 proto::TransactionState proto;
27 proto.set_pid(t.originPid);
28 proto.set_uid(t.originUid);
29 proto.set_vsync_id(t.frameTimelineInfo.vsyncId);
30 proto.set_input_event_id(t.frameTimelineInfo.inputEventId);
31 proto.set_post_time(t.postTime);
Vishnu Naird37343b2022-01-12 16:18:56 -080032 proto.set_transaction_id(t.id);
Vishnu Nair6b591152021-10-08 11:45:14 -070033
Vishnu Nair685cfef2022-02-02 10:01:25 -080034 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(t.states.size()));
Vishnu Nair6b591152021-10-08 11:45:14 -070035 for (auto& layerState : t.states) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080036 proto.mutable_layer_changes()->Add(std::move(toProto(layerState.state)));
Vishnu Nair6b591152021-10-08 11:45:14 -070037 }
38
Vishnu Nair685cfef2022-02-02 10:01:25 -080039 proto.mutable_display_changes()->Reserve(static_cast<int32_t>(t.displays.size()));
Vishnu Nair6b591152021-10-08 11:45:14 -070040 for (auto& displayState : t.displays) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080041 proto.mutable_display_changes()->Add(std::move(toProto(displayState)));
Vishnu Nair6b591152021-10-08 11:45:14 -070042 }
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;
Vishnu Nair685cfef2022-02-02 10:01:25 -080049 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(states.size()));
Vishnu Nair68dee2b2021-11-08 18:52:12 -080050 for (auto& [layerId, state] : states) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080051 proto::LayerState layerProto = toProto(state);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080052 if (layerProto.has_buffer_data()) {
53 proto::LayerState_BufferData* bufferProto = layerProto.mutable_buffer_data();
54 bufferProto->set_buffer_id(state.bufferId);
55 bufferProto->set_width(state.bufferWidth);
56 bufferProto->set_height(state.bufferHeight);
Vishnu Naird37343b2022-01-12 16:18:56 -080057 bufferProto->set_pixel_format(
58 static_cast<proto::LayerState_BufferData_PixelFormat>(state.pixelFormat));
59 bufferProto->set_usage(state.bufferUsage);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080060 }
61 layerProto.set_has_sideband_stream(state.hasSidebandStream);
62 layerProto.set_layer_id(state.layerId);
63 layerProto.set_parent_id(state.parentId);
64 layerProto.set_relative_parent_id(state.relativeParentId);
65 if (layerProto.has_window_info_handle()) {
66 layerProto.mutable_window_info_handle()->set_crop_layer_id(state.inputCropId);
67 }
68 proto.mutable_layer_changes()->Add(std::move(layerProto));
69 }
70 return proto;
71}
72
Vishnu Nair685cfef2022-02-02 10:01:25 -080073proto::LayerState TransactionProtoParser::toProto(const layer_state_t& layer) {
Vishnu Nair6b591152021-10-08 11:45:14 -070074 proto::LayerState proto;
Vishnu Nair685cfef2022-02-02 10:01:25 -080075 if (layer.surface) {
76 proto.set_layer_id(mMapper->getLayerId(layer.surface));
Vishnu Nair68dee2b2021-11-08 18:52:12 -080077 } 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 Nair685cfef2022-02-02 10:01:25 -0800139 if (layer.bufferData->hasBuffer()) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800140 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 Nair685cfef2022-02-02 10:01:25 -0800146 } else {
147 uint64_t bufferId;
148 uint32_t width;
149 uint32_t height;
150 int32_t pixelFormat;
151 uint64_t usage;
152 mMapper->getGraphicBufferPropertiesFromCache(layer.bufferData->cachedBuffer, &bufferId,
153 &width, &height, &pixelFormat, &usage);
154 bufferProto->set_buffer_id(bufferId);
155 bufferProto->set_width(width);
156 bufferProto->set_height(height);
157 bufferProto->set_pixel_format(
158 static_cast<proto::LayerState_BufferData_PixelFormat>(pixelFormat));
159 bufferProto->set_usage(usage);
Vishnu Nair6b591152021-10-08 11:45:14 -0700160 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800161 bufferProto->set_frame_number(layer.bufferData->frameNumber);
162 bufferProto->set_flags(layer.bufferData->flags.get());
163 bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id);
Vishnu Nair6b591152021-10-08 11:45:14 -0700164 }
165 if (layer.what & layer_state_t::eSidebandStreamChanged) {
166 proto.set_has_sideband_stream(layer.sidebandStream != nullptr);
167 }
168
169 if (layer.what & layer_state_t::eApiChanged) {
170 proto.set_api(layer.api);
171 }
172
173 if (layer.what & layer_state_t::eColorTransformChanged) {
174 LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform());
175 }
176 if (layer.what & layer_state_t::eBlurRegionsChanged) {
177 for (auto& region : layer.blurRegions) {
178 LayerProtoHelper::writeToProto(region, proto.add_blur_regions());
179 }
180 }
181
Vishnu Nair685cfef2022-02-02 10:01:25 -0800182 if (layer.what & layer_state_t::eReparent) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700183 int32_t layerId = layer.parentSurfaceControlForChild
Vishnu Nair685cfef2022-02-02 10:01:25 -0800184 ? mMapper->getLayerId(layer.parentSurfaceControlForChild->getHandle())
Vishnu Nair6b591152021-10-08 11:45:14 -0700185 : -1;
186 proto.set_parent_id(layerId);
187 }
Vishnu Nair685cfef2022-02-02 10:01:25 -0800188 if (layer.what & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700189 int32_t layerId = layer.relativeLayerSurfaceControl
Vishnu Nair685cfef2022-02-02 10:01:25 -0800190 ? mMapper->getLayerId(layer.relativeLayerSurfaceControl->getHandle())
Vishnu Nair6b591152021-10-08 11:45:14 -0700191 : -1;
192 proto.set_relative_parent_id(layerId);
Vishnu Naird37343b2022-01-12 16:18:56 -0800193 proto.set_z(layer.z);
Vishnu Nair6b591152021-10-08 11:45:14 -0700194 }
195
196 if (layer.what & layer_state_t::eInputInfoChanged) {
197 if (layer.windowInfoHandle) {
198 const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo();
199 proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle();
200 windowInfoProto->set_layout_params_flags(inputInfo->flags.get());
201 windowInfoProto->set_layout_params_type(static_cast<int32_t>(inputInfo->type));
202 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
203 windowInfoProto->mutable_touchable_region());
204 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
205 windowInfoProto->set_focusable(inputInfo->focusable);
206 windowInfoProto->set_has_wallpaper(inputInfo->hasWallpaper);
207 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
208 proto::LayerState_Transform* transformProto = windowInfoProto->mutable_transform();
209 transformProto->set_dsdx(inputInfo->transform.dsdx());
210 transformProto->set_dtdx(inputInfo->transform.dtdx());
211 transformProto->set_dtdy(inputInfo->transform.dtdy());
212 transformProto->set_dsdy(inputInfo->transform.dsdy());
213 transformProto->set_tx(inputInfo->transform.tx());
214 transformProto->set_ty(inputInfo->transform.ty());
215 windowInfoProto->set_replace_touchable_region_with_crop(
216 inputInfo->replaceTouchableRegionWithCrop);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800217 windowInfoProto->set_crop_layer_id(
218 mMapper->getLayerId(inputInfo->touchableRegionCropHandle.promote()));
Vishnu Nair6b591152021-10-08 11:45:14 -0700219 }
220 }
221 if (layer.what & layer_state_t::eBackgroundColorChanged) {
222 proto.set_bg_color_alpha(layer.bgColorAlpha);
223 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
224 proto::LayerState_Color3* colorProto = proto.mutable_color();
225 colorProto->set_r(layer.color.r);
226 colorProto->set_g(layer.color.g);
227 colorProto->set_b(layer.color.b);
228 }
229 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
230 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
231 }
232 if (layer.what & layer_state_t::eShadowRadiusChanged) {
233 proto.set_shadow_radius(layer.shadowRadius);
234 }
235 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
236 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
237 }
238 if (layer.what & layer_state_t::eFrameRateChanged) {
239 proto.set_frame_rate(layer.frameRate);
240 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
241 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
242 }
243 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
244 proto.set_fixed_transform_hint(layer.fixedTransformHint);
245 }
246 if (layer.what & layer_state_t::eAutoRefreshChanged) {
247 proto.set_auto_refresh(layer.autoRefresh);
248 }
249 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
250 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
251 }
252 if (layer.what & layer_state_t::eBufferCropChanged) {
253 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
254 }
255 if (layer.what & layer_state_t::eDestinationFrameChanged) {
256 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
257 }
258 if (layer.what & layer_state_t::eDropInputModeChanged) {
259 proto.set_drop_input_mode(
260 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
261 }
262 return proto;
263}
264
Vishnu Nair685cfef2022-02-02 10:01:25 -0800265proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700266 proto::DisplayState proto;
267 proto.set_what(display.what);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800268 proto.set_id(mMapper->getDisplayId(display.token));
Vishnu Nair6b591152021-10-08 11:45:14 -0700269
270 if (display.what & DisplayState::eLayerStackChanged) {
271 proto.set_layer_stack(display.layerStack.id);
272 }
273 if (display.what & DisplayState::eDisplayProjectionChanged) {
274 proto.set_orientation(static_cast<uint32_t>(display.orientation));
275 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
276 proto.mutable_oriented_display_space_rect());
277 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
278 proto.mutable_layer_stack_space_rect());
279 }
280 if (display.what & DisplayState::eDisplaySizeChanged) {
281 proto.set_width(display.width);
282 proto.set_height(display.height);
283 }
284 if (display.what & DisplayState::eFlagsChanged) {
285 proto.set_flags(display.flags);
286 }
287 return proto;
288}
289
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800290proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) {
291 proto::LayerCreationArgs proto;
292 proto.set_layer_id(args.layerId);
293 proto.set_name(args.name);
294 proto.set_flags(args.flags);
295 proto.set_parent_id(args.parentId);
Vishnu Nair84125ac2021-12-02 08:47:48 -0800296 proto.set_mirror_from_id(args.mirrorFromId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800297 return proto;
298}
299
Vishnu Nair685cfef2022-02-02 10:01:25 -0800300TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700301 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();
Vishnu Naird37343b2022-01-12 16:18:56 -0800307 t.id = proto.transaction_id();
308
Vishnu Nair6b591152021-10-08 11:45:14 -0700309 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 ComposerState s;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800313 s.state.what = 0;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800314 fromProto(proto.layer_changes(i), s.state);
Vishnu Nair6b591152021-10-08 11:45:14 -0700315 t.states.add(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++) {
Vishnu Nair685cfef2022-02-02 10:01:25 -0800321 t.displays.add(fromProto(proto.display_changes(i)));
Vishnu Nair6b591152021-10-08 11:45:14 -0700322 }
323 return t;
324}
325
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800326void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
327 TracingLayerCreationArgs& outArgs) {
328 outArgs.layerId = proto.layer_id();
329 outArgs.name = proto.name();
330 outArgs.flags = proto.flags();
331 outArgs.parentId = proto.parent_id();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800332 outArgs.mirrorFromId = proto.mirror_from_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800333}
Vishnu Nair6b591152021-10-08 11:45:14 -0700334
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800335void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto,
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800336 TracingLayerState& outState) {
337 layer_state_t state;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800338 fromProto(proto, state);
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800339 outState.merge(state);
340
341 if (state.what & layer_state_t::eReparent) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800342 outState.parentId = proto.parent_id();
343 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800344 if (state.what & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800345 outState.relativeParentId = proto.relative_parent_id();
346 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800347 if (state.what & layer_state_t::eInputInfoChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800348 outState.inputCropId = proto.window_info_handle().crop_layer_id();
349 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800350 if (state.what & layer_state_t::eBufferChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800351 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
352 outState.bufferId = bufferProto.buffer_id();
353 outState.bufferWidth = bufferProto.width();
354 outState.bufferHeight = bufferProto.height();
Vishnu Naird37343b2022-01-12 16:18:56 -0800355 outState.pixelFormat = bufferProto.pixel_format();
356 outState.bufferUsage = bufferProto.usage();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800357 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800358 if (state.what & layer_state_t::eSidebandStreamChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800359 outState.hasSidebandStream = proto.has_sideband_stream();
360 }
361}
362
Vishnu Nair685cfef2022-02-02 10:01:25 -0800363void TransactionProtoParser::fromProto(const proto::LayerState& proto, layer_state_t& layer) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800364 layer.layerId = proto.layer_id();
365 layer.what |= proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800366 layer.surface = mMapper->getLayerHandle(layer.layerId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800367
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 Nair6b591152021-10-08 11:45:14 -0700423 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800424 layer.bufferData =
425 std::move(mMapper->getGraphicData(bufferProto.buffer_id(), bufferProto.width(),
426 bufferProto.height(), bufferProto.pixel_format(),
427 bufferProto.usage()));
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800428 layer.bufferData->frameNumber = bufferProto.frame_number();
429 layer.bufferData->flags = Flags<BufferData::BufferDataChange>(bufferProto.flags());
430 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
Vishnu Nair6b591152021-10-08 11:45:14 -0700431 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700432
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800433 if (proto.what() & layer_state_t::eApiChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700434 layer.api = proto.api();
435 }
436
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800437 if (proto.what() & layer_state_t::eColorTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700438 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
439 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800440 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700441 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
442 for (int i = 0; i < proto.blur_regions_size(); i++) {
443 android::BlurRegion region;
444 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
445 layer.blurRegions.push_back(region);
446 }
447 }
448
Vishnu Nair685cfef2022-02-02 10:01:25 -0800449 if (proto.what() & layer_state_t::eReparent) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700450 int32_t layerId = proto.parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800451 if (layerId == -1) {
452 layer.parentSurfaceControlForChild = nullptr;
453 } else {
454 layer.parentSurfaceControlForChild =
Vishnu Nair685cfef2022-02-02 10:01:25 -0800455 new SurfaceControl(SurfaceComposerClient::getDefault(),
456 mMapper->getLayerHandle(layerId), nullptr, layerId);
Vishnu Naird37343b2022-01-12 16:18:56 -0800457 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700458 }
Vishnu Naird37343b2022-01-12 16:18:56 -0800459 if (proto.what() & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700460 int32_t layerId = proto.relative_parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800461 if (layerId == -1) {
462 layer.relativeLayerSurfaceControl = nullptr;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800463 } else {
Vishnu Naird37343b2022-01-12 16:18:56 -0800464 layer.relativeLayerSurfaceControl =
Vishnu Nair685cfef2022-02-02 10:01:25 -0800465 new SurfaceControl(SurfaceComposerClient::getDefault(),
466 mMapper->getLayerHandle(layerId), nullptr, layerId);
Vishnu Naird37343b2022-01-12 16:18:56 -0800467 }
468 layer.z = proto.z();
Vishnu Nair6b591152021-10-08 11:45:14 -0700469 }
470
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800471 if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700472 gui::WindowInfo inputInfo;
473 const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
474
475 inputInfo.flags = static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
476 inputInfo.type = static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
477 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
478 inputInfo.touchableRegion);
479 inputInfo.surfaceInset = windowInfoProto.surface_inset();
480 inputInfo.focusable = windowInfoProto.focusable();
481 inputInfo.hasWallpaper = windowInfoProto.has_wallpaper();
482 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
483 const proto::LayerState_Transform& transformProto = windowInfoProto.transform();
484 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
485 transformProto.dsdy());
486 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
487 inputInfo.replaceTouchableRegionWithCrop =
488 windowInfoProto.replace_touchable_region_with_crop();
489 int32_t layerId = windowInfoProto.crop_layer_id();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800490 inputInfo.touchableRegionCropHandle = mMapper->getLayerHandle(layerId);
Vishnu Nair6b591152021-10-08 11:45:14 -0700491 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
492 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800493 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700494 layer.bgColorAlpha = proto.bg_color_alpha();
495 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
496 const proto::LayerState_Color3& colorProto = proto.color();
497 layer.color.r = colorProto.r();
498 layer.color.g = colorProto.g();
499 layer.color.b = colorProto.b();
500 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800501 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700502 layer.colorSpaceAgnostic = proto.color_space_agnostic();
503 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800504 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700505 layer.shadowRadius = proto.shadow_radius();
506 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800507 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700508 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
509 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800510 if (proto.what() & layer_state_t::eFrameRateChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700511 layer.frameRate = proto.frame_rate();
512 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
513 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
514 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800515 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700516 layer.fixedTransformHint =
517 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
518 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800519 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700520 layer.autoRefresh = proto.auto_refresh();
521 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800522 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700523 layer.isTrustedOverlay = proto.is_trusted_overlay();
524 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800525 if (proto.what() & layer_state_t::eBufferCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700526 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
527 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800528 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700529 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
530 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800531 if (proto.what() & layer_state_t::eDropInputModeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700532 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
533 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700534}
535
Vishnu Nair685cfef2022-02-02 10:01:25 -0800536DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700537 DisplayState display;
538 display.what = proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800539 display.token = mMapper->getDisplayHandle(proto.id());
Vishnu Nair6b591152021-10-08 11:45:14 -0700540
541 if (display.what & DisplayState::eLayerStackChanged) {
542 display.layerStack.id = proto.layer_stack();
543 }
544 if (display.what & DisplayState::eDisplayProjectionChanged) {
545 display.orientation = static_cast<ui::Rotation>(proto.orientation());
546 LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
547 display.orientedDisplaySpaceRect);
548 LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
549 display.layerStackSpaceRect);
550 }
551 if (display.what & DisplayState::eDisplaySizeChanged) {
552 display.width = proto.width();
553 display.height = proto.height();
554 }
555 if (display.what & DisplayState::eFlagsChanged) {
556 display.flags = proto.flags();
557 }
558 return display;
559}
560
561} // namespace android::surfaceflinger