• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include <hilog/log.h>
18 
19 #include "platform/common/rs_system_properties.h"
20 #include "render_context.h"
21 
22 using namespace testing::ext;
23 
24 namespace OHOS::Rosen {
25 class RenderContextTest : public testing::Test {
26 public:
27     static constexpr HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, 0, "RenderContextTest" };
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp() override;
31     void TearDown() override;
32 };
33 
SetUpTestCase()34 void RenderContextTest::SetUpTestCase() {}
TearDownTestCase()35 void RenderContextTest::TearDownTestCase() {}
SetUp()36 void RenderContextTest::SetUp() {}
TearDown()37 void RenderContextTest::TearDown() {}
38 
39 /**
40  * @tc.name: CreateEGLSurfaceTest001
41  * @tc.desc: Verify the CreateEGLSurfaceTest001 of RenderContextTest
42  * @tc.type: FUNC
43  */
44 HWTEST_F(RenderContextTest, CreateEGLSurfaceTest001, Function | SmallTest | Level2)
45 {
46 #ifdef ACE_ENABLE_GL
47     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
48         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
49         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
50         return;
51     }
52     // start CreateEGLSurfaceTest001 test
53     RenderContext renderContext;
54     EGLSurface eglSurface = renderContext.CreateEGLSurface(nullptr);
55     EXPECT_EQ(eglSurface, EGL_NO_SURFACE);
56 #endif
57 }
58 
59 /**
60  * @tc.name: CreateEGLSurfaceTest002
61  * @tc.desc: Verify the CreateEGLSurfaceTest002 of RenderContextTest
62  * @tc.type: FUNC
63  */
64 HWTEST_F(RenderContextTest, CreateEGLSurfaceTest002, Function | SmallTest | Level2)
65 {
66 #ifdef ACE_ENABLE_GL
67     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
68         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
69         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
70         return;
71     }
72     // start CreateEGLSurfaceTest002 test
73     RenderContext renderContext;
74     renderContext.InitializeEglContext();
75     EGLSurface eglSurface = renderContext.CreateEGLSurface(nullptr);
76     EXPECT_EQ(eglSurface, EGL_NO_SURFACE);
77 #endif
78 }
79 
80 /**
81  * @tc.name: SetUpGrContextTest
82  * @tc.desc: Verify the SetUpGrContextTest of RenderContextTest
83  * @tc.type: FUNC
84  */
85 HWTEST_F(RenderContextTest, SetUpGrContextTest, Function | SmallTest | Level2)
86 {
87 #ifdef ACE_ENABLE_GL
88     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
89         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
90         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
91         return;
92     }
93     // start SetUpGrContextTest test
94     RenderContext renderContext;
95 #ifndef USE_ROSEN_DRAWING
96     bool grContext = renderContext.SetUpGrContext(nullptr);
97 #else
98     bool grContext = renderContext.SetUpGpuContext();
99 #endif
100     EXPECT_EQ(grContext, false);
101 #endif
102 }
103 
104 /**
105  * @tc.name: AcquireSurfaceTest
106  * @tc.desc: Verify the AcquireSurfaceTest of RenderContextTest
107  * @tc.type: FUNC
108  */
109 HWTEST_F(RenderContextTest, AcquireSurfaceTest, Function | SmallTest | Level2)
110 {
111 #ifdef ACE_ENABLE_GL
112     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
113         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
114         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
115         return;
116     }
117     // start AcquireSurfaceTest test
118     RenderContext renderContext;
119     auto surface = renderContext.AcquireSurface(0, 0);
120     EXPECT_TRUE(surface == nullptr);
121 #endif
122 }
123 
124 /**
125  * @tc.name: QueryEglBufferAgeTest001
126  * @tc.desc: Verify the QueryEglBufferAgeTest001 of RenderContextTest
127  * @tc.type: FUNC
128  */
129 HWTEST_F(RenderContextTest, QueryEglBufferAgeTest001, Function | SmallTest | Level2)
130 {
131 #ifdef ACE_ENABLE_GL
132     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
133         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
134         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
135         return;
136     }
137     // start QueryEglBufferAgeTest001 test
138     RenderContext renderContext;
139     EGLint bufferAge = renderContext.QueryEglBufferAge();
140     EXPECT_EQ(bufferAge, EGL_UNKNOWN);
141 #endif
142 }
143 
144 /**
145  * @tc.name: QueryEglBufferAgeTest002
146  * @tc.desc: Verify the QueryEglBufferAgeTest002 of RenderContextTest
147  * @tc.type: FUNC
148  */
149 HWTEST_F(RenderContextTest, QueryEglBufferAgeTest002, Function | SmallTest | Level2)
150 {
151 #ifdef ACE_ENABLE_GL
152     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
153         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
154         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
155         return;
156     }
157     // start QueryEglBufferAgeTest002 test
158     RenderContext renderContext;
159     EGLint bufferAge = renderContext.QueryEglBufferAge();
160     EXPECT_EQ(bufferAge, EGL_UNKNOWN);
161 #endif
162 }
163 
164 /**
165  * @tc.name: ClearRedundantResourcesTest001
166  * @tc.desc: Verify the ClearRedundantResourcesTest002 of RenderContextTest
167  * @tc.type: FUNC
168  */
HWTEST_F(RenderContextTest,ClearRedundantResourcesTest001,Level1)169 HWTEST_F(RenderContextTest, ClearRedundantResourcesTest001, Level1)
170 {
171 #ifdef ACE_ENABLE_GL
172     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
173         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
174         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
175         return;
176     }
177     // start ClearRedundantResourcesTest001 test
178     RenderContext renderContext;
179     renderContext.InitializeEglContext();
180     renderContext.ClearRedundantResources();
181 #endif
182 }
183 
184 /**
185  * @tc.name: DamageFrameTest001
186  * @tc.desc: Verify the DamageFrameTest001 of RenderContextTest
187  * @tc.type: FUNC
188  */
HWTEST_F(RenderContextTest,DamageFrameTest001,Level1)189 HWTEST_F(RenderContextTest, DamageFrameTest001, Level1)
190 {
191 #ifdef ACE_ENABLE_GL
192     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
193         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
194         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
195         return;
196     }
197     // start DamageFrameTest001 test
198     RenderContext renderContext;
199     renderContext.InitializeEglContext();
200     renderContext.DamageFrame(0, 0, 0, 0);
201 #endif
202 }
203 
204 /**
205  * @tc.name: MakeSelfCurrentTest001
206  * @tc.desc: Verify the MakeSelfCurrentTest001 of RenderContextTest
207  * @tc.type: FUNC
208  */
HWTEST_F(RenderContextTest,MakeSelfCurrentTest001,Level1)209 HWTEST_F(RenderContextTest, MakeSelfCurrentTest001, Level1)
210 {
211 #ifdef ACE_ENABLE_GL
212     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
213         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
214         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
215         return;
216     }
217     // start MakeSelfCurrentTest001 test
218     RenderContext renderContext;
219     renderContext.InitializeEglContext();
220     renderContext.MakeSelfCurrent();
221 #endif
222 }
223 
224 /**
225  * @tc.name: ColorSpaceTest001
226  * @tc.desc: Verify the SetColorSpaceTest and GetColorSpaceTest of RenderContextTest
227  * @tc.type: FUNC
228  */
HWTEST_F(RenderContextTest,ColorSpaceTest001,Level1)229 HWTEST_F(RenderContextTest, ColorSpaceTest001, Level1)
230 {
231 #ifdef ACE_ENABLE_GL
232     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
233         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
234         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
235         return;
236     }
237     // start ColorSpaceTest001 test
238     RenderContext renderContext;
239     renderContext.SetColorSpace(GRAPHIC_COLOR_GAMUT_DISPLAY_P3);
240     ASSERT_EQ(renderContext.GetColorSpace(), GRAPHIC_COLOR_GAMUT_DISPLAY_P3);
241 #endif
242 }
243 
244 /**
245  * @tc.name: PixelFormatTest001
246  * @tc.desc: Verify the SetPixelFormatTest and GetPixelFormat of RenderContextTest
247  * @tc.type: FUNC
248  */
HWTEST_F(RenderContextTest,PixelFormatTest001,Level1)249 HWTEST_F(RenderContextTest, PixelFormatTest001, Level1)
250 {
251 #ifdef ACE_ENABLE_GL
252     if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
253         RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
254         GTEST_LOG_(INFO) << "vulkan enable! skip opengl test case";
255         return;
256     }
257     // start PixelFormatTest001 test
258     RenderContext renderContext;
259     renderContext.SetPixelFormat(GRAPHIC_PIXEL_FMT_RGBA_1010102);
260     ASSERT_EQ(renderContext.GetPixelFormat(), GRAPHIC_PIXEL_FMT_RGBA_1010102);
261 #endif
262 }
263 } // namespace OHOS::Rosen