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) { |
Yi Kong | 01b8126 | 2024-08-12 07:30:15 +0800 | [diff] [blame] | 65 | proto.mutable_layer_changes()->Add(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) { |
Yi Kong | 01b8126 | 2024-08-12 07:30:15 +0800 | [diff] [blame] | 70 | proto.mutable_display_changes()->Add(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) { |
Vishnu Nair | 9e0017e | 2024-05-22 19:02:44 +0000 | [diff] [blame] | 250 | proto.set_is_trusted_overlay(layer.trustedOverlay == gui::TrustedOverlay::ENABLED); |
| 251 | // TODO(b/339701674) update protos |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 252 | } |
| 253 | if (layer.what & layer_state_t::eBufferCropChanged) { |
| 254 | LayerProtoHelper::writeToProto(layer.bufferCrop, proto.mutable_buffer_crop()); |
| 255 | } |
| 256 | if (layer.what & layer_state_t::eDestinationFrameChanged) { |
| 257 | LayerProtoHelper::writeToProto(layer.destinationFrame, proto.mutable_destination_frame()); |
| 258 | } |
| 259 | if (layer.what & layer_state_t::eDropInputModeChanged) { |
| 260 | proto.set_drop_input_mode( |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 261 | static_cast<perfetto::protos::LayerState_DropInputMode>(layer.dropInputMode)); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 262 | } |
| 263 | return proto; |
| 264 | } |
| 265 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 266 | perfetto::protos::DisplayState TransactionProtoParser::toProto(const DisplayState& display) { |
| 267 | perfetto::protos::DisplayState proto; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 268 | proto.set_what(display.what); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 269 | proto.set_id(mMapper->getDisplayId(display.token)); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 270 | |
| 271 | if (display.what & DisplayState::eLayerStackChanged) { |
| 272 | proto.set_layer_stack(display.layerStack.id); |
| 273 | } |
| 274 | if (display.what & DisplayState::eDisplayProjectionChanged) { |
| 275 | proto.set_orientation(static_cast<uint32_t>(display.orientation)); |
| 276 | LayerProtoHelper::writeToProto(display.orientedDisplaySpaceRect, |
| 277 | proto.mutable_oriented_display_space_rect()); |
| 278 | LayerProtoHelper::writeToProto(display.layerStackSpaceRect, |
| 279 | proto.mutable_layer_stack_space_rect()); |
| 280 | } |
| 281 | if (display.what & DisplayState::eDisplaySizeChanged) { |
| 282 | proto.set_width(display.width); |
| 283 | proto.set_height(display.height); |
| 284 | } |
| 285 | if (display.what & DisplayState::eFlagsChanged) { |
| 286 | proto.set_flags(display.flags); |
| 287 | } |
| 288 | return proto; |
| 289 | } |
| 290 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 291 | perfetto::protos::LayerCreationArgs TransactionProtoParser::toProto(const LayerCreationArgs& args) { |
| 292 | perfetto::protos::LayerCreationArgs proto; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 293 | proto.set_layer_id(args.sequence); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 294 | proto.set_name(args.name); |
| 295 | proto.set_flags(args.flags); |
| 296 | proto.set_parent_id(args.parentId); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 297 | proto.set_mirror_from_id(args.layerIdToMirror); |
| 298 | proto.set_add_to_root(args.addToRoot); |
| 299 | proto.set_layer_stack_to_mirror(args.layerStackToMirror.id); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 300 | return proto; |
| 301 | } |
| 302 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 303 | TransactionState TransactionProtoParser::fromProto( |
| 304 | const perfetto::protos::TransactionState& proto) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 305 | TransactionState t; |
| 306 | t.originPid = proto.pid(); |
| 307 | t.originUid = proto.uid(); |
| 308 | t.frameTimelineInfo.vsyncId = proto.vsync_id(); |
| 309 | t.frameTimelineInfo.inputEventId = proto.input_event_id(); |
| 310 | t.postTime = proto.post_time(); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 311 | t.id = proto.transaction_id(); |
| 312 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 313 | int32_t layerCount = proto.layer_changes_size(); |
| 314 | t.states.reserve(static_cast<size_t>(layerCount)); |
| 315 | for (int i = 0; i < layerCount; i++) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 316 | ResolvedComposerState s; |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 317 | s.state.what = 0; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 318 | fromProto(proto.layer_changes(i), s); |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 319 | t.states.emplace_back(s); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | int32_t displayCount = proto.display_changes_size(); |
| 323 | t.displays.reserve(static_cast<size_t>(displayCount)); |
| 324 | for (int i = 0; i < displayCount; i++) { |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 325 | t.displays.add(fromProto(proto.display_changes(i))); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 326 | } |
| 327 | return t; |
| 328 | } |
| 329 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 330 | void TransactionProtoParser::fromProto(const perfetto::protos::LayerCreationArgs& proto, |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 331 | LayerCreationArgs& outArgs) { |
| 332 | outArgs.sequence = proto.layer_id(); |
| 333 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 334 | outArgs.name = proto.name(); |
| 335 | outArgs.flags = proto.flags(); |
| 336 | outArgs.parentId = proto.parent_id(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 337 | outArgs.layerIdToMirror = proto.mirror_from_id(); |
| 338 | outArgs.addToRoot = proto.add_to_root(); |
| 339 | outArgs.layerStackToMirror.id = proto.layer_stack_to_mirror(); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 340 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 341 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 342 | void TransactionProtoParser::mergeFromProto(const perfetto::protos::LayerState& proto, |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 343 | TracingLayerState& outState) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 344 | ResolvedComposerState resolvedComposerState; |
| 345 | fromProto(proto, resolvedComposerState); |
| 346 | layer_state_t& state = resolvedComposerState.state; |
| 347 | outState.state.merge(state); |
| 348 | outState.layerId = resolvedComposerState.layerId; |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 349 | |
| 350 | if (state.what & layer_state_t::eReparent) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 351 | outState.parentId = resolvedComposerState.parentId; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 352 | } |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 353 | if (state.what & layer_state_t::eRelativeLayerChanged) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 354 | outState.relativeParentId = resolvedComposerState.relativeParentId; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 355 | } |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 356 | if (state.what & layer_state_t::eInputInfoChanged) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 357 | outState.touchCropId = resolvedComposerState.touchCropId; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 358 | } |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 359 | if (state.what & layer_state_t::eBufferChanged) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 360 | outState.externalTexture = resolvedComposerState.externalTexture; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 361 | } |
Vishnu Nair | 7b0f18b | 2022-01-12 16:39:08 -0800 | [diff] [blame] | 362 | if (state.what & layer_state_t::eSidebandStreamChanged) { |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 363 | outState.hasSidebandStream = proto.has_sideband_stream(); |
| 364 | } |
| 365 | } |
| 366 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 367 | void TransactionProtoParser::fromProto(const perfetto::protos::LayerState& proto, |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 368 | ResolvedComposerState& resolvedComposerState) { |
| 369 | auto& layer = resolvedComposerState.state; |
| 370 | resolvedComposerState.layerId = proto.layer_id(); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 371 | layer.what |= proto.what(); |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 372 | |
| 373 | if (proto.what() & layer_state_t::ePositionChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 374 | layer.x = proto.x(); |
| 375 | layer.y = proto.y(); |
| 376 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 377 | if (proto.what() & layer_state_t::eLayerChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 378 | layer.z = proto.z(); |
| 379 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 380 | if (proto.what() & layer_state_t::eLayerStackChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 381 | layer.layerStack.id = proto.layer_stack(); |
| 382 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 383 | if (proto.what() & layer_state_t::eFlagsChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 384 | layer.flags = proto.flags(); |
| 385 | layer.mask = proto.mask(); |
| 386 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 387 | if (proto.what() & layer_state_t::eMatrixChanged) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 388 | const perfetto::protos::LayerState_Matrix22& matrixProto = proto.matrix(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 389 | layer.matrix.dsdx = matrixProto.dsdx(); |
| 390 | layer.matrix.dsdy = matrixProto.dsdy(); |
| 391 | layer.matrix.dtdx = matrixProto.dtdx(); |
| 392 | layer.matrix.dtdy = matrixProto.dtdy(); |
| 393 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 394 | if (proto.what() & layer_state_t::eCornerRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 395 | layer.cornerRadius = proto.corner_radius(); |
| 396 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 397 | if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 398 | layer.backgroundBlurRadius = proto.background_blur_radius(); |
| 399 | } |
| 400 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 401 | if (proto.what() & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 402 | layer.color.a = proto.alpha(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 405 | if (proto.what() & layer_state_t::eColorChanged) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 406 | const perfetto::protos::LayerState_Color3& colorProto = proto.color(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 407 | layer.color.r = colorProto.r(); |
| 408 | layer.color.g = colorProto.g(); |
| 409 | layer.color.b = colorProto.b(); |
| 410 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 411 | if (proto.what() & layer_state_t::eTransparentRegionChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 412 | LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion); |
| 413 | } |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 414 | if (proto.what() & layer_state_t::eBufferTransformChanged) { |
| 415 | layer.bufferTransform = proto.transform(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 416 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 417 | if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 418 | layer.transformToDisplayInverse = proto.transform_to_display_inverse(); |
| 419 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 420 | if (proto.what() & layer_state_t::eCropChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 421 | LayerProtoHelper::readFromProto(proto.crop(), layer.crop); |
| 422 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 423 | if (proto.what() & layer_state_t::eBufferChanged) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 424 | const perfetto::protos::LayerState_BufferData& bufferProto = proto.buffer_data(); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 425 | layer.bufferData = |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 426 | std::make_shared<fake::BufferData>(bufferProto.buffer_id(), bufferProto.width(), |
| 427 | bufferProto.height(), bufferProto.pixel_format(), |
| 428 | bufferProto.usage()); |
| 429 | resolvedComposerState.externalTexture = |
| 430 | std::make_shared<FakeExternalTexture>(layer.bufferData->getWidth(), |
| 431 | layer.bufferData->getHeight(), |
| 432 | layer.bufferData->getId(), |
| 433 | layer.bufferData->getPixelFormat(), |
| 434 | layer.bufferData->getUsage()); |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame] | 435 | layer.bufferData->frameNumber = bufferProto.frame_number(); |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 436 | layer.bufferData->flags = ftl::Flags<BufferData::BufferDataChange>(bufferProto.flags()); |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame] | 437 | layer.bufferData->cachedBuffer.id = bufferProto.cached_buffer_id(); |
Vishnu Nair | 8eebba4 | 2022-02-25 07:57:15 -0800 | [diff] [blame] | 438 | layer.bufferData->acquireFence = Fence::NO_FENCE; |
Nergi Rahardi | 39f510f | 2024-05-23 15:16:54 +0900 | [diff] [blame] | 439 | layer.bufferData->dequeueTime = -1; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 440 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 441 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 442 | if (proto.what() & layer_state_t::eApiChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 443 | layer.api = proto.api(); |
| 444 | } |
| 445 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 446 | if (proto.what() & layer_state_t::eColorTransformChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 447 | LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform); |
| 448 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 449 | if (proto.what() & layer_state_t::eBlurRegionsChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 450 | layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size())); |
| 451 | for (int i = 0; i < proto.blur_regions_size(); i++) { |
| 452 | android::BlurRegion region; |
| 453 | LayerProtoHelper::readFromProto(proto.blur_regions(i), region); |
| 454 | layer.blurRegions.push_back(region); |
| 455 | } |
| 456 | } |
| 457 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 458 | if (proto.what() & layer_state_t::eReparent) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 459 | resolvedComposerState.parentId = proto.parent_id(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 460 | } |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 461 | if (proto.what() & layer_state_t::eRelativeLayerChanged) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 462 | resolvedComposerState.relativeParentId = proto.relative_parent_id(); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 463 | layer.z = proto.z(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 466 | if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 467 | gui::WindowInfo inputInfo; |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 468 | const perfetto::protos::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 469 | |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 470 | inputInfo.layoutParamsFlags = |
| 471 | static_cast<gui::WindowInfo::Flag>(windowInfoProto.layout_params_flags()); |
| 472 | inputInfo.layoutParamsType = |
| 473 | static_cast<gui::WindowInfo::Type>(windowInfoProto.layout_params_type()); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 474 | LayerProtoHelper::readFromProto(windowInfoProto.touchable_region(), |
| 475 | inputInfo.touchableRegion); |
Siarhei Vishniakou | e2eff11 | 2023-06-21 14:20:39 -0700 | [diff] [blame] | 476 | inputInfo.inputConfig = |
| 477 | ftl::Flags<gui::WindowInfo::InputConfig>(windowInfoProto.input_config()); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 478 | inputInfo.surfaceInset = windowInfoProto.surface_inset(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 479 | inputInfo.globalScaleFactor = windowInfoProto.global_scale_factor(); |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 480 | const perfetto::protos::Transform& transformProto = windowInfoProto.transform(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 481 | inputInfo.transform.set(transformProto.dsdx(), transformProto.dtdx(), transformProto.dtdy(), |
| 482 | transformProto.dsdy()); |
| 483 | inputInfo.transform.set(transformProto.tx(), transformProto.ty()); |
| 484 | inputInfo.replaceTouchableRegionWithCrop = |
| 485 | windowInfoProto.replace_touchable_region_with_crop(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 486 | resolvedComposerState.touchCropId = windowInfoProto.crop_layer_id(); |
Vishnu Nair | 286f4f9 | 2022-06-08 16:37:39 -0700 | [diff] [blame] | 487 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 488 | layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo); |
| 489 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 490 | if (proto.what() & layer_state_t::eBackgroundColorChanged) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 491 | layer.bgColor.a = proto.bg_color_alpha(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 492 | layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace()); |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 493 | const perfetto::protos::LayerState_Color3& colorProto = proto.color(); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 494 | layer.bgColor.r = colorProto.r(); |
| 495 | layer.bgColor.g = colorProto.g(); |
| 496 | layer.bgColor.b = colorProto.b(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 497 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 498 | if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 499 | layer.colorSpaceAgnostic = proto.color_space_agnostic(); |
| 500 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 501 | if (proto.what() & layer_state_t::eShadowRadiusChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 502 | layer.shadowRadius = proto.shadow_radius(); |
| 503 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 504 | if (proto.what() & layer_state_t::eFrameRateSelectionPriority) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 505 | layer.frameRateSelectionPriority = proto.frame_rate_selection_priority(); |
| 506 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 507 | if (proto.what() & layer_state_t::eFrameRateChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 508 | layer.frameRate = proto.frame_rate(); |
| 509 | layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility()); |
| 510 | layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy()); |
| 511 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 512 | if (proto.what() & layer_state_t::eFixedTransformHintChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 513 | layer.fixedTransformHint = |
| 514 | static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint()); |
| 515 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 516 | if (proto.what() & layer_state_t::eAutoRefreshChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 517 | layer.autoRefresh = proto.auto_refresh(); |
| 518 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 519 | if (proto.what() & layer_state_t::eTrustedOverlayChanged) { |
Vishnu Nair | 9e0017e | 2024-05-22 19:02:44 +0000 | [diff] [blame] | 520 | layer.trustedOverlay = proto.is_trusted_overlay() ? gui::TrustedOverlay::ENABLED |
| 521 | : gui::TrustedOverlay::UNSET; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 522 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 523 | if (proto.what() & layer_state_t::eBufferCropChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 524 | LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop); |
| 525 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 526 | if (proto.what() & layer_state_t::eDestinationFrameChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 527 | LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame); |
| 528 | } |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 529 | if (proto.what() & layer_state_t::eDropInputModeChanged) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 530 | layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode()); |
| 531 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 534 | DisplayState TransactionProtoParser::fromProto(const perfetto::protos::DisplayState& proto) { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 535 | DisplayState display; |
| 536 | display.what = proto.what(); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 537 | display.token = mMapper->getDisplayHandle(proto.id()); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 538 | |
| 539 | if (display.what & DisplayState::eLayerStackChanged) { |
| 540 | display.layerStack.id = proto.layer_stack(); |
| 541 | } |
| 542 | if (display.what & DisplayState::eDisplayProjectionChanged) { |
| 543 | display.orientation = static_cast<ui::Rotation>(proto.orientation()); |
| 544 | LayerProtoHelper::readFromProto(proto.oriented_display_space_rect(), |
| 545 | display.orientedDisplaySpaceRect); |
| 546 | LayerProtoHelper::readFromProto(proto.layer_stack_space_rect(), |
| 547 | display.layerStackSpaceRect); |
| 548 | } |
| 549 | if (display.what & DisplayState::eDisplaySizeChanged) { |
| 550 | display.width = proto.width(); |
| 551 | display.height = proto.height(); |
| 552 | } |
| 553 | if (display.what & DisplayState::eFlagsChanged) { |
| 554 | display.flags = proto.flags(); |
| 555 | } |
| 556 | return display; |
| 557 | } |
| 558 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 559 | void asProto(perfetto::protos::Transform* proto, const ui::Transform& transform) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 560 | proto->set_dsdx(transform.dsdx()); |
| 561 | proto->set_dtdx(transform.dtdx()); |
| 562 | proto->set_dtdy(transform.dtdy()); |
| 563 | proto->set_dsdy(transform.dsdy()); |
| 564 | proto->set_tx(transform.tx()); |
| 565 | proto->set_ty(transform.ty()); |
| 566 | } |
| 567 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 568 | perfetto::protos::DisplayInfo TransactionProtoParser::toProto( |
| 569 | const frontend::DisplayInfo& displayInfo, uint32_t layerStack) { |
| 570 | perfetto::protos::DisplayInfo proto; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 571 | proto.set_layer_stack(layerStack); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 572 | proto.set_display_id(displayInfo.info.displayId.val()); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 573 | proto.set_logical_width(displayInfo.info.logicalWidth); |
| 574 | proto.set_logical_height(displayInfo.info.logicalHeight); |
| 575 | asProto(proto.mutable_transform_inverse(), displayInfo.info.transform); |
| 576 | asProto(proto.mutable_transform(), displayInfo.transform); |
| 577 | proto.set_receives_input(displayInfo.receivesInput); |
| 578 | proto.set_is_secure(displayInfo.isSecure); |
| 579 | proto.set_is_primary(displayInfo.isPrimary); |
| 580 | proto.set_is_virtual(displayInfo.isVirtual); |
| 581 | proto.set_rotation_flags((int)displayInfo.rotationFlags); |
| 582 | proto.set_transform_hint((int)displayInfo.transformHint); |
| 583 | return proto; |
| 584 | } |
| 585 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 586 | void fromProto2(ui::Transform& outTransform, const perfetto::protos::Transform& proto) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 587 | outTransform.set(proto.dsdx(), proto.dtdx(), proto.dtdy(), proto.dsdy()); |
| 588 | outTransform.set(proto.tx(), proto.ty()); |
| 589 | } |
| 590 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 591 | frontend::DisplayInfo TransactionProtoParser::fromProto( |
| 592 | const perfetto::protos::DisplayInfo& proto) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 593 | frontend::DisplayInfo displayInfo; |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 594 | displayInfo.info.displayId = ui::LogicalDisplayId{proto.display_id()}; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 595 | displayInfo.info.logicalWidth = proto.logical_width(); |
| 596 | displayInfo.info.logicalHeight = proto.logical_height(); |
| 597 | fromProto2(displayInfo.info.transform, proto.transform_inverse()); |
| 598 | fromProto2(displayInfo.transform, proto.transform()); |
| 599 | displayInfo.receivesInput = proto.receives_input(); |
| 600 | displayInfo.isSecure = proto.is_secure(); |
| 601 | displayInfo.isPrimary = proto.is_primary(); |
Vishnu Nair | 0d13b91 | 2023-03-27 22:06:38 +0000 | [diff] [blame] | 602 | displayInfo.isVirtual = proto.is_virtual(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 603 | displayInfo.rotationFlags = (ui::Transform::RotationFlags)proto.rotation_flags(); |
| 604 | displayInfo.transformHint = (ui::Transform::RotationFlags)proto.transform_hint(); |
| 605 | return displayInfo; |
| 606 | } |
| 607 | |
| 608 | void TransactionProtoParser::fromProto( |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 609 | const google::protobuf::RepeatedPtrField<perfetto::protos::DisplayInfo>& proto, |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 610 | frontend::DisplayInfos& outDisplayInfos) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 611 | outDisplayInfos.clear(); |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 612 | for (const perfetto::protos::DisplayInfo& displayInfo : proto) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 613 | outDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(displayInfo.layer_stack()), |
| 614 | fromProto(displayInfo)); |
| 615 | } |
| 616 | } |
| 617 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 618 | } // namespace android::surfaceflinger |