blob: 4cd5ace45fa5a3dd124b8f325d4965b0b1c775d4 [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>
Vishnu Nair8eebba42022-02-25 07:57:15 -080018#include <ui/Fence.h>
Vishnu Nair6b591152021-10-08 11:45:14 -070019#include <ui/Rect.h>
20
21#include "LayerProtoHelper.h"
22#include "TransactionProtoParser.h"
23
24namespace android::surfaceflinger {
25
Vishnu Nair685cfef2022-02-02 10:01:25 -080026proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t) {
Vishnu Nair6b591152021-10-08 11:45:14 -070027 proto::TransactionState proto;
28 proto.set_pid(t.originPid);
29 proto.set_uid(t.originUid);
30 proto.set_vsync_id(t.frameTimelineInfo.vsyncId);
31 proto.set_input_event_id(t.frameTimelineInfo.inputEventId);
32 proto.set_post_time(t.postTime);
Vishnu Naird37343b2022-01-12 16:18:56 -080033 proto.set_transaction_id(t.id);
Vishnu Nair6b591152021-10-08 11:45:14 -070034
Vishnu Nair685cfef2022-02-02 10:01:25 -080035 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(t.states.size()));
Vishnu Nair6b591152021-10-08 11:45:14 -070036 for (auto& layerState : t.states) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080037 proto.mutable_layer_changes()->Add(std::move(toProto(layerState.state)));
Vishnu Nair6b591152021-10-08 11:45:14 -070038 }
39
Vishnu Nair685cfef2022-02-02 10:01:25 -080040 proto.mutable_display_changes()->Reserve(static_cast<int32_t>(t.displays.size()));
Vishnu Nair6b591152021-10-08 11:45:14 -070041 for (auto& displayState : t.displays) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080042 proto.mutable_display_changes()->Add(std::move(toProto(displayState)));
Vishnu Nair6b591152021-10-08 11:45:14 -070043 }
44 return proto;
45}
46
Vishnu Nair68dee2b2021-11-08 18:52:12 -080047proto::TransactionState TransactionProtoParser::toProto(
Greg Kaiser2c909852021-12-07 09:45:29 -080048 const std::map<int32_t /* layerId */, TracingLayerState>& states) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -080049 proto::TransactionState proto;
Vishnu Nair685cfef2022-02-02 10:01:25 -080050 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(states.size()));
Vishnu Nair68dee2b2021-11-08 18:52:12 -080051 for (auto& [layerId, state] : states) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080052 proto::LayerState layerProto = toProto(state);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080053 if (layerProto.has_buffer_data()) {
54 proto::LayerState_BufferData* bufferProto = layerProto.mutable_buffer_data();
55 bufferProto->set_buffer_id(state.bufferId);
56 bufferProto->set_width(state.bufferWidth);
57 bufferProto->set_height(state.bufferHeight);
Vishnu Naird37343b2022-01-12 16:18:56 -080058 bufferProto->set_pixel_format(
59 static_cast<proto::LayerState_BufferData_PixelFormat>(state.pixelFormat));
60 bufferProto->set_usage(state.bufferUsage);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080061 }
62 layerProto.set_has_sideband_stream(state.hasSidebandStream);
63 layerProto.set_layer_id(state.layerId);
64 layerProto.set_parent_id(state.parentId);
65 layerProto.set_relative_parent_id(state.relativeParentId);
66 if (layerProto.has_window_info_handle()) {
67 layerProto.mutable_window_info_handle()->set_crop_layer_id(state.inputCropId);
68 }
69 proto.mutable_layer_changes()->Add(std::move(layerProto));
70 }
71 return proto;
72}
73
Vishnu Nair685cfef2022-02-02 10:01:25 -080074proto::LayerState TransactionProtoParser::toProto(const layer_state_t& layer) {
Vishnu Nair6b591152021-10-08 11:45:14 -070075 proto::LayerState proto;
Vishnu Nair685cfef2022-02-02 10:01:25 -080076 if (layer.surface) {
77 proto.set_layer_id(mMapper->getLayerId(layer.surface));
Vishnu Nair68dee2b2021-11-08 18:52:12 -080078 } else {
79 proto.set_layer_id(layer.layerId);
80 }
81
Vishnu Nair6b591152021-10-08 11:45:14 -070082 proto.set_what(layer.what);
83
84 if (layer.what & layer_state_t::ePositionChanged) {
85 proto.set_x(layer.x);
86 proto.set_y(layer.y);
87 }
88 if (layer.what & layer_state_t::eLayerChanged) {
89 proto.set_z(layer.z);
90 }
91 if (layer.what & layer_state_t::eSizeChanged) {
92 proto.set_w(layer.w);
93 proto.set_h(layer.h);
94 }
95 if (layer.what & layer_state_t::eLayerStackChanged) {
96 proto.set_layer_stack(layer.layerStack.id);
97 }
98 if (layer.what & layer_state_t::eFlagsChanged) {
99 proto.set_flags(layer.flags);
100 proto.set_mask(layer.mask);
101 }
102 if (layer.what & layer_state_t::eMatrixChanged) {
103 proto::LayerState_Matrix22* matrixProto = proto.mutable_matrix();
104 matrixProto->set_dsdx(layer.matrix.dsdx);
105 matrixProto->set_dsdy(layer.matrix.dsdy);
106 matrixProto->set_dtdx(layer.matrix.dtdx);
107 matrixProto->set_dtdy(layer.matrix.dtdy);
108 }
109 if (layer.what & layer_state_t::eCornerRadiusChanged) {
110 proto.set_corner_radius(layer.cornerRadius);
111 }
112 if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) {
113 proto.set_background_blur_radius(layer.backgroundBlurRadius);
114 }
115
116 if (layer.what & layer_state_t::eAlphaChanged) {
117 proto.set_alpha(layer.alpha);
118 }
119
120 if (layer.what & layer_state_t::eColorChanged) {
121 proto::LayerState_Color3* colorProto = proto.mutable_color();
122 colorProto->set_r(layer.color.r);
123 colorProto->set_g(layer.color.g);
124 colorProto->set_b(layer.color.b);
125 }
126 if (layer.what & layer_state_t::eTransparentRegionChanged) {
127 LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region());
128 }
129 if (layer.what & layer_state_t::eTransformChanged) {
130 proto.set_transform(layer.transform);
131 }
132 if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
133 proto.set_transform_to_display_inverse(layer.transformToDisplayInverse);
134 }
135 if (layer.what & layer_state_t::eCropChanged) {
136 LayerProtoHelper::writeToProto(layer.crop, proto.mutable_crop());
137 }
138 if (layer.what & layer_state_t::eBufferChanged) {
139 proto::LayerState_BufferData* bufferProto = proto.mutable_buffer_data();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800140 if (layer.bufferData->hasBuffer()) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800141 bufferProto->set_buffer_id(layer.bufferData->getId());
142 bufferProto->set_width(layer.bufferData->getWidth());
143 bufferProto->set_height(layer.bufferData->getHeight());
Vishnu Naird37343b2022-01-12 16:18:56 -0800144 bufferProto->set_pixel_format(static_cast<proto::LayerState_BufferData_PixelFormat>(
145 layer.bufferData->getPixelFormat()));
146 bufferProto->set_usage(layer.bufferData->getUsage());
Vishnu Nair685cfef2022-02-02 10:01:25 -0800147 } else {
148 uint64_t bufferId;
149 uint32_t width;
150 uint32_t height;
151 int32_t pixelFormat;
152 uint64_t usage;
153 mMapper->getGraphicBufferPropertiesFromCache(layer.bufferData->cachedBuffer, &bufferId,
154 &width, &height, &pixelFormat, &usage);
155 bufferProto->set_buffer_id(bufferId);
156 bufferProto->set_width(width);
157 bufferProto->set_height(height);
158 bufferProto->set_pixel_format(
159 static_cast<proto::LayerState_BufferData_PixelFormat>(pixelFormat));
160 bufferProto->set_usage(usage);
Vishnu Nair6b591152021-10-08 11:45:14 -0700161 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800162 bufferProto->set_frame_number(layer.bufferData->frameNumber);
163 bufferProto->set_flags(layer.bufferData->flags.get());
164 bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id);
Vishnu Nair6b591152021-10-08 11:45:14 -0700165 }
166 if (layer.what & layer_state_t::eSidebandStreamChanged) {
167 proto.set_has_sideband_stream(layer.sidebandStream != nullptr);
168 }
169
170 if (layer.what & layer_state_t::eApiChanged) {
171 proto.set_api(layer.api);
172 }
173
174 if (layer.what & layer_state_t::eColorTransformChanged) {
175 LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform());
176 }
177 if (layer.what & layer_state_t::eBlurRegionsChanged) {
178 for (auto& region : layer.blurRegions) {
179 LayerProtoHelper::writeToProto(region, proto.add_blur_regions());
180 }
181 }
182
Vishnu Nair685cfef2022-02-02 10:01:25 -0800183 if (layer.what & layer_state_t::eReparent) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700184 int32_t layerId = layer.parentSurfaceControlForChild
Vishnu Nair685cfef2022-02-02 10:01:25 -0800185 ? mMapper->getLayerId(layer.parentSurfaceControlForChild->getHandle())
Vishnu Nair6b591152021-10-08 11:45:14 -0700186 : -1;
187 proto.set_parent_id(layerId);
188 }
Vishnu Nair685cfef2022-02-02 10:01:25 -0800189 if (layer.what & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700190 int32_t layerId = layer.relativeLayerSurfaceControl
Vishnu Nair685cfef2022-02-02 10:01:25 -0800191 ? mMapper->getLayerId(layer.relativeLayerSurfaceControl->getHandle())
Vishnu Nair6b591152021-10-08 11:45:14 -0700192 : -1;
193 proto.set_relative_parent_id(layerId);
Vishnu Naird37343b2022-01-12 16:18:56 -0800194 proto.set_z(layer.z);
Vishnu Nair6b591152021-10-08 11:45:14 -0700195 }
196
197 if (layer.what & layer_state_t::eInputInfoChanged) {
198 if (layer.windowInfoHandle) {
199 const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo();
200 proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800201 windowInfoProto->set_layout_params_flags(inputInfo->layoutParamsFlags.get());
202 windowInfoProto->set_layout_params_type(
203 static_cast<int32_t>(inputInfo->layoutParamsType));
Vishnu Nair6b591152021-10-08 11:45:14 -0700204 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
205 windowInfoProto->mutable_touchable_region());
206 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800207 windowInfoProto->set_focusable(
208 !inputInfo->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE));
209 windowInfoProto->set_has_wallpaper(inputInfo->inputConfig.test(
210 gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER));
Vishnu Nair6b591152021-10-08 11:45:14 -0700211 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
212 proto::LayerState_Transform* transformProto = windowInfoProto->mutable_transform();
213 transformProto->set_dsdx(inputInfo->transform.dsdx());
214 transformProto->set_dtdx(inputInfo->transform.dtdx());
215 transformProto->set_dtdy(inputInfo->transform.dtdy());
216 transformProto->set_dsdy(inputInfo->transform.dsdy());
217 transformProto->set_tx(inputInfo->transform.tx());
218 transformProto->set_ty(inputInfo->transform.ty());
219 windowInfoProto->set_replace_touchable_region_with_crop(
220 inputInfo->replaceTouchableRegionWithCrop);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800221 windowInfoProto->set_crop_layer_id(
222 mMapper->getLayerId(inputInfo->touchableRegionCropHandle.promote()));
Vishnu Nair6b591152021-10-08 11:45:14 -0700223 }
224 }
225 if (layer.what & layer_state_t::eBackgroundColorChanged) {
226 proto.set_bg_color_alpha(layer.bgColorAlpha);
227 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
228 proto::LayerState_Color3* colorProto = proto.mutable_color();
229 colorProto->set_r(layer.color.r);
230 colorProto->set_g(layer.color.g);
231 colorProto->set_b(layer.color.b);
232 }
233 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
234 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
235 }
236 if (layer.what & layer_state_t::eShadowRadiusChanged) {
237 proto.set_shadow_radius(layer.shadowRadius);
238 }
239 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
240 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
241 }
242 if (layer.what & layer_state_t::eFrameRateChanged) {
243 proto.set_frame_rate(layer.frameRate);
244 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
245 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
246 }
247 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
248 proto.set_fixed_transform_hint(layer.fixedTransformHint);
249 }
250 if (layer.what & layer_state_t::eAutoRefreshChanged) {
251 proto.set_auto_refresh(layer.autoRefresh);
252 }
253 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
254 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
255 }
256 if (layer.what & layer_state_t::eBufferCropChanged) {
257 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
258 }
259 if (layer.what & layer_state_t::eDestinationFrameChanged) {
260 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
261 }
262 if (layer.what & layer_state_t::eDropInputModeChanged) {
263 proto.set_drop_input_mode(
264 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
265 }
266 return proto;
267}
268
Vishnu Nair685cfef2022-02-02 10:01:25 -0800269proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700270 proto::DisplayState proto;
271 proto.set_what(display.what);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800272 proto.set_id(mMapper->getDisplayId(display.token));
Vishnu Nair6b591152021-10-08 11:45:14 -0700273
274 if (display.what & DisplayState::eLayerStackChanged) {
275 proto.set_layer_stack(display.layerStack.id);
276 }
277 if (display.what & DisplayState::eDisplayProjectionChanged) {
278 proto.set_orientation(static_cast<uint32_t>(display.orientation));
279 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
280 proto.mutable_oriented_display_space_rect());
281 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
282 proto.mutable_layer_stack_space_rect());
283 }
284 if (display.what & DisplayState::eDisplaySizeChanged) {
285 proto.set_width(display.width);
286 proto.set_height(display.height);
287 }
288 if (display.what & DisplayState::eFlagsChanged) {
289 proto.set_flags(display.flags);
290 }
291 return proto;
292}
293
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800294proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) {
295 proto::LayerCreationArgs proto;
296 proto.set_layer_id(args.layerId);
297 proto.set_name(args.name);
298 proto.set_flags(args.flags);
299 proto.set_parent_id(args.parentId);
Vishnu Nair84125ac2021-12-02 08:47:48 -0800300 proto.set_mirror_from_id(args.mirrorFromId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800301 return proto;
302}
303
Vishnu Nair685cfef2022-02-02 10:01:25 -0800304TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700305 TransactionState t;
306 t.originPid = proto.pid();
307 t.originUid = proto.uid();
308 t.frameTimelineInfo.vsyncId = proto.vsync_id();
309 t.frameTimelineInfo.inputEventId = proto.input_event_id();
310 t.postTime = proto.post_time();
Vishnu Naird37343b2022-01-12 16:18:56 -0800311 t.id = proto.transaction_id();
312
Vishnu Nair6b591152021-10-08 11:45:14 -0700313 int32_t layerCount = proto.layer_changes_size();
314 t.states.reserve(static_cast<size_t>(layerCount));
315 for (int i = 0; i < layerCount; i++) {
316 ComposerState s;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800317 s.state.what = 0;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800318 fromProto(proto.layer_changes(i), s.state);
Vishnu Nair6b591152021-10-08 11:45:14 -0700319 t.states.add(s);
320 }
321
322 int32_t displayCount = proto.display_changes_size();
323 t.displays.reserve(static_cast<size_t>(displayCount));
324 for (int i = 0; i < displayCount; i++) {
Vishnu Nair685cfef2022-02-02 10:01:25 -0800325 t.displays.add(fromProto(proto.display_changes(i)));
Vishnu Nair6b591152021-10-08 11:45:14 -0700326 }
327 return t;
328}
329
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800330void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
331 TracingLayerCreationArgs& outArgs) {
332 outArgs.layerId = proto.layer_id();
333 outArgs.name = proto.name();
334 outArgs.flags = proto.flags();
335 outArgs.parentId = proto.parent_id();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800336 outArgs.mirrorFromId = proto.mirror_from_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800337}
Vishnu Nair6b591152021-10-08 11:45:14 -0700338
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800339void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto,
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800340 TracingLayerState& outState) {
341 layer_state_t state;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800342 fromProto(proto, state);
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800343 outState.merge(state);
344
345 if (state.what & layer_state_t::eReparent) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800346 outState.parentId = proto.parent_id();
347 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800348 if (state.what & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800349 outState.relativeParentId = proto.relative_parent_id();
350 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800351 if (state.what & layer_state_t::eInputInfoChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800352 outState.inputCropId = proto.window_info_handle().crop_layer_id();
353 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800354 if (state.what & layer_state_t::eBufferChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800355 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
356 outState.bufferId = bufferProto.buffer_id();
357 outState.bufferWidth = bufferProto.width();
358 outState.bufferHeight = bufferProto.height();
Vishnu Naird37343b2022-01-12 16:18:56 -0800359 outState.pixelFormat = bufferProto.pixel_format();
360 outState.bufferUsage = bufferProto.usage();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800361 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800362 if (state.what & layer_state_t::eSidebandStreamChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800363 outState.hasSidebandStream = proto.has_sideband_stream();
364 }
365}
366
Vishnu Nair685cfef2022-02-02 10:01:25 -0800367void TransactionProtoParser::fromProto(const proto::LayerState& proto, layer_state_t& layer) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800368 layer.layerId = proto.layer_id();
369 layer.what |= proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800370 layer.surface = mMapper->getLayerHandle(layer.layerId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800371
372 if (proto.what() & layer_state_t::ePositionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700373 layer.x = proto.x();
374 layer.y = proto.y();
375 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800376 if (proto.what() & layer_state_t::eLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700377 layer.z = proto.z();
378 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800379 if (proto.what() & layer_state_t::eSizeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700380 layer.w = proto.w();
381 layer.h = proto.h();
382 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800383 if (proto.what() & layer_state_t::eLayerStackChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700384 layer.layerStack.id = proto.layer_stack();
385 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800386 if (proto.what() & layer_state_t::eFlagsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700387 layer.flags = proto.flags();
388 layer.mask = proto.mask();
389 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800390 if (proto.what() & layer_state_t::eMatrixChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700391 const proto::LayerState_Matrix22& matrixProto = proto.matrix();
392 layer.matrix.dsdx = matrixProto.dsdx();
393 layer.matrix.dsdy = matrixProto.dsdy();
394 layer.matrix.dtdx = matrixProto.dtdx();
395 layer.matrix.dtdy = matrixProto.dtdy();
396 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800397 if (proto.what() & layer_state_t::eCornerRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700398 layer.cornerRadius = proto.corner_radius();
399 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800400 if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700401 layer.backgroundBlurRadius = proto.background_blur_radius();
402 }
403
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800404 if (proto.what() & layer_state_t::eAlphaChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700405 layer.alpha = proto.alpha();
406 }
407
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800408 if (proto.what() & layer_state_t::eColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700409 const proto::LayerState_Color3& colorProto = proto.color();
410 layer.color.r = colorProto.r();
411 layer.color.g = colorProto.g();
412 layer.color.b = colorProto.b();
413 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800414 if (proto.what() & layer_state_t::eTransparentRegionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700415 LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
416 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800417 if (proto.what() & layer_state_t::eTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700418 layer.transform = proto.transform();
419 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800420 if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700421 layer.transformToDisplayInverse = proto.transform_to_display_inverse();
422 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800423 if (proto.what() & layer_state_t::eCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700424 LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
425 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800426 if (proto.what() & layer_state_t::eBufferChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700427 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800428 layer.bufferData =
429 std::move(mMapper->getGraphicData(bufferProto.buffer_id(), bufferProto.width(),
430 bufferProto.height(), bufferProto.pixel_format(),
431 bufferProto.usage()));
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800432 layer.bufferData->frameNumber = bufferProto.frame_number();
433 layer.bufferData->flags = Flags<BufferData::BufferDataChange>(bufferProto.flags());
434 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
Vishnu Nair8eebba42022-02-25 07:57:15 -0800435 layer.bufferData->acquireFence = Fence::NO_FENCE;
Vishnu Nair6b591152021-10-08 11:45:14 -0700436 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700437
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800438 if (proto.what() & layer_state_t::eApiChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700439 layer.api = proto.api();
440 }
441
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800442 if (proto.what() & layer_state_t::eColorTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700443 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
444 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800445 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700446 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
447 for (int i = 0; i < proto.blur_regions_size(); i++) {
448 android::BlurRegion region;
449 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
450 layer.blurRegions.push_back(region);
451 }
452 }
453
Vishnu Nair685cfef2022-02-02 10:01:25 -0800454 if (proto.what() & layer_state_t::eReparent) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700455 int32_t layerId = proto.parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800456 if (layerId == -1) {
457 layer.parentSurfaceControlForChild = nullptr;
458 } else {
459 layer.parentSurfaceControlForChild =
Vishnu Nair685cfef2022-02-02 10:01:25 -0800460 new SurfaceControl(SurfaceComposerClient::getDefault(),
461 mMapper->getLayerHandle(layerId), nullptr, 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) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700465 int32_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(),
471 mMapper->getLayerHandle(layerId), nullptr, layerId);
Vishnu Naird37343b2022-01-12 16:18:56 -0800472 }
473 layer.z = proto.z();
Vishnu Nair6b591152021-10-08 11:45:14 -0700474 }
475
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800476 if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700477 gui::WindowInfo inputInfo;
478 const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
479
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800480 inputInfo.layoutParamsFlags =
481 static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
482 inputInfo.layoutParamsType =
483 static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
Vishnu Nair6b591152021-10-08 11:45:14 -0700484 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
485 inputInfo.touchableRegion);
486 inputInfo.surfaceInset = windowInfoProto.surface_inset();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800487 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_FOCUSABLE,
488 !windowInfoProto.focusable());
489 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER,
490 windowInfoProto.has_wallpaper());
Vishnu Nair6b591152021-10-08 11:45:14 -0700491 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
492 const proto::LayerState_Transform& transformProto = windowInfoProto.transform();
493 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
494 transformProto.dsdy());
495 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
496 inputInfo.replaceTouchableRegionWithCrop =
497 windowInfoProto.replace_touchable_region_with_crop();
498 int32_t layerId = windowInfoProto.crop_layer_id();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800499 inputInfo.touchableRegionCropHandle = mMapper->getLayerHandle(layerId);
Vishnu Nair6b591152021-10-08 11:45:14 -0700500 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
501 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800502 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700503 layer.bgColorAlpha = proto.bg_color_alpha();
504 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
505 const proto::LayerState_Color3& colorProto = proto.color();
506 layer.color.r = colorProto.r();
507 layer.color.g = colorProto.g();
508 layer.color.b = colorProto.b();
509 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800510 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700511 layer.colorSpaceAgnostic = proto.color_space_agnostic();
512 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800513 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700514 layer.shadowRadius = proto.shadow_radius();
515 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800516 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700517 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
518 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800519 if (proto.what() & layer_state_t::eFrameRateChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700520 layer.frameRate = proto.frame_rate();
521 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
522 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
523 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800524 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700525 layer.fixedTransformHint =
526 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
527 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800528 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700529 layer.autoRefresh = proto.auto_refresh();
530 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800531 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700532 layer.isTrustedOverlay = proto.is_trusted_overlay();
533 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800534 if (proto.what() & layer_state_t::eBufferCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700535 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
536 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800537 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700538 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
539 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800540 if (proto.what() & layer_state_t::eDropInputModeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700541 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
542 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700543}
544
Vishnu Nair685cfef2022-02-02 10:01:25 -0800545DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700546 DisplayState display;
547 display.what = proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800548 display.token = mMapper->getDisplayHandle(proto.id());
Vishnu Nair6b591152021-10-08 11:45:14 -0700549
550 if (display.what & DisplayState::eLayerStackChanged) {
551 display.layerStack.id = proto.layer_stack();
552 }
553 if (display.what & DisplayState::eDisplayProjectionChanged) {
554 display.orientation = static_cast<ui::Rotation>(proto.orientation());
555 LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
556 display.orientedDisplaySpaceRect);
557 LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
558 display.layerStackSpaceRect);
559 }
560 if (display.what & DisplayState::eDisplaySizeChanged) {
561 display.width = proto.width();
562 display.height = proto.height();
563 }
564 if (display.what & DisplayState::eFlagsChanged) {
565 display.flags = proto.flags();
566 }
567 return display;
568}
569
570} // namespace android::surfaceflinger