blob: 872a901b2175dffd396823d847e314d6d8d679a9 [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
18#include <layerproto/TransactionProto.h>
19#include <utils/RefBase.h>
20
21#include "TransactionState.h"
22
23namespace android::surfaceflinger {
Vishnu Nair68dee2b2021-11-08 18:52:12 -080024
25struct TracingLayerCreationArgs {
26 int32_t layerId;
27 std::string name;
Vishnu Nair84125ac2021-12-02 08:47:48 -080028 uint32_t flags = 0;
29 int32_t parentId = -1;
30 int32_t mirrorFromId = -1;
Vishnu Nair68dee2b2021-11-08 18:52:12 -080031};
32
33struct TracingLayerState : layer_state_t {
34 uint64_t bufferId;
35 uint32_t bufferHeight;
36 uint32_t bufferWidth;
Vishnu Naird37343b2022-01-12 16:18:56 -080037 int32_t pixelFormat;
38 uint64_t bufferUsage;
Vishnu Nair68dee2b2021-11-08 18:52:12 -080039 bool hasSidebandStream;
40 int32_t parentId;
41 int32_t relativeParentId;
42 int32_t inputCropId;
Vishnu Nair84125ac2021-12-02 08:47:48 -080043 TracingLayerCreationArgs args;
Vishnu Nair68dee2b2021-11-08 18:52:12 -080044};
45
Vishnu Nair685cfef2022-02-02 10:01:25 -080046// Class which exposes buffer properties from BufferData without holding on to the actual buffer
47// handle.
48class BufferDataStub : public BufferData {
Vishnu Nair6b591152021-10-08 11:45:14 -070049public:
Vishnu Nair685cfef2022-02-02 10:01:25 -080050 BufferDataStub(uint64_t bufferId, uint32_t width, uint32_t height, int32_t pixelFormat,
51 uint64_t outUsage)
52 : mBufferId(bufferId),
53 mWidth(width),
54 mHeight(height),
55 mPixelFormat(pixelFormat),
56 mOutUsage(outUsage) {}
57 bool hasBuffer() const override { return mBufferId != 0; }
58 bool hasSameBuffer(const BufferData& other) const override {
59 return getId() == other.getId() && frameNumber == other.frameNumber;
60 }
61 uint32_t getWidth() const override { return mWidth; }
62 uint32_t getHeight() const override { return mHeight; }
63 uint64_t getId() const override { return mBufferId; }
64 PixelFormat getPixelFormat() const override { return mPixelFormat; }
65 uint64_t getUsage() const override { return mOutUsage; }
Vishnu Nair6b591152021-10-08 11:45:14 -070066
67private:
Vishnu Nair685cfef2022-02-02 10:01:25 -080068 uint64_t mBufferId;
69 uint32_t mWidth;
70 uint32_t mHeight;
71 int32_t mPixelFormat;
72 uint64_t mOutUsage;
73};
74
75class TransactionProtoParser {
76public:
77 // Utility class to map handles to ids and buffers to buffer properties without pulling
78 // in SurfaceFlinger dependencies.
79 class FlingerDataMapper {
80 public:
81 virtual ~FlingerDataMapper() = default;
82 virtual sp<IBinder> getLayerHandle(int32_t /* layerId */) const { return nullptr; }
Robert Carra63d52a2022-03-03 08:03:37 -080083 virtual int64_t getLayerId(const sp<IBinder>& /* layerHandle */) const { return -1; }
84 virtual int64_t getLayerId(BBinder* /* layerHandle */) const { return -1; }
Vishnu Nair685cfef2022-02-02 10:01:25 -080085 virtual sp<IBinder> getDisplayHandle(int32_t /* displayId */) const { return nullptr; }
86 virtual int32_t getDisplayId(const sp<IBinder>& /* displayHandle */) const { return -1; }
87 virtual std::shared_ptr<BufferData> getGraphicData(uint64_t bufferId, uint32_t width,
88 uint32_t height, int32_t pixelFormat,
89 uint64_t usage) const {
90 return std::make_shared<BufferDataStub>(bufferId, width, height, pixelFormat, usage);
91 }
92 virtual void getGraphicBufferPropertiesFromCache(client_cache_t /* cachedBuffer */,
93 uint64_t* /* outBufferId */,
94 uint32_t* /* outWidth */,
95 uint32_t* /* outHeight */,
96 int32_t* /* outPixelFormat */,
97 uint64_t* /* outUsage */) const {}
98 };
99
100 TransactionProtoParser(std::unique_ptr<FlingerDataMapper> provider)
101 : mMapper(std::move(provider)) {}
102
103 proto::TransactionState toProto(const TransactionState&);
104 proto::TransactionState toProto(const std::map<int32_t /* layerId */, TracingLayerState>&);
105 proto::LayerCreationArgs toProto(const TracingLayerCreationArgs& args);
106
107 TransactionState fromProto(const proto::TransactionState&);
108 void mergeFromProto(const proto::LayerState&, TracingLayerState& outState);
109 void fromProto(const proto::LayerCreationArgs&, TracingLayerCreationArgs& outArgs);
Robert Carra63d52a2022-03-03 08:03:37 -0800110 std::unique_ptr<FlingerDataMapper> mMapper;
Vishnu Nair685cfef2022-02-02 10:01:25 -0800111
112private:
113 proto::LayerState toProto(const layer_state_t&);
114 proto::DisplayState toProto(const DisplayState&);
115 void fromProto(const proto::LayerState&, layer_state_t& out);
116 DisplayState fromProto(const proto::DisplayState&);
117
Vishnu Nair6b591152021-10-08 11:45:14 -0700118};
119
Greg Kaiser2c909852021-12-07 09:45:29 -0800120} // namespace android::surfaceflinger