blob: 593c4ffc039e8ec221b9f84242c4f615bdf38819 [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
Vishnu Nair81750622023-03-08 15:02:06 -080021#include "FrontEnd/LayerCreationArgs.h"
Vishnu Nair6b591152021-10-08 11:45:14 -070022#include "LayerProtoHelper.h"
23#include "TransactionProtoParser.h"
Vishnu Nair81750622023-03-08 15:02:06 -080024#include "TransactionState.h"
25#include "gui/LayerState.h"
Vishnu Nair6b591152021-10-08 11:45:14 -070026
27namespace android::surfaceflinger {
28
Vishnu Nair81750622023-03-08 15:02:06 -080029class FakeExternalTexture : public renderengine::ExternalTexture {
Vishnu Nair32ebda42023-03-16 10:04:29 -070030 const sp<GraphicBuffer> mEmptyBuffer = nullptr;
Vishnu Nair81750622023-03-08 15:02:06 -080031 uint32_t mWidth;
32 uint32_t mHeight;
33 uint64_t mId;
34 PixelFormat mPixelFormat;
35 uint64_t mUsage;
36
37public:
38 FakeExternalTexture(uint32_t width, uint32_t height, uint64_t id, PixelFormat pixelFormat,
39 uint64_t usage)
40 : mWidth(width), mHeight(height), mId(id), mPixelFormat(pixelFormat), mUsage(usage) {}
41 const sp<GraphicBuffer>& getBuffer() const { return mEmptyBuffer; }
42 bool hasSameBuffer(const renderengine::ExternalTexture& other) const override {
43 return getId() == other.getId();
44 }
45 uint32_t getWidth() const override { return mWidth; }
46 uint32_t getHeight() const override { return mHeight; }
47 uint64_t getId() const override { return mId; }
48 PixelFormat getPixelFormat() const override { return mPixelFormat; }
49 uint64_t getUsage() const override { return mUsage; }
50 ~FakeExternalTexture() = default;
51};
52
Vishnu Nair685cfef2022-02-02 10:01:25 -080053proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t) {
Vishnu Nair6b591152021-10-08 11:45:14 -070054 proto::TransactionState proto;
55 proto.set_pid(t.originPid);
56 proto.set_uid(t.originUid);
57 proto.set_vsync_id(t.frameTimelineInfo.vsyncId);
58 proto.set_input_event_id(t.frameTimelineInfo.inputEventId);
59 proto.set_post_time(t.postTime);
Vishnu Naird37343b2022-01-12 16:18:56 -080060 proto.set_transaction_id(t.id);
Vishnu Nair6b591152021-10-08 11:45:14 -070061
Vishnu Nair685cfef2022-02-02 10:01:25 -080062 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(t.states.size()));
Vishnu Nair6b591152021-10-08 11:45:14 -070063 for (auto& layerState : t.states) {
Vishnu Nair81750622023-03-08 15:02:06 -080064 proto.mutable_layer_changes()->Add(std::move(toProto(layerState)));
Vishnu Nair6b591152021-10-08 11:45:14 -070065 }
66
Vishnu Nair685cfef2022-02-02 10:01:25 -080067 proto.mutable_display_changes()->Reserve(static_cast<int32_t>(t.displays.size()));
Vishnu Nair6b591152021-10-08 11:45:14 -070068 for (auto& displayState : t.displays) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080069 proto.mutable_display_changes()->Add(std::move(toProto(displayState)));
Vishnu Nair6b591152021-10-08 11:45:14 -070070 }
71 return proto;
72}
73
Vishnu Nair68dee2b2021-11-08 18:52:12 -080074proto::TransactionState TransactionProtoParser::toProto(
Vishnu Nair81750622023-03-08 15:02:06 -080075 const std::map<uint32_t /* layerId */, TracingLayerState>& states) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -080076 proto::TransactionState proto;
Vishnu Nair685cfef2022-02-02 10:01:25 -080077 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(states.size()));
Vishnu Nair68dee2b2021-11-08 18:52:12 -080078 for (auto& [layerId, state] : states) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080079 proto::LayerState layerProto = toProto(state);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080080 layerProto.set_has_sideband_stream(state.hasSidebandStream);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080081 proto.mutable_layer_changes()->Add(std::move(layerProto));
82 }
83 return proto;
84}
85
Vishnu Nair81750622023-03-08 15:02:06 -080086proto::LayerState TransactionProtoParser::toProto(
87 const ResolvedComposerState& resolvedComposerState) {
Vishnu Nair6b591152021-10-08 11:45:14 -070088 proto::LayerState proto;
Vishnu Nair81750622023-03-08 15:02:06 -080089 auto& layer = resolvedComposerState.state;
90 proto.set_layer_id(resolvedComposerState.layerId);
Vishnu Nair6b591152021-10-08 11:45:14 -070091 proto.set_what(layer.what);
92
93 if (layer.what & layer_state_t::ePositionChanged) {
94 proto.set_x(layer.x);
95 proto.set_y(layer.y);
96 }
97 if (layer.what & layer_state_t::eLayerChanged) {
98 proto.set_z(layer.z);
99 }
Vishnu Nairea04b6f2022-08-19 21:28:17 +0000100
Vishnu Nair6b591152021-10-08 11:45:14 -0700101 if (layer.what & layer_state_t::eLayerStackChanged) {
102 proto.set_layer_stack(layer.layerStack.id);
103 }
104 if (layer.what & layer_state_t::eFlagsChanged) {
105 proto.set_flags(layer.flags);
106 proto.set_mask(layer.mask);
107 }
108 if (layer.what & layer_state_t::eMatrixChanged) {
109 proto::LayerState_Matrix22* matrixProto = proto.mutable_matrix();
110 matrixProto->set_dsdx(layer.matrix.dsdx);
111 matrixProto->set_dsdy(layer.matrix.dsdy);
112 matrixProto->set_dtdx(layer.matrix.dtdx);
113 matrixProto->set_dtdy(layer.matrix.dtdy);
114 }
115 if (layer.what & layer_state_t::eCornerRadiusChanged) {
116 proto.set_corner_radius(layer.cornerRadius);
117 }
118 if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) {
119 proto.set_background_blur_radius(layer.backgroundBlurRadius);
120 }
121
122 if (layer.what & layer_state_t::eAlphaChanged) {
Vishnu Nairbbceb462022-10-10 04:52:13 +0000123 proto.set_alpha(layer.color.a);
Vishnu Nair6b591152021-10-08 11:45:14 -0700124 }
125
126 if (layer.what & layer_state_t::eColorChanged) {
127 proto::LayerState_Color3* colorProto = proto.mutable_color();
128 colorProto->set_r(layer.color.r);
129 colorProto->set_g(layer.color.g);
130 colorProto->set_b(layer.color.b);
131 }
132 if (layer.what & layer_state_t::eTransparentRegionChanged) {
133 LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region());
134 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000135 if (layer.what & layer_state_t::eBufferTransformChanged) {
136 proto.set_transform(layer.bufferTransform);
Vishnu Nair6b591152021-10-08 11:45:14 -0700137 }
138 if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
139 proto.set_transform_to_display_inverse(layer.transformToDisplayInverse);
140 }
141 if (layer.what & layer_state_t::eCropChanged) {
142 LayerProtoHelper::writeToProto(layer.crop, proto.mutable_crop());
143 }
144 if (layer.what & layer_state_t::eBufferChanged) {
145 proto::LayerState_BufferData* bufferProto = proto.mutable_buffer_data();
Vishnu Nair81750622023-03-08 15:02:06 -0800146 if (resolvedComposerState.externalTexture) {
147 bufferProto->set_buffer_id(resolvedComposerState.externalTexture->getId());
148 bufferProto->set_width(resolvedComposerState.externalTexture->getWidth());
149 bufferProto->set_height(resolvedComposerState.externalTexture->getHeight());
Vishnu Naird37343b2022-01-12 16:18:56 -0800150 bufferProto->set_pixel_format(static_cast<proto::LayerState_BufferData_PixelFormat>(
Vishnu Nair81750622023-03-08 15:02:06 -0800151 resolvedComposerState.externalTexture->getPixelFormat()));
152 bufferProto->set_usage(resolvedComposerState.externalTexture->getUsage());
Vishnu Nair6b591152021-10-08 11:45:14 -0700153 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800154 bufferProto->set_frame_number(layer.bufferData->frameNumber);
155 bufferProto->set_flags(layer.bufferData->flags.get());
156 bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id);
Vishnu Nair6b591152021-10-08 11:45:14 -0700157 }
158 if (layer.what & layer_state_t::eSidebandStreamChanged) {
159 proto.set_has_sideband_stream(layer.sidebandStream != nullptr);
160 }
161
162 if (layer.what & layer_state_t::eApiChanged) {
163 proto.set_api(layer.api);
164 }
165
166 if (layer.what & layer_state_t::eColorTransformChanged) {
167 LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform());
168 }
169 if (layer.what & layer_state_t::eBlurRegionsChanged) {
170 for (auto& region : layer.blurRegions) {
171 LayerProtoHelper::writeToProto(region, proto.add_blur_regions());
172 }
173 }
174
Vishnu Nair685cfef2022-02-02 10:01:25 -0800175 if (layer.what & layer_state_t::eReparent) {
Vishnu Nair81750622023-03-08 15:02:06 -0800176 proto.set_parent_id(resolvedComposerState.parentId);
Vishnu Nair6b591152021-10-08 11:45:14 -0700177 }
Vishnu Nair685cfef2022-02-02 10:01:25 -0800178 if (layer.what & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair81750622023-03-08 15:02:06 -0800179 proto.set_relative_parent_id(resolvedComposerState.relativeParentId);
Vishnu Naird37343b2022-01-12 16:18:56 -0800180 proto.set_z(layer.z);
Vishnu Nair6b591152021-10-08 11:45:14 -0700181 }
182
183 if (layer.what & layer_state_t::eInputInfoChanged) {
184 if (layer.windowInfoHandle) {
185 const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo();
186 proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800187 windowInfoProto->set_layout_params_flags(inputInfo->layoutParamsFlags.get());
188 windowInfoProto->set_layout_params_type(
189 static_cast<int32_t>(inputInfo->layoutParamsType));
Vishnu Nair6b591152021-10-08 11:45:14 -0700190 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
191 windowInfoProto->mutable_touchable_region());
192 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800193 windowInfoProto->set_focusable(
194 !inputInfo->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE));
195 windowInfoProto->set_has_wallpaper(inputInfo->inputConfig.test(
196 gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER));
Vishnu Nair6b591152021-10-08 11:45:14 -0700197 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
Vishnu Nair81750622023-03-08 15:02:06 -0800198 proto::Transform* transformProto = windowInfoProto->mutable_transform();
Vishnu Nair6b591152021-10-08 11:45:14 -0700199 transformProto->set_dsdx(inputInfo->transform.dsdx());
200 transformProto->set_dtdx(inputInfo->transform.dtdx());
201 transformProto->set_dtdy(inputInfo->transform.dtdy());
202 transformProto->set_dsdy(inputInfo->transform.dsdy());
203 transformProto->set_tx(inputInfo->transform.tx());
204 transformProto->set_ty(inputInfo->transform.ty());
205 windowInfoProto->set_replace_touchable_region_with_crop(
206 inputInfo->replaceTouchableRegionWithCrop);
Vishnu Nair81750622023-03-08 15:02:06 -0800207 windowInfoProto->set_crop_layer_id(resolvedComposerState.touchCropId);
Vishnu Nair6b591152021-10-08 11:45:14 -0700208 }
209 }
210 if (layer.what & layer_state_t::eBackgroundColorChanged) {
Vishnu Naird47bcee2023-02-24 18:08:51 +0000211 proto.set_bg_color_alpha(layer.bgColor.a);
Vishnu Nair6b591152021-10-08 11:45:14 -0700212 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
213 proto::LayerState_Color3* colorProto = proto.mutable_color();
Vishnu Naird47bcee2023-02-24 18:08:51 +0000214 colorProto->set_r(layer.bgColor.r);
215 colorProto->set_g(layer.bgColor.g);
216 colorProto->set_b(layer.bgColor.b);
Vishnu Nair6b591152021-10-08 11:45:14 -0700217 }
218 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
219 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
220 }
221 if (layer.what & layer_state_t::eShadowRadiusChanged) {
222 proto.set_shadow_radius(layer.shadowRadius);
223 }
224 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
225 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
226 }
227 if (layer.what & layer_state_t::eFrameRateChanged) {
228 proto.set_frame_rate(layer.frameRate);
229 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
230 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
231 }
232 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
233 proto.set_fixed_transform_hint(layer.fixedTransformHint);
234 }
235 if (layer.what & layer_state_t::eAutoRefreshChanged) {
236 proto.set_auto_refresh(layer.autoRefresh);
237 }
238 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
239 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
240 }
241 if (layer.what & layer_state_t::eBufferCropChanged) {
242 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
243 }
244 if (layer.what & layer_state_t::eDestinationFrameChanged) {
245 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
246 }
247 if (layer.what & layer_state_t::eDropInputModeChanged) {
248 proto.set_drop_input_mode(
249 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
250 }
251 return proto;
252}
253
Vishnu Nair685cfef2022-02-02 10:01:25 -0800254proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700255 proto::DisplayState proto;
256 proto.set_what(display.what);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800257 proto.set_id(mMapper->getDisplayId(display.token));
Vishnu Nair6b591152021-10-08 11:45:14 -0700258
259 if (display.what & DisplayState::eLayerStackChanged) {
260 proto.set_layer_stack(display.layerStack.id);
261 }
262 if (display.what & DisplayState::eDisplayProjectionChanged) {
263 proto.set_orientation(static_cast<uint32_t>(display.orientation));
264 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
265 proto.mutable_oriented_display_space_rect());
266 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
267 proto.mutable_layer_stack_space_rect());
268 }
269 if (display.what & DisplayState::eDisplaySizeChanged) {
270 proto.set_width(display.width);
271 proto.set_height(display.height);
272 }
273 if (display.what & DisplayState::eFlagsChanged) {
274 proto.set_flags(display.flags);
275 }
276 return proto;
277}
278
Vishnu Nair81750622023-03-08 15:02:06 -0800279proto::LayerCreationArgs TransactionProtoParser::toProto(const LayerCreationArgs& args) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800280 proto::LayerCreationArgs proto;
Vishnu Nair81750622023-03-08 15:02:06 -0800281 proto.set_layer_id(args.sequence);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800282 proto.set_name(args.name);
283 proto.set_flags(args.flags);
284 proto.set_parent_id(args.parentId);
Vishnu Nair81750622023-03-08 15:02:06 -0800285 proto.set_mirror_from_id(args.layerIdToMirror);
286 proto.set_add_to_root(args.addToRoot);
287 proto.set_layer_stack_to_mirror(args.layerStackToMirror.id);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800288 return proto;
289}
290
Vishnu Nair685cfef2022-02-02 10:01:25 -0800291TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700292 TransactionState t;
293 t.originPid = proto.pid();
294 t.originUid = proto.uid();
295 t.frameTimelineInfo.vsyncId = proto.vsync_id();
296 t.frameTimelineInfo.inputEventId = proto.input_event_id();
297 t.postTime = proto.post_time();
Vishnu Naird37343b2022-01-12 16:18:56 -0800298 t.id = proto.transaction_id();
299
Vishnu Nair6b591152021-10-08 11:45:14 -0700300 int32_t layerCount = proto.layer_changes_size();
301 t.states.reserve(static_cast<size_t>(layerCount));
302 for (int i = 0; i < layerCount; i++) {
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000303 ResolvedComposerState s;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800304 s.state.what = 0;
Vishnu Nair81750622023-03-08 15:02:06 -0800305 fromProto(proto.layer_changes(i), s);
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000306 t.states.emplace_back(s);
Vishnu Nair6b591152021-10-08 11:45:14 -0700307 }
308
309 int32_t displayCount = proto.display_changes_size();
310 t.displays.reserve(static_cast<size_t>(displayCount));
311 for (int i = 0; i < displayCount; i++) {
Vishnu Nair685cfef2022-02-02 10:01:25 -0800312 t.displays.add(fromProto(proto.display_changes(i)));
Vishnu Nair6b591152021-10-08 11:45:14 -0700313 }
314 return t;
315}
316
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800317void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
Vishnu Nair81750622023-03-08 15:02:06 -0800318 LayerCreationArgs& outArgs) {
319 outArgs.sequence = proto.layer_id();
320
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800321 outArgs.name = proto.name();
322 outArgs.flags = proto.flags();
323 outArgs.parentId = proto.parent_id();
Vishnu Nair81750622023-03-08 15:02:06 -0800324 outArgs.layerIdToMirror = proto.mirror_from_id();
325 outArgs.addToRoot = proto.add_to_root();
326 outArgs.layerStackToMirror.id = proto.layer_stack_to_mirror();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800327}
Vishnu Nair6b591152021-10-08 11:45:14 -0700328
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800329void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto,
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800330 TracingLayerState& outState) {
Vishnu Nair81750622023-03-08 15:02:06 -0800331 ResolvedComposerState resolvedComposerState;
332 fromProto(proto, resolvedComposerState);
333 layer_state_t& state = resolvedComposerState.state;
334 outState.state.merge(state);
335 outState.layerId = resolvedComposerState.layerId;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800336
337 if (state.what & layer_state_t::eReparent) {
Vishnu Nair81750622023-03-08 15:02:06 -0800338 outState.parentId = resolvedComposerState.parentId;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800339 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800340 if (state.what & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair81750622023-03-08 15:02:06 -0800341 outState.relativeParentId = resolvedComposerState.relativeParentId;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800342 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800343 if (state.what & layer_state_t::eInputInfoChanged) {
Vishnu Nair81750622023-03-08 15:02:06 -0800344 outState.touchCropId = resolvedComposerState.touchCropId;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800345 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800346 if (state.what & layer_state_t::eBufferChanged) {
Vishnu Nair81750622023-03-08 15:02:06 -0800347 outState.externalTexture = resolvedComposerState.externalTexture;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800348 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800349 if (state.what & layer_state_t::eSidebandStreamChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800350 outState.hasSidebandStream = proto.has_sideband_stream();
351 }
352}
353
Vishnu Nair81750622023-03-08 15:02:06 -0800354void TransactionProtoParser::fromProto(const proto::LayerState& proto,
355 ResolvedComposerState& resolvedComposerState) {
356 auto& layer = resolvedComposerState.state;
357 resolvedComposerState.layerId = proto.layer_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800358 layer.what |= proto.what();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800359
360 if (proto.what() & layer_state_t::ePositionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700361 layer.x = proto.x();
362 layer.y = proto.y();
363 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800364 if (proto.what() & layer_state_t::eLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700365 layer.z = proto.z();
366 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800367 if (proto.what() & layer_state_t::eLayerStackChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700368 layer.layerStack.id = proto.layer_stack();
369 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800370 if (proto.what() & layer_state_t::eFlagsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700371 layer.flags = proto.flags();
372 layer.mask = proto.mask();
373 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800374 if (proto.what() & layer_state_t::eMatrixChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700375 const proto::LayerState_Matrix22& matrixProto = proto.matrix();
376 layer.matrix.dsdx = matrixProto.dsdx();
377 layer.matrix.dsdy = matrixProto.dsdy();
378 layer.matrix.dtdx = matrixProto.dtdx();
379 layer.matrix.dtdy = matrixProto.dtdy();
380 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800381 if (proto.what() & layer_state_t::eCornerRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700382 layer.cornerRadius = proto.corner_radius();
383 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800384 if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700385 layer.backgroundBlurRadius = proto.background_blur_radius();
386 }
387
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800388 if (proto.what() & layer_state_t::eAlphaChanged) {
Vishnu Nairbbceb462022-10-10 04:52:13 +0000389 layer.color.a = proto.alpha();
Vishnu Nair6b591152021-10-08 11:45:14 -0700390 }
391
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800392 if (proto.what() & layer_state_t::eColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700393 const proto::LayerState_Color3& colorProto = proto.color();
394 layer.color.r = colorProto.r();
395 layer.color.g = colorProto.g();
396 layer.color.b = colorProto.b();
397 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800398 if (proto.what() & layer_state_t::eTransparentRegionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700399 LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
400 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000401 if (proto.what() & layer_state_t::eBufferTransformChanged) {
402 layer.bufferTransform = proto.transform();
Vishnu Nair6b591152021-10-08 11:45:14 -0700403 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800404 if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700405 layer.transformToDisplayInverse = proto.transform_to_display_inverse();
406 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800407 if (proto.what() & layer_state_t::eCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700408 LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
409 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800410 if (proto.what() & layer_state_t::eBufferChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700411 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800412 layer.bufferData =
Vishnu Nair81750622023-03-08 15:02:06 -0800413 std::make_shared<fake::BufferData>(bufferProto.buffer_id(), bufferProto.width(),
414 bufferProto.height(), bufferProto.pixel_format(),
415 bufferProto.usage());
416 resolvedComposerState.externalTexture =
417 std::make_shared<FakeExternalTexture>(layer.bufferData->getWidth(),
418 layer.bufferData->getHeight(),
419 layer.bufferData->getId(),
420 layer.bufferData->getPixelFormat(),
421 layer.bufferData->getUsage());
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800422 layer.bufferData->frameNumber = bufferProto.frame_number();
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700423 layer.bufferData->flags = ftl::Flags<BufferData::BufferDataChange>(bufferProto.flags());
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800424 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
Vishnu Nair8eebba42022-02-25 07:57:15 -0800425 layer.bufferData->acquireFence = Fence::NO_FENCE;
Vishnu Nair6b591152021-10-08 11:45:14 -0700426 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700427
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800428 if (proto.what() & layer_state_t::eApiChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700429 layer.api = proto.api();
430 }
431
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800432 if (proto.what() & layer_state_t::eColorTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700433 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
434 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800435 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700436 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
437 for (int i = 0; i < proto.blur_regions_size(); i++) {
438 android::BlurRegion region;
439 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
440 layer.blurRegions.push_back(region);
441 }
442 }
443
Vishnu Nair685cfef2022-02-02 10:01:25 -0800444 if (proto.what() & layer_state_t::eReparent) {
Vishnu Nair81750622023-03-08 15:02:06 -0800445 resolvedComposerState.parentId = proto.parent_id();
Vishnu Nair6b591152021-10-08 11:45:14 -0700446 }
Vishnu Naird37343b2022-01-12 16:18:56 -0800447 if (proto.what() & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair81750622023-03-08 15:02:06 -0800448 resolvedComposerState.relativeParentId = proto.relative_parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800449 layer.z = proto.z();
Vishnu Nair6b591152021-10-08 11:45:14 -0700450 }
451
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800452 if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700453 gui::WindowInfo inputInfo;
454 const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
455
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800456 inputInfo.layoutParamsFlags =
457 static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
458 inputInfo.layoutParamsType =
459 static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
Vishnu Nair6b591152021-10-08 11:45:14 -0700460 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
461 inputInfo.touchableRegion);
462 inputInfo.surfaceInset = windowInfoProto.surface_inset();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800463 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_FOCUSABLE,
464 !windowInfoProto.focusable());
465 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER,
466 windowInfoProto.has_wallpaper());
Vishnu Nair6b591152021-10-08 11:45:14 -0700467 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
Vishnu Nair81750622023-03-08 15:02:06 -0800468 const proto::Transform& transformProto = windowInfoProto.transform();
Vishnu Nair6b591152021-10-08 11:45:14 -0700469 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
470 transformProto.dsdy());
471 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
472 inputInfo.replaceTouchableRegionWithCrop =
473 windowInfoProto.replace_touchable_region_with_crop();
Vishnu Nair81750622023-03-08 15:02:06 -0800474 resolvedComposerState.touchCropId = windowInfoProto.crop_layer_id();
Vishnu Nair286f4f92022-06-08 16:37:39 -0700475
Vishnu Nair6b591152021-10-08 11:45:14 -0700476 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
477 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800478 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
Vishnu Naird47bcee2023-02-24 18:08:51 +0000479 layer.bgColor.a = proto.bg_color_alpha();
Vishnu Nair6b591152021-10-08 11:45:14 -0700480 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
481 const proto::LayerState_Color3& colorProto = proto.color();
Vishnu Naird47bcee2023-02-24 18:08:51 +0000482 layer.bgColor.r = colorProto.r();
483 layer.bgColor.g = colorProto.g();
484 layer.bgColor.b = colorProto.b();
Vishnu Nair6b591152021-10-08 11:45:14 -0700485 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800486 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700487 layer.colorSpaceAgnostic = proto.color_space_agnostic();
488 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800489 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700490 layer.shadowRadius = proto.shadow_radius();
491 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800492 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700493 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
494 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800495 if (proto.what() & layer_state_t::eFrameRateChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700496 layer.frameRate = proto.frame_rate();
497 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
498 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
499 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800500 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700501 layer.fixedTransformHint =
502 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
503 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800504 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700505 layer.autoRefresh = proto.auto_refresh();
506 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800507 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700508 layer.isTrustedOverlay = proto.is_trusted_overlay();
509 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800510 if (proto.what() & layer_state_t::eBufferCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700511 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
512 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800513 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700514 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
515 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800516 if (proto.what() & layer_state_t::eDropInputModeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700517 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
518 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700519}
520
Vishnu Nair685cfef2022-02-02 10:01:25 -0800521DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700522 DisplayState display;
523 display.what = proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800524 display.token = mMapper->getDisplayHandle(proto.id());
Vishnu Nair6b591152021-10-08 11:45:14 -0700525
526 if (display.what & DisplayState::eLayerStackChanged) {
527 display.layerStack.id = proto.layer_stack();
528 }
529 if (display.what & DisplayState::eDisplayProjectionChanged) {
530 display.orientation = static_cast<ui::Rotation>(proto.orientation());
531 LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
532 display.orientedDisplaySpaceRect);
533 LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
534 display.layerStackSpaceRect);
535 }
536 if (display.what & DisplayState::eDisplaySizeChanged) {
537 display.width = proto.width();
538 display.height = proto.height();
539 }
540 if (display.what & DisplayState::eFlagsChanged) {
541 display.flags = proto.flags();
542 }
543 return display;
544}
545
Vishnu Nair81750622023-03-08 15:02:06 -0800546void asProto(proto::Transform* proto, const ui::Transform& transform) {
547 proto->set_dsdx(transform.dsdx());
548 proto->set_dtdx(transform.dtdx());
549 proto->set_dtdy(transform.dtdy());
550 proto->set_dsdy(transform.dsdy());
551 proto->set_tx(transform.tx());
552 proto->set_ty(transform.ty());
553}
554
555proto::DisplayInfo TransactionProtoParser::toProto(const frontend::DisplayInfo& displayInfo,
556 uint32_t layerStack) {
557 proto::DisplayInfo proto;
558 proto.set_layer_stack(layerStack);
559 proto.set_display_id(displayInfo.info.displayId);
560 proto.set_logical_width(displayInfo.info.logicalWidth);
561 proto.set_logical_height(displayInfo.info.logicalHeight);
562 asProto(proto.mutable_transform_inverse(), displayInfo.info.transform);
563 asProto(proto.mutable_transform(), displayInfo.transform);
564 proto.set_receives_input(displayInfo.receivesInput);
565 proto.set_is_secure(displayInfo.isSecure);
566 proto.set_is_primary(displayInfo.isPrimary);
567 proto.set_is_virtual(displayInfo.isVirtual);
568 proto.set_rotation_flags((int)displayInfo.rotationFlags);
569 proto.set_transform_hint((int)displayInfo.transformHint);
570 return proto;
571}
572
573void fromProto2(ui::Transform& outTransform, const proto::Transform& proto) {
574 outTransform.set(proto.dsdx(), proto.dtdx(), proto.dtdy(), proto.dsdy());
575 outTransform.set(proto.tx(), proto.ty());
576}
577
578frontend::DisplayInfo TransactionProtoParser::fromProto(const proto::DisplayInfo& proto) {
579 frontend::DisplayInfo displayInfo;
580 displayInfo.info.displayId = proto.display_id();
581 displayInfo.info.logicalWidth = proto.logical_width();
582 displayInfo.info.logicalHeight = proto.logical_height();
583 fromProto2(displayInfo.info.transform, proto.transform_inverse());
584 fromProto2(displayInfo.transform, proto.transform());
585 displayInfo.receivesInput = proto.receives_input();
586 displayInfo.isSecure = proto.is_secure();
587 displayInfo.isPrimary = proto.is_primary();
Vishnu Nair0d13b912023-03-27 22:06:38 +0000588 displayInfo.isVirtual = proto.is_virtual();
Vishnu Nair81750622023-03-08 15:02:06 -0800589 displayInfo.rotationFlags = (ui::Transform::RotationFlags)proto.rotation_flags();
590 displayInfo.transformHint = (ui::Transform::RotationFlags)proto.transform_hint();
591 return displayInfo;
592}
593
594void TransactionProtoParser::fromProto(
595 const google::protobuf::RepeatedPtrField<proto::DisplayInfo>& proto,
Vishnu Nair0d13b912023-03-27 22:06:38 +0000596 display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& outDisplayInfos) {
Vishnu Nair81750622023-03-08 15:02:06 -0800597 outDisplayInfos.clear();
598 for (const proto::DisplayInfo& displayInfo : proto) {
599 outDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(displayInfo.layer_stack()),
600 fromProto(displayInfo));
601 }
602}
603
Vishnu Nair6b591152021-10-08 11:45:14 -0700604} // namespace android::surfaceflinger