blob: 2232bb9cb143298250ae03342544500db6a8c6c0 [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
22#include "TransactionState.h"
23
24namespace android::surfaceflinger {
Vishnu Nair68dee2b2021-11-08 18:52:12 -080025
26struct TracingLayerCreationArgs {
27 int32_t layerId;
28 std::string name;
Vishnu Nair84125ac2021-12-02 08:47:48 -080029 uint32_t flags = 0;
30 int32_t parentId = -1;
31 int32_t mirrorFromId = -1;
Vishnu Nair68dee2b2021-11-08 18:52:12 -080032};
33
34struct TracingLayerState : layer_state_t {
35 uint64_t bufferId;
36 uint32_t bufferHeight;
37 uint32_t bufferWidth;
Vishnu Naird37343b2022-01-12 16:18:56 -080038 int32_t pixelFormat;
39 uint64_t bufferUsage;
Vishnu Nair68dee2b2021-11-08 18:52:12 -080040 bool hasSidebandStream;
41 int32_t parentId;
42 int32_t relativeParentId;
43 int32_t inputCropId;
Vishnu Nair84125ac2021-12-02 08:47:48 -080044 TracingLayerCreationArgs args;
Vishnu Nair68dee2b2021-11-08 18:52:12 -080045};
46
Vishnu Nair685cfef2022-02-02 10:01:25 -080047class TransactionProtoParser {
48public:
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 Carra63d52a2022-03-03 08:03:37 -080055 virtual int64_t getLayerId(const sp<IBinder>& /* layerHandle */) const { return -1; }
56 virtual int64_t getLayerId(BBinder* /* layerHandle */) const { return -1; }
Vishnu Nair685cfef2022-02-02 10:01:25 -080057 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 Nair59f6d2d2022-10-05 16:59:56 -070062 return std::make_shared<fake::BufferData>(bufferId, width, height, pixelFormat, usage);
Vishnu Nair685cfef2022-02-02 10:01:25 -080063 }
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 Carra63d52a2022-03-03 08:03:37 -080082 std::unique_ptr<FlingerDataMapper> mMapper;
Vishnu Nair685cfef2022-02-02 10:01:25 -080083
84private:
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 Nair6b591152021-10-08 11:45:14 -070090};
91
Greg Kaiser2c909852021-12-07 09:45:29 -080092} // namespace android::surfaceflinger