blob: 9082a222fddb2f88bb435b839ce3acd5fc08b4bb [file] [log] [blame]
Valerie Hau64499682019-04-10 11:04:29 -07001/*
2 * Copyright 2019 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#undef LOG_TAG
18#define LOG_TAG "CachingTest"
19
20#include <gmock/gmock.h>
21#include <gtest/gtest.h>
22#include <gui/BufferQueue.h>
23#include "BufferStateLayer.h"
24
25namespace android {
26
27class SlotGenerationTest : public testing::Test {
28protected:
Vishnu Nair397a0e32022-07-26 00:01:48 +000029 sp<HwcSlotGenerator> mHwcSlotGenerator = sp<HwcSlotGenerator>::make();
Ady Abrahamd11bade2022-08-01 16:18:03 -070030 sp<GraphicBuffer> mBuffer1 =
31 sp<GraphicBuffer>::make(1u, 1u, HAL_PIXEL_FORMAT_RGBA_8888, 1u, 0u);
32 sp<GraphicBuffer> mBuffer2 =
33 sp<GraphicBuffer>::make(1u, 1u, HAL_PIXEL_FORMAT_RGBA_8888, 1u, 0u);
34 sp<GraphicBuffer> mBuffer3 =
35 sp<GraphicBuffer>::make(10u, 10u, HAL_PIXEL_FORMAT_RGBA_8888, 1u, 0u);
Valerie Hau64499682019-04-10 11:04:29 -070036};
37
38TEST_F(SlotGenerationTest, getHwcCacheSlot_Invalid) {
Ady Abrahamd11bade2022-08-01 16:18:03 -070039 sp<IBinder> binder = sp<BBinder>::make();
Valerie Hau64499682019-04-10 11:04:29 -070040 // test getting invalid client_cache_id
41 client_cache_t id;
rnleeed20fa42021-08-10 18:00:03 -070042 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070043 EXPECT_EQ(BufferQueue::INVALID_BUFFER_SLOT, slot);
44}
45
46TEST_F(SlotGenerationTest, getHwcCacheSlot_Basic) {
Ady Abrahamd11bade2022-08-01 16:18:03 -070047 sp<IBinder> binder = sp<BBinder>::make();
Valerie Hau64499682019-04-10 11:04:29 -070048 client_cache_t id;
49 id.token = binder;
50 id.id = 0;
rnleeed20fa42021-08-10 18:00:03 -070051 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070052 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);
53
54 client_cache_t idB;
55 idB.token = binder;
56 idB.id = 1;
Ady Abrahama0a16272021-03-03 15:23:35 -080057 slot = mHwcSlotGenerator->getHwcCacheSlot(idB);
Valerie Hau64499682019-04-10 11:04:29 -070058 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 2, slot);
59
Ady Abrahama0a16272021-03-03 15:23:35 -080060 slot = mHwcSlotGenerator->getHwcCacheSlot(idB);
Valerie Hau64499682019-04-10 11:04:29 -070061 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 2, slot);
62
Ady Abrahama0a16272021-03-03 15:23:35 -080063 slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070064 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);
65}
66
67TEST_F(SlotGenerationTest, getHwcCacheSlot_Reuse) {
Ady Abrahamd11bade2022-08-01 16:18:03 -070068 sp<IBinder> binder = sp<BBinder>::make();
Valerie Hau64499682019-04-10 11:04:29 -070069 std::vector<client_cache_t> ids;
70 uint32_t cacheId = 0;
71 // fill up cache
rnleeed20fa42021-08-10 18:00:03 -070072 for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
Valerie Hau64499682019-04-10 11:04:29 -070073 client_cache_t id;
74 id.token = binder;
75 id.id = cacheId;
76 ids.push_back(id);
77
rnleeed20fa42021-08-10 18:00:03 -070078 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070079 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
80 cacheId++;
81 }
rnleeed20fa42021-08-10 18:00:03 -070082 for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
83 int slot = mHwcSlotGenerator->getHwcCacheSlot(ids[static_cast<uint32_t>(i)]);
Valerie Hau64499682019-04-10 11:04:29 -070084 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
85 }
86
rnleeed20fa42021-08-10 18:00:03 -070087 for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
Valerie Hau64499682019-04-10 11:04:29 -070088 client_cache_t id;
89 id.token = binder;
90 id.id = cacheId;
rnleeed20fa42021-08-10 18:00:03 -070091 int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
Valerie Hau64499682019-04-10 11:04:29 -070092 EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
93 cacheId++;
94 }
95}
96} // namespace android