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 | |
| 18 | #include <layerproto/TransactionProto.h> |
| 19 | #include <utils/RefBase.h> |
| 20 | |
| 21 | #include "TransactionState.h" |
| 22 | |
| 23 | namespace android::surfaceflinger { |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 24 | |
| 25 | struct TracingLayerCreationArgs { |
| 26 | int32_t layerId; |
| 27 | std::string name; |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 28 | uint32_t flags = 0; |
| 29 | int32_t parentId = -1; |
| 30 | int32_t mirrorFromId = -1; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | struct TracingLayerState : layer_state_t { |
| 34 | uint64_t bufferId; |
| 35 | uint32_t bufferHeight; |
| 36 | uint32_t bufferWidth; |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 37 | int32_t pixelFormat; |
| 38 | uint64_t bufferUsage; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 39 | bool hasSidebandStream; |
| 40 | int32_t parentId; |
| 41 | int32_t relativeParentId; |
| 42 | int32_t inputCropId; |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 43 | TracingLayerCreationArgs args; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame^] | 46 | // Class which exposes buffer properties from BufferData without holding on to the actual buffer |
| 47 | // handle. |
| 48 | class BufferDataStub : public BufferData { |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 49 | public: |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame^] | 50 | 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 Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 66 | |
| 67 | private: |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame^] | 68 | uint64_t mBufferId; |
| 69 | uint32_t mWidth; |
| 70 | uint32_t mHeight; |
| 71 | int32_t mPixelFormat; |
| 72 | uint64_t mOutUsage; |
| 73 | }; |
| 74 | |
| 75 | class TransactionProtoParser { |
| 76 | public: |
| 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; } |
| 83 | virtual int32_t getLayerId(const sp<IBinder>& /* layerHandle */) const { return -1; } |
| 84 | virtual sp<IBinder> getDisplayHandle(int32_t /* displayId */) const { return nullptr; } |
| 85 | virtual int32_t getDisplayId(const sp<IBinder>& /* displayHandle */) const { return -1; } |
| 86 | virtual std::shared_ptr<BufferData> getGraphicData(uint64_t bufferId, uint32_t width, |
| 87 | uint32_t height, int32_t pixelFormat, |
| 88 | uint64_t usage) const { |
| 89 | return std::make_shared<BufferDataStub>(bufferId, width, height, pixelFormat, usage); |
| 90 | } |
| 91 | virtual void getGraphicBufferPropertiesFromCache(client_cache_t /* cachedBuffer */, |
| 92 | uint64_t* /* outBufferId */, |
| 93 | uint32_t* /* outWidth */, |
| 94 | uint32_t* /* outHeight */, |
| 95 | int32_t* /* outPixelFormat */, |
| 96 | uint64_t* /* outUsage */) const {} |
| 97 | }; |
| 98 | |
| 99 | TransactionProtoParser(std::unique_ptr<FlingerDataMapper> provider) |
| 100 | : mMapper(std::move(provider)) {} |
| 101 | |
| 102 | proto::TransactionState toProto(const TransactionState&); |
| 103 | proto::TransactionState toProto(const std::map<int32_t /* layerId */, TracingLayerState>&); |
| 104 | proto::LayerCreationArgs toProto(const TracingLayerCreationArgs& args); |
| 105 | |
| 106 | TransactionState fromProto(const proto::TransactionState&); |
| 107 | void mergeFromProto(const proto::LayerState&, TracingLayerState& outState); |
| 108 | void fromProto(const proto::LayerCreationArgs&, TracingLayerCreationArgs& outArgs); |
| 109 | |
| 110 | private: |
| 111 | proto::LayerState toProto(const layer_state_t&); |
| 112 | proto::DisplayState toProto(const DisplayState&); |
| 113 | void fromProto(const proto::LayerState&, layer_state_t& out); |
| 114 | DisplayState fromProto(const proto::DisplayState&); |
| 115 | |
| 116 | std::unique_ptr<FlingerDataMapper> mMapper; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Greg Kaiser | 2c90985 | 2021-12-07 09:45:29 -0800 | [diff] [blame] | 119 | } // namespace android::surfaceflinger |