blob: 475c76be5311566caa655b4bbc2734ea377ef60d [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 Nair63a662a2023-02-22 20:17:18 +000018#include <renderengine/mock/FakeExternalTexture.h>
Vishnu Nair8eebba42022-02-25 07:57:15 -080019#include <ui/Fence.h>
Vishnu Nair6b591152021-10-08 11:45:14 -070020#include <ui/Rect.h>
21
22#include "LayerProtoHelper.h"
23#include "TransactionProtoParser.h"
24
25namespace android::surfaceflinger {
26
Vishnu Nair685cfef2022-02-02 10:01:25 -080027proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t) {
Vishnu Nair6b591152021-10-08 11:45:14 -070028 proto::TransactionState proto;
29 proto.set_pid(t.originPid);
30 proto.set_uid(t.originUid);
31 proto.set_vsync_id(t.frameTimelineInfo.vsyncId);
32 proto.set_input_event_id(t.frameTimelineInfo.inputEventId);
33 proto.set_post_time(t.postTime);
Vishnu Naird37343b2022-01-12 16:18:56 -080034 proto.set_transaction_id(t.id);
Vishnu Nair6b591152021-10-08 11:45:14 -070035
Vishnu Nair685cfef2022-02-02 10:01:25 -080036 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(t.states.size()));
Vishnu Nair6b591152021-10-08 11:45:14 -070037 for (auto& layerState : t.states) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080038 proto.mutable_layer_changes()->Add(std::move(toProto(layerState.state)));
Vishnu Nair6b591152021-10-08 11:45:14 -070039 }
40
Vishnu Nair685cfef2022-02-02 10:01:25 -080041 proto.mutable_display_changes()->Reserve(static_cast<int32_t>(t.displays.size()));
Vishnu Nair6b591152021-10-08 11:45:14 -070042 for (auto& displayState : t.displays) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080043 proto.mutable_display_changes()->Add(std::move(toProto(displayState)));
Vishnu Nair6b591152021-10-08 11:45:14 -070044 }
45 return proto;
46}
47
Vishnu Nair68dee2b2021-11-08 18:52:12 -080048proto::TransactionState TransactionProtoParser::toProto(
Greg Kaiser2c909852021-12-07 09:45:29 -080049 const std::map<int32_t /* layerId */, TracingLayerState>& states) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -080050 proto::TransactionState proto;
Vishnu Nair685cfef2022-02-02 10:01:25 -080051 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(states.size()));
Vishnu Nair68dee2b2021-11-08 18:52:12 -080052 for (auto& [layerId, state] : states) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080053 proto::LayerState layerProto = toProto(state);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080054 if (layerProto.has_buffer_data()) {
55 proto::LayerState_BufferData* bufferProto = layerProto.mutable_buffer_data();
56 bufferProto->set_buffer_id(state.bufferId);
57 bufferProto->set_width(state.bufferWidth);
58 bufferProto->set_height(state.bufferHeight);
Vishnu Naird37343b2022-01-12 16:18:56 -080059 bufferProto->set_pixel_format(
60 static_cast<proto::LayerState_BufferData_PixelFormat>(state.pixelFormat));
61 bufferProto->set_usage(state.bufferUsage);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080062 }
63 layerProto.set_has_sideband_stream(state.hasSidebandStream);
64 layerProto.set_layer_id(state.layerId);
65 layerProto.set_parent_id(state.parentId);
66 layerProto.set_relative_parent_id(state.relativeParentId);
67 if (layerProto.has_window_info_handle()) {
68 layerProto.mutable_window_info_handle()->set_crop_layer_id(state.inputCropId);
69 }
70 proto.mutable_layer_changes()->Add(std::move(layerProto));
71 }
72 return proto;
73}
74
Vishnu Nair685cfef2022-02-02 10:01:25 -080075proto::LayerState TransactionProtoParser::toProto(const layer_state_t& layer) {
Vishnu Nair6b591152021-10-08 11:45:14 -070076 proto::LayerState proto;
Vishnu Nair685cfef2022-02-02 10:01:25 -080077 if (layer.surface) {
78 proto.set_layer_id(mMapper->getLayerId(layer.surface));
Vishnu Nair68dee2b2021-11-08 18:52:12 -080079 } else {
80 proto.set_layer_id(layer.layerId);
81 }
82
Vishnu Nair6b591152021-10-08 11:45:14 -070083 proto.set_what(layer.what);
84
85 if (layer.what & layer_state_t::ePositionChanged) {
86 proto.set_x(layer.x);
87 proto.set_y(layer.y);
88 }
89 if (layer.what & layer_state_t::eLayerChanged) {
90 proto.set_z(layer.z);
91 }
Vishnu Nairea04b6f2022-08-19 21:28:17 +000092
Vishnu Nair6b591152021-10-08 11:45:14 -070093 if (layer.what & layer_state_t::eLayerStackChanged) {
94 proto.set_layer_stack(layer.layerStack.id);
95 }
96 if (layer.what & layer_state_t::eFlagsChanged) {
97 proto.set_flags(layer.flags);
98 proto.set_mask(layer.mask);
99 }
100 if (layer.what & layer_state_t::eMatrixChanged) {
101 proto::LayerState_Matrix22* matrixProto = proto.mutable_matrix();
102 matrixProto->set_dsdx(layer.matrix.dsdx);
103 matrixProto->set_dsdy(layer.matrix.dsdy);
104 matrixProto->set_dtdx(layer.matrix.dtdx);
105 matrixProto->set_dtdy(layer.matrix.dtdy);
106 }
107 if (layer.what & layer_state_t::eCornerRadiusChanged) {
108 proto.set_corner_radius(layer.cornerRadius);
109 }
110 if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) {
111 proto.set_background_blur_radius(layer.backgroundBlurRadius);
112 }
113
114 if (layer.what & layer_state_t::eAlphaChanged) {
Vishnu Nairbbceb462022-10-10 04:52:13 +0000115 proto.set_alpha(layer.color.a);
Vishnu Nair6b591152021-10-08 11:45:14 -0700116 }
117
118 if (layer.what & layer_state_t::eColorChanged) {
119 proto::LayerState_Color3* colorProto = proto.mutable_color();
120 colorProto->set_r(layer.color.r);
121 colorProto->set_g(layer.color.g);
122 colorProto->set_b(layer.color.b);
123 }
124 if (layer.what & layer_state_t::eTransparentRegionChanged) {
125 LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region());
126 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000127 if (layer.what & layer_state_t::eBufferTransformChanged) {
128 proto.set_transform(layer.bufferTransform);
Vishnu Nair6b591152021-10-08 11:45:14 -0700129 }
130 if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
131 proto.set_transform_to_display_inverse(layer.transformToDisplayInverse);
132 }
133 if (layer.what & layer_state_t::eCropChanged) {
134 LayerProtoHelper::writeToProto(layer.crop, proto.mutable_crop());
135 }
136 if (layer.what & layer_state_t::eBufferChanged) {
137 proto::LayerState_BufferData* bufferProto = proto.mutable_buffer_data();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800138 if (layer.bufferData->hasBuffer()) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800139 bufferProto->set_buffer_id(layer.bufferData->getId());
140 bufferProto->set_width(layer.bufferData->getWidth());
141 bufferProto->set_height(layer.bufferData->getHeight());
Vishnu Naird37343b2022-01-12 16:18:56 -0800142 bufferProto->set_pixel_format(static_cast<proto::LayerState_BufferData_PixelFormat>(
143 layer.bufferData->getPixelFormat()));
144 bufferProto->set_usage(layer.bufferData->getUsage());
Vishnu Nair685cfef2022-02-02 10:01:25 -0800145 } else {
146 uint64_t bufferId;
147 uint32_t width;
148 uint32_t height;
149 int32_t pixelFormat;
150 uint64_t usage;
151 mMapper->getGraphicBufferPropertiesFromCache(layer.bufferData->cachedBuffer, &bufferId,
152 &width, &height, &pixelFormat, &usage);
153 bufferProto->set_buffer_id(bufferId);
154 bufferProto->set_width(width);
155 bufferProto->set_height(height);
156 bufferProto->set_pixel_format(
157 static_cast<proto::LayerState_BufferData_PixelFormat>(pixelFormat));
158 bufferProto->set_usage(usage);
Vishnu Nair6b591152021-10-08 11:45:14 -0700159 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800160 bufferProto->set_frame_number(layer.bufferData->frameNumber);
161 bufferProto->set_flags(layer.bufferData->flags.get());
162 bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id);
Vishnu Nair6b591152021-10-08 11:45:14 -0700163 }
164 if (layer.what & layer_state_t::eSidebandStreamChanged) {
165 proto.set_has_sideband_stream(layer.sidebandStream != nullptr);
166 }
167
168 if (layer.what & layer_state_t::eApiChanged) {
169 proto.set_api(layer.api);
170 }
171
172 if (layer.what & layer_state_t::eColorTransformChanged) {
173 LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform());
174 }
175 if (layer.what & layer_state_t::eBlurRegionsChanged) {
176 for (auto& region : layer.blurRegions) {
177 LayerProtoHelper::writeToProto(region, proto.add_blur_regions());
178 }
179 }
180
Vishnu Nair685cfef2022-02-02 10:01:25 -0800181 if (layer.what & layer_state_t::eReparent) {
Robert Carra63d52a2022-03-03 08:03:37 -0800182 int64_t layerId = layer.parentSurfaceControlForChild
Vishnu Nair685cfef2022-02-02 10:01:25 -0800183 ? mMapper->getLayerId(layer.parentSurfaceControlForChild->getHandle())
Vishnu Nair6b591152021-10-08 11:45:14 -0700184 : -1;
185 proto.set_parent_id(layerId);
186 }
Vishnu Nair685cfef2022-02-02 10:01:25 -0800187 if (layer.what & layer_state_t::eRelativeLayerChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800188 int64_t layerId = layer.relativeLayerSurfaceControl
Vishnu Nair685cfef2022-02-02 10:01:25 -0800189 ? mMapper->getLayerId(layer.relativeLayerSurfaceControl->getHandle())
Vishnu Nair6b591152021-10-08 11:45:14 -0700190 : -1;
191 proto.set_relative_parent_id(layerId);
Vishnu Naird37343b2022-01-12 16:18:56 -0800192 proto.set_z(layer.z);
Vishnu Nair6b591152021-10-08 11:45:14 -0700193 }
194
195 if (layer.what & layer_state_t::eInputInfoChanged) {
196 if (layer.windowInfoHandle) {
197 const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo();
198 proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800199 windowInfoProto->set_layout_params_flags(inputInfo->layoutParamsFlags.get());
200 windowInfoProto->set_layout_params_type(
201 static_cast<int32_t>(inputInfo->layoutParamsType));
Vishnu Nair6b591152021-10-08 11:45:14 -0700202 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
203 windowInfoProto->mutable_touchable_region());
204 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800205 windowInfoProto->set_focusable(
206 !inputInfo->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE));
207 windowInfoProto->set_has_wallpaper(inputInfo->inputConfig.test(
208 gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER));
Vishnu Nair6b591152021-10-08 11:45:14 -0700209 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
210 proto::LayerState_Transform* transformProto = windowInfoProto->mutable_transform();
211 transformProto->set_dsdx(inputInfo->transform.dsdx());
212 transformProto->set_dtdx(inputInfo->transform.dtdx());
213 transformProto->set_dtdy(inputInfo->transform.dtdy());
214 transformProto->set_dsdy(inputInfo->transform.dsdy());
215 transformProto->set_tx(inputInfo->transform.tx());
216 transformProto->set_ty(inputInfo->transform.ty());
217 windowInfoProto->set_replace_touchable_region_with_crop(
218 inputInfo->replaceTouchableRegionWithCrop);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800219 windowInfoProto->set_crop_layer_id(
220 mMapper->getLayerId(inputInfo->touchableRegionCropHandle.promote()));
Vishnu Nair6b591152021-10-08 11:45:14 -0700221 }
222 }
223 if (layer.what & layer_state_t::eBackgroundColorChanged) {
224 proto.set_bg_color_alpha(layer.bgColorAlpha);
225 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
226 proto::LayerState_Color3* colorProto = proto.mutable_color();
227 colorProto->set_r(layer.color.r);
228 colorProto->set_g(layer.color.g);
229 colorProto->set_b(layer.color.b);
230 }
231 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
232 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
233 }
234 if (layer.what & layer_state_t::eShadowRadiusChanged) {
235 proto.set_shadow_radius(layer.shadowRadius);
236 }
237 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
238 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
239 }
240 if (layer.what & layer_state_t::eFrameRateChanged) {
241 proto.set_frame_rate(layer.frameRate);
242 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
243 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
244 }
245 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
246 proto.set_fixed_transform_hint(layer.fixedTransformHint);
247 }
248 if (layer.what & layer_state_t::eAutoRefreshChanged) {
249 proto.set_auto_refresh(layer.autoRefresh);
250 }
251 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
252 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
253 }
254 if (layer.what & layer_state_t::eBufferCropChanged) {
255 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
256 }
257 if (layer.what & layer_state_t::eDestinationFrameChanged) {
258 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
259 }
260 if (layer.what & layer_state_t::eDropInputModeChanged) {
261 proto.set_drop_input_mode(
262 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
263 }
264 return proto;
265}
266
Vishnu Nair685cfef2022-02-02 10:01:25 -0800267proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700268 proto::DisplayState proto;
269 proto.set_what(display.what);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800270 proto.set_id(mMapper->getDisplayId(display.token));
Vishnu Nair6b591152021-10-08 11:45:14 -0700271
272 if (display.what & DisplayState::eLayerStackChanged) {
273 proto.set_layer_stack(display.layerStack.id);
274 }
275 if (display.what & DisplayState::eDisplayProjectionChanged) {
276 proto.set_orientation(static_cast<uint32_t>(display.orientation));
277 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
278 proto.mutable_oriented_display_space_rect());
279 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
280 proto.mutable_layer_stack_space_rect());
281 }
282 if (display.what & DisplayState::eDisplaySizeChanged) {
283 proto.set_width(display.width);
284 proto.set_height(display.height);
285 }
286 if (display.what & DisplayState::eFlagsChanged) {
287 proto.set_flags(display.flags);
288 }
289 return proto;
290}
291
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800292proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) {
293 proto::LayerCreationArgs proto;
294 proto.set_layer_id(args.layerId);
295 proto.set_name(args.name);
296 proto.set_flags(args.flags);
297 proto.set_parent_id(args.parentId);
Vishnu Nair84125ac2021-12-02 08:47:48 -0800298 proto.set_mirror_from_id(args.mirrorFromId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800299 return proto;
300}
301
Vishnu Nair685cfef2022-02-02 10:01:25 -0800302TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700303 TransactionState t;
304 t.originPid = proto.pid();
305 t.originUid = proto.uid();
306 t.frameTimelineInfo.vsyncId = proto.vsync_id();
307 t.frameTimelineInfo.inputEventId = proto.input_event_id();
308 t.postTime = proto.post_time();
Vishnu Naird37343b2022-01-12 16:18:56 -0800309 t.id = proto.transaction_id();
310
Vishnu Nair6b591152021-10-08 11:45:14 -0700311 int32_t layerCount = proto.layer_changes_size();
312 t.states.reserve(static_cast<size_t>(layerCount));
313 for (int i = 0; i < layerCount; i++) {
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000314 ResolvedComposerState s;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800315 s.state.what = 0;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800316 fromProto(proto.layer_changes(i), s.state);
Vishnu Nair63a662a2023-02-22 20:17:18 +0000317 if (s.state.bufferData) {
318 s.externalTexture = std::make_shared<
319 renderengine::mock::FakeExternalTexture>(s.state.bufferData->getWidth(),
320 s.state.bufferData->getHeight(),
321 s.state.bufferData->getId(),
322 s.state.bufferData->getPixelFormat(),
323 s.state.bufferData->getUsage());
324 }
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000325 t.states.emplace_back(s);
Vishnu Nair6b591152021-10-08 11:45:14 -0700326 }
327
328 int32_t displayCount = proto.display_changes_size();
329 t.displays.reserve(static_cast<size_t>(displayCount));
330 for (int i = 0; i < displayCount; i++) {
Vishnu Nair685cfef2022-02-02 10:01:25 -0800331 t.displays.add(fromProto(proto.display_changes(i)));
Vishnu Nair6b591152021-10-08 11:45:14 -0700332 }
333 return t;
334}
335
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800336void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
337 TracingLayerCreationArgs& outArgs) {
338 outArgs.layerId = proto.layer_id();
339 outArgs.name = proto.name();
340 outArgs.flags = proto.flags();
341 outArgs.parentId = proto.parent_id();
Vishnu Nair84125ac2021-12-02 08:47:48 -0800342 outArgs.mirrorFromId = proto.mirror_from_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800343}
Vishnu Nair6b591152021-10-08 11:45:14 -0700344
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800345void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto,
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800346 TracingLayerState& outState) {
347 layer_state_t state;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800348 fromProto(proto, state);
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800349 outState.merge(state);
350
351 if (state.what & layer_state_t::eReparent) {
Robert Carra63d52a2022-03-03 08:03:37 -0800352 outState.parentId = static_cast<int32_t>(proto.parent_id());
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800353 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800354 if (state.what & layer_state_t::eRelativeLayerChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800355 outState.relativeParentId = static_cast<int32_t>(proto.relative_parent_id());
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800356 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800357 if (state.what & layer_state_t::eInputInfoChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800358 outState.inputCropId = static_cast<int32_t>(proto.window_info_handle().crop_layer_id());
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800359 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800360 if (state.what & layer_state_t::eBufferChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800361 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
362 outState.bufferId = bufferProto.buffer_id();
363 outState.bufferWidth = bufferProto.width();
364 outState.bufferHeight = bufferProto.height();
Vishnu Naird37343b2022-01-12 16:18:56 -0800365 outState.pixelFormat = bufferProto.pixel_format();
366 outState.bufferUsage = bufferProto.usage();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800367 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800368 if (state.what & layer_state_t::eSidebandStreamChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800369 outState.hasSidebandStream = proto.has_sideband_stream();
370 }
371}
372
Vishnu Nair685cfef2022-02-02 10:01:25 -0800373void TransactionProtoParser::fromProto(const proto::LayerState& proto, layer_state_t& layer) {
Robert Carra63d52a2022-03-03 08:03:37 -0800374 layer.layerId = (int32_t)proto.layer_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800375 layer.what |= proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800376 layer.surface = mMapper->getLayerHandle(layer.layerId);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800377
378 if (proto.what() & layer_state_t::ePositionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700379 layer.x = proto.x();
380 layer.y = proto.y();
381 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800382 if (proto.what() & layer_state_t::eLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700383 layer.z = proto.z();
384 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800385 if (proto.what() & layer_state_t::eLayerStackChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700386 layer.layerStack.id = proto.layer_stack();
387 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800388 if (proto.what() & layer_state_t::eFlagsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700389 layer.flags = proto.flags();
390 layer.mask = proto.mask();
391 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800392 if (proto.what() & layer_state_t::eMatrixChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700393 const proto::LayerState_Matrix22& matrixProto = proto.matrix();
394 layer.matrix.dsdx = matrixProto.dsdx();
395 layer.matrix.dsdy = matrixProto.dsdy();
396 layer.matrix.dtdx = matrixProto.dtdx();
397 layer.matrix.dtdy = matrixProto.dtdy();
398 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800399 if (proto.what() & layer_state_t::eCornerRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700400 layer.cornerRadius = proto.corner_radius();
401 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800402 if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700403 layer.backgroundBlurRadius = proto.background_blur_radius();
404 }
405
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800406 if (proto.what() & layer_state_t::eAlphaChanged) {
Vishnu Nairbbceb462022-10-10 04:52:13 +0000407 layer.color.a = proto.alpha();
Vishnu Nair6b591152021-10-08 11:45:14 -0700408 }
409
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800410 if (proto.what() & layer_state_t::eColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700411 const proto::LayerState_Color3& colorProto = proto.color();
412 layer.color.r = colorProto.r();
413 layer.color.g = colorProto.g();
414 layer.color.b = colorProto.b();
415 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800416 if (proto.what() & layer_state_t::eTransparentRegionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700417 LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
418 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000419 if (proto.what() & layer_state_t::eBufferTransformChanged) {
420 layer.bufferTransform = proto.transform();
Vishnu Nair6b591152021-10-08 11:45:14 -0700421 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800422 if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700423 layer.transformToDisplayInverse = proto.transform_to_display_inverse();
424 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800425 if (proto.what() & layer_state_t::eCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700426 LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
427 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800428 if (proto.what() & layer_state_t::eBufferChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700429 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800430 layer.bufferData =
431 std::move(mMapper->getGraphicData(bufferProto.buffer_id(), bufferProto.width(),
432 bufferProto.height(), bufferProto.pixel_format(),
433 bufferProto.usage()));
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800434 layer.bufferData->frameNumber = bufferProto.frame_number();
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700435 layer.bufferData->flags = ftl::Flags<BufferData::BufferDataChange>(bufferProto.flags());
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800436 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
Vishnu Nair8eebba42022-02-25 07:57:15 -0800437 layer.bufferData->acquireFence = Fence::NO_FENCE;
Vishnu Nair6b591152021-10-08 11:45:14 -0700438 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700439
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800440 if (proto.what() & layer_state_t::eApiChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700441 layer.api = proto.api();
442 }
443
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800444 if (proto.what() & layer_state_t::eColorTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700445 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
446 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800447 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700448 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
449 for (int i = 0; i < proto.blur_regions_size(); i++) {
450 android::BlurRegion region;
451 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
452 layer.blurRegions.push_back(region);
453 }
454 }
455
Vishnu Nair685cfef2022-02-02 10:01:25 -0800456 if (proto.what() & layer_state_t::eReparent) {
Robert Carra63d52a2022-03-03 08:03:37 -0800457 int64_t layerId = proto.parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800458 if (layerId == -1) {
459 layer.parentSurfaceControlForChild = nullptr;
460 } else {
461 layer.parentSurfaceControlForChild =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700462 sp<SurfaceControl>::make(SurfaceComposerClient::getDefault(),
463 mMapper->getLayerHandle(static_cast<int32_t>(layerId)),
Patrick Williamsa361de62022-10-06 20:34:10 +0000464 static_cast<int32_t>(layerId), "");
Vishnu Naird37343b2022-01-12 16:18:56 -0800465 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700466 }
Vishnu Naird37343b2022-01-12 16:18:56 -0800467 if (proto.what() & layer_state_t::eRelativeLayerChanged) {
Robert Carra63d52a2022-03-03 08:03:37 -0800468 int64_t layerId = proto.relative_parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800469 if (layerId == -1) {
470 layer.relativeLayerSurfaceControl = nullptr;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800471 } else {
Vishnu Naird37343b2022-01-12 16:18:56 -0800472 layer.relativeLayerSurfaceControl =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700473 sp<SurfaceControl>::make(SurfaceComposerClient::getDefault(),
474 mMapper->getLayerHandle(static_cast<int32_t>(layerId)),
Patrick Williamsa361de62022-10-06 20:34:10 +0000475 static_cast<int32_t>(layerId), "");
Vishnu Naird37343b2022-01-12 16:18:56 -0800476 }
477 layer.z = proto.z();
Vishnu Nair6b591152021-10-08 11:45:14 -0700478 }
479
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800480 if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700481 gui::WindowInfo inputInfo;
482 const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
483
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800484 inputInfo.layoutParamsFlags =
485 static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
486 inputInfo.layoutParamsType =
487 static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
Vishnu Nair6b591152021-10-08 11:45:14 -0700488 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
489 inputInfo.touchableRegion);
490 inputInfo.surfaceInset = windowInfoProto.surface_inset();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800491 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_FOCUSABLE,
492 !windowInfoProto.focusable());
493 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER,
494 windowInfoProto.has_wallpaper());
Vishnu Nair6b591152021-10-08 11:45:14 -0700495 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
496 const proto::LayerState_Transform& transformProto = windowInfoProto.transform();
497 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
498 transformProto.dsdy());
499 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
500 inputInfo.replaceTouchableRegionWithCrop =
501 windowInfoProto.replace_touchable_region_with_crop();
Robert Carra63d52a2022-03-03 08:03:37 -0800502 int64_t layerId = windowInfoProto.crop_layer_id();
Vishnu Nair286f4f92022-06-08 16:37:39 -0700503 if (layerId != -1) {
504 inputInfo.touchableRegionCropHandle =
505 mMapper->getLayerHandle(static_cast<int32_t>(layerId));
506 } else {
Ady Abrahamd11bade2022-08-01 16:18:03 -0700507 inputInfo.touchableRegionCropHandle = wp<IBinder>();
Vishnu Nair286f4f92022-06-08 16:37:39 -0700508 }
509
Vishnu Nair6b591152021-10-08 11:45:14 -0700510 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
511 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800512 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700513 layer.bgColorAlpha = proto.bg_color_alpha();
514 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
515 const proto::LayerState_Color3& colorProto = proto.color();
516 layer.color.r = colorProto.r();
517 layer.color.g = colorProto.g();
518 layer.color.b = colorProto.b();
519 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800520 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700521 layer.colorSpaceAgnostic = proto.color_space_agnostic();
522 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800523 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700524 layer.shadowRadius = proto.shadow_radius();
525 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800526 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700527 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
528 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800529 if (proto.what() & layer_state_t::eFrameRateChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700530 layer.frameRate = proto.frame_rate();
531 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
532 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
533 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800534 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700535 layer.fixedTransformHint =
536 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
537 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800538 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700539 layer.autoRefresh = proto.auto_refresh();
540 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800541 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700542 layer.isTrustedOverlay = proto.is_trusted_overlay();
543 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800544 if (proto.what() & layer_state_t::eBufferCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700545 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
546 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800547 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700548 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
549 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800550 if (proto.what() & layer_state_t::eDropInputModeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700551 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
552 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700553}
554
Vishnu Nair685cfef2022-02-02 10:01:25 -0800555DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700556 DisplayState display;
557 display.what = proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800558 display.token = mMapper->getDisplayHandle(proto.id());
Vishnu Nair6b591152021-10-08 11:45:14 -0700559
560 if (display.what & DisplayState::eLayerStackChanged) {
561 display.layerStack.id = proto.layer_stack();
562 }
563 if (display.what & DisplayState::eDisplayProjectionChanged) {
564 display.orientation = static_cast<ui::Rotation>(proto.orientation());
565 LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
566 display.orientedDisplaySpaceRect);
567 LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
568 display.layerStackSpaceRect);
569 }
570 if (display.what & DisplayState::eDisplaySizeChanged) {
571 display.width = proto.width();
572 display.height = proto.height();
573 }
574 if (display.what & DisplayState::eFlagsChanged) {
575 display.flags = proto.flags();
576 }
577 return display;
578}
579
580} // namespace android::surfaceflinger