Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 1 | /* |
| 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> |
| 18 | #include <ui/Rect.h> |
| 19 | |
| 20 | #include "LayerProtoHelper.h" |
| 21 | #include "TransactionProtoParser.h" |
| 22 | |
| 23 | namespace android::surfaceflinger { |
| 24 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 25 | proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t, |
| 26 | LayerHandleToIdFn getLayerId, |
| 27 | DisplayHandleToIdFn getDisplayId) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 28 | 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); |
| 34 | |
| 35 | for (auto& layerState : t.states) { |
| 36 | proto.mutable_layer_changes()->Add(std::move(toProto(layerState.state, getLayerId))); |
| 37 | } |
| 38 | |
| 39 | for (auto& displayState : t.displays) { |
| 40 | proto.mutable_display_changes()->Add(std::move(toProto(displayState, getDisplayId))); |
| 41 | } |
| 42 | return proto; |
| 43 | } |
| 44 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 45 | proto::TransactionState TransactionProtoParser::toProto( |
Greg Kaiser | 2c90985 | 2021-12-07 09:45:29 -0800 | [diff] [blame] | 46 | const std::map<int32_t /* layerId */, TracingLayerState>& states) { |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 47 | proto::TransactionState proto; |
| 48 | for (auto& [layerId, state] : states) { |
| 49 | proto::LayerState layerProto = toProto(state, nullptr); |
| 50 | if (layerProto.has_buffer_data()) { |
| 51 | proto::LayerState_BufferData* bufferProto = layerProto.mutable_buffer_data(); |
| 52 | bufferProto->set_buffer_id(state.bufferId); |
| 53 | bufferProto->set_width(state.bufferWidth); |
| 54 | bufferProto->set_height(state.bufferHeight); |
| 55 | } |
| 56 | layerProto.set_has_sideband_stream(state.hasSidebandStream); |
| 57 | layerProto.set_layer_id(state.layerId); |
| 58 | layerProto.set_parent_id(state.parentId); |
| 59 | layerProto.set_relative_parent_id(state.relativeParentId); |
| 60 | if (layerProto.has_window_info_handle()) { |
| 61 | layerProto.mutable_window_info_handle()->set_crop_layer_id(state.inputCropId); |
| 62 | } |
| 63 | proto.mutable_layer_changes()->Add(std::move(layerProto)); |
| 64 | } |
| 65 | return proto; |
| 66 | } |
| 67 | |
| 68 | proto::LayerState TransactionProtoParser::toProto(const layer_state_t& layer, |
| 69 | LayerHandleToIdFn getLayerId) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 70 | proto::LayerState proto; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 71 | if (getLayerId != nullptr) { |
| 72 | proto.set_layer_id(getLayerId(layer.surface)); |
| 73 | } else { |
| 74 | proto.set_layer_id(layer.layerId); |
| 75 | } |
| 76 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 77 | proto.set_what(layer.what); |
| 78 | |
| 79 | if (layer.what & layer_state_t::ePositionChanged) { |
| 80 | proto.set_x(layer.x); |
| 81 | proto.set_y(layer.y); |
| 82 | } |
| 83 | if (layer.what & layer_state_t::eLayerChanged) { |
| 84 | proto.set_z(layer.z); |
| 85 | } |
| 86 | if (layer.what & layer_state_t::eSizeChanged) { |
| 87 | proto.set_w(layer.w); |
| 88 | proto.set_h(layer.h); |
| 89 | } |
| 90 | if (layer.what & layer_state_t::eLayerStackChanged) { |
| 91 | proto.set_layer_stack(layer.layerStack.id); |
| 92 | } |
| 93 | if (layer.what & layer_state_t::eFlagsChanged) { |
| 94 | proto.set_flags(layer.flags); |
| 95 | proto.set_mask(layer.mask); |
| 96 | } |
| 97 | if (layer.what & layer_state_t::eMatrixChanged) { |
| 98 | proto::LayerState_Matrix22* matrixProto = proto.mutable_matrix(); |
| 99 | matrixProto->set_dsdx(layer.matrix.dsdx); |
| 100 | matrixProto->set_dsdy(layer.matrix.dsdy); |
| 101 | matrixProto->set_dtdx(layer.matrix.dtdx); |
| 102 | matrixProto->set_dtdy(layer.matrix.dtdy); |
| 103 | } |
| 104 | if (layer.what & layer_state_t::eCornerRadiusChanged) { |
| 105 | proto.set_corner_radius(layer.cornerRadius); |
| 106 | } |
| 107 | if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) { |
| 108 | proto.set_background_blur_radius(layer.backgroundBlurRadius); |
| 109 | } |
| 110 | |
| 111 | if (layer.what & layer_state_t::eAlphaChanged) { |
| 112 | proto.set_alpha(layer.alpha); |
| 113 | } |
| 114 | |
| 115 | if (layer.what & layer_state_t::eColorChanged) { |
| 116 | proto::LayerState_Color3* colorProto = proto.mutable_color(); |
| 117 | colorProto->set_r(layer.color.r); |
| 118 | colorProto->set_g(layer.color.g); |
| 119 | colorProto->set_b(layer.color.b); |
| 120 | } |
| 121 | if (layer.what & layer_state_t::eTransparentRegionChanged) { |
| 122 | LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region()); |
| 123 | } |
| 124 | if (layer.what & layer_state_t::eTransformChanged) { |
| 125 | proto.set_transform(layer.transform); |
| 126 | } |
| 127 | if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 128 | proto.set_transform_to_display_inverse(layer.transformToDisplayInverse); |
| 129 | } |
| 130 | if (layer.what & layer_state_t::eCropChanged) { |
| 131 | LayerProtoHelper::writeToProto(layer.crop, proto.mutable_crop()); |
| 132 | } |
| 133 | if (layer.what & layer_state_t::eBufferChanged) { |
| 134 | proto::LayerState_BufferData* bufferProto = proto.mutable_buffer_data(); |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame^] | 135 | if (layer.bufferData->buffer) { |
| 136 | bufferProto->set_buffer_id(layer.bufferData->getId()); |
| 137 | bufferProto->set_width(layer.bufferData->getWidth()); |
| 138 | bufferProto->set_height(layer.bufferData->getHeight()); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 139 | } |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame^] | 140 | bufferProto->set_frame_number(layer.bufferData->frameNumber); |
| 141 | bufferProto->set_flags(layer.bufferData->flags.get()); |
| 142 | bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 143 | } |
| 144 | if (layer.what & layer_state_t::eSidebandStreamChanged) { |
| 145 | proto.set_has_sideband_stream(layer.sidebandStream != nullptr); |
| 146 | } |
| 147 | |
| 148 | if (layer.what & layer_state_t::eApiChanged) { |
| 149 | proto.set_api(layer.api); |
| 150 | } |
| 151 | |
| 152 | if (layer.what & layer_state_t::eColorTransformChanged) { |
| 153 | LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform()); |
| 154 | } |
| 155 | if (layer.what & layer_state_t::eBlurRegionsChanged) { |
| 156 | for (auto& region : layer.blurRegions) { |
| 157 | LayerProtoHelper::writeToProto(region, proto.add_blur_regions()); |
| 158 | } |
| 159 | } |
| 160 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 161 | if ((layer.what & layer_state_t::eReparent) && getLayerId != nullptr) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 162 | int32_t layerId = layer.parentSurfaceControlForChild |
| 163 | ? getLayerId(layer.parentSurfaceControlForChild->getHandle()) |
| 164 | : -1; |
| 165 | proto.set_parent_id(layerId); |
| 166 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 167 | if ((layer.what & layer_state_t::eRelativeLayerChanged) && getLayerId != nullptr) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 168 | int32_t layerId = layer.relativeLayerSurfaceControl |
| 169 | ? getLayerId(layer.relativeLayerSurfaceControl->getHandle()) |
| 170 | : -1; |
| 171 | proto.set_relative_parent_id(layerId); |
| 172 | } |
| 173 | |
| 174 | if (layer.what & layer_state_t::eInputInfoChanged) { |
| 175 | if (layer.windowInfoHandle) { |
| 176 | const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo(); |
| 177 | proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle(); |
| 178 | windowInfoProto->set_layout_params_flags(inputInfo->flags.get()); |
| 179 | windowInfoProto->set_layout_params_type(static_cast<int32_t>(inputInfo->type)); |
| 180 | LayerProtoHelper::writeToProto(inputInfo->touchableRegion, |
| 181 | windowInfoProto->mutable_touchable_region()); |
| 182 | windowInfoProto->set_surface_inset(inputInfo->surfaceInset); |
| 183 | windowInfoProto->set_focusable(inputInfo->focusable); |
| 184 | windowInfoProto->set_has_wallpaper(inputInfo->hasWallpaper); |
| 185 | windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor); |
| 186 | proto::LayerState_Transform* transformProto = windowInfoProto->mutable_transform(); |
| 187 | transformProto->set_dsdx(inputInfo->transform.dsdx()); |
| 188 | transformProto->set_dtdx(inputInfo->transform.dtdx()); |
| 189 | transformProto->set_dtdy(inputInfo->transform.dtdy()); |
| 190 | transformProto->set_dsdy(inputInfo->transform.dsdy()); |
| 191 | transformProto->set_tx(inputInfo->transform.tx()); |
| 192 | transformProto->set_ty(inputInfo->transform.ty()); |
| 193 | windowInfoProto->set_replace_touchable_region_with_crop( |
| 194 | inputInfo->replaceTouchableRegionWithCrop); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 195 | if (getLayerId != nullptr) { |
| 196 | windowInfoProto->set_crop_layer_id( |
| 197 | getLayerId(inputInfo->touchableRegionCropHandle.promote())); |
| 198 | } else { |
| 199 | windowInfoProto->set_crop_layer_id(-1); |
| 200 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | if (layer.what & layer_state_t::eBackgroundColorChanged) { |
| 204 | proto.set_bg_color_alpha(layer.bgColorAlpha); |
| 205 | proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace)); |
| 206 | proto::LayerState_Color3* colorProto = proto.mutable_color(); |
| 207 | colorProto->set_r(layer.color.r); |
| 208 | colorProto->set_g(layer.color.g); |
| 209 | colorProto->set_b(layer.color.b); |
| 210 | } |
| 211 | if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 212 | proto.set_color_space_agnostic(layer.colorSpaceAgnostic); |
| 213 | } |
| 214 | if (layer.what & layer_state_t::eShadowRadiusChanged) { |
| 215 | proto.set_shadow_radius(layer.shadowRadius); |
| 216 | } |
| 217 | if (layer.what & layer_state_t::eFrameRateSelectionPriority) { |
| 218 | proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority); |
| 219 | } |
| 220 | if (layer.what & layer_state_t::eFrameRateChanged) { |
| 221 | proto.set_frame_rate(layer.frameRate); |
| 222 | proto.set_frame_rate_compatibility(layer.frameRateCompatibility); |
| 223 | proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy); |
| 224 | } |
| 225 | if (layer.what & layer_state_t::eFixedTransformHintChanged) { |
| 226 | proto.set_fixed_transform_hint(layer.fixedTransformHint); |
| 227 | } |
| 228 | if (layer.what & layer_state_t::eAutoRefreshChanged) { |
| 229 | proto.set_auto_refresh(layer.autoRefresh); |
| 230 | } |
| 231 | if (layer.what & layer_state_t::eTrustedOverlayChanged) { |
| 232 | proto.set_is_trusted_overlay(layer.isTrustedOverlay); |
| 233 | } |
| 234 | if (layer.what & layer_state_t::eBufferCropChanged) { |
| 235 | LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop()); |
| 236 | } |
| 237 | if (layer.what & layer_state_t::eDestinationFrameChanged) { |
| 238 | LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame()); |
| 239 | } |
| 240 | if (layer.what & layer_state_t::eDropInputModeChanged) { |
| 241 | proto.set_drop_input_mode( |
| 242 | static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode)); |
| 243 | } |
| 244 | return proto; |
| 245 | } |
| 246 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 247 | proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display, |
| 248 | DisplayHandleToIdFn getDisplayId) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 249 | proto::DisplayState proto; |
| 250 | proto.set_what(display.what); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 251 | if (getDisplayId != nullptr) { |
| 252 | proto.set_id(getDisplayId(display.token)); |
| 253 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 254 | |
| 255 | if (display.what & DisplayState::eLayerStackChanged) { |
| 256 | proto.set_layer_stack(display.layerStack.id); |
| 257 | } |
| 258 | if (display.what & DisplayState::eDisplayProjectionChanged) { |
| 259 | proto.set_orientation(static_cast<uint32_t>(display.orientation)); |
| 260 | LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect, |
| 261 | proto.mutable_oriented_display_space_rect()); |
| 262 | LayerProtoHelper::writeToProto(display.layerStackSpaceRect, |
| 263 | proto.mutable_layer_stack_space_rect()); |
| 264 | } |
| 265 | if (display.what & DisplayState::eDisplaySizeChanged) { |
| 266 | proto.set_width(display.width); |
| 267 | proto.set_height(display.height); |
| 268 | } |
| 269 | if (display.what & DisplayState::eFlagsChanged) { |
| 270 | proto.set_flags(display.flags); |
| 271 | } |
| 272 | return proto; |
| 273 | } |
| 274 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 275 | proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) { |
| 276 | proto::LayerCreationArgs proto; |
| 277 | proto.set_layer_id(args.layerId); |
| 278 | proto.set_name(args.name); |
| 279 | proto.set_flags(args.flags); |
| 280 | proto.set_parent_id(args.parentId); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 281 | proto.set_mirror_from_id(args.mirrorFromId); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 282 | return proto; |
| 283 | } |
| 284 | |
| 285 | TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto, |
| 286 | LayerIdToHandleFn getLayerHandle, |
| 287 | DisplayIdToHandleFn getDisplayHandle) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 288 | TransactionState t; |
| 289 | t.originPid = proto.pid(); |
| 290 | t.originUid = proto.uid(); |
| 291 | t.frameTimelineInfo.vsyncId = proto.vsync_id(); |
| 292 | t.frameTimelineInfo.inputEventId = proto.input_event_id(); |
| 293 | t.postTime = proto.post_time(); |
| 294 | int32_t layerCount = proto.layer_changes_size(); |
| 295 | t.states.reserve(static_cast<size_t>(layerCount)); |
| 296 | for (int i = 0; i < layerCount; i++) { |
| 297 | ComposerState s; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 298 | fromProto(proto.layer_changes(i), getLayerHandle, s.state); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 299 | t.states.add(s); |
| 300 | } |
| 301 | |
| 302 | int32_t displayCount = proto.display_changes_size(); |
| 303 | t.displays.reserve(static_cast<size_t>(displayCount)); |
| 304 | for (int i = 0; i < displayCount; i++) { |
| 305 | t.displays.add(fromProto(proto.display_changes(i), getDisplayHandle)); |
| 306 | } |
| 307 | return t; |
| 308 | } |
| 309 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 310 | void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto, |
| 311 | TracingLayerCreationArgs& outArgs) { |
| 312 | outArgs.layerId = proto.layer_id(); |
| 313 | outArgs.name = proto.name(); |
| 314 | outArgs.flags = proto.flags(); |
| 315 | outArgs.parentId = proto.parent_id(); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 316 | outArgs.mirrorFromId = proto.mirror_from_id(); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 317 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 318 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 319 | void TransactionProtoParser::fromProto(const proto::LayerState& proto, |
| 320 | LayerIdToHandleFn getLayerHandle, |
| 321 | TracingLayerState& outState) { |
| 322 | fromProto(proto, getLayerHandle, static_cast<layer_state_t&>(outState)); |
| 323 | if (proto.what() & layer_state_t::eReparent) { |
| 324 | outState.parentId = proto.parent_id(); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 325 | outState.args.parentId = outState.parentId; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 326 | } |
| 327 | if (proto.what() & layer_state_t::eRelativeLayerChanged) { |
| 328 | outState.relativeParentId = proto.relative_parent_id(); |
| 329 | } |
| 330 | if (proto.what() & layer_state_t::eInputInfoChanged) { |
| 331 | outState.inputCropId = proto.window_info_handle().crop_layer_id(); |
| 332 | } |
| 333 | if (proto.what() & layer_state_t::eBufferChanged) { |
| 334 | const proto::LayerState_BufferData& bufferProto = proto.buffer_data(); |
| 335 | outState.bufferId = bufferProto.buffer_id(); |
| 336 | outState.bufferWidth = bufferProto.width(); |
| 337 | outState.bufferHeight = bufferProto.height(); |
| 338 | } |
| 339 | if (proto.what() & layer_state_t::eSidebandStreamChanged) { |
| 340 | outState.hasSidebandStream = proto.has_sideband_stream(); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | void TransactionProtoParser::fromProto(const proto::LayerState& proto, |
| 345 | LayerIdToHandleFn getLayerHandle, layer_state_t& layer) { |
| 346 | layer.layerId = proto.layer_id(); |
| 347 | layer.what |= proto.what(); |
| 348 | |
| 349 | if (getLayerHandle != nullptr) { |
| 350 | layer.surface = getLayerHandle(layer.layerId); |
| 351 | } |
| 352 | |
| 353 | if (proto.what() & layer_state_t::ePositionChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 354 | layer.x = proto.x(); |
| 355 | layer.y = proto.y(); |
| 356 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 357 | if (proto.what() & layer_state_t::eLayerChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 358 | layer.z = proto.z(); |
| 359 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 360 | if (proto.what() & layer_state_t::eSizeChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 361 | layer.w = proto.w(); |
| 362 | layer.h = proto.h(); |
| 363 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 364 | if (proto.what() & layer_state_t::eLayerStackChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 365 | layer.layerStack.id = proto.layer_stack(); |
| 366 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 367 | if (proto.what() & layer_state_t::eFlagsChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 368 | layer.flags = proto.flags(); |
| 369 | layer.mask = proto.mask(); |
| 370 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 371 | if (proto.what() & layer_state_t::eMatrixChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 372 | const proto::LayerState_Matrix22& matrixProto = proto.matrix(); |
| 373 | layer.matrix.dsdx = matrixProto.dsdx(); |
| 374 | layer.matrix.dsdy = matrixProto.dsdy(); |
| 375 | layer.matrix.dtdx = matrixProto.dtdx(); |
| 376 | layer.matrix.dtdy = matrixProto.dtdy(); |
| 377 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 378 | if (proto.what() & layer_state_t::eCornerRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 379 | layer.cornerRadius = proto.corner_radius(); |
| 380 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 381 | if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 382 | layer.backgroundBlurRadius = proto.background_blur_radius(); |
| 383 | } |
| 384 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 385 | if (proto.what() & layer_state_t::eAlphaChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 386 | layer.alpha = proto.alpha(); |
| 387 | } |
| 388 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 389 | if (proto.what() & layer_state_t::eColorChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 390 | const proto::LayerState_Color3& colorProto = proto.color(); |
| 391 | layer.color.r = colorProto.r(); |
| 392 | layer.color.g = colorProto.g(); |
| 393 | layer.color.b = colorProto.b(); |
| 394 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 395 | if (proto.what() & layer_state_t::eTransparentRegionChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 396 | LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion); |
| 397 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 398 | if (proto.what() & layer_state_t::eTransformChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 399 | layer.transform = proto.transform(); |
| 400 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 401 | if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 402 | layer.transformToDisplayInverse = proto.transform_to_display_inverse(); |
| 403 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 404 | if (proto.what() & layer_state_t::eCropChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 405 | LayerProtoHelper::readFromProto(proto.crop(), layer.crop); |
| 406 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 407 | if (proto.what() & layer_state_t::eBufferChanged) { |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame^] | 408 | if (!layer.bufferData) { |
| 409 | layer.bufferData = std::make_shared<BufferData>(); |
| 410 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 411 | const proto::LayerState_BufferData& bufferProto = proto.buffer_data(); |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame^] | 412 | layer.bufferData->frameNumber = bufferProto.frame_number(); |
| 413 | layer.bufferData->flags = Flags<BufferData::BufferDataChange>(bufferProto.flags()); |
| 414 | layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 415 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 416 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 417 | if (proto.what() & layer_state_t::eApiChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 418 | layer.api = proto.api(); |
| 419 | } |
| 420 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 421 | if (proto.what() & layer_state_t::eColorTransformChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 422 | LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform); |
| 423 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 424 | if (proto.what() & layer_state_t::eBlurRegionsChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 425 | layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size())); |
| 426 | for (int i = 0; i < proto.blur_regions_size(); i++) { |
| 427 | android::BlurRegion region; |
| 428 | LayerProtoHelper::readFromProto(proto.blur_regions(i), region); |
| 429 | layer.blurRegions.push_back(region); |
| 430 | } |
| 431 | } |
| 432 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 433 | if ((proto.what() & layer_state_t::eReparent) && (getLayerHandle != nullptr)) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 434 | int32_t layerId = proto.parent_id(); |
| 435 | layer.parentSurfaceControlForChild = |
| 436 | new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId), |
| 437 | nullptr, layerId); |
| 438 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 439 | if ((proto.what() & layer_state_t::eRelativeLayerChanged) && (getLayerHandle != nullptr)) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 440 | int32_t layerId = proto.relative_parent_id(); |
| 441 | layer.relativeLayerSurfaceControl = |
| 442 | new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId), |
| 443 | nullptr, layerId); |
| 444 | } |
| 445 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 446 | if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 447 | gui::WindowInfo inputInfo; |
| 448 | const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle(); |
| 449 | |
| 450 | inputInfo.flags = static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags()); |
| 451 | inputInfo.type = static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type()); |
| 452 | LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(), |
| 453 | inputInfo.touchableRegion); |
| 454 | inputInfo.surfaceInset = windowInfoProto.surface_inset(); |
| 455 | inputInfo.focusable = windowInfoProto.focusable(); |
| 456 | inputInfo.hasWallpaper = windowInfoProto.has_wallpaper(); |
| 457 | inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor(); |
| 458 | const proto::LayerState_Transform& transformProto = windowInfoProto.transform(); |
| 459 | inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(), |
| 460 | transformProto.dsdy()); |
| 461 | inputInfo.transform.set(transformProto.tx(), transformProto.ty()); |
| 462 | inputInfo.replaceTouchableRegionWithCrop = |
| 463 | windowInfoProto.replace_touchable_region_with_crop(); |
| 464 | int32_t layerId = windowInfoProto.crop_layer_id(); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 465 | if (getLayerHandle != nullptr) { |
| 466 | inputInfo.touchableRegionCropHandle = getLayerHandle(layerId); |
| 467 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 468 | layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo); |
| 469 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 470 | if (proto.what() & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 471 | layer.bgColorAlpha = proto.bg_color_alpha(); |
| 472 | layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace()); |
| 473 | const proto::LayerState_Color3& colorProto = proto.color(); |
| 474 | layer.color.r = colorProto.r(); |
| 475 | layer.color.g = colorProto.g(); |
| 476 | layer.color.b = colorProto.b(); |
| 477 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 478 | if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 479 | layer.colorSpaceAgnostic = proto.color_space_agnostic(); |
| 480 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 481 | if (proto.what() & layer_state_t::eShadowRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 482 | layer.shadowRadius = proto.shadow_radius(); |
| 483 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 484 | if (proto.what() & layer_state_t::eFrameRateSelectionPriority) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 485 | layer.frameRateSelectionPriority = proto.frame_rate_selection_priority(); |
| 486 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 487 | if (proto.what() & layer_state_t::eFrameRateChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 488 | layer.frameRate = proto.frame_rate(); |
| 489 | layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility()); |
| 490 | layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy()); |
| 491 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 492 | if (proto.what() & layer_state_t::eFixedTransformHintChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 493 | layer.fixedTransformHint = |
| 494 | static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint()); |
| 495 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 496 | if (proto.what() & layer_state_t::eAutoRefreshChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 497 | layer.autoRefresh = proto.auto_refresh(); |
| 498 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 499 | if (proto.what() & layer_state_t::eTrustedOverlayChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 500 | layer.isTrustedOverlay = proto.is_trusted_overlay(); |
| 501 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 502 | if (proto.what() & layer_state_t::eBufferCropChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 503 | LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop); |
| 504 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 505 | if (proto.what() & layer_state_t::eDestinationFrameChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 506 | LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame); |
| 507 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 508 | if (proto.what() & layer_state_t::eDropInputModeChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 509 | layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode()); |
| 510 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 513 | DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto, |
| 514 | DisplayIdToHandleFn getDisplayHandle) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 515 | DisplayState display; |
| 516 | display.what = proto.what(); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 517 | if (getDisplayHandle != nullptr) { |
| 518 | display.token = getDisplayHandle(proto.id()); |
| 519 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 520 | |
| 521 | if (display.what & DisplayState::eLayerStackChanged) { |
| 522 | display.layerStack.id = proto.layer_stack(); |
| 523 | } |
| 524 | if (display.what & DisplayState::eDisplayProjectionChanged) { |
| 525 | display.orientation = static_cast<ui::Rotation>(proto.orientation()); |
| 526 | LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(), |
| 527 | display.orientedDisplaySpaceRect); |
| 528 | LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(), |
| 529 | display.layerStackSpaceRect); |
| 530 | } |
| 531 | if (display.what & DisplayState::eDisplaySizeChanged) { |
| 532 | display.width = proto.width(); |
| 533 | display.height = proto.height(); |
| 534 | } |
| 535 | if (display.what & DisplayState::eFlagsChanged) { |
| 536 | display.flags = proto.flags(); |
| 537 | } |
| 538 | return display; |
| 539 | } |
| 540 | |
| 541 | } // namespace android::surfaceflinger |