blob: 457c3bec409a88ef5c8384e7052c9739213f890d [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
47 proto::TransactionState toProto(const TransactionState&);
Vishnu Nair81750622023-03-08 15:02:06 -080048 proto::TransactionState toProto(const std::map<uint32_t /* layerId */, TracingLayerState>&);
49 proto::LayerCreationArgs toProto(const LayerCreationArgs& args);
50 proto::LayerState toProto(const ResolvedComposerState&);
Vishnu Nair0d13b912023-03-27 22:06:38 +000051 static proto::DisplayInfo toProto(const frontend::DisplayInfo&, uint32_t layerStack);
Vishnu Nair685cfef2022-02-02 10:01:25 -080052
53 TransactionState fromProto(const proto::TransactionState&);
54 void mergeFromProto(const proto::LayerState&, TracingLayerState& outState);
Vishnu Nair81750622023-03-08 15:02:06 -080055 void fromProto(const proto::LayerCreationArgs&, LayerCreationArgs& outArgs);
Robert Carra63d52a2022-03-03 08:03:37 -080056 std::unique_ptr<FlingerDataMapper> mMapper;
Vishnu Nair0d13b912023-03-27 22:06:38 +000057 static frontend::DisplayInfo fromProto(const proto::DisplayInfo&);
Dominik Laskowski6b049ff2023-01-29 15:46:45 -050058 static void fromProto(const google::protobuf::RepeatedPtrField<proto::DisplayInfo>&,
59 frontend::DisplayInfos& outDisplayInfos);
Vishnu Nair685cfef2022-02-02 10:01:25 -080060
61private:
Vishnu Nair685cfef2022-02-02 10:01:25 -080062 proto::DisplayState toProto(const DisplayState&);
Vishnu Nair81750622023-03-08 15:02:06 -080063 void fromProto(const proto::LayerState&, ResolvedComposerState& out);
Vishnu Nair685cfef2022-02-02 10:01:25 -080064 DisplayState fromProto(const proto::DisplayState&);
65
Vishnu Nair6b591152021-10-08 11:45:14 -070066};
67
Greg Kaiser2c909852021-12-07 09:45:29 -080068} // namespace android::surfaceflinger