blob: d249b60f2ad7b91b2010022cdab6e9792c8592a0 [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) {
Robert Carra63d52a2022-03-03 08:03:37 -0800183 int64_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) {
Robert Carra63d52a2022-03-03 08:03:37 -0800189 int64_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();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800200 windowInfoProto->set_layout_params_flags(inputInfo->layoutParamsFlags.get());
201 windowInfoProto->set_layout_params_type(
202 static_cast<int32_t>(inputInfo->layoutParamsType));
Vishnu Nair6b591152021-10-08 11:45:14 -0700203 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
204 windowInfoProto->mutable_touchable_region());
205 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800206 windowInfoProto->set_focusable(
207 !inputInfo->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE));
208 windowInfoProto->set_has_wallpaper(inputInfo->inputConfig.test(
209 gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER));
Vishnu Nair6b591152021-10-08 11:45:14 -0700210 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
211 proto::LayerState_Transform* transformProto = windowInfoProto->mutable_transform();
212 transformProto->set_dsdx(inputInfo->transform.dsdx());
213 transformProto->set_dtdx(inputInfo->transform.dtdx());
214 transformProto->set_dtdy(inputInfo->transform.dtdy());
215 transformProto->set_dsdy(inputInfo->transform.dsdy());
216 transformProto->set_tx(inputInfo->transform.tx());
217 transformProto->set_ty(inputInfo->transform.ty());
218 windowInfoProto->set_replace_touchable_region_with_crop(
219 inputInfo->replaceTouchableRegionWithCrop);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800220 windowInfoProto->set_crop_layer_id(
221 mMapper->getLayerId(inputInfo->touchableRegionCropHandle.promote()));
Vishnu Nair6b591152021-10-08 11:45:14 -0700222 }
223 }
224 if (layer.what & layer_state_t::eBackgroundColorChanged) {
225 proto.set_bg_color_alpha(layer.bgColorAlpha);
226 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
227 proto::LayerState_Color3* colorProto = proto.mutable_color();
228 colorProto->set_r(layer.color.r);
229 colorProto->set_g(layer.color.g);
230 colorProto->set_b(layer.color.b);
231 }
232 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
233 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
234 }
235 if (layer.what & layer_state_t::eShadowRadiusChanged) {
236 proto.set_shadow_radius(layer.shadowRadius);
237 }
238 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
239 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
240 }
241 if (layer.what & layer_state_t::eFrameRateChanged) {
242 proto.set_frame_rate(layer.frameRate);
243 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
244 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
245 }
246 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
247 proto.set_fixed_transform_hint(layer.fixedTransformHint);
248 }
249 if (layer.what & layer_state_t::eAutoRefreshChanged) {
250 proto.set_auto_refresh(layer.autoRefresh);
251 }
252 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
253 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
254 }
255 if (layer.what & layer_state_t::eBufferCropChanged) {
256 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
257 }
258 if (layer.what & layer_state_t::eDestinationFrameChanged) {
259 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
260 }
261 if (layer.what & layer_state_t::eDropInputModeChanged) {
262 proto.set_drop_input_mode(
263 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
264 }
265 return proto;
266}
267
Vishnu Nair685cfef2022-02-02 10:01:25 -0800268proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700269 proto::DisplayState proto;
270 proto.set_what(display.what);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800271 proto.set_id(mMapper->getDisplayId(display.token));
Vishnu Nair6b591152021-10-08 11:45:14 -0700272
273 if (display.what & DisplayState::eLayerStackChanged) {
274 proto.set_layer_stack(display.layerStack.id);
275 }
276 if (display.what & DisplayState::eDisplayProjectionChanged) {
277 proto.set_orientation(static_cast<uint32_t>(display.orientation));
278 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
279 proto.mutable_oriented_display_space_rect());
280 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
281 proto.mutable_layer_stack_space_rect());
282 }
283 if (display.what & DisplayState::eDisplaySizeChanged) {
284 proto.set_width(display.width);
285 proto.set_height(display.height);
286 }
287 if (display.what & DisplayState::eFlagsChanged) {
288 proto.set_flags(display.flags);
289 }
290 return proto;
291}
292
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800293proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) {
294 proto::LayerCreationArgs proto;
295 proto.set_layer_id(args.layerId);
296 proto.set_name(args.name);
297 proto.set_flags(args.flags);
298 proto.set_parent_id(args.parentId);
Vishnu Nair84125ac2021-12-02 08:47:48 -0800299 proto.set_mirror_from_id(args.mirrorFromId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800300 return proto;
301}
302
Vishnu Nair685cfef2022-02-02 10:01:25 -0800303TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700304 TransactionState t;
305 t.originPid = proto.pid();
306 t.originUid = proto.uid();
307 t.frameTimelineInfo.vsyncId = proto.vsync_id();
308 t.frameTimelineInfo.inputEventId = proto.input_event_id();
309 t.postTime = proto.post_time();
Vishnu Naird37343b2022-01-12 16:18:56 -0800310 t.id = proto.transaction_id();
311
Vishnu Nair6b591152021-10-08 11:45:14 -0700312 int32_t layerCount = proto.layer_changes_size();
313 t.states.reserve(static_cast<size_t>(layerCount));
314 for (int i = 0; i < layerCount; i++) {
315 ComposerState s;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800316 s.state.what = 0;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800317 fromProto(proto.layer_changes(i), s.state);
Vishnu Nair6b591152021-10-08 11:45:14 -0700318 t.states.add(s);
319 }
320
321 int32_t displayCount = proto.display_changes_size();
322 t.displays.reserve(static_cast<size_t>(displayCount));
323 for (int i = 0; i < displayCount; i++) {
Vishnu Nair685cfef2022-02-02 10:01:25 -0800324 t.displays.add(fromProto(proto.display_changes(i)));
Vishnu Nair6b591152021-10-08 11:45:14 -0700325 }
326 return t;
327}
328
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800329void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
330 TracingLayerCreationArgs& outArgs) {
331 outArgs.layerId = proto.layer_id();
332 outArgs.name = proto.name();
333 outArgs.flags = proto.flags();
334 outArgs.parentId = proto.parent_id();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800335 outArgs.mirrorFromId = proto.mirror_from_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800336}
Vishnu Nair6b591152021-10-08 11:45:14 -0700337
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800338void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto,
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800339 TracingLayerState& outState) {
340 layer_state_t state;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800341 fromProto(proto, state);
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800342 outState.merge(state);
343
344 if (state.what & layer_state_t::eReparent) {
Robert Carra63d52a2022-03-03 08:03:37 -0800345 outState.parentId = static_cast<int32_t>(proto.parent_id());
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800346 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800347 if (state.what & layer_state_t::eRelativeLayerChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800348 outState.relativeParentId = static_cast<int32_t>(proto.relative_parent_id());
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800349 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800350 if (state.what & layer_state_t::eInputInfoChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800351 outState.inputCropId = static_cast<int32_t>(proto.window_info_handle().crop_layer_id());
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800352 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800353 if (state.what & layer_state_t::eBufferChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800354 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
355 outState.bufferId = bufferProto.buffer_id();
356 outState.bufferWidth = bufferProto.width();
357 outState.bufferHeight = bufferProto.height();
Vishnu Naird37343b2022-01-12 16:18:56 -0800358 outState.pixelFormat = bufferProto.pixel_format();
359 outState.bufferUsage = bufferProto.usage();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800360 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800361 if (state.what & layer_state_t::eSidebandStreamChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800362 outState.hasSidebandStream = proto.has_sideband_stream();
363 }
364}
365
Vishnu Nair685cfef2022-02-02 10:01:25 -0800366void TransactionProtoParser::fromProto(const proto::LayerState& proto, layer_state_t& layer) {
Robert Carra63d52a2022-03-03 08:03:37 -0800367 layer.layerId = (int32_t)proto.layer_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800368 layer.what |= proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800369 layer.surface = mMapper->getLayerHandle(layer.layerId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800370
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 Nair6b591152021-10-08 11:45:14 -0700426 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800427 layer.bufferData =
428 std::move(mMapper->getGraphicData(bufferProto.buffer_id(), bufferProto.width(),
429 bufferProto.height(), bufferProto.pixel_format(),
430 bufferProto.usage()));
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800431 layer.bufferData->frameNumber = bufferProto.frame_number();
432 layer.bufferData->flags = Flags<BufferData::BufferDataChange>(bufferProto.flags());
433 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
Robert Carr4ade7bf2022-03-05 14:25:47 -0800434 layer.bufferData->acquireFence = Fence::NO_FENCE;
Vishnu Nair6b591152021-10-08 11:45:14 -0700435 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700436
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800437 if (proto.what() & layer_state_t::eApiChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700438 layer.api = proto.api();
439 }
440
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800441 if (proto.what() & layer_state_t::eColorTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700442 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
443 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800444 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700445 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
446 for (int i = 0; i < proto.blur_regions_size(); i++) {
447 android::BlurRegion region;
448 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
449 layer.blurRegions.push_back(region);
450 }
451 }
452
Vishnu Nair685cfef2022-02-02 10:01:25 -0800453 if (proto.what() & layer_state_t::eReparent) {
Robert Carra63d52a2022-03-03 08:03:37 -0800454 int64_t layerId = proto.parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800455 if (layerId == -1) {
456 layer.parentSurfaceControlForChild = nullptr;
457 } else {
458 layer.parentSurfaceControlForChild =
Vishnu Nair685cfef2022-02-02 10:01:25 -0800459 new SurfaceControl(SurfaceComposerClient::getDefault(),
Robert Carra63d52a2022-03-03 08:03:37 -0800460 mMapper->getLayerHandle(static_cast<int32_t>(layerId)),
461 nullptr, static_cast<int32_t>(layerId));
Vishnu Naird37343b2022-01-12 16:18:56 -0800462 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700463 }
Vishnu Naird37343b2022-01-12 16:18:56 -0800464 if (proto.what() & layer_state_t::eRelativeLayerChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800465 int64_t layerId = proto.relative_parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800466 if (layerId == -1) {
467 layer.relativeLayerSurfaceControl = nullptr;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800468 } else {
Vishnu Naird37343b2022-01-12 16:18:56 -0800469 layer.relativeLayerSurfaceControl =
Vishnu Nair685cfef2022-02-02 10:01:25 -0800470 new SurfaceControl(SurfaceComposerClient::getDefault(),
Robert Carra63d52a2022-03-03 08:03:37 -0800471 mMapper->getLayerHandle(static_cast<int32_t>(layerId)),
472 nullptr, static_cast<int32_t>(layerId));
Vishnu Naird37343b2022-01-12 16:18:56 -0800473 }
474 layer.z = proto.z();
Vishnu Nair6b591152021-10-08 11:45:14 -0700475 }
476
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800477 if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700478 gui::WindowInfo inputInfo;
479 const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
480
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800481 inputInfo.layoutParamsFlags =
482 static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
483 inputInfo.layoutParamsType =
484 static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
Vishnu Nair6b591152021-10-08 11:45:14 -0700485 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
486 inputInfo.touchableRegion);
487 inputInfo.surfaceInset = windowInfoProto.surface_inset();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800488 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_FOCUSABLE,
489 !windowInfoProto.focusable());
490 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER,
491 windowInfoProto.has_wallpaper());
Vishnu Nair6b591152021-10-08 11:45:14 -0700492 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
493 const proto::LayerState_Transform& transformProto = windowInfoProto.transform();
494 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
495 transformProto.dsdy());
496 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
497 inputInfo.replaceTouchableRegionWithCrop =
498 windowInfoProto.replace_touchable_region_with_crop();
Robert Carra63d52a2022-03-03 08:03:37 -0800499 int64_t layerId = windowInfoProto.crop_layer_id();
500 inputInfo.touchableRegionCropHandle =
501 mMapper->getLayerHandle(static_cast<int32_t>(layerId));
Vishnu Nair6b591152021-10-08 11:45:14 -0700502 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
503 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800504 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700505 layer.bgColorAlpha = proto.bg_color_alpha();
506 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
507 const proto::LayerState_Color3& colorProto = proto.color();
508 layer.color.r = colorProto.r();
509 layer.color.g = colorProto.g();
510 layer.color.b = colorProto.b();
511 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800512 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700513 layer.colorSpaceAgnostic = proto.color_space_agnostic();
514 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800515 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700516 layer.shadowRadius = proto.shadow_radius();
517 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800518 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700519 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
520 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800521 if (proto.what() & layer_state_t::eFrameRateChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700522 layer.frameRate = proto.frame_rate();
523 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
524 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
525 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800526 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700527 layer.fixedTransformHint =
528 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
529 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800530 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700531 layer.autoRefresh = proto.auto_refresh();
532 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800533 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700534 layer.isTrustedOverlay = proto.is_trusted_overlay();
535 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800536 if (proto.what() & layer_state_t::eBufferCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700537 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
538 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800539 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700540 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
541 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800542 if (proto.what() & layer_state_t::eDropInputModeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700543 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
544 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700545}
546
Vishnu Nair685cfef2022-02-02 10:01:25 -0800547DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700548 DisplayState display;
549 display.what = proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800550 display.token = mMapper->getDisplayHandle(proto.id());
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