blob: 06941809ba78d0f49aed64e8d75a7c21a1e32228 [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; }
Alec Mouri74c7ae12023-03-26 02:57:47 +000050 void remapBuffer() override {}
Vishnu Nair81750622023-03-08 15:02:06 -080051 ~FakeExternalTexture() = default;
52};
53
Vishnu Nair685cfef2022-02-02 10:01:25 -080054proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t) {
Vishnu Nair6b591152021-10-08 11:45:14 -070055 proto::TransactionState proto;
56 proto.set_pid(t.originPid);
57 proto.set_uid(t.originUid);
58 proto.set_vsync_id(t.frameTimelineInfo.vsyncId);
59 proto.set_input_event_id(t.frameTimelineInfo.inputEventId);
60 proto.set_post_time(t.postTime);
Vishnu Naird37343b2022-01-12 16:18:56 -080061 proto.set_transaction_id(t.id);
Vishnu Nair6b591152021-10-08 11:45:14 -070062
Vishnu Nair685cfef2022-02-02 10:01:25 -080063 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(t.states.size()));
Vishnu Nair6b591152021-10-08 11:45:14 -070064 for (auto& layerState : t.states) {
Vishnu Nair81750622023-03-08 15:02:06 -080065 proto.mutable_layer_changes()->Add(std::move(toProto(layerState)));
Vishnu Nair6b591152021-10-08 11:45:14 -070066 }
67
Vishnu Nair685cfef2022-02-02 10:01:25 -080068 proto.mutable_display_changes()->Reserve(static_cast<int32_t>(t.displays.size()));
Vishnu Nair6b591152021-10-08 11:45:14 -070069 for (auto& displayState : t.displays) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080070 proto.mutable_display_changes()->Add(std::move(toProto(displayState)));
Vishnu Nair6b591152021-10-08 11:45:14 -070071 }
Pablo Gamito23780be2023-04-18 08:30:00 +000072
73 proto.mutable_merged_transaction_ids()->Reserve(
74 static_cast<int32_t>(t.mergedTransactionIds.size()));
75 for (auto& mergedTransactionId : t.mergedTransactionIds) {
76 proto.mutable_merged_transaction_ids()->Add(mergedTransactionId);
77 }
78
Vishnu Nair6b591152021-10-08 11:45:14 -070079 return proto;
80}
81
Vishnu Nair68dee2b2021-11-08 18:52:12 -080082proto::TransactionState TransactionProtoParser::toProto(
Vishnu Nair81750622023-03-08 15:02:06 -080083 const std::map<uint32_t /* layerId */, TracingLayerState>& states) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -080084 proto::TransactionState proto;
Vishnu Nair685cfef2022-02-02 10:01:25 -080085 proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(states.size()));
Vishnu Nair68dee2b2021-11-08 18:52:12 -080086 for (auto& [layerId, state] : states) {
Vishnu Nair685cfef2022-02-02 10:01:25 -080087 proto::LayerState layerProto = toProto(state);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080088 layerProto.set_has_sideband_stream(state.hasSidebandStream);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080089 proto.mutable_layer_changes()->Add(std::move(layerProto));
90 }
91 return proto;
92}
93
Vishnu Nair81750622023-03-08 15:02:06 -080094proto::LayerState TransactionProtoParser::toProto(
95 const ResolvedComposerState& resolvedComposerState) {
Vishnu Nair6b591152021-10-08 11:45:14 -070096 proto::LayerState proto;
Vishnu Nair81750622023-03-08 15:02:06 -080097 auto& layer = resolvedComposerState.state;
98 proto.set_layer_id(resolvedComposerState.layerId);
Vishnu Nair6b591152021-10-08 11:45:14 -070099 proto.set_what(layer.what);
100
101 if (layer.what & layer_state_t::ePositionChanged) {
102 proto.set_x(layer.x);
103 proto.set_y(layer.y);
104 }
105 if (layer.what & layer_state_t::eLayerChanged) {
106 proto.set_z(layer.z);
107 }
Vishnu Nairea04b6f2022-08-19 21:28:17 +0000108
Vishnu Nair6b591152021-10-08 11:45:14 -0700109 if (layer.what & layer_state_t::eLayerStackChanged) {
110 proto.set_layer_stack(layer.layerStack.id);
111 }
112 if (layer.what & layer_state_t::eFlagsChanged) {
113 proto.set_flags(layer.flags);
114 proto.set_mask(layer.mask);
115 }
116 if (layer.what & layer_state_t::eMatrixChanged) {
117 proto::LayerState_Matrix22* matrixProto = proto.mutable_matrix();
118 matrixProto->set_dsdx(layer.matrix.dsdx);
119 matrixProto->set_dsdy(layer.matrix.dsdy);
120 matrixProto->set_dtdx(layer.matrix.dtdx);
121 matrixProto->set_dtdy(layer.matrix.dtdy);
122 }
123 if (layer.what & layer_state_t::eCornerRadiusChanged) {
124 proto.set_corner_radius(layer.cornerRadius);
125 }
126 if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) {
127 proto.set_background_blur_radius(layer.backgroundBlurRadius);
128 }
129
130 if (layer.what & layer_state_t::eAlphaChanged) {
Vishnu Nairbbceb462022-10-10 04:52:13 +0000131 proto.set_alpha(layer.color.a);
Vishnu Nair6b591152021-10-08 11:45:14 -0700132 }
133
134 if (layer.what & layer_state_t::eColorChanged) {
135 proto::LayerState_Color3* colorProto = proto.mutable_color();
136 colorProto->set_r(layer.color.r);
137 colorProto->set_g(layer.color.g);
138 colorProto->set_b(layer.color.b);
139 }
140 if (layer.what & layer_state_t::eTransparentRegionChanged) {
141 LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region());
142 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000143 if (layer.what & layer_state_t::eBufferTransformChanged) {
144 proto.set_transform(layer.bufferTransform);
Vishnu Nair6b591152021-10-08 11:45:14 -0700145 }
146 if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
147 proto.set_transform_to_display_inverse(layer.transformToDisplayInverse);
148 }
149 if (layer.what & layer_state_t::eCropChanged) {
150 LayerProtoHelper::writeToProto(layer.crop, proto.mutable_crop());
151 }
152 if (layer.what & layer_state_t::eBufferChanged) {
153 proto::LayerState_BufferData* bufferProto = proto.mutable_buffer_data();
Vishnu Nair81750622023-03-08 15:02:06 -0800154 if (resolvedComposerState.externalTexture) {
155 bufferProto->set_buffer_id(resolvedComposerState.externalTexture->getId());
156 bufferProto->set_width(resolvedComposerState.externalTexture->getWidth());
157 bufferProto->set_height(resolvedComposerState.externalTexture->getHeight());
Vishnu Naird37343b2022-01-12 16:18:56 -0800158 bufferProto->set_pixel_format(static_cast<proto::LayerState_BufferData_PixelFormat>(
Vishnu Nair81750622023-03-08 15:02:06 -0800159 resolvedComposerState.externalTexture->getPixelFormat()));
160 bufferProto->set_usage(resolvedComposerState.externalTexture->getUsage());
Vishnu Nair6b591152021-10-08 11:45:14 -0700161 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800162 bufferProto->set_frame_number(layer.bufferData->frameNumber);
163 bufferProto->set_flags(layer.bufferData->flags.get());
164 bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id);
Vishnu Nair6b591152021-10-08 11:45:14 -0700165 }
166 if (layer.what & layer_state_t::eSidebandStreamChanged) {
167 proto.set_has_sideband_stream(layer.sidebandStream != nullptr);
168 }
169
170 if (layer.what & layer_state_t::eApiChanged) {
171 proto.set_api(layer.api);
172 }
173
174 if (layer.what & layer_state_t::eColorTransformChanged) {
175 LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform());
176 }
177 if (layer.what & layer_state_t::eBlurRegionsChanged) {
178 for (auto& region : layer.blurRegions) {
179 LayerProtoHelper::writeToProto(region, proto.add_blur_regions());
180 }
181 }
182
Vishnu Nair685cfef2022-02-02 10:01:25 -0800183 if (layer.what & layer_state_t::eReparent) {
Vishnu Nair81750622023-03-08 15:02:06 -0800184 proto.set_parent_id(resolvedComposerState.parentId);
Vishnu Nair6b591152021-10-08 11:45:14 -0700185 }
Vishnu Nair685cfef2022-02-02 10:01:25 -0800186 if (layer.what & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair81750622023-03-08 15:02:06 -0800187 proto.set_relative_parent_id(resolvedComposerState.relativeParentId);
Vishnu Naird37343b2022-01-12 16:18:56 -0800188 proto.set_z(layer.z);
Vishnu Nair6b591152021-10-08 11:45:14 -0700189 }
190
191 if (layer.what & layer_state_t::eInputInfoChanged) {
192 if (layer.windowInfoHandle) {
193 const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo();
194 proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800195 windowInfoProto->set_layout_params_flags(inputInfo->layoutParamsFlags.get());
196 windowInfoProto->set_layout_params_type(
197 static_cast<int32_t>(inputInfo->layoutParamsType));
Vishnu Nair6b591152021-10-08 11:45:14 -0700198 LayerProtoHelper::writeToProto(inputInfo->touchableRegion,
199 windowInfoProto->mutable_touchable_region());
200 windowInfoProto->set_surface_inset(inputInfo->surfaceInset);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800201 windowInfoProto->set_focusable(
202 !inputInfo->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE));
203 windowInfoProto->set_has_wallpaper(inputInfo->inputConfig.test(
204 gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER));
Vishnu Nair6b591152021-10-08 11:45:14 -0700205 windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor);
Vishnu Nair81750622023-03-08 15:02:06 -0800206 proto::Transform* transformProto = windowInfoProto->mutable_transform();
Vishnu Nair6b591152021-10-08 11:45:14 -0700207 transformProto->set_dsdx(inputInfo->transform.dsdx());
208 transformProto->set_dtdx(inputInfo->transform.dtdx());
209 transformProto->set_dtdy(inputInfo->transform.dtdy());
210 transformProto->set_dsdy(inputInfo->transform.dsdy());
211 transformProto->set_tx(inputInfo->transform.tx());
212 transformProto->set_ty(inputInfo->transform.ty());
213 windowInfoProto->set_replace_touchable_region_with_crop(
214 inputInfo->replaceTouchableRegionWithCrop);
Vishnu Nair81750622023-03-08 15:02:06 -0800215 windowInfoProto->set_crop_layer_id(resolvedComposerState.touchCropId);
Vishnu Nair6b591152021-10-08 11:45:14 -0700216 }
217 }
218 if (layer.what & layer_state_t::eBackgroundColorChanged) {
Vishnu Naird47bcee2023-02-24 18:08:51 +0000219 proto.set_bg_color_alpha(layer.bgColor.a);
Vishnu Nair6b591152021-10-08 11:45:14 -0700220 proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace));
221 proto::LayerState_Color3* colorProto = proto.mutable_color();
Vishnu Naird47bcee2023-02-24 18:08:51 +0000222 colorProto->set_r(layer.bgColor.r);
223 colorProto->set_g(layer.bgColor.g);
224 colorProto->set_b(layer.bgColor.b);
Vishnu Nair6b591152021-10-08 11:45:14 -0700225 }
226 if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) {
227 proto.set_color_space_agnostic(layer.colorSpaceAgnostic);
228 }
229 if (layer.what & layer_state_t::eShadowRadiusChanged) {
230 proto.set_shadow_radius(layer.shadowRadius);
231 }
232 if (layer.what & layer_state_t::eFrameRateSelectionPriority) {
233 proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority);
234 }
235 if (layer.what & layer_state_t::eFrameRateChanged) {
236 proto.set_frame_rate(layer.frameRate);
237 proto.set_frame_rate_compatibility(layer.frameRateCompatibility);
238 proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy);
239 }
240 if (layer.what & layer_state_t::eFixedTransformHintChanged) {
241 proto.set_fixed_transform_hint(layer.fixedTransformHint);
242 }
243 if (layer.what & layer_state_t::eAutoRefreshChanged) {
244 proto.set_auto_refresh(layer.autoRefresh);
245 }
246 if (layer.what & layer_state_t::eTrustedOverlayChanged) {
247 proto.set_is_trusted_overlay(layer.isTrustedOverlay);
248 }
249 if (layer.what & layer_state_t::eBufferCropChanged) {
250 LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop());
251 }
252 if (layer.what & layer_state_t::eDestinationFrameChanged) {
253 LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame());
254 }
255 if (layer.what & layer_state_t::eDropInputModeChanged) {
256 proto.set_drop_input_mode(
257 static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode));
258 }
259 return proto;
260}
261
Vishnu Nair685cfef2022-02-02 10:01:25 -0800262proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700263 proto::DisplayState proto;
264 proto.set_what(display.what);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800265 proto.set_id(mMapper->getDisplayId(display.token));
Vishnu Nair6b591152021-10-08 11:45:14 -0700266
267 if (display.what & DisplayState::eLayerStackChanged) {
268 proto.set_layer_stack(display.layerStack.id);
269 }
270 if (display.what & DisplayState::eDisplayProjectionChanged) {
271 proto.set_orientation(static_cast<uint32_t>(display.orientation));
272 LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect,
273 proto.mutable_oriented_display_space_rect());
274 LayerProtoHelper::writeToProto(display.layerStackSpaceRect,
275 proto.mutable_layer_stack_space_rect());
276 }
277 if (display.what & DisplayState::eDisplaySizeChanged) {
278 proto.set_width(display.width);
279 proto.set_height(display.height);
280 }
281 if (display.what & DisplayState::eFlagsChanged) {
282 proto.set_flags(display.flags);
283 }
284 return proto;
285}
286
Vishnu Nair81750622023-03-08 15:02:06 -0800287proto::LayerCreationArgs TransactionProtoParser::toProto(const LayerCreationArgs& args) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800288 proto::LayerCreationArgs proto;
Vishnu Nair81750622023-03-08 15:02:06 -0800289 proto.set_layer_id(args.sequence);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800290 proto.set_name(args.name);
291 proto.set_flags(args.flags);
292 proto.set_parent_id(args.parentId);
Vishnu Nair81750622023-03-08 15:02:06 -0800293 proto.set_mirror_from_id(args.layerIdToMirror);
294 proto.set_add_to_root(args.addToRoot);
295 proto.set_layer_stack_to_mirror(args.layerStackToMirror.id);
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800296 return proto;
297}
298
Vishnu Nair685cfef2022-02-02 10:01:25 -0800299TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700300 TransactionState t;
301 t.originPid = proto.pid();
302 t.originUid = proto.uid();
303 t.frameTimelineInfo.vsyncId = proto.vsync_id();
304 t.frameTimelineInfo.inputEventId = proto.input_event_id();
305 t.postTime = proto.post_time();
Vishnu Naird37343b2022-01-12 16:18:56 -0800306 t.id = proto.transaction_id();
307
Vishnu Nair6b591152021-10-08 11:45:14 -0700308 int32_t layerCount = proto.layer_changes_size();
309 t.states.reserve(static_cast<size_t>(layerCount));
310 for (int i = 0; i < layerCount; i++) {
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000311 ResolvedComposerState s;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800312 s.state.what = 0;
Vishnu Nair81750622023-03-08 15:02:06 -0800313 fromProto(proto.layer_changes(i), s);
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000314 t.states.emplace_back(s);
Vishnu Nair6b591152021-10-08 11:45:14 -0700315 }
316
317 int32_t displayCount = proto.display_changes_size();
318 t.displays.reserve(static_cast<size_t>(displayCount));
319 for (int i = 0; i < displayCount; i++) {
Vishnu Nair685cfef2022-02-02 10:01:25 -0800320 t.displays.add(fromProto(proto.display_changes(i)));
Vishnu Nair6b591152021-10-08 11:45:14 -0700321 }
322 return t;
323}
324
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800325void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto,
Vishnu Nair81750622023-03-08 15:02:06 -0800326 LayerCreationArgs& outArgs) {
327 outArgs.sequence = proto.layer_id();
328
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800329 outArgs.name = proto.name();
330 outArgs.flags = proto.flags();
331 outArgs.parentId = proto.parent_id();
Vishnu Nair81750622023-03-08 15:02:06 -0800332 outArgs.layerIdToMirror = proto.mirror_from_id();
333 outArgs.addToRoot = proto.add_to_root();
334 outArgs.layerStackToMirror.id = proto.layer_stack_to_mirror();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800335}
Vishnu Nair6b591152021-10-08 11:45:14 -0700336
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800337void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto,
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800338 TracingLayerState& outState) {
Vishnu Nair81750622023-03-08 15:02:06 -0800339 ResolvedComposerState resolvedComposerState;
340 fromProto(proto, resolvedComposerState);
341 layer_state_t& state = resolvedComposerState.state;
342 outState.state.merge(state);
343 outState.layerId = resolvedComposerState.layerId;
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800344
345 if (state.what & layer_state_t::eReparent) {
Vishnu Nair81750622023-03-08 15:02:06 -0800346 outState.parentId = resolvedComposerState.parentId;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800347 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800348 if (state.what & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair81750622023-03-08 15:02:06 -0800349 outState.relativeParentId = resolvedComposerState.relativeParentId;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800350 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800351 if (state.what & layer_state_t::eInputInfoChanged) {
Vishnu Nair81750622023-03-08 15:02:06 -0800352 outState.touchCropId = resolvedComposerState.touchCropId;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800353 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800354 if (state.what & layer_state_t::eBufferChanged) {
Vishnu Nair81750622023-03-08 15:02:06 -0800355 outState.externalTexture = resolvedComposerState.externalTexture;
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800356 }
Vishnu Nair7b0f18b2022-01-12 16:39:08 -0800357 if (state.what & layer_state_t::eSidebandStreamChanged) {
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800358 outState.hasSidebandStream = proto.has_sideband_stream();
359 }
360}
361
Vishnu Nair81750622023-03-08 15:02:06 -0800362void TransactionProtoParser::fromProto(const proto::LayerState& proto,
363 ResolvedComposerState& resolvedComposerState) {
364 auto& layer = resolvedComposerState.state;
365 resolvedComposerState.layerId = proto.layer_id();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800366 layer.what |= proto.what();
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800367
368 if (proto.what() & layer_state_t::ePositionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700369 layer.x = proto.x();
370 layer.y = proto.y();
371 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800372 if (proto.what() & layer_state_t::eLayerChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700373 layer.z = proto.z();
374 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800375 if (proto.what() & layer_state_t::eLayerStackChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700376 layer.layerStack.id = proto.layer_stack();
377 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800378 if (proto.what() & layer_state_t::eFlagsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700379 layer.flags = proto.flags();
380 layer.mask = proto.mask();
381 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800382 if (proto.what() & layer_state_t::eMatrixChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700383 const proto::LayerState_Matrix22& matrixProto = proto.matrix();
384 layer.matrix.dsdx = matrixProto.dsdx();
385 layer.matrix.dsdy = matrixProto.dsdy();
386 layer.matrix.dtdx = matrixProto.dtdx();
387 layer.matrix.dtdy = matrixProto.dtdy();
388 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800389 if (proto.what() & layer_state_t::eCornerRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700390 layer.cornerRadius = proto.corner_radius();
391 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800392 if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700393 layer.backgroundBlurRadius = proto.background_blur_radius();
394 }
395
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800396 if (proto.what() & layer_state_t::eAlphaChanged) {
Vishnu Nairbbceb462022-10-10 04:52:13 +0000397 layer.color.a = proto.alpha();
Vishnu Nair6b591152021-10-08 11:45:14 -0700398 }
399
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800400 if (proto.what() & layer_state_t::eColorChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700401 const proto::LayerState_Color3& colorProto = proto.color();
402 layer.color.r = colorProto.r();
403 layer.color.g = colorProto.g();
404 layer.color.b = colorProto.b();
405 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800406 if (proto.what() & layer_state_t::eTransparentRegionChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700407 LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
408 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000409 if (proto.what() & layer_state_t::eBufferTransformChanged) {
410 layer.bufferTransform = proto.transform();
Vishnu Nair6b591152021-10-08 11:45:14 -0700411 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800412 if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700413 layer.transformToDisplayInverse = proto.transform_to_display_inverse();
414 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800415 if (proto.what() & layer_state_t::eCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700416 LayerProtoHelper::readFromProto(proto.crop(), layer.crop);
417 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800418 if (proto.what() & layer_state_t::eBufferChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700419 const proto::LayerState_BufferData& bufferProto = proto.buffer_data();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800420 layer.bufferData =
Vishnu Nair81750622023-03-08 15:02:06 -0800421 std::make_shared<fake::BufferData>(bufferProto.buffer_id(), bufferProto.width(),
422 bufferProto.height(), bufferProto.pixel_format(),
423 bufferProto.usage());
424 resolvedComposerState.externalTexture =
425 std::make_shared<FakeExternalTexture>(layer.bufferData->getWidth(),
426 layer.bufferData->getHeight(),
427 layer.bufferData->getId(),
428 layer.bufferData->getPixelFormat(),
429 layer.bufferData->getUsage());
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800430 layer.bufferData->frameNumber = bufferProto.frame_number();
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700431 layer.bufferData->flags = ftl::Flags<BufferData::BufferDataChange>(bufferProto.flags());
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800432 layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id();
Vishnu Nair8eebba42022-02-25 07:57:15 -0800433 layer.bufferData->acquireFence = Fence::NO_FENCE;
Vishnu Nair6b591152021-10-08 11:45:14 -0700434 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700435
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800436 if (proto.what() & layer_state_t::eApiChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700437 layer.api = proto.api();
438 }
439
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800440 if (proto.what() & layer_state_t::eColorTransformChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700441 LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform);
442 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800443 if (proto.what() & layer_state_t::eBlurRegionsChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700444 layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size()));
445 for (int i = 0; i < proto.blur_regions_size(); i++) {
446 android::BlurRegion region;
447 LayerProtoHelper::readFromProto(proto.blur_regions(i), region);
448 layer.blurRegions.push_back(region);
449 }
450 }
451
Vishnu Nair685cfef2022-02-02 10:01:25 -0800452 if (proto.what() & layer_state_t::eReparent) {
Vishnu Nair81750622023-03-08 15:02:06 -0800453 resolvedComposerState.parentId = proto.parent_id();
Vishnu Nair6b591152021-10-08 11:45:14 -0700454 }
Vishnu Naird37343b2022-01-12 16:18:56 -0800455 if (proto.what() & layer_state_t::eRelativeLayerChanged) {
Vishnu Nair81750622023-03-08 15:02:06 -0800456 resolvedComposerState.relativeParentId = proto.relative_parent_id();
Vishnu Naird37343b2022-01-12 16:18:56 -0800457 layer.z = proto.z();
Vishnu Nair6b591152021-10-08 11:45:14 -0700458 }
459
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800460 if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700461 gui::WindowInfo inputInfo;
462 const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle();
463
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800464 inputInfo.layoutParamsFlags =
465 static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags());
466 inputInfo.layoutParamsType =
467 static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type());
Vishnu Nair6b591152021-10-08 11:45:14 -0700468 LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(),
469 inputInfo.touchableRegion);
470 inputInfo.surfaceInset = windowInfoProto.surface_inset();
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -0800471 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_FOCUSABLE,
472 !windowInfoProto.focusable());
473 inputInfo.setInputConfig(gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER,
474 windowInfoProto.has_wallpaper());
Vishnu Nair6b591152021-10-08 11:45:14 -0700475 inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor();
Vishnu Nair81750622023-03-08 15:02:06 -0800476 const proto::Transform& transformProto = windowInfoProto.transform();
Vishnu Nair6b591152021-10-08 11:45:14 -0700477 inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(),
478 transformProto.dsdy());
479 inputInfo.transform.set(transformProto.tx(), transformProto.ty());
480 inputInfo.replaceTouchableRegionWithCrop =
481 windowInfoProto.replace_touchable_region_with_crop();
Vishnu Nair81750622023-03-08 15:02:06 -0800482 resolvedComposerState.touchCropId = windowInfoProto.crop_layer_id();
Vishnu Nair286f4f92022-06-08 16:37:39 -0700483
Vishnu Nair6b591152021-10-08 11:45:14 -0700484 layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo);
485 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800486 if (proto.what() & layer_state_t::eBackgroundColorChanged) {
Vishnu Naird47bcee2023-02-24 18:08:51 +0000487 layer.bgColor.a = proto.bg_color_alpha();
Vishnu Nair6b591152021-10-08 11:45:14 -0700488 layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace());
489 const proto::LayerState_Color3& colorProto = proto.color();
Vishnu Naird47bcee2023-02-24 18:08:51 +0000490 layer.bgColor.r = colorProto.r();
491 layer.bgColor.g = colorProto.g();
492 layer.bgColor.b = colorProto.b();
Vishnu Nair6b591152021-10-08 11:45:14 -0700493 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800494 if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700495 layer.colorSpaceAgnostic = proto.color_space_agnostic();
496 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800497 if (proto.what() & layer_state_t::eShadowRadiusChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700498 layer.shadowRadius = proto.shadow_radius();
499 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800500 if (proto.what() & layer_state_t::eFrameRateSelectionPriority) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700501 layer.frameRateSelectionPriority = proto.frame_rate_selection_priority();
502 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800503 if (proto.what() & layer_state_t::eFrameRateChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700504 layer.frameRate = proto.frame_rate();
505 layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility());
506 layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy());
507 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800508 if (proto.what() & layer_state_t::eFixedTransformHintChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700509 layer.fixedTransformHint =
510 static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint());
511 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800512 if (proto.what() & layer_state_t::eAutoRefreshChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700513 layer.autoRefresh = proto.auto_refresh();
514 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800515 if (proto.what() & layer_state_t::eTrustedOverlayChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700516 layer.isTrustedOverlay = proto.is_trusted_overlay();
517 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800518 if (proto.what() & layer_state_t::eBufferCropChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700519 LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop);
520 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800521 if (proto.what() & layer_state_t::eDestinationFrameChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700522 LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame);
523 }
Vishnu Nair68dee2b2021-11-08 18:52:12 -0800524 if (proto.what() & layer_state_t::eDropInputModeChanged) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700525 layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode());
526 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700527}
528
Vishnu Nair685cfef2022-02-02 10:01:25 -0800529DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto) {
Vishnu Nair6b591152021-10-08 11:45:14 -0700530 DisplayState display;
531 display.what = proto.what();
Vishnu Nair685cfef2022-02-02 10:01:25 -0800532 display.token = mMapper->getDisplayHandle(proto.id());
Vishnu Nair6b591152021-10-08 11:45:14 -0700533
534 if (display.what & DisplayState::eLayerStackChanged) {
535 display.layerStack.id = proto.layer_stack();
536 }
537 if (display.what & DisplayState::eDisplayProjectionChanged) {
538 display.orientation = static_cast<ui::Rotation>(proto.orientation());
539 LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(),
540 display.orientedDisplaySpaceRect);
541 LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(),
542 display.layerStackSpaceRect);
543 }
544 if (display.what & DisplayState::eDisplaySizeChanged) {
545 display.width = proto.width();
546 display.height = proto.height();
547 }
548 if (display.what & DisplayState::eFlagsChanged) {
549 display.flags = proto.flags();
550 }
551 return display;
552}
553
Vishnu Nair81750622023-03-08 15:02:06 -0800554void asProto(proto::Transform* proto, const ui::Transform& transform) {
555 proto->set_dsdx(transform.dsdx());
556 proto->set_dtdx(transform.dtdx());
557 proto->set_dtdy(transform.dtdy());
558 proto->set_dsdy(transform.dsdy());
559 proto->set_tx(transform.tx());
560 proto->set_ty(transform.ty());
561}
562
563proto::DisplayInfo TransactionProtoParser::toProto(const frontend::DisplayInfo& displayInfo,
564 uint32_t layerStack) {
565 proto::DisplayInfo proto;
566 proto.set_layer_stack(layerStack);
567 proto.set_display_id(displayInfo.info.displayId);
568 proto.set_logical_width(displayInfo.info.logicalWidth);
569 proto.set_logical_height(displayInfo.info.logicalHeight);
570 asProto(proto.mutable_transform_inverse(), displayInfo.info.transform);
571 asProto(proto.mutable_transform(), displayInfo.transform);
572 proto.set_receives_input(displayInfo.receivesInput);
573 proto.set_is_secure(displayInfo.isSecure);
574 proto.set_is_primary(displayInfo.isPrimary);
575 proto.set_is_virtual(displayInfo.isVirtual);
576 proto.set_rotation_flags((int)displayInfo.rotationFlags);
577 proto.set_transform_hint((int)displayInfo.transformHint);
578 return proto;
579}
580
581void fromProto2(ui::Transform& outTransform, const proto::Transform& proto) {
582 outTransform.set(proto.dsdx(), proto.dtdx(), proto.dtdy(), proto.dsdy());
583 outTransform.set(proto.tx(), proto.ty());
584}
585
586frontend::DisplayInfo TransactionProtoParser::fromProto(const proto::DisplayInfo& proto) {
587 frontend::DisplayInfo displayInfo;
588 displayInfo.info.displayId = proto.display_id();
589 displayInfo.info.logicalWidth = proto.logical_width();
590 displayInfo.info.logicalHeight = proto.logical_height();
591 fromProto2(displayInfo.info.transform, proto.transform_inverse());
592 fromProto2(displayInfo.transform, proto.transform());
593 displayInfo.receivesInput = proto.receives_input();
594 displayInfo.isSecure = proto.is_secure();
595 displayInfo.isPrimary = proto.is_primary();
Vishnu Nair0d13b912023-03-27 22:06:38 +0000596 displayInfo.isVirtual = proto.is_virtual();
Vishnu Nair81750622023-03-08 15:02:06 -0800597 displayInfo.rotationFlags = (ui::Transform::RotationFlags)proto.rotation_flags();
598 displayInfo.transformHint = (ui::Transform::RotationFlags)proto.transform_hint();
599 return displayInfo;
600}
601
602void TransactionProtoParser::fromProto(
603 const google::protobuf::RepeatedPtrField<proto::DisplayInfo>& proto,
Vishnu Nair0d13b912023-03-27 22:06:38 +0000604 display::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& outDisplayInfos) {
Vishnu Nair81750622023-03-08 15:02:06 -0800605 outDisplayInfos.clear();
606 for (const proto::DisplayInfo& displayInfo : proto) {
607 outDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(displayInfo.layer_stack()),
608 fromProto(displayInfo));
609 }
610}
611
Vishnu Nair6b591152021-10-08 11:45:14 -0700612} // namespace android::surfaceflinger