blob: b3ab71cfb5930fad1b0bb9de39f212f92562ac5f [file] [log] [blame]
Vishnu Nair6b591152021-10-08 11:45:14 -07001/*
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 Nair59f6d2d2022-10-05 16:59:56 -070018#include <gui/fake/BufferData.h>
Vishnu Nair6b591152021-10-08 11:45:14 -070019#include <layerproto/TransactionProto.h>
20#include <utils/RefBase.h>
21
Dominik Laskowski6b049ff2023-01-29 15:46:45 -050022#include "FrontEnd/DisplayInfo.h"
Vishnu Nair81750622023-03-08 15:02:06 -080023#include "FrontEnd/LayerCreationArgs.h"
Vishnu Nair6b591152021-10-08 11:45:14 -070024#include "TransactionState.h"
25
26namespace android::surfaceflinger {
Vishnu Nair68dee2b2021-11-08 18:52:12 -080027
Vishnu Nair81750622023-03-08 15:02:06 -080028struct TracingLayerState : ResolvedComposerState {
Vishnu Nair68dee2b2021-11-08 18:52:12 -080029 bool hasSidebandStream;
Vishnu Nair81750622023-03-08 15:02:06 -080030 LayerCreationArgs args;
Vishnu Nair68dee2b2021-11-08 18:52:12 -080031};
32
Vishnu Nair685cfef2022-02-02 10:01:25 -080033class TransactionProtoParser {
34public:
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 Nair685cfef2022-02-02 10:01:25 -080040 virtual sp<IBinder> getDisplayHandle(int32_t /* displayId */) const { return nullptr; }
41 virtual int32_t getDisplayId(const sp<IBinder>& /* displayHandle */) const { return -1; }
Vishnu Nair685cfef2022-02-02 10:01:25 -080042 };
43
44 TransactionProtoParser(std::unique_ptr<FlingerDataMapper> provider)
45 : mMapper(std::move(provider)) {}
46
Kean Mariotti4ba343c2023-04-19 13:31:02 +000047 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 Nair685cfef2022-02-02 10:01:25 -080053
Kean Mariotti4ba343c2023-04-19 13:31:02 +000054 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 Carra63d52a2022-03-03 08:03:37 -080057 std::unique_ptr<FlingerDataMapper> mMapper;
Kean Mariotti4ba343c2023-04-19 13:31:02 +000058 static frontend::DisplayInfo fromProto(const perfetto::protos::DisplayInfo&);
59 static void fromProto(const google::protobuf::RepeatedPtrField<perfetto::protos::DisplayInfo>&,
Dominik Laskowski6b049ff2023-01-29 15:46:45 -050060 frontend::DisplayInfos& outDisplayInfos);
Vishnu Nair685cfef2022-02-02 10:01:25 -080061
62private:
Kean Mariotti4ba343c2023-04-19 13:31:02 +000063 perfetto::protos::DisplayState toProto(const DisplayState&);
64 void fromProto(const perfetto::protos::LayerState&, ResolvedComposerState& out);
65 DisplayState fromProto(const perfetto::protos::DisplayState&);
Vishnu Nair6b591152021-10-08 11:45:14 -070066};
67
Greg Kaiser2c909852021-12-07 09:45:29 -080068} // namespace android::surfaceflinger