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 | #pragma once |
| 17 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 18 | #include <gui/fake/BufferData.h> |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 19 | #include <layerproto/TransactionProto.h> |
| 20 | #include <utils/RefBase.h> |
| 21 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 22 | #include "FrontEnd/DisplayInfo.h" |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 23 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 24 | #include "TransactionState.h" |
| 25 | |
| 26 | namespace android::surfaceflinger { |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 27 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 28 | struct TracingLayerState : ResolvedComposerState { |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 29 | bool hasSidebandStream; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 30 | LayerCreationArgs args; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 31 | }; |
| 32 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 33 | class TransactionProtoParser { |
| 34 | public: |
| 35 | // Utility class to map handles to ids and buffers to buffer properties without pulling |
| 36 | // in SurfaceFlinger dependencies. |
| 37 | class FlingerDataMapper { |
| 38 | public: |
| 39 | virtual ~FlingerDataMapper() = default; |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 40 | virtual sp<IBinder> getDisplayHandle(int32_t /* displayId */) const { return nullptr; } |
| 41 | virtual int32_t getDisplayId(const sp<IBinder>& /* displayHandle */) const { return -1; } |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | TransactionProtoParser(std::unique_ptr<FlingerDataMapper> provider) |
| 45 | : mMapper(std::move(provider)) {} |
| 46 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 47 | perfetto::protos::TransactionState toProto(const TransactionState&); |
| 48 | perfetto::protos::TransactionState toProto( |
| 49 | const std::map<uint32_t /* layerId */, TracingLayerState>&); |
| 50 | perfetto::protos::LayerCreationArgs toProto(const LayerCreationArgs& args); |
| 51 | perfetto::protos::LayerState toProto(const ResolvedComposerState&); |
| 52 | static perfetto::protos::DisplayInfo toProto(const frontend::DisplayInfo&, uint32_t layerStack); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 53 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 54 | TransactionState fromProto(const perfetto::protos::TransactionState&); |
| 55 | void mergeFromProto(const perfetto::protos::LayerState&, TracingLayerState& outState); |
| 56 | void fromProto(const perfetto::protos::LayerCreationArgs&, LayerCreationArgs& outArgs); |
Robert Carr | a63d52a | 2022-03-03 08:03:37 -0800 | [diff] [blame] | 57 | std::unique_ptr<FlingerDataMapper> mMapper; |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 58 | static frontend::DisplayInfo fromProto(const perfetto::protos::DisplayInfo&); |
| 59 | static void fromProto(const google::protobuf::RepeatedPtrField<perfetto::protos::DisplayInfo>&, |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 60 | frontend::DisplayInfos& outDisplayInfos); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 61 | |
| 62 | private: |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 63 | perfetto::protos::DisplayState toProto(const DisplayState&); |
| 64 | void fromProto(const perfetto::protos::LayerState&, ResolvedComposerState& out); |
| 65 | DisplayState fromProto(const perfetto::protos::DisplayState&); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Greg Kaiser | 2c90985 | 2021-12-07 09:45:29 -0800 | [diff] [blame] | 68 | } // namespace android::surfaceflinger |