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> |
Vishnu Nair | 8eebba4 | 2022-02-25 07:57:15 -0800 | [diff] [blame] | 18 | #include <ui/Fence.h> |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 19 | #include <ui/Rect.h> |
| 20 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 21 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 22 | #include "LayerProtoHelper.h" |
| 23 | #include "TransactionProtoParser.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 24 | #include "TransactionState.h" |
| 25 | #include "gui/LayerState.h" |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android::surfaceflinger { |
| 28 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 29 | class FakeExternalTexture : public renderengine::ExternalTexture { |
| 30 | const sp<GraphicBuffer> mEmptyBuffer = |
| 31 | sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_8888, |
| 32 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN); |
| 33 | uint32_t mWidth; |
| 34 | uint32_t mHeight; |
| 35 | uint64_t mId; |
| 36 | PixelFormat mPixelFormat; |
| 37 | uint64_t mUsage; |
| 38 | |
| 39 | public: |
| 40 | FakeExternalTexture(uint32_t width, uint32_t height, uint64_t id, PixelFormat pixelFormat, |
| 41 | uint64_t usage) |
| 42 | : mWidth(width), mHeight(height), mId(id), mPixelFormat(pixelFormat), mUsage(usage) {} |
| 43 | const sp<GraphicBuffer>& getBuffer() const { return mEmptyBuffer; } |
| 44 | bool hasSameBuffer(const renderengine::ExternalTexture& other) const override { |
| 45 | return getId() == other.getId(); |
| 46 | } |
| 47 | uint32_t getWidth() const override { return mWidth; } |
| 48 | uint32_t getHeight() const override { return mHeight; } |
| 49 | uint64_t getId() const override { return mId; } |
| 50 | PixelFormat getPixelFormat() const override { return mPixelFormat; } |
| 51 | uint64_t getUsage() const override { return mUsage; } |
| 52 | ~FakeExternalTexture() = default; |
| 53 | }; |
| 54 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 55 | proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 56 | proto::TransactionState proto; |
| 57 | proto.set_pid(t.originPid); |
| 58 | proto.set_uid(t.originUid); |
| 59 | proto.set_vsync_id(t.frameTimelineInfo.vsyncId); |
| 60 | proto.set_input_event_id(t.frameTimelineInfo.inputEventId); |
| 61 | proto.set_post_time(t.postTime); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 62 | proto.set_transaction_id(t.id); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 63 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 64 | proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(t.states.size())); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 65 | for (auto& layerState : t.states) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 66 | proto.mutable_layer_changes()->Add(std::move(toProto(layerState))); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 69 | proto.mutable_display_changes()->Reserve(static_cast<int32_t>(t.displays.size())); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 70 | for (auto& displayState : t.displays) { |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 71 | proto.mutable_display_changes()->Add(std::move(toProto(displayState))); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 72 | } |
| 73 | return proto; |
| 74 | } |
| 75 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 76 | proto::TransactionState TransactionProtoParser::toProto( |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 77 | const std::map<uint32_t /* layerId */, TracingLayerState>& states) { |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 78 | proto::TransactionState proto; |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 79 | proto.mutable_layer_changes()->Reserve(static_cast<int32_t>(states.size())); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 80 | for (auto& [layerId, state] : states) { |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 81 | proto::LayerState layerProto = toProto(state); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 82 | layerProto.set_has_sideband_stream(state.hasSidebandStream); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 83 | proto.mutable_layer_changes()->Add(std::move(layerProto)); |
| 84 | } |
| 85 | return proto; |
| 86 | } |
| 87 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 88 | proto::LayerState TransactionProtoParser::toProto( |
| 89 | const ResolvedComposerState& resolvedComposerState) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 90 | proto::LayerState proto; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 91 | auto& layer = resolvedComposerState.state; |
| 92 | proto.set_layer_id(resolvedComposerState.layerId); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 93 | proto.set_what(layer.what); |
| 94 | |
| 95 | if (layer.what & layer_state_t::ePositionChanged) { |
| 96 | proto.set_x(layer.x); |
| 97 | proto.set_y(layer.y); |
| 98 | } |
| 99 | if (layer.what & layer_state_t::eLayerChanged) { |
| 100 | proto.set_z(layer.z); |
| 101 | } |
Vishnu Nair | ea04b6f | 2022-08-19 21:28:17 +0000 | [diff] [blame] | 102 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 103 | if (layer.what & layer_state_t::eLayerStackChanged) { |
| 104 | proto.set_layer_stack(layer.layerStack.id); |
| 105 | } |
| 106 | if (layer.what & layer_state_t::eFlagsChanged) { |
| 107 | proto.set_flags(layer.flags); |
| 108 | proto.set_mask(layer.mask); |
| 109 | } |
| 110 | if (layer.what & layer_state_t::eMatrixChanged) { |
| 111 | proto::LayerState_Matrix22* matrixProto = proto.mutable_matrix(); |
| 112 | matrixProto->set_dsdx(layer.matrix.dsdx); |
| 113 | matrixProto->set_dsdy(layer.matrix.dsdy); |
| 114 | matrixProto->set_dtdx(layer.matrix.dtdx); |
| 115 | matrixProto->set_dtdy(layer.matrix.dtdy); |
| 116 | } |
| 117 | if (layer.what & layer_state_t::eCornerRadiusChanged) { |
| 118 | proto.set_corner_radius(layer.cornerRadius); |
| 119 | } |
| 120 | if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) { |
| 121 | proto.set_background_blur_radius(layer.backgroundBlurRadius); |
| 122 | } |
| 123 | |
| 124 | if (layer.what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 125 | proto.set_alpha(layer.color.a); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | if (layer.what & layer_state_t::eColorChanged) { |
| 129 | proto::LayerState_Color3* colorProto = proto.mutable_color(); |
| 130 | colorProto->set_r(layer.color.r); |
| 131 | colorProto->set_g(layer.color.g); |
| 132 | colorProto->set_b(layer.color.b); |
| 133 | } |
| 134 | if (layer.what & layer_state_t::eTransparentRegionChanged) { |
| 135 | LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region()); |
| 136 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 137 | if (layer.what & layer_state_t::eBufferTransformChanged) { |
| 138 | proto.set_transform(layer.bufferTransform); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 139 | } |
| 140 | if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 141 | proto.set_transform_to_display_inverse(layer.transformToDisplayInverse); |
| 142 | } |
| 143 | if (layer.what & layer_state_t::eCropChanged) { |
| 144 | LayerProtoHelper::writeToProto(layer.crop, proto.mutable_crop()); |
| 145 | } |
| 146 | if (layer.what & layer_state_t::eBufferChanged) { |
| 147 | proto::LayerState_BufferData* bufferProto = proto.mutable_buffer_data(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 148 | if (resolvedComposerState.externalTexture) { |
| 149 | bufferProto->set_buffer_id(resolvedComposerState.externalTexture->getId()); |
| 150 | bufferProto->set_width(resolvedComposerState.externalTexture->getWidth()); |
| 151 | bufferProto->set_height(resolvedComposerState.externalTexture->getHeight()); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 152 | bufferProto->set_pixel_format(static_cast<proto::LayerState_BufferData_PixelFormat>( |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 153 | resolvedComposerState.externalTexture->getPixelFormat())); |
| 154 | bufferProto->set_usage(resolvedComposerState.externalTexture->getUsage()); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 155 | } |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame] | 156 | bufferProto->set_frame_number(layer.bufferData->frameNumber); |
| 157 | bufferProto->set_flags(layer.bufferData->flags.get()); |
| 158 | bufferProto->set_cached_buffer_id(layer.bufferData->cachedBuffer.id); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 159 | } |
| 160 | if (layer.what & layer_state_t::eSidebandStreamChanged) { |
| 161 | proto.set_has_sideband_stream(layer.sidebandStream != nullptr); |
| 162 | } |
| 163 | |
| 164 | if (layer.what & layer_state_t::eApiChanged) { |
| 165 | proto.set_api(layer.api); |
| 166 | } |
| 167 | |
| 168 | if (layer.what & layer_state_t::eColorTransformChanged) { |
| 169 | LayerProtoHelper::writeToProto(layer.colorTransform, proto.mutable_color_transform()); |
| 170 | } |
| 171 | if (layer.what & layer_state_t::eBlurRegionsChanged) { |
| 172 | for (auto& region : layer.blurRegions) { |
| 173 | LayerProtoHelper::writeToProto(region, proto.add_blur_regions()); |
| 174 | } |
| 175 | } |
| 176 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 177 | if (layer.what & layer_state_t::eReparent) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 178 | proto.set_parent_id(resolvedComposerState.parentId); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 179 | } |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 180 | if (layer.what & layer_state_t::eRelativeLayerChanged) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 181 | proto.set_relative_parent_id(resolvedComposerState.relativeParentId); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 182 | proto.set_z(layer.z); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | if (layer.what & layer_state_t::eInputInfoChanged) { |
| 186 | if (layer.windowInfoHandle) { |
| 187 | const gui::WindowInfo* inputInfo = layer.windowInfoHandle->getInfo(); |
| 188 | proto::LayerState_WindowInfo* windowInfoProto = proto.mutable_window_info_handle(); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 189 | windowInfoProto->set_layout_params_flags(inputInfo->layoutParamsFlags.get()); |
| 190 | windowInfoProto->set_layout_params_type( |
| 191 | static_cast<int32_t>(inputInfo->layoutParamsType)); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 192 | LayerProtoHelper::writeToProto(inputInfo->touchableRegion, |
| 193 | windowInfoProto->mutable_touchable_region()); |
| 194 | windowInfoProto->set_surface_inset(inputInfo->surfaceInset); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 195 | windowInfoProto->set_focusable( |
| 196 | !inputInfo->inputConfig.test(gui::WindowInfo::InputConfig::NOT_FOCUSABLE)); |
| 197 | windowInfoProto->set_has_wallpaper(inputInfo->inputConfig.test( |
| 198 | gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER)); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 199 | windowInfoProto->set_global_scale_factor(inputInfo->globalScaleFactor); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 200 | proto::Transform* transformProto = windowInfoProto->mutable_transform(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 201 | transformProto->set_dsdx(inputInfo->transform.dsdx()); |
| 202 | transformProto->set_dtdx(inputInfo->transform.dtdx()); |
| 203 | transformProto->set_dtdy(inputInfo->transform.dtdy()); |
| 204 | transformProto->set_dsdy(inputInfo->transform.dsdy()); |
| 205 | transformProto->set_tx(inputInfo->transform.tx()); |
| 206 | transformProto->set_ty(inputInfo->transform.ty()); |
| 207 | windowInfoProto->set_replace_touchable_region_with_crop( |
| 208 | inputInfo->replaceTouchableRegionWithCrop); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 209 | windowInfoProto->set_crop_layer_id(resolvedComposerState.touchCropId); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | if (layer.what & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 213 | proto.set_bg_color_alpha(layer.bgColor.a); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 214 | proto.set_bg_color_dataspace(static_cast<int32_t>(layer.bgColorDataspace)); |
| 215 | proto::LayerState_Color3* colorProto = proto.mutable_color(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 216 | colorProto->set_r(layer.bgColor.r); |
| 217 | colorProto->set_g(layer.bgColor.g); |
| 218 | colorProto->set_b(layer.bgColor.b); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 219 | } |
| 220 | if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 221 | proto.set_color_space_agnostic(layer.colorSpaceAgnostic); |
| 222 | } |
| 223 | if (layer.what & layer_state_t::eShadowRadiusChanged) { |
| 224 | proto.set_shadow_radius(layer.shadowRadius); |
| 225 | } |
| 226 | if (layer.what & layer_state_t::eFrameRateSelectionPriority) { |
| 227 | proto.set_frame_rate_selection_priority(layer.frameRateSelectionPriority); |
| 228 | } |
| 229 | if (layer.what & layer_state_t::eFrameRateChanged) { |
| 230 | proto.set_frame_rate(layer.frameRate); |
| 231 | proto.set_frame_rate_compatibility(layer.frameRateCompatibility); |
| 232 | proto.set_change_frame_rate_strategy(layer.changeFrameRateStrategy); |
| 233 | } |
| 234 | if (layer.what & layer_state_t::eFixedTransformHintChanged) { |
| 235 | proto.set_fixed_transform_hint(layer.fixedTransformHint); |
| 236 | } |
| 237 | if (layer.what & layer_state_t::eAutoRefreshChanged) { |
| 238 | proto.set_auto_refresh(layer.autoRefresh); |
| 239 | } |
| 240 | if (layer.what & layer_state_t::eTrustedOverlayChanged) { |
| 241 | proto.set_is_trusted_overlay(layer.isTrustedOverlay); |
| 242 | } |
| 243 | if (layer.what & layer_state_t::eBufferCropChanged) { |
| 244 | LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop()); |
| 245 | } |
| 246 | if (layer.what & layer_state_t::eDestinationFrameChanged) { |
| 247 | LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame()); |
| 248 | } |
| 249 | if (layer.what & layer_state_t::eDropInputModeChanged) { |
| 250 | proto.set_drop_input_mode( |
| 251 | static_cast<proto::LayerState_DropInputMode>(layer.dropInputMode)); |
| 252 | } |
| 253 | return proto; |
| 254 | } |
| 255 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 256 | proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 257 | proto::DisplayState proto; |
| 258 | proto.set_what(display.what); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 259 | proto.set_id(mMapper->getDisplayId(display.token)); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 260 | |
| 261 | if (display.what & DisplayState::eLayerStackChanged) { |
| 262 | proto.set_layer_stack(display.layerStack.id); |
| 263 | } |
| 264 | if (display.what & DisplayState::eDisplayProjectionChanged) { |
| 265 | proto.set_orientation(static_cast<uint32_t>(display.orientation)); |
| 266 | LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect, |
| 267 | proto.mutable_oriented_display_space_rect()); |
| 268 | LayerProtoHelper::writeToProto(display.layerStackSpaceRect, |
| 269 | proto.mutable_layer_stack_space_rect()); |
| 270 | } |
| 271 | if (display.what & DisplayState::eDisplaySizeChanged) { |
| 272 | proto.set_width(display.width); |
| 273 | proto.set_height(display.height); |
| 274 | } |
| 275 | if (display.what & DisplayState::eFlagsChanged) { |
| 276 | proto.set_flags(display.flags); |
| 277 | } |
| 278 | return proto; |
| 279 | } |
| 280 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 281 | proto::LayerCreationArgs TransactionProtoParser::toProto(const LayerCreationArgs& args) { |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 282 | proto::LayerCreationArgs proto; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 283 | proto.set_layer_id(args.sequence); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 284 | proto.set_name(args.name); |
| 285 | proto.set_flags(args.flags); |
| 286 | proto.set_parent_id(args.parentId); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 287 | proto.set_mirror_from_id(args.layerIdToMirror); |
| 288 | proto.set_add_to_root(args.addToRoot); |
| 289 | proto.set_layer_stack_to_mirror(args.layerStackToMirror.id); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 290 | return proto; |
| 291 | } |
| 292 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 293 | TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 294 | TransactionState t; |
| 295 | t.originPid = proto.pid(); |
| 296 | t.originUid = proto.uid(); |
| 297 | t.frameTimelineInfo.vsyncId = proto.vsync_id(); |
| 298 | t.frameTimelineInfo.inputEventId = proto.input_event_id(); |
| 299 | t.postTime = proto.post_time(); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 300 | t.id = proto.transaction_id(); |
| 301 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 302 | int32_t layerCount = proto.layer_changes_size(); |
| 303 | t.states.reserve(static_cast<size_t>(layerCount)); |
| 304 | for (int i = 0; i < layerCount; i++) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 305 | ResolvedComposerState s; |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 306 | s.state.what = 0; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 307 | fromProto(proto.layer_changes(i), s); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 308 | t.states.emplace_back(s); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | int32_t displayCount = proto.display_changes_size(); |
| 312 | t.displays.reserve(static_cast<size_t>(displayCount)); |
| 313 | for (int i = 0; i < displayCount; i++) { |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 314 | t.displays.add(fromProto(proto.display_changes(i))); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 315 | } |
| 316 | return t; |
| 317 | } |
| 318 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 319 | void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto, |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 320 | LayerCreationArgs& outArgs) { |
| 321 | outArgs.sequence = proto.layer_id(); |
| 322 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 323 | outArgs.name = proto.name(); |
| 324 | outArgs.flags = proto.flags(); |
| 325 | outArgs.parentId = proto.parent_id(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 326 | outArgs.layerIdToMirror = proto.mirror_from_id(); |
| 327 | outArgs.addToRoot = proto.add_to_root(); |
| 328 | outArgs.layerStackToMirror.id = proto.layer_stack_to_mirror(); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 329 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 330 | |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 331 | void TransactionProtoParser::mergeFromProto(const proto::LayerState& proto, |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 332 | TracingLayerState& outState) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 333 | ResolvedComposerState resolvedComposerState; |
| 334 | fromProto(proto, resolvedComposerState); |
| 335 | layer_state_t& state = resolvedComposerState.state; |
| 336 | outState.state.merge(state); |
| 337 | outState.layerId = resolvedComposerState.layerId; |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 338 | |
| 339 | if (state.what & layer_state_t::eReparent) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 340 | outState.parentId = resolvedComposerState.parentId; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 341 | } |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 342 | if (state.what & layer_state_t::eRelativeLayerChanged) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 343 | outState.relativeParentId = resolvedComposerState.relativeParentId; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 344 | } |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 345 | if (state.what & layer_state_t::eInputInfoChanged) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 346 | outState.touchCropId = resolvedComposerState.touchCropId; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 347 | } |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 348 | if (state.what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 349 | outState.externalTexture = resolvedComposerState.externalTexture; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 350 | } |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 351 | if (state.what & layer_state_t::eSidebandStreamChanged) { |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 352 | outState.hasSidebandStream = proto.has_sideband_stream(); |
| 353 | } |
| 354 | } |
| 355 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 356 | void TransactionProtoParser::fromProto(const proto::LayerState& proto, |
| 357 | ResolvedComposerState& resolvedComposerState) { |
| 358 | auto& layer = resolvedComposerState.state; |
| 359 | resolvedComposerState.layerId = proto.layer_id(); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 360 | layer.what |= proto.what(); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 361 | |
| 362 | if (proto.what() & layer_state_t::ePositionChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 363 | layer.x = proto.x(); |
| 364 | layer.y = proto.y(); |
| 365 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 366 | if (proto.what() & layer_state_t::eLayerChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 367 | layer.z = proto.z(); |
| 368 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 369 | if (proto.what() & layer_state_t::eLayerStackChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 370 | layer.layerStack.id = proto.layer_stack(); |
| 371 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 372 | if (proto.what() & layer_state_t::eFlagsChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 373 | layer.flags = proto.flags(); |
| 374 | layer.mask = proto.mask(); |
| 375 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 376 | if (proto.what() & layer_state_t::eMatrixChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 377 | const proto::LayerState_Matrix22& matrixProto = proto.matrix(); |
| 378 | layer.matrix.dsdx = matrixProto.dsdx(); |
| 379 | layer.matrix.dsdy = matrixProto.dsdy(); |
| 380 | layer.matrix.dtdx = matrixProto.dtdx(); |
| 381 | layer.matrix.dtdy = matrixProto.dtdy(); |
| 382 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 383 | if (proto.what() & layer_state_t::eCornerRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 384 | layer.cornerRadius = proto.corner_radius(); |
| 385 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 386 | if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 387 | layer.backgroundBlurRadius = proto.background_blur_radius(); |
| 388 | } |
| 389 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 390 | if (proto.what() & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 391 | layer.color.a = proto.alpha(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 394 | if (proto.what() & layer_state_t::eColorChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 395 | const proto::LayerState_Color3& colorProto = proto.color(); |
| 396 | layer.color.r = colorProto.r(); |
| 397 | layer.color.g = colorProto.g(); |
| 398 | layer.color.b = colorProto.b(); |
| 399 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 400 | if (proto.what() & layer_state_t::eTransparentRegionChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 401 | LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion); |
| 402 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 403 | if (proto.what() & layer_state_t::eBufferTransformChanged) { |
| 404 | layer.bufferTransform = proto.transform(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 405 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 406 | if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 407 | layer.transformToDisplayInverse = proto.transform_to_display_inverse(); |
| 408 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 409 | if (proto.what() & layer_state_t::eCropChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 410 | LayerProtoHelper::readFromProto(proto.crop(), layer.crop); |
| 411 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 412 | if (proto.what() & layer_state_t::eBufferChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 413 | const proto::LayerState_BufferData& bufferProto = proto.buffer_data(); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 414 | layer.bufferData = |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 415 | std::make_shared<fake::BufferData>(bufferProto.buffer_id(), bufferProto.width(), |
| 416 | bufferProto.height(), bufferProto.pixel_format(), |
| 417 | bufferProto.usage()); |
| 418 | resolvedComposerState.externalTexture = |
| 419 | std::make_shared<FakeExternalTexture>(layer.bufferData->getWidth(), |
| 420 | layer.bufferData->getHeight(), |
| 421 | layer.bufferData->getId(), |
| 422 | layer.bufferData->getPixelFormat(), |
| 423 | layer.bufferData->getUsage()); |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame] | 424 | layer.bufferData->frameNumber = bufferProto.frame_number(); |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 425 | layer.bufferData->flags = ftl::Flags<BufferData::BufferDataChange>(bufferProto.flags()); |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame] | 426 | layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id(); |
Vishnu Nair | 8eebba4 | 2022-02-25 07:57:15 -0800 | [diff] [blame] | 427 | layer.bufferData->acquireFence = Fence::NO_FENCE; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 428 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 429 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 430 | if (proto.what() & layer_state_t::eApiChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 431 | layer.api = proto.api(); |
| 432 | } |
| 433 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 434 | if (proto.what() & layer_state_t::eColorTransformChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 435 | LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform); |
| 436 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 437 | if (proto.what() & layer_state_t::eBlurRegionsChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 438 | layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size())); |
| 439 | for (int i = 0; i < proto.blur_regions_size(); i++) { |
| 440 | android::BlurRegion region; |
| 441 | LayerProtoHelper::readFromProto(proto.blur_regions(i), region); |
| 442 | layer.blurRegions.push_back(region); |
| 443 | } |
| 444 | } |
| 445 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 446 | if (proto.what() & layer_state_t::eReparent) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 447 | resolvedComposerState.parentId = proto.parent_id(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 448 | } |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 449 | if (proto.what() & layer_state_t::eRelativeLayerChanged) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 450 | resolvedComposerState.relativeParentId = proto.relative_parent_id(); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 451 | layer.z = proto.z(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 454 | if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 455 | gui::WindowInfo inputInfo; |
| 456 | const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle(); |
| 457 | |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 458 | inputInfo.layoutParamsFlags = |
| 459 | static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags()); |
| 460 | inputInfo.layoutParamsType = |
| 461 | static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type()); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 462 | LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(), |
| 463 | inputInfo.touchableRegion); |
| 464 | inputInfo.surfaceInset = windowInfoProto.surface_inset(); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 465 | inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_FOCUSABLE, |
| 466 | !windowInfoProto.focusable()); |
| 467 | inputInfo.setInputConfig(gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER, |
| 468 | windowInfoProto.has_wallpaper()); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 469 | inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 470 | const proto::Transform& transformProto = windowInfoProto.transform(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 471 | inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(), |
| 472 | transformProto.dsdy()); |
| 473 | inputInfo.transform.set(transformProto.tx(), transformProto.ty()); |
| 474 | inputInfo.replaceTouchableRegionWithCrop = |
| 475 | windowInfoProto.replace_touchable_region_with_crop(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 476 | resolvedComposerState.touchCropId = windowInfoProto.crop_layer_id(); |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 477 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 478 | layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo); |
| 479 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 480 | if (proto.what() & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 481 | layer.bgColor.a = proto.bg_color_alpha(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 482 | layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace()); |
| 483 | const proto::LayerState_Color3& colorProto = proto.color(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 484 | layer.bgColor.r = colorProto.r(); |
| 485 | layer.bgColor.g = colorProto.g(); |
| 486 | layer.bgColor.b = colorProto.b(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 487 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 488 | if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 489 | layer.colorSpaceAgnostic = proto.color_space_agnostic(); |
| 490 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 491 | if (proto.what() & layer_state_t::eShadowRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 492 | layer.shadowRadius = proto.shadow_radius(); |
| 493 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 494 | if (proto.what() & layer_state_t::eFrameRateSelectionPriority) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 495 | layer.frameRateSelectionPriority = proto.frame_rate_selection_priority(); |
| 496 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 497 | if (proto.what() & layer_state_t::eFrameRateChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 498 | layer.frameRate = proto.frame_rate(); |
| 499 | layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility()); |
| 500 | layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy()); |
| 501 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 502 | if (proto.what() & layer_state_t::eFixedTransformHintChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 503 | layer.fixedTransformHint = |
| 504 | static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint()); |
| 505 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 506 | if (proto.what() & layer_state_t::eAutoRefreshChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 507 | layer.autoRefresh = proto.auto_refresh(); |
| 508 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 509 | if (proto.what() & layer_state_t::eTrustedOverlayChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 510 | layer.isTrustedOverlay = proto.is_trusted_overlay(); |
| 511 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 512 | if (proto.what() & layer_state_t::eBufferCropChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 513 | LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop); |
| 514 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 515 | if (proto.what() & layer_state_t::eDestinationFrameChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 516 | LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame); |
| 517 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 518 | if (proto.what() & layer_state_t::eDropInputModeChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 519 | layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode()); |
| 520 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 523 | DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 524 | DisplayState display; |
| 525 | display.what = proto.what(); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 526 | display.token = mMapper->getDisplayHandle(proto.id()); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 527 | |
| 528 | if (display.what & DisplayState::eLayerStackChanged) { |
| 529 | display.layerStack.id = proto.layer_stack(); |
| 530 | } |
| 531 | if (display.what & DisplayState::eDisplayProjectionChanged) { |
| 532 | display.orientation = static_cast<ui::Rotation>(proto.orientation()); |
| 533 | LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(), |
| 534 | display.orientedDisplaySpaceRect); |
| 535 | LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(), |
| 536 | display.layerStackSpaceRect); |
| 537 | } |
| 538 | if (display.what & DisplayState::eDisplaySizeChanged) { |
| 539 | display.width = proto.width(); |
| 540 | display.height = proto.height(); |
| 541 | } |
| 542 | if (display.what & DisplayState::eFlagsChanged) { |
| 543 | display.flags = proto.flags(); |
| 544 | } |
| 545 | return display; |
| 546 | } |
| 547 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 548 | void asProto(proto::Transform* proto, const ui::Transform& transform) { |
| 549 | proto->set_dsdx(transform.dsdx()); |
| 550 | proto->set_dtdx(transform.dtdx()); |
| 551 | proto->set_dtdy(transform.dtdy()); |
| 552 | proto->set_dsdy(transform.dsdy()); |
| 553 | proto->set_tx(transform.tx()); |
| 554 | proto->set_ty(transform.ty()); |
| 555 | } |
| 556 | |
| 557 | proto::DisplayInfo TransactionProtoParser::toProto(const frontend::DisplayInfo& displayInfo, |
| 558 | uint32_t layerStack) { |
| 559 | proto::DisplayInfo proto; |
| 560 | proto.set_layer_stack(layerStack); |
| 561 | proto.set_display_id(displayInfo.info.displayId); |
| 562 | proto.set_logical_width(displayInfo.info.logicalWidth); |
| 563 | proto.set_logical_height(displayInfo.info.logicalHeight); |
| 564 | asProto(proto.mutable_transform_inverse(), displayInfo.info.transform); |
| 565 | asProto(proto.mutable_transform(), displayInfo.transform); |
| 566 | proto.set_receives_input(displayInfo.receivesInput); |
| 567 | proto.set_is_secure(displayInfo.isSecure); |
| 568 | proto.set_is_primary(displayInfo.isPrimary); |
| 569 | proto.set_is_virtual(displayInfo.isVirtual); |
| 570 | proto.set_rotation_flags((int)displayInfo.rotationFlags); |
| 571 | proto.set_transform_hint((int)displayInfo.transformHint); |
| 572 | return proto; |
| 573 | } |
| 574 | |
| 575 | void fromProto2(ui::Transform& outTransform, const proto::Transform& proto) { |
| 576 | outTransform.set(proto.dsdx(), proto.dtdx(), proto.dtdy(), proto.dsdy()); |
| 577 | outTransform.set(proto.tx(), proto.ty()); |
| 578 | } |
| 579 | |
| 580 | frontend::DisplayInfo TransactionProtoParser::fromProto(const proto::DisplayInfo& proto) { |
| 581 | frontend::DisplayInfo displayInfo; |
| 582 | displayInfo.info.displayId = proto.display_id(); |
| 583 | displayInfo.info.logicalWidth = proto.logical_width(); |
| 584 | displayInfo.info.logicalHeight = proto.logical_height(); |
| 585 | fromProto2(displayInfo.info.transform, proto.transform_inverse()); |
| 586 | fromProto2(displayInfo.transform, proto.transform()); |
| 587 | displayInfo.receivesInput = proto.receives_input(); |
| 588 | displayInfo.isSecure = proto.is_secure(); |
| 589 | displayInfo.isPrimary = proto.is_primary(); |
| 590 | displayInfo.isPrimary = proto.is_virtual(); |
| 591 | displayInfo.rotationFlags = (ui::Transform::RotationFlags)proto.rotation_flags(); |
| 592 | displayInfo.transformHint = (ui::Transform::RotationFlags)proto.transform_hint(); |
| 593 | return displayInfo; |
| 594 | } |
| 595 | |
| 596 | void TransactionProtoParser::fromProto( |
| 597 | const google::protobuf::RepeatedPtrField<proto::DisplayInfo>& proto, |
| 598 | display::DisplayMap<ui::LayerStack, frontend::DisplayInfo> outDisplayInfos) { |
| 599 | outDisplayInfos.clear(); |
| 600 | for (const proto::DisplayInfo& displayInfo : proto) { |
| 601 | outDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(displayInfo.layer_stack()), |
| 602 | fromProto(displayInfo)); |
| 603 | } |
| 604 | } |
| 605 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 606 | } // namespace android::surfaceflinger |