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 <memory>
17 #include "gtest/gtest.h"
18
19 #include "draw/surface.h"
20 #include "effect/color_space.h"
21 #include "image/gpu_context.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Rosen {
28 namespace Drawing {
29 class SurfaceTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35 };
36
SetUpTestCase()37 void SurfaceTest::SetUpTestCase() {}
TearDownTestCase()38 void SurfaceTest::TearDownTestCase() {}
SetUp()39 void SurfaceTest::SetUp() {}
TearDown()40 void SurfaceTest::TearDown() {}
41
42 /**
43 * @tc.name: Surface001
44 * @tc.desc: Test for creating Surface.
45 * @tc.type: FUNC
46 * @tc.require:I774GD
47 */
48 HWTEST_F(SurfaceTest, Surface001, TestSize.Level1)
49 {
50 auto surface = std::make_unique<Surface>();
51 ASSERT_TRUE(surface != nullptr);
52 }
53
54 /**
55 * @tc.name: SurfaceBind001
56 * @tc.desc: Test for binding raster Surface.
57 * @tc.type: FUNC
58 * @tc.require:I774GD
59 */
60 HWTEST_F(SurfaceTest, SurfaceBind001, TestSize.Level1)
61 {
62 auto surface = std::make_unique<Surface>();
63 ASSERT_TRUE(surface != nullptr);
64 Bitmap bitmap;
65 ASSERT_FALSE(surface->Bind(bitmap));
66 }
67
68 /**
69 * @tc.name: SurfaceBind002
70 * @tc.desc: Test for binding raster Surface.
71 * @tc.type: FUNC
72 * @tc.require:I774GD
73 */
74 HWTEST_F(SurfaceTest, SurfaceBind002, TestSize.Level1)
75 {
76 auto surface = std::make_unique<Surface>();
77 ASSERT_TRUE(surface != nullptr);
78 Bitmap bitmap;
79 BitmapFormat bitmapFormat { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
80 bitmap.Build(10, 10, bitmapFormat);
81 ASSERT_TRUE(surface->Bind(bitmap));
82 }
83
84 #ifdef RS_ENABLE_GPU
85 /**
86 * @tc.name: SurfaceBind003
87 * @tc.desc: Test for binding texture Surface.
88 * @tc.type: FUNC
89 * @tc.require:I774GD
90 */
91 HWTEST_F(SurfaceTest, SurfaceBind003, TestSize.Level1)
92 {
93 auto surface = std::make_unique<Surface>();
94 ASSERT_TRUE(surface != nullptr);
95 Image image;
96 ASSERT_FALSE(surface->Bind(image));
97 }
98
99 /**
100 * @tc.name: SurfaceBind004
101 * @tc.desc: Test for binding FrameBuffer Surface.
102 * @tc.type: FUNC
103 * @tc.require:I774GD
104 */
105 HWTEST_F(SurfaceTest, SurfaceBind004, TestSize.Level1)
106 {
107 auto surface = std::make_unique<Surface>();
108 ASSERT_TRUE(surface != nullptr);
109 FrameBuffer info;
110 ASSERT_FALSE(surface->Bind(info));
111
112 info.gpuContext = std::make_shared<GPUContext>();
113 ASSERT_FALSE(surface->Bind(info));
114
115 info.colorSpace = ColorSpace::CreateSRGB();
116 ASSERT_FALSE(surface->Bind(info));
117 }
118 #endif
119
120 /**
121 * @tc.name: GetCanvas001
122 * @tc.desc: Test for geting Canvas that draws into Surface.
123 * @tc.type: FUNC
124 * @tc.require:I774GD
125 */
126 HWTEST_F(SurfaceTest, GetCanvas001, TestSize.Level1)
127 {
128 auto surface = std::make_unique<Surface>();
129 ASSERT_TRUE(surface != nullptr);
130 auto ret = surface->GetCanvas();
131 ASSERT_EQ(ret, nullptr);
132 }
133
134 /**
135 * @tc.name: GetCanvas002
136 * @tc.desc: Test for geting Canvas that draws into Surface.
137 * @tc.type: FUNC
138 * @tc.require:I774GD
139 */
140 HWTEST_F(SurfaceTest, GetCanvas002, TestSize.Level1)
141 {
142 auto surface = std::make_unique<Surface>();
143 ASSERT_TRUE(surface != nullptr);
144 Bitmap bitmap;
145 BitmapFormat bitmapFormat { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
146 bitmap.Build(10, 10, bitmapFormat);
147 ASSERT_TRUE(surface->Bind(bitmap));
148 auto ret = surface->GetCanvas();
149 ASSERT_TRUE(ret != nullptr);
150 }
151
152 /**
153 * @tc.name: GetImageSnapshot001
154 * @tc.desc: Test for geting Image capturing Surface contents.
155 * @tc.type: FUNC
156 * @tc.require:I774GD
157 */
158 HWTEST_F(SurfaceTest, GetImageSnapshot001, TestSize.Level1)
159 {
160 auto surface = std::make_unique<Surface>();
161 ASSERT_TRUE(surface != nullptr);
162 auto ret = surface->GetImageSnapshot();
163 ASSERT_EQ(ret, nullptr);
164 }
165
166 /**
167 * @tc.name: GetImageSnapshot002
168 * @tc.desc: Test for geting Image capturing Surface contents.
169 * @tc.type: FUNC
170 * @tc.require:I774GD
171 */
172 HWTEST_F(SurfaceTest, GetImageSnapshot002, TestSize.Level1)
173 {
174 auto surface = std::make_unique<Surface>();
175 ASSERT_TRUE(surface != nullptr);
176 Bitmap bitmap;
177 BitmapFormat bitmapFormat { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
178 bitmap.Build(10, 10, bitmapFormat);
179 ASSERT_TRUE(surface->Bind(bitmap));
180 auto ret = surface->GetImageSnapshot();
181 ASSERT_TRUE(ret != nullptr);
182 }
183
184 /**
185 * @tc.name: GetImageSnapshot003
186 * @tc.desc: Test for geting Image capturing Surface contents.
187 * @tc.type: FUNC
188 * @tc.require:I774GD
189 */
190 HWTEST_F(SurfaceTest, GetImageSnapshot003, TestSize.Level1)
191 {
192 auto surface = std::make_unique<Surface>();
193 ASSERT_TRUE(surface != nullptr);
194 RectI bounds;
195 auto ret = surface->GetImageSnapshot(bounds);
196 ASSERT_EQ(ret, nullptr);
197 }
198
199 /**
200 * @tc.name: GetImageSnapshot004
201 * @tc.desc: Test for geting Image capturing Surface contents.
202 * @tc.type: FUNC
203 * @tc.require:I774GD
204 */
205 HWTEST_F(SurfaceTest, GetImageSnapshot004, TestSize.Level1)
206 {
207 auto surface = std::make_unique<Surface>();
208 ASSERT_TRUE(surface != nullptr);
209 Bitmap bitmap;
210 BitmapFormat bitmapFormat { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
211 bitmap.Build(10, 10, bitmapFormat);
212 ASSERT_TRUE(surface->Bind(bitmap));
213 RectI bounds(1, 1, 15, 20);
214 auto ret = surface->GetImageSnapshot(bounds);
215 ASSERT_TRUE(ret != nullptr);
216 }
217
218 /**
219 * @tc.name: GetImageSnapshot005
220 * @tc.desc: Test for geting Image capturing Surface contents, when bounds does not intersect the surface.
221 * @tc.type: FUNC
222 * @tc.require:I774GD
223 */
224 HWTEST_F(SurfaceTest, GetImageSnapshot005, TestSize.Level1)
225 {
226 auto surface = std::make_unique<Surface>();
227 ASSERT_TRUE(surface != nullptr);
228 Bitmap bitmap;
229 BitmapFormat bitmapFormat { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
230 bitmap.Build(10, 10, bitmapFormat);
231 ASSERT_TRUE(surface->Bind(bitmap));
232 RectI bounds(70, 75, 100, 100);
233 auto ret = surface->GetImageSnapshot(bounds);
234 ASSERT_TRUE(ret == nullptr);
235 }
236
237 #ifdef RS_ENABLE_GL
238 /**
239 * @tc.name: Wait006
240 * @tc.desc: Test wait for the surface.
241 * @tc.type: FUNC
242 * @tc.require:IALEIN
243 */
244 HWTEST_F(SurfaceTest, Wait006, TestSize.Level1)
245 {
246 auto surface = std::make_unique<Surface>();
247 ASSERT_TRUE(surface != nullptr);
248 std::vector<GrGLsync> syncs;
249 surface->Wait(syncs);
250 }
251 #endif
252 } // namespace Drawing
253 } // namespace Rosen
254 } // namespace OHOS
255