Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | |
| 17 | #include <gmock/gmock.h> |
| 18 | #include <gtest/gtest.h> |
| 19 | #include <limits> // std::numeric_limits |
| 20 | |
| 21 | #include <gui/SurfaceComposerClient.h> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 22 | #include "LayerProtoHelper.h" |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 23 | |
| 24 | #include "Tracing/TransactionProtoParser.h" |
| 25 | |
| 26 | using namespace android::surfaceflinger; |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | TEST(TransactionProtoParserTest, parse) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 31 | const sp<IBinder> displayHandle = sp<BBinder>::make(); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 32 | TransactionState t1; |
| 33 | t1.originPid = 1; |
| 34 | t1.originUid = 2; |
| 35 | t1.frameTimelineInfo.vsyncId = 3; |
| 36 | t1.frameTimelineInfo.inputEventId = 4; |
| 37 | t1.postTime = 5; |
| 38 | |
| 39 | layer_state_t layer; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 40 | layer.what = std::numeric_limits<uint64_t>::max(); |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame] | 41 | layer.what &= ~static_cast<uint64_t>(layer_state_t::eBufferChanged); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 42 | layer.x = 7; |
| 43 | layer.matrix.dsdx = 15; |
| 44 | |
| 45 | size_t layerCount = 2; |
| 46 | t1.states.reserve(layerCount); |
| 47 | for (uint32_t i = 0; i < layerCount; i++) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 48 | ResolvedComposerState s; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 49 | if (i == 1) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 50 | s.parentId = 42; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 51 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 52 | s.layerId = 6 + i; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 53 | s.state = layer; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 54 | t1.states.emplace_back(s); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | size_t displayCount = 2; |
| 58 | t1.displays.reserve(displayCount); |
| 59 | for (uint32_t i = 0; i < displayCount; i++) { |
| 60 | DisplayState display; |
| 61 | display.what = std::numeric_limits<uint32_t>::max(); |
| 62 | if (i == 0) { |
| 63 | display.token = displayHandle; |
| 64 | } else { |
| 65 | display.token = nullptr; |
| 66 | } |
| 67 | display.width = 85; |
| 68 | t1.displays.add(display); |
| 69 | } |
| 70 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 71 | class TestMapper : public TransactionProtoParser::FlingerDataMapper { |
| 72 | public: |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 73 | sp<IBinder> displayHandle; |
| 74 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 75 | TestMapper(sp<IBinder> displayHandle) : displayHandle(displayHandle) {} |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 76 | |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 77 | sp<IBinder> getDisplayHandle(int32_t id) const { |
| 78 | return (id == 43) ? displayHandle : nullptr; |
| 79 | } |
| 80 | int32_t getDisplayId(const sp<IBinder>& handle) const { |
| 81 | return (handle == displayHandle) ? 43 : -1; |
| 82 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 85 | TransactionProtoParser parser(std::make_unique<TestMapper>(displayHandle)); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 86 | |
| 87 | proto::TransactionState proto = parser.toProto(t1); |
| 88 | TransactionState t2 = parser.fromProto(proto); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 89 | |
| 90 | ASSERT_EQ(t1.originPid, t2.originPid); |
| 91 | ASSERT_EQ(t1.originUid, t2.originUid); |
| 92 | ASSERT_EQ(t1.frameTimelineInfo.vsyncId, t2.frameTimelineInfo.vsyncId); |
| 93 | ASSERT_EQ(t1.frameTimelineInfo.inputEventId, t2.frameTimelineInfo.inputEventId); |
| 94 | ASSERT_EQ(t1.postTime, t2.postTime); |
| 95 | ASSERT_EQ(t1.states.size(), t2.states.size()); |
| 96 | ASSERT_EQ(t1.states[0].state.x, t2.states[0].state.x); |
| 97 | ASSERT_EQ(t1.states[0].state.matrix.dsdx, t2.states[0].state.matrix.dsdx); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame^] | 98 | ASSERT_EQ(t1.states[1].layerId, t2.states[1].layerId); |
| 99 | ASSERT_EQ(t1.states[1].parentId, t2.states[1].parentId); |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 100 | |
| 101 | ASSERT_EQ(t1.displays.size(), t2.displays.size()); |
| 102 | ASSERT_EQ(t1.displays[1].width, t2.displays[1].width); |
| 103 | ASSERT_EQ(t1.displays[0].token, t2.displays[0].token); |
| 104 | } |
| 105 | |
| 106 | } // namespace android |