blob: a5f115e462846ba30a2abaf9422863183255375f [file] [log] [blame]
Valerie Hauc5011f92019-10-11 09:52:07 -07001/*
2 * Copyright (C) 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#define LOG_TAG "BLASTBufferQueue_test"
18
19#include <gui/BLASTBufferQueue.h>
20
21#include <gui/SurfaceComposerClient.h>
22#include <ui/GraphicBuffer.h>
23
24#include <gtest/gtest.h>
25
26using namespace std::chrono_literals;
27
28namespace android {
29
30const int DEFAULT_WIDTH = 100;
31const int DEFAULT_HEIGHT = 100;
32
33using Transaction = SurfaceComposerClient::Transaction;
34
35class BLASTBufferQueueHelper {
36public:
37 BLASTBufferQueueHelper(const sp<SurfaceControl>& sc, int width, int height) {
38 mBlastBufferQueueAdapter = new BLASTBufferQueue(sc, width, height);
39 }
40
41 void update(const sp<SurfaceControl>& sc, int width, int height) {
42 mBlastBufferQueueAdapter->update(sc, width, height);
43 }
44
45 void setNextTransaction(Transaction* next) {
46 mBlastBufferQueueAdapter->setNextTransaction(next);
47 }
48
49 int getWidth() { return mBlastBufferQueueAdapter->mWidth; }
50 int getHeight() { return mBlastBufferQueueAdapter->mHeight; }
51 Transaction* getNextTransaction() { return mBlastBufferQueueAdapter->mNextTransaction; }
52 const sp<SurfaceControl> getSurfaceControl() {
53 return mBlastBufferQueueAdapter->mSurfaceControl;
54 }
55
56private:
57 sp<BLASTBufferQueue> mBlastBufferQueueAdapter;
58};
59
60class BLASTBufferQueueTest : public ::testing::Test {
61public:
62protected:
63 BLASTBufferQueueTest() {
64 const ::testing::TestInfo* const testInfo =
65 ::testing::UnitTest::GetInstance()->current_test_info();
66 ALOGV("Begin test: %s.%s", testInfo->test_case_name(), testInfo->name());
67 }
68
69 ~BLASTBufferQueueTest() {
70 const ::testing::TestInfo* const testInfo =
71 ::testing::UnitTest::GetInstance()->current_test_info();
72 ALOGV("End test: %s.%s", testInfo->test_case_name(), testInfo->name());
73 }
74
75 void SetUp() {
76 mClient = new SurfaceComposerClient();
77 mSurfaceControl = mClient->createSurface(String8("TestSurface"), DEFAULT_WIDTH,
78 DEFAULT_HEIGHT, PIXEL_FORMAT_RGBA_8888);
79 }
80
81 sp<SurfaceComposerClient> mClient;
82 sp<SurfaceControl> mSurfaceControl;
83};
84
85TEST_F(BLASTBufferQueueTest, CreateBLASTBufferQueue) {
86 // create BLASTBufferQueue adapter associated with this surface
87 BLASTBufferQueueHelper adapter(mSurfaceControl, DEFAULT_WIDTH, DEFAULT_HEIGHT);
88 ASSERT_EQ(mSurfaceControl, adapter.getSurfaceControl());
89 ASSERT_EQ(DEFAULT_WIDTH, adapter.getWidth());
90 ASSERT_EQ(DEFAULT_HEIGHT, adapter.getHeight());
91 ASSERT_EQ(nullptr, adapter.getNextTransaction());
92}
93
94TEST_F(BLASTBufferQueueTest, Update) {
95 BLASTBufferQueueHelper adapter(mSurfaceControl, DEFAULT_WIDTH, DEFAULT_HEIGHT);
96 sp<SurfaceControl> updateSurface =
97 mClient->createSurface(String8("UpdateTest"), DEFAULT_WIDTH / 2, DEFAULT_HEIGHT / 2,
98 PIXEL_FORMAT_RGB_888);
99 adapter.update(updateSurface, DEFAULT_WIDTH / 2, DEFAULT_HEIGHT / 2);
100 ASSERT_EQ(updateSurface, adapter.getSurfaceControl());
101 ASSERT_EQ(DEFAULT_WIDTH / 2, adapter.getWidth());
102 ASSERT_EQ(DEFAULT_HEIGHT / 2, adapter.getHeight());
103}
104
105TEST_F(BLASTBufferQueueTest, SetNextTransaction) {
106 BLASTBufferQueueHelper adapter(mSurfaceControl, DEFAULT_WIDTH, DEFAULT_HEIGHT);
107 Transaction next;
108 adapter.setNextTransaction(&next);
109 ASSERT_EQ(&next, adapter.getNextTransaction());
110}
111} // namespace android