blob: 3418c82f9ec8fc7fba777b54be0184419c63df3e [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 }
Vishnu Nairea04b6f2022-08-19 21:28:17 +000091
Vishnu Nair6b591152021-10-08 11:45:14 -070092 if (layer.what & layer_state_t::eLayerStackChanged) {
93 proto.set_layer_stack(layer.layerStack.id);
94 }
95 if (layer.what & layer_state_t::eFlagsChanged) {
96 proto.set_flags(layer.flags);
97 proto.set_mask(layer.mask);
98 }
99 if (layer.what & layer_state_t::eMatrixChanged) {
100 proto::LayerState_Matrix22* matrixProto = proto.mutable_matrix();
101 matrixProto->set_dsdx(layer.matrix.dsdx);
102 matrixProto->set_dsdy(layer.matrix.dsdy);
103 matrixProto->set_dtdx(layer.matrix.dtdx);
104 matrixProto->set_dtdy(layer.matrix.dtdy);
105 }
106 if (layer.what & layer_state_t::eCornerRadiusChanged) {
107 proto.set_corner_radius(layer.cornerRadius);
108 }
109 if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) {
110 proto.set_background_blur_radius(layer.backgroundBlurRadius);
111 }
112
113 if (layer.what & layer_state_t::eAlphaChanged) {
Vishnu Nairbbceb462022-10-10 04:52:13 +0000114 proto.set_alpha(layer.color.a);
Vishnu Nair6b591152021-10-08 11:45:14 -0700115 }
116
117 if (layer.what & layer_state_t::eColorChanged) {
118 proto::LayerState_Color3* colorProto = proto.mutable_color();
119 colorProto->set_r(layer.color.r);
120 colorProto->set_g(layer.color.g);
121 colorProto->set_b(layer.color.b);
122 }
123 if (layer.what & layer_state_t::eTransparentRegionChanged) {
124 LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region());
125 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000126 if (layer.what & layer_state_t::eBufferTransformChanged) {
127 proto.set_transform(layer.bufferTransform);
Vishnu Nair6b591152021-10-08 11:45:14 -0700128 }
129 if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
130 proto.set_transform_to_display_inverse(layer.transformToDisplayInverse);
131 }
132 if (layer.what & layer_state_t::eCropChanged) {
133 LayerProtoHelper::writeToProto(layer.crop, proto.mutable_crop());
134 }
135 if (layer.what & layer_state_t::eBufferChanged) {
136 proto::LayerState_BufferData* bufferProto = proto.mutable_buffer_data();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800137 if (layer.bufferData->hasBuffer()) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800138 bufferProto->set_buffer_id(layer.bufferData->getId());
139 bufferProto->set_width(layer.bufferData->getWidth());
140 bufferProto->set_height(layer.bufferData->getHeight());
Vishnu Naird37343b2022-01-12 16:18:56 -0800141 bufferProto->set_pixel_format(static_cast<proto::LayerState_BufferData_PixelFormat>(
142 layer.bufferData->getPixelFormat()));
143 bufferProto->set_usage(layer.bufferData->getUsage());
Vishnu Nair685cfef2022-02-02 10:01:25 -0800144 } else {
145 uint64_t bufferId;
146 uint32_t width;
147 uint32_t height;
148 int32_t pixelFormat;
149 uint64_t usage;
150 mMapper->getGraphicBufferPropertiesFromCache(layer.bufferData->cachedBuffer, &bufferId,
151 &width, &height, &pixelFormat, &usage);
152 bufferProto->set_buffer_id(bufferId);
153 bufferProto->set_width(width);
154 bufferProto->set_height(height);
155 bufferProto->set_pixel_format(
156 static_cast<proto::LayerState_BufferData_PixelFormat>(pixelFormat));
157 bufferProto->set_usage(usage);
Vishnu Nair6b591152021-10-08 11:45:14 -0700158 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800159 bufferProto->set_frame_number(layer.bufferData->frameNumber);
160 bufferProto->set_flags(layer.bufferData->flags.get());
161 bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id);
Vishnu Nair6b591152021-10-08 11:45:14 -0700162 }
163 if (layer.what & layer_state_t::eSidebandStreamChanged) {
164 proto.set_has_sideband_stream(layer.sidebandStream != nullptr);
165 }
166
167 if (layer.what & layer_state_t::eApiChanged) {
168 proto.set_api(layer.api);
169 }
170
171 if (layer.what & layer_state_t::eColorTransformChanged) {
172 LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform());
173 }
174 if (layer.what & layer_state_t::eBlurRegionsChanged) {
175 for (auto& region : layer.blurRegions) {
176 LayerProtoHelper::writeToProto(region, proto.add_blur_regions());
177 }
178 }
179
Vishnu Nair685cfef2022-02-02 10:01:25 -0800180 if (layer.what & layer_state_t::eReparent) {
Robert Carra63d52a2022-03-03 08:03:37 -0800181 int64_t layerId = layer.parentSurfaceControlForChild
Vishnu Nair685cfef2022-02-02 10:01:25 -0800182 ? mMapper->getLayerId(layer.parentSurfaceControlForChild->getHandle())
Vishnu Nair6b591152021-10-08 11:45:14 -0700183 : -1;
184 proto.set_parent_id(layerId);
185 }
Vishnu Nair685cfef2022-02-02 10:01:25 -0800186 if (layer.what & layer_state_t::eRelativeLayerChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800187 int64_t layerId = layer.relativeLayerSurfaceControl
Vishnu Nair685cfef2022-02-02 10:01:25 -0800188 ? mMapper->getLayerId(layer.relativeLayerSurfaceControl->getHandle())
Vishnu Nair6b591152021-10-08 11:45:14 -0700189 : -1;
190 proto.set_relative_parent_id(layerId);
Vishnu Naird37343b2022-01-12 16:18:56 -0800191 proto.set_z(layer.z);
Vishnu Nair6b591152021-10-08 11:45:14 -0700192 }
193
194 if (layer.what & layer_state_t::eInputInfoChanged) {
195 if (layer.windowInfoHandle) {
196 const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo();
197 proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800198 windowInfoProto->set_layout_params_flags(inputInfo->layoutParamsFlags.get());
199 windowInfoProto->set_layout_params_type(
200 static_cast<int32_t>(inputInfo->layoutParamsType));
Vishnu Nair6b591152021-10-08 11:45:14 -0700201 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
202 windowInfoProto->mutable_touchable_region());
203 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800204 windowInfoProto->set_focusable(
205 !inputInfo->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE));
206 windowInfoProto->set_has_wallpaper(inputInfo->inputConfig.test(
207 gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER));
Vishnu Nair6b591152021-10-08 11:45:14 -0700208 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
209 proto::LayerState_Transform* transformProto = windowInfoProto->mutable_transform();
210 transformProto->set_dsdx(inputInfo->transform.dsdx());
211 transformProto->set_dtdx(inputInfo->transform.dtdx());
212 transformProto->set_dtdy(inputInfo->transform.dtdy());
213 transformProto->set_dsdy(inputInfo->transform.dsdy());
214 transformProto->set_tx(inputInfo->transform.tx());
215 transformProto->set_ty(inputInfo->transform.ty());
216 windowInfoProto->set_replace_touchable_region_with_crop(
217 inputInfo->replaceTouchableRegionWithCrop);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800218 windowInfoProto->set_crop_layer_id(
219 mMapper->getLayerId(inputInfo->touchableRegionCropHandle.promote()));
Vishnu Nair6b591152021-10-08 11:45:14 -0700220 }
221 }
222 if (layer.what & layer_state_t::eBackgroundColorChanged) {
223 proto.set_bg_color_alpha(layer.bgColorAlpha);
224 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
225 proto::LayerState_Color3* colorProto = proto.mutable_color();
226 colorProto->set_r(layer.color.r);
227 colorProto->set_g(layer.color.g);
228 colorProto->set_b(layer.color.b);
229 }
230 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
231 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
232 }
233 if (layer.what & layer_state_t::eShadowRadiusChanged) {
234 proto.set_shadow_radius(layer.shadowRadius);
235 }
236 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
237 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
238 }
239 if (layer.what & layer_state_t::eFrameRateChanged) {
240 proto.set_frame_rate(layer.frameRate);
241 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
242 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
243 }
244 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
245 proto.set_fixed_transform_hint(layer.fixedTransformHint);
246 }
247 if (layer.what & layer_state_t::eAutoRefreshChanged) {
248 proto.set_auto_refresh(layer.autoRefresh);
249 }
250 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
251 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
252 }
253 if (layer.what & layer_state_t::eBufferCropChanged) {
254 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
255 }
256 if (layer.what & layer_state_t::eDestinationFrameChanged) {
257 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
258 }
259 if (layer.what & layer_state_t::eDropInputModeChanged) {
260 proto.set_drop_input_mode(
261 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
262 }
263 return proto;
264}
265
Vishnu Nair685cfef2022-02-02 10:01:25 -0800266proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700267 proto::DisplayState proto;
268 proto.set_what(display.what);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800269 proto.set_id(mMapper->getDisplayId(display.token));
Vishnu Nair6b591152021-10-08 11:45:14 -0700270
271 if (display.what & DisplayState::eLayerStackChanged) {
272 proto.set_layer_stack(display.layerStack.id);
273 }
274 if (display.what & DisplayState::eDisplayProjectionChanged) {
275 proto.set_orientation(static_cast<uint32_t>(display.orientation));
276 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
277 proto.mutable_oriented_display_space_rect());
278 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
279 proto.mutable_layer_stack_space_rect());
280 }
281 if (display.what & DisplayState::eDisplaySizeChanged) {
282 proto.set_width(display.width);
283 proto.set_height(display.height);
284 }
285 if (display.what & DisplayState::eFlagsChanged) {
286 proto.set_flags(display.flags);
287 }
288 return proto;
289}
290
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800291proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) {
292 proto::LayerCreationArgs proto;
293 proto.set_layer_id(args.layerId);
294 proto.set_name(args.name);
295 proto.set_flags(args.flags);
296 proto.set_parent_id(args.parentId);
Vishnu Nair84125ac2021-12-02 08:47:48 -0800297 proto.set_mirror_from_id(args.mirrorFromId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800298 return proto;
299}
300
Vishnu Nair685cfef2022-02-02 10:01:25 -0800301TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700302 TransactionState t;
303 t.originPid = proto.pid();
304 t.originUid = proto.uid();
305 t.frameTimelineInfo.vsyncId = proto.vsync_id();
306 t.frameTimelineInfo.inputEventId = proto.input_event_id();
307 t.postTime = proto.post_time();
Vishnu Naird37343b2022-01-12 16:18:56 -0800308 t.id = proto.transaction_id();
309
Vishnu Nair6b591152021-10-08 11:45:14 -0700310 int32_t layerCount = proto.layer_changes_size();
311 t.states.reserve(static_cast<size_t>(layerCount));
312 for (int i = 0; i < layerCount; i++) {
313 ComposerState s;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800314 s.state.what = 0;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800315 fromProto(proto.layer_changes(i), s.state);
Vishnu Nair6b591152021-10-08 11:45:14 -0700316 t.states.add(s);
317 }
318
319 int32_t displayCount = proto.display_changes_size();
320 t.displays.reserve(static_cast<size_t>(displayCount));
321 for (int i = 0; i < displayCount; i++) {
Vishnu Nair685cfef2022-02-02 10:01:25 -0800322 t.displays.add(fromProto(proto.display_changes(i)));
Vishnu Nair6b591152021-10-08 11:45:14 -0700323 }
324 return t;
325}
326
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800327void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
328 TracingLayerCreationArgs& outArgs) {
329 outArgs.layerId = proto.layer_id();
330 outArgs.name = proto.name();
331 outArgs.flags = proto.flags();
332 outArgs.parentId = proto.parent_id();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800333 outArgs.mirrorFromId = proto.mirror_from_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800334}
Vishnu Nair6b591152021-10-08 11:45:14 -0700335
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800336void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto,
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800337 TracingLayerState& outState) {
338 layer_state_t state;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800339 fromProto(proto, state);
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800340 outState.merge(state);
341
342 if (state.what & layer_state_t::eReparent) {
Robert Carra63d52a2022-03-03 08:03:37 -0800343 outState.parentId = static_cast<int32_t>(proto.parent_id());
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800344 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800345 if (state.what & layer_state_t::eRelativeLayerChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800346 outState.relativeParentId = static_cast<int32_t>(proto.relative_parent_id());
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800347 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800348 if (state.what & layer_state_t::eInputInfoChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800349 outState.inputCropId = static_cast<int32_t>(proto.window_info_handle().crop_layer_id());
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800350 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800351 if (state.what & layer_state_t::eBufferChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800352 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
353 outState.bufferId = bufferProto.buffer_id();
354 outState.bufferWidth = bufferProto.width();
355 outState.bufferHeight = bufferProto.height();
Vishnu Naird37343b2022-01-12 16:18:56 -0800356 outState.pixelFormat = bufferProto.pixel_format();
357 outState.bufferUsage = bufferProto.usage();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800358 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800359 if (state.what & layer_state_t::eSidebandStreamChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800360 outState.hasSidebandStream = proto.has_sideband_stream();
361 }
362}
363
Vishnu Nair685cfef2022-02-02 10:01:25 -0800364void TransactionProtoParser::fromProto(const proto::LayerState& proto, layer_state_t& layer) {
Robert Carra63d52a2022-03-03 08:03:37 -0800365 layer.layerId = (int32_t)proto.layer_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800366 layer.what |= proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800367 layer.surface = mMapper->getLayerHandle(layer.layerId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800368
369 if (proto.what() & layer_state_t::ePositionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700370 layer.x = proto.x();
371 layer.y = proto.y();
372 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800373 if (proto.what() & layer_state_t::eLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700374 layer.z = proto.z();
375 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800376 if (proto.what() & layer_state_t::eLayerStackChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700377 layer.layerStack.id = proto.layer_stack();
378 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800379 if (proto.what() & layer_state_t::eFlagsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700380 layer.flags = proto.flags();
381 layer.mask = proto.mask();
382 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800383 if (proto.what() & layer_state_t::eMatrixChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700384 const proto::LayerState_Matrix22& matrixProto = proto.matrix();
385 layer.matrix.dsdx = matrixProto.dsdx();
386 layer.matrix.dsdy = matrixProto.dsdy();
387 layer.matrix.dtdx = matrixProto.dtdx();
388 layer.matrix.dtdy = matrixProto.dtdy();
389 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800390 if (proto.what() & layer_state_t::eCornerRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700391 layer.cornerRadius = proto.corner_radius();
392 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800393 if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700394 layer.backgroundBlurRadius = proto.background_blur_radius();
395 }
396
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800397 if (proto.what() & layer_state_t::eAlphaChanged) {
Vishnu Nairbbceb462022-10-10 04:52:13 +0000398 layer.color.a = proto.alpha();
Vishnu Nair6b591152021-10-08 11:45:14 -0700399 }
400
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800401 if (proto.what() & layer_state_t::eColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700402 const proto::LayerState_Color3& colorProto = proto.color();
403 layer.color.r = colorProto.r();
404 layer.color.g = colorProto.g();
405 layer.color.b = colorProto.b();
406 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800407 if (proto.what() & layer_state_t::eTransparentRegionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700408 LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
409 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000410 if (proto.what() & layer_state_t::eBufferTransformChanged) {
411 layer.bufferTransform = proto.transform();
Vishnu Nair6b591152021-10-08 11:45:14 -0700412 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800413 if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700414 layer.transformToDisplayInverse = proto.transform_to_display_inverse();
415 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800416 if (proto.what() & layer_state_t::eCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700417 LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
418 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800419 if (proto.what() & layer_state_t::eBufferChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700420 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800421 layer.bufferData =
422 std::move(mMapper->getGraphicData(bufferProto.buffer_id(), bufferProto.width(),
423 bufferProto.height(), bufferProto.pixel_format(),
424 bufferProto.usage()));
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800425 layer.bufferData->frameNumber = bufferProto.frame_number();
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700426 layer.bufferData->flags = ftl::Flags<BufferData::BufferDataChange>(bufferProto.flags());
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800427 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
Vishnu Nair8eebba42022-02-25 07:57:15 -0800428 layer.bufferData->acquireFence = Fence::NO_FENCE;
Vishnu Nair6b591152021-10-08 11:45:14 -0700429 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700430
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800431 if (proto.what() & layer_state_t::eApiChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700432 layer.api = proto.api();
433 }
434
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800435 if (proto.what() & layer_state_t::eColorTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700436 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
437 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800438 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700439 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
440 for (int i = 0; i < proto.blur_regions_size(); i++) {
441 android::BlurRegion region;
442 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
443 layer.blurRegions.push_back(region);
444 }
445 }
446
Vishnu Nair685cfef2022-02-02 10:01:25 -0800447 if (proto.what() & layer_state_t::eReparent) {
Robert Carra63d52a2022-03-03 08:03:37 -0800448 int64_t layerId = proto.parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800449 if (layerId == -1) {
450 layer.parentSurfaceControlForChild = nullptr;
451 } else {
452 layer.parentSurfaceControlForChild =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700453 sp<SurfaceControl>::make(SurfaceComposerClient::getDefault(),
454 mMapper->getLayerHandle(static_cast<int32_t>(layerId)),
Patrick Williamsa361de62022-10-06 20:34:10 +0000455 static_cast<int32_t>(layerId), "");
Vishnu Naird37343b2022-01-12 16:18:56 -0800456 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700457 }
Vishnu Naird37343b2022-01-12 16:18:56 -0800458 if (proto.what() & layer_state_t::eRelativeLayerChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800459 int64_t layerId = proto.relative_parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800460 if (layerId == -1) {
461 layer.relativeLayerSurfaceControl = nullptr;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800462 } else {
Vishnu Naird37343b2022-01-12 16:18:56 -0800463 layer.relativeLayerSurfaceControl =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700464 sp<SurfaceControl>::make(SurfaceComposerClient::getDefault(),
465 mMapper->getLayerHandle(static_cast<int32_t>(layerId)),
Patrick Williamsa361de62022-10-06 20:34:10 +0000466 static_cast<int32_t>(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
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800475 inputInfo.layoutParamsFlags =
476 static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
477 inputInfo.layoutParamsType =
478 static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
Vishnu Nair6b591152021-10-08 11:45:14 -0700479 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
480 inputInfo.touchableRegion);
481 inputInfo.surfaceInset = windowInfoProto.surface_inset();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800482 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_FOCUSABLE,
483 !windowInfoProto.focusable());
484 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER,
485 windowInfoProto.has_wallpaper());
Vishnu Nair6b591152021-10-08 11:45:14 -0700486 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
487 const proto::LayerState_Transform& transformProto = windowInfoProto.transform();
488 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
489 transformProto.dsdy());
490 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
491 inputInfo.replaceTouchableRegionWithCrop =
492 windowInfoProto.replace_touchable_region_with_crop();
Robert Carra63d52a2022-03-03 08:03:37 -0800493 int64_t layerId = windowInfoProto.crop_layer_id();
Vishnu Nair286f4f92022-06-08 16:37:39 -0700494 if (layerId != -1) {
495 inputInfo.touchableRegionCropHandle =
496 mMapper->getLayerHandle(static_cast<int32_t>(layerId));
497 } else {
Ady Abrahamd11bade2022-08-01 16:18:03 -0700498 inputInfo.touchableRegionCropHandle = wp<IBinder>();
Vishnu Nair286f4f92022-06-08 16:37:39 -0700499 }
500
Vishnu Nair6b591152021-10-08 11:45:14 -0700501 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
502 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800503 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700504 layer.bgColorAlpha = proto.bg_color_alpha();
505 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
506 const proto::LayerState_Color3& colorProto = proto.color();
507 layer.color.r = colorProto.r();
508 layer.color.g = colorProto.g();
509 layer.color.b = colorProto.b();
510 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800511 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700512 layer.colorSpaceAgnostic = proto.color_space_agnostic();
513 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800514 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700515 layer.shadowRadius = proto.shadow_radius();
516 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800517 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700518 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
519 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800520 if (proto.what() & layer_state_t::eFrameRateChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700521 layer.frameRate = proto.frame_rate();
522 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
523 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
524 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800525 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700526 layer.fixedTransformHint =
527 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
528 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800529 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700530 layer.autoRefresh = proto.auto_refresh();
531 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800532 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700533 layer.isTrustedOverlay = proto.is_trusted_overlay();
534 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800535 if (proto.what() & layer_state_t::eBufferCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700536 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
537 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800538 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700539 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
540 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800541 if (proto.what() & layer_state_t::eDropInputModeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700542 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
543 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700544}
545
Vishnu Nair685cfef2022-02-02 10:01:25 -0800546DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700547 DisplayState display;
548 display.what = proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800549 display.token = mMapper->getDisplayHandle(proto.id());
Vishnu Nair6b591152021-10-08 11:45:14 -0700550
551 if (display.what & DisplayState::eLayerStackChanged) {
552 display.layerStack.id = proto.layer_stack();
553 }
554 if (display.what & DisplayState::eDisplayProjectionChanged) {
555 display.orientation = static_cast<ui::Rotation>(proto.orientation());
556 LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
557 display.orientedDisplaySpaceRect);
558 LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
559 display.layerStackSpaceRect);
560 }
561 if (display.what & DisplayState::eDisplaySizeChanged) {
562 display.width = proto.width();
563 display.height = proto.height();
564 }
565 if (display.what & DisplayState::eFlagsChanged) {
566 display.flags = proto.flags();
567 }
568 return display;
569}
570
571} // namespace android::surfaceflinger