• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "gtest/gtest.h"
17 
18 #include "pipeline/parallel_render/rs_filter_sub_thread.h"
19 #include "render/rs_filter.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS::Rosen {
25 class RsFilterSubThreadTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp() override;
30     void TearDown() override;
31 };
32 
SetUpTestCase()33 void RsFilterSubThreadTest::SetUpTestCase() {}
TearDownTestCase()34 void RsFilterSubThreadTest::TearDownTestCase() {}
SetUp()35 void RsFilterSubThreadTest::SetUp() {}
TearDown()36 void RsFilterSubThreadTest::TearDown() {}
37 
38 /**
39  * @tc.name: PostTaskTest
40  * @tc.desc: Test RsFilterSubThreadTest.PostTaskTest
41  * @tc.type: FUNC
42  * @tc.require:
43  */
44 HWTEST_F(RsFilterSubThreadTest, PostTaskTest, TestSize.Level1)
45 {
46     auto renderContext = new RenderContext();
47     ASSERT_TRUE(renderContext != nullptr);
48     renderContext->InitializeEglContext();
49     auto curThread = std::make_shared<RSFilterSubThread>(renderContext);
__anonbc55ba4b0102null50     curThread->PostTask([] {});
51     curThread->Start();
__anonbc55ba4b0202null52     curThread->PostTask([] {});
53     delete renderContext;
54     renderContext = nullptr;
55     usleep(1000 * 1000); // 1000 * 1000us
56 }
57 
58 /**
59  * @tc.name: CreateShareEglContextTest
60  * @tc.desc: Test RsFilterSubThreadTest.CreateShareEglContextTest
61  * @tc.type: FUNC
62  * @tc.require:
63  */
64 HWTEST_F(RsFilterSubThreadTest, CreateShareEglContextTest, TestSize.Level1)
65 {
66     auto curThread1 = std::make_shared<RSFilterSubThread>(nullptr);
67     curThread1->CreateShareEglContext();
68     auto renderContext = new RenderContext();
69     ASSERT_TRUE(renderContext != nullptr);
70     renderContext->InitializeEglContext();
71     auto curThread2 = std::make_shared<RSFilterSubThread>(renderContext);
72     curThread2->CreateShareEglContext();
73     delete renderContext;
74     renderContext = nullptr;
75 }
76 
77 /**
78  * @tc.name: DestroyShareEglContextgTest
79  * @tc.desc: Test RsFilterSubThreadTest.DestroyShareEglContextgTest
80  * @tc.type: FUNC
81  * @tc.require:
82  */
83 HWTEST_F(RsFilterSubThreadTest, DestroyShareEglContextTest, TestSize.Level1)
84 {
85     auto curThread1 = std::make_shared<RSFilterSubThread>(nullptr);
86     curThread1->DestroyShareEglContext();
87     auto renderContext = new RenderContext();
88     ASSERT_TRUE(renderContext != nullptr);
89     renderContext->InitializeEglContext();
90     auto curThread2 = std::make_shared<RSFilterSubThread>(renderContext);
91     curThread2->DestroyShareEglContext();
92     delete renderContext;
93     renderContext = nullptr;
94 }
95 
96 /**
97  * @tc.name: CreateShareGrContextTest
98  * @tc.desc: Test RsFilterSubThreadTest.CreateShareGrContextTest
99  * @tc.type: FUNC
100  * @tc.require:
101  */
102 HWTEST_F(RsFilterSubThreadTest, CreateShareGrContextTest, TestSize.Level1)
103 {
104     auto curThread = std::make_shared<RSFilterSubThread>(nullptr);
105     curThread->CreateShareGrContext();
106 }
107 
108 /**
109  * @tc.name: RSFilterTaskTest
110  * @tc.desc: Test RsFilterSubThreadTest.RSFilterTaskTest
111  * @tc.type: FUNC
112  * @tc.require:
113  */
114 HWTEST_F(RsFilterSubThreadTest, RSFilterTaskTest, TestSize.Level1)
115 {
116     class RSFilterCacheTask : public RSFilter::RSFilterTask {
117     public:
118 #ifndef USE_ROSEN_DRAWING
InitSurface(GrRecordingContext * grContext)119         bool InitSurface(GrRecordingContext* grContext) override
120 #else
121         bool InitSurface(Drawing::GPUContext* grContext) override
122 #endif
123         {
124             return true;
125         }
Render()126         bool Render() override
127         {
128             return true;
129         }
130     };
131     RSFilterCacheTask task;
132 #ifndef USE_ROSEN_DRAWING
133     GrRecordingContext* grContext = nullptr;
134 #else
135     Drawing::GPUContext* grContext = nullptr;
136 #endif
137     ASSERT_TRUE(task.InitSurface(grContext));
138     ASSERT_TRUE(task.Render());
139 }
140 } // namespace OHOS::Rosen