blob: bb0b13478e73f893094cd03c3cd4c4851380fd88 [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 Nair6b591152021-10-08 11:45:14 -070046class TransactionProtoParser {
47public:
Vishnu Nair68dee2b2021-11-08 18:52:12 -080048 typedef std::function<sp<IBinder>(int32_t)> LayerIdToHandleFn;
49 typedef std::function<sp<IBinder>(int32_t)> DisplayIdToHandleFn;
50 typedef std::function<int32_t(const sp<IBinder>&)> LayerHandleToIdFn;
51 typedef std::function<int32_t(const sp<IBinder>&)> DisplayHandleToIdFn;
52
53 static proto::TransactionState toProto(const TransactionState&, LayerHandleToIdFn getLayerIdFn,
54 DisplayHandleToIdFn getDisplayIdFn);
Vishnu Nair6b591152021-10-08 11:45:14 -070055 static proto::TransactionState toProto(
Greg Kaiser2c909852021-12-07 09:45:29 -080056 const std::map<int32_t /* layerId */, TracingLayerState>&);
Vishnu Nair68dee2b2021-11-08 18:52:12 -080057
58 static proto::LayerCreationArgs toProto(const TracingLayerCreationArgs& args);
59
Vishnu Nair6b591152021-10-08 11:45:14 -070060 static TransactionState fromProto(const proto::TransactionState&,
Vishnu Nair68dee2b2021-11-08 18:52:12 -080061 LayerIdToHandleFn getLayerHandleFn,
62 DisplayIdToHandleFn getDisplayHandleFn);
63 static void fromProto(const proto::LayerState&, LayerIdToHandleFn getLayerHandleFn,
64 TracingLayerState& outState);
65 static void fromProto(const proto::LayerCreationArgs&, TracingLayerCreationArgs& outArgs);
Vishnu Nair6b591152021-10-08 11:45:14 -070066
67private:
Vishnu Nair68dee2b2021-11-08 18:52:12 -080068 static proto::LayerState toProto(const layer_state_t&, LayerHandleToIdFn getLayerId);
69 static proto::DisplayState toProto(const DisplayState&, DisplayHandleToIdFn getDisplayId);
70 static void fromProto(const proto::LayerState&, LayerIdToHandleFn getLayerHandle,
71 layer_state_t& out);
72 static DisplayState fromProto(const proto::DisplayState&, DisplayIdToHandleFn getDisplayHandle);
Vishnu Nair6b591152021-10-08 11:45:14 -070073};
74
Greg Kaiser2c909852021-12-07 09:45:29 -080075} // namespace android::surfaceflinger