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