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( |
| 46 | std::vector<std::pair<int32_t /* layerId */, TracingLayerState>> states) { |
| 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(); |
| 135 | if (layer.bufferData.buffer) { |
| 136 | bufferProto->set_buffer_id(layer.bufferData.buffer->getId()); |
| 137 | bufferProto->set_width(layer.bufferData.buffer->getWidth()); |
| 138 | bufferProto->set_height(layer.bufferData.buffer->getHeight()); |
| 139 | } |
| 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); |
| 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); |
| 281 | return proto; |
| 282 | } |
| 283 | |
| 284 | TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto, |
| 285 | LayerIdToHandleFn getLayerHandle, |
| 286 | DisplayIdToHandleFn getDisplayHandle) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 287 | TransactionState t; |
| 288 | t.originPid = proto.pid(); |
| 289 | t.originUid = proto.uid(); |
| 290 | t.frameTimelineInfo.vsyncId = proto.vsync_id(); |
| 291 | t.frameTimelineInfo.inputEventId = proto.input_event_id(); |
| 292 | t.postTime = proto.post_time(); |
| 293 | int32_t layerCount = proto.layer_changes_size(); |
| 294 | t.states.reserve(static_cast<size_t>(layerCount)); |
| 295 | for (int i = 0; i < layerCount; i++) { |
| 296 | ComposerState s; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 297 | fromProto(proto.layer_changes(i), getLayerHandle, s.state); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 298 | t.states.add(s); |
| 299 | } |
| 300 | |
| 301 | int32_t displayCount = proto.display_changes_size(); |
| 302 | t.displays.reserve(static_cast<size_t>(displayCount)); |
| 303 | for (int i = 0; i < displayCount; i++) { |
| 304 | t.displays.add(fromProto(proto.display_changes(i), getDisplayHandle)); |
| 305 | } |
| 306 | return t; |
| 307 | } |
| 308 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 309 | void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto, |
| 310 | TracingLayerCreationArgs& outArgs) { |
| 311 | outArgs.layerId = proto.layer_id(); |
| 312 | outArgs.name = proto.name(); |
| 313 | outArgs.flags = proto.flags(); |
| 314 | outArgs.parentId = proto.parent_id(); |
| 315 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 316 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 317 | void TransactionProtoParser::fromProto(const proto::LayerState& proto, |
| 318 | LayerIdToHandleFn getLayerHandle, |
| 319 | TracingLayerState& outState) { |
| 320 | fromProto(proto, getLayerHandle, static_cast<layer_state_t&>(outState)); |
| 321 | if (proto.what() & layer_state_t::eReparent) { |
| 322 | outState.parentId = proto.parent_id(); |
| 323 | } |
| 324 | if (proto.what() & layer_state_t::eRelativeLayerChanged) { |
| 325 | outState.relativeParentId = proto.relative_parent_id(); |
| 326 | } |
| 327 | if (proto.what() & layer_state_t::eInputInfoChanged) { |
| 328 | outState.inputCropId = proto.window_info_handle().crop_layer_id(); |
| 329 | } |
| 330 | if (proto.what() & layer_state_t::eBufferChanged) { |
| 331 | const proto::LayerState_BufferData& bufferProto = proto.buffer_data(); |
| 332 | outState.bufferId = bufferProto.buffer_id(); |
| 333 | outState.bufferWidth = bufferProto.width(); |
| 334 | outState.bufferHeight = bufferProto.height(); |
| 335 | } |
| 336 | if (proto.what() & layer_state_t::eSidebandStreamChanged) { |
| 337 | outState.hasSidebandStream = proto.has_sideband_stream(); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | void TransactionProtoParser::fromProto(const proto::LayerState& proto, |
| 342 | LayerIdToHandleFn getLayerHandle, layer_state_t& layer) { |
| 343 | layer.layerId = proto.layer_id(); |
| 344 | layer.what |= proto.what(); |
| 345 | |
| 346 | if (getLayerHandle != nullptr) { |
| 347 | layer.surface = getLayerHandle(layer.layerId); |
| 348 | } |
| 349 | |
| 350 | if (proto.what() & layer_state_t::ePositionChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 351 | layer.x = proto.x(); |
| 352 | layer.y = proto.y(); |
| 353 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 354 | if (proto.what() & layer_state_t::eLayerChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 355 | layer.z = proto.z(); |
| 356 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 357 | if (proto.what() & layer_state_t::eSizeChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 358 | layer.w = proto.w(); |
| 359 | layer.h = proto.h(); |
| 360 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 361 | if (proto.what() & layer_state_t::eLayerStackChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 362 | layer.layerStack.id = proto.layer_stack(); |
| 363 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 364 | if (proto.what() & layer_state_t::eFlagsChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 365 | layer.flags = proto.flags(); |
| 366 | layer.mask = proto.mask(); |
| 367 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 368 | if (proto.what() & layer_state_t::eMatrixChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 369 | const proto::LayerState_Matrix22& matrixProto = proto.matrix(); |
| 370 | layer.matrix.dsdx = matrixProto.dsdx(); |
| 371 | layer.matrix.dsdy = matrixProto.dsdy(); |
| 372 | layer.matrix.dtdx = matrixProto.dtdx(); |
| 373 | layer.matrix.dtdy = matrixProto.dtdy(); |
| 374 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 375 | if (proto.what() & layer_state_t::eCornerRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 376 | layer.cornerRadius = proto.corner_radius(); |
| 377 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 378 | if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 379 | layer.backgroundBlurRadius = proto.background_blur_radius(); |
| 380 | } |
| 381 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 382 | if (proto.what() & layer_state_t::eAlphaChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 383 | layer.alpha = proto.alpha(); |
| 384 | } |
| 385 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 386 | if (proto.what() & layer_state_t::eColorChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 387 | const proto::LayerState_Color3& colorProto = proto.color(); |
| 388 | layer.color.r = colorProto.r(); |
| 389 | layer.color.g = colorProto.g(); |
| 390 | layer.color.b = colorProto.b(); |
| 391 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 392 | if (proto.what() & layer_state_t::eTransparentRegionChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 393 | LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion); |
| 394 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 395 | if (proto.what() & layer_state_t::eTransformChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 396 | layer.transform = proto.transform(); |
| 397 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 398 | if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 399 | layer.transformToDisplayInverse = proto.transform_to_display_inverse(); |
| 400 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 401 | if (proto.what() & layer_state_t::eCropChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 402 | LayerProtoHelper::readFromProto(proto.crop(), layer.crop); |
| 403 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 404 | if (proto.what() & layer_state_t::eBufferChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 405 | const proto::LayerState_BufferData& bufferProto = proto.buffer_data(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 406 | layer.bufferData.frameNumber = bufferProto.frame_number(); |
| 407 | layer.bufferData.flags = Flags<BufferData::BufferDataChange>(bufferProto.flags()); |
| 408 | layer.bufferData.cachedBuffer.id = bufferProto.cached_buffer_id(); |
| 409 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 410 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 411 | if (proto.what() & layer_state_t::eApiChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 412 | layer.api = proto.api(); |
| 413 | } |
| 414 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 415 | if (proto.what() & layer_state_t::eColorTransformChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 416 | LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform); |
| 417 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 418 | if (proto.what() & layer_state_t::eBlurRegionsChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 419 | layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size())); |
| 420 | for (int i = 0; i < proto.blur_regions_size(); i++) { |
| 421 | android::BlurRegion region; |
| 422 | LayerProtoHelper::readFromProto(proto.blur_regions(i), region); |
| 423 | layer.blurRegions.push_back(region); |
| 424 | } |
| 425 | } |
| 426 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 427 | if ((proto.what() & layer_state_t::eReparent) && (getLayerHandle != nullptr)) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 428 | int32_t layerId = proto.parent_id(); |
| 429 | layer.parentSurfaceControlForChild = |
| 430 | new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId), |
| 431 | nullptr, layerId); |
| 432 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 433 | if ((proto.what() & layer_state_t::eRelativeLayerChanged) && (getLayerHandle != nullptr)) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 434 | int32_t layerId = proto.relative_parent_id(); |
| 435 | layer.relativeLayerSurfaceControl = |
| 436 | new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId), |
| 437 | nullptr, layerId); |
| 438 | } |
| 439 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 440 | if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 441 | gui::WindowInfo inputInfo; |
| 442 | const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle(); |
| 443 | |
| 444 | inputInfo.flags = static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags()); |
| 445 | inputInfo.type = static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type()); |
| 446 | LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(), |
| 447 | inputInfo.touchableRegion); |
| 448 | inputInfo.surfaceInset = windowInfoProto.surface_inset(); |
| 449 | inputInfo.focusable = windowInfoProto.focusable(); |
| 450 | inputInfo.hasWallpaper = windowInfoProto.has_wallpaper(); |
| 451 | inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor(); |
| 452 | const proto::LayerState_Transform& transformProto = windowInfoProto.transform(); |
| 453 | inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(), |
| 454 | transformProto.dsdy()); |
| 455 | inputInfo.transform.set(transformProto.tx(), transformProto.ty()); |
| 456 | inputInfo.replaceTouchableRegionWithCrop = |
| 457 | windowInfoProto.replace_touchable_region_with_crop(); |
| 458 | int32_t layerId = windowInfoProto.crop_layer_id(); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 459 | if (getLayerHandle != nullptr) { |
| 460 | inputInfo.touchableRegionCropHandle = getLayerHandle(layerId); |
| 461 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 462 | layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo); |
| 463 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 464 | if (proto.what() & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 465 | layer.bgColorAlpha = proto.bg_color_alpha(); |
| 466 | layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace()); |
| 467 | const proto::LayerState_Color3& colorProto = proto.color(); |
| 468 | layer.color.r = colorProto.r(); |
| 469 | layer.color.g = colorProto.g(); |
| 470 | layer.color.b = colorProto.b(); |
| 471 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 472 | if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 473 | layer.colorSpaceAgnostic = proto.color_space_agnostic(); |
| 474 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 475 | if (proto.what() & layer_state_t::eShadowRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 476 | layer.shadowRadius = proto.shadow_radius(); |
| 477 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 478 | if (proto.what() & layer_state_t::eFrameRateSelectionPriority) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 479 | layer.frameRateSelectionPriority = proto.frame_rate_selection_priority(); |
| 480 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 481 | if (proto.what() & layer_state_t::eFrameRateChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 482 | layer.frameRate = proto.frame_rate(); |
| 483 | layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility()); |
| 484 | layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy()); |
| 485 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 486 | if (proto.what() & layer_state_t::eFixedTransformHintChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 487 | layer.fixedTransformHint = |
| 488 | static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint()); |
| 489 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 490 | if (proto.what() & layer_state_t::eAutoRefreshChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 491 | layer.autoRefresh = proto.auto_refresh(); |
| 492 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 493 | if (proto.what() & layer_state_t::eTrustedOverlayChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 494 | layer.isTrustedOverlay = proto.is_trusted_overlay(); |
| 495 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 496 | if (proto.what() & layer_state_t::eBufferCropChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 497 | LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop); |
| 498 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 499 | if (proto.what() & layer_state_t::eDestinationFrameChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 500 | LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame); |
| 501 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 502 | if (proto.what() & layer_state_t::eDropInputModeChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 503 | layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode()); |
| 504 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame^] | 507 | DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto, |
| 508 | DisplayIdToHandleFn getDisplayHandle) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 509 | DisplayState display; |
| 510 | display.what = proto.what(); |
| 511 | display.token = getDisplayHandle(proto.id()); |
| 512 | |
| 513 | if (display.what & DisplayState::eLayerStackChanged) { |
| 514 | display.layerStack.id = proto.layer_stack(); |
| 515 | } |
| 516 | if (display.what & DisplayState::eDisplayProjectionChanged) { |
| 517 | display.orientation = static_cast<ui::Rotation>(proto.orientation()); |
| 518 | LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(), |
| 519 | display.orientedDisplaySpaceRect); |
| 520 | LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(), |
| 521 | display.layerStackSpaceRect); |
| 522 | } |
| 523 | if (display.what & DisplayState::eDisplaySizeChanged) { |
| 524 | display.width = proto.width(); |
| 525 | display.height = proto.height(); |
| 526 | } |
| 527 | if (display.what & DisplayState::eFlagsChanged) { |
| 528 | display.flags = proto.flags(); |
| 529 | } |
| 530 | return display; |
| 531 | } |
| 532 | |
| 533 | } // namespace android::surfaceflinger |