xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/Tracing/TransactionProtoParser.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2021 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker #pragma once
17*38e8c45fSAndroid Build Coastguard Worker 
18*38e8c45fSAndroid Build Coastguard Worker #include <gui/fake/BufferData.h>
19*38e8c45fSAndroid Build Coastguard Worker #include <layerproto/TransactionProto.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <utils/RefBase.h>
21*38e8c45fSAndroid Build Coastguard Worker 
22*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/DisplayInfo.h"
23*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/LayerCreationArgs.h"
24*38e8c45fSAndroid Build Coastguard Worker #include "TransactionState.h"
25*38e8c45fSAndroid Build Coastguard Worker 
26*38e8c45fSAndroid Build Coastguard Worker namespace android::surfaceflinger {
27*38e8c45fSAndroid Build Coastguard Worker 
28*38e8c45fSAndroid Build Coastguard Worker struct TracingLayerState : ResolvedComposerState {
29*38e8c45fSAndroid Build Coastguard Worker     bool hasSidebandStream;
30*38e8c45fSAndroid Build Coastguard Worker     LayerCreationArgs args;
31*38e8c45fSAndroid Build Coastguard Worker };
32*38e8c45fSAndroid Build Coastguard Worker 
33*38e8c45fSAndroid Build Coastguard Worker class TransactionProtoParser {
34*38e8c45fSAndroid Build Coastguard Worker public:
35*38e8c45fSAndroid Build Coastguard Worker     // Utility class to map handles to ids and buffers to buffer properties without pulling
36*38e8c45fSAndroid Build Coastguard Worker     // in SurfaceFlinger dependencies.
37*38e8c45fSAndroid Build Coastguard Worker     class FlingerDataMapper {
38*38e8c45fSAndroid Build Coastguard Worker     public:
39*38e8c45fSAndroid Build Coastguard Worker         virtual ~FlingerDataMapper() = default;
getDisplayHandle(int32_t)40*38e8c45fSAndroid Build Coastguard Worker         virtual sp<IBinder> getDisplayHandle(int32_t /* displayId */) const { return nullptr; }
getDisplayId(const sp<IBinder> &)41*38e8c45fSAndroid Build Coastguard Worker         virtual int32_t getDisplayId(const sp<IBinder>& /* displayHandle */) const { return -1; }
42*38e8c45fSAndroid Build Coastguard Worker     };
43*38e8c45fSAndroid Build Coastguard Worker 
TransactionProtoParser(std::unique_ptr<FlingerDataMapper> provider)44*38e8c45fSAndroid Build Coastguard Worker     TransactionProtoParser(std::unique_ptr<FlingerDataMapper> provider)
45*38e8c45fSAndroid Build Coastguard Worker           : mMapper(std::move(provider)) {}
46*38e8c45fSAndroid Build Coastguard Worker 
47*38e8c45fSAndroid Build Coastguard Worker     perfetto::protos::TransactionState toProto(const TransactionState&);
48*38e8c45fSAndroid Build Coastguard Worker     perfetto::protos::TransactionState toProto(
49*38e8c45fSAndroid Build Coastguard Worker             const std::map<uint32_t /* layerId */, TracingLayerState>&);
50*38e8c45fSAndroid Build Coastguard Worker     perfetto::protos::LayerCreationArgs toProto(const LayerCreationArgs& args);
51*38e8c45fSAndroid Build Coastguard Worker     perfetto::protos::LayerState toProto(const ResolvedComposerState&);
52*38e8c45fSAndroid Build Coastguard Worker     static perfetto::protos::DisplayInfo toProto(const frontend::DisplayInfo&, uint32_t layerStack);
53*38e8c45fSAndroid Build Coastguard Worker 
54*38e8c45fSAndroid Build Coastguard Worker     TransactionState fromProto(const perfetto::protos::TransactionState&);
55*38e8c45fSAndroid Build Coastguard Worker     void mergeFromProto(const perfetto::protos::LayerState&, TracingLayerState& outState);
56*38e8c45fSAndroid Build Coastguard Worker     void fromProto(const perfetto::protos::LayerCreationArgs&, LayerCreationArgs& outArgs);
57*38e8c45fSAndroid Build Coastguard Worker     std::unique_ptr<FlingerDataMapper> mMapper;
58*38e8c45fSAndroid Build Coastguard Worker     static frontend::DisplayInfo fromProto(const perfetto::protos::DisplayInfo&);
59*38e8c45fSAndroid Build Coastguard Worker     static void fromProto(const google::protobuf::RepeatedPtrField<perfetto::protos::DisplayInfo>&,
60*38e8c45fSAndroid Build Coastguard Worker                           frontend::DisplayInfos& outDisplayInfos);
61*38e8c45fSAndroid Build Coastguard Worker 
62*38e8c45fSAndroid Build Coastguard Worker private:
63*38e8c45fSAndroid Build Coastguard Worker     perfetto::protos::DisplayState toProto(const DisplayState&);
64*38e8c45fSAndroid Build Coastguard Worker     void fromProto(const perfetto::protos::LayerState&, ResolvedComposerState& out);
65*38e8c45fSAndroid Build Coastguard Worker     DisplayState fromProto(const perfetto::protos::DisplayState&);
66*38e8c45fSAndroid Build Coastguard Worker };
67*38e8c45fSAndroid Build Coastguard Worker 
68*38e8c45fSAndroid Build Coastguard Worker } // namespace android::surfaceflinger
69