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