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 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame^] | 18 | #include <gui/fake/BufferData.h> |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 19 | #include <layerproto/TransactionProto.h> |
| 20 | #include <utils/RefBase.h> |
| 21 | |
| 22 | #include "TransactionState.h" |
| 23 | |
| 24 | namespace android::surfaceflinger { |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 25 | |
| 26 | struct TracingLayerCreationArgs { |
| 27 | int32_t layerId; |
| 28 | std::string name; |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 29 | uint32_t flags = 0; |
| 30 | int32_t parentId = -1; |
| 31 | int32_t mirrorFromId = -1; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | struct TracingLayerState : layer_state_t { |
| 35 | uint64_t bufferId; |
| 36 | uint32_t bufferHeight; |
| 37 | uint32_t bufferWidth; |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 38 | int32_t pixelFormat; |
| 39 | uint64_t bufferUsage; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 40 | bool hasSidebandStream; |
| 41 | int32_t parentId; |
| 42 | int32_t relativeParentId; |
| 43 | int32_t inputCropId; |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 44 | TracingLayerCreationArgs args; |
Vishnu Nair | 68dee2b | 2021-11-08 18:52:12 -0800 | [diff] [blame] | 45 | }; |
| 46 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 47 | class TransactionProtoParser { |
| 48 | public: |
| 49 | // Utility class to map handles to ids and buffers to buffer properties without pulling |
| 50 | // in SurfaceFlinger dependencies. |
| 51 | class FlingerDataMapper { |
| 52 | public: |
| 53 | virtual ~FlingerDataMapper() = default; |
| 54 | virtual sp<IBinder> getLayerHandle(int32_t /* layerId */) const { return nullptr; } |
Robert Carr | a63d52a | 2022-03-03 08:03:37 -0800 | [diff] [blame] | 55 | virtual int64_t getLayerId(const sp<IBinder>& /* layerHandle */) const { return -1; } |
| 56 | virtual int64_t getLayerId(BBinder* /* layerHandle */) const { return -1; } |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 57 | virtual sp<IBinder> getDisplayHandle(int32_t /* displayId */) const { return nullptr; } |
| 58 | virtual int32_t getDisplayId(const sp<IBinder>& /* displayHandle */) const { return -1; } |
| 59 | virtual std::shared_ptr<BufferData> getGraphicData(uint64_t bufferId, uint32_t width, |
| 60 | uint32_t height, int32_t pixelFormat, |
| 61 | uint64_t usage) const { |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame^] | 62 | return std::make_shared<fake::BufferData>(bufferId, width, height, pixelFormat, usage); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 63 | } |
| 64 | virtual void getGraphicBufferPropertiesFromCache(client_cache_t /* cachedBuffer */, |
| 65 | uint64_t* /* outBufferId */, |
| 66 | uint32_t* /* outWidth */, |
| 67 | uint32_t* /* outHeight */, |
| 68 | int32_t* /* outPixelFormat */, |
| 69 | uint64_t* /* outUsage */) const {} |
| 70 | }; |
| 71 | |
| 72 | TransactionProtoParser(std::unique_ptr<FlingerDataMapper> provider) |
| 73 | : mMapper(std::move(provider)) {} |
| 74 | |
| 75 | proto::TransactionState toProto(const TransactionState&); |
| 76 | proto::TransactionState toProto(const std::map<int32_t /* layerId */, TracingLayerState>&); |
| 77 | proto::LayerCreationArgs toProto(const TracingLayerCreationArgs& args); |
| 78 | |
| 79 | TransactionState fromProto(const proto::TransactionState&); |
| 80 | void mergeFromProto(const proto::LayerState&, TracingLayerState& outState); |
| 81 | void fromProto(const proto::LayerCreationArgs&, TracingLayerCreationArgs& outArgs); |
Robert Carr | a63d52a | 2022-03-03 08:03:37 -0800 | [diff] [blame] | 82 | std::unique_ptr<FlingerDataMapper> mMapper; |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | proto::LayerState toProto(const layer_state_t&); |
| 86 | proto::DisplayState toProto(const DisplayState&); |
| 87 | void fromProto(const proto::LayerState&, layer_state_t& out); |
| 88 | DisplayState fromProto(const proto::DisplayState&); |
| 89 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Greg Kaiser | 2c90985 | 2021-12-07 09:45:29 -0800 | [diff] [blame] | 92 | } // namespace android::surfaceflinger |