• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 "EGL/egl.h"
17 #include "EGL/eglext.h"
18 #include "drawing_bitmap.h"
19 #include "drawing_error_code.h"
20 #include "drawing_gpu_context.h"
21 #include "drawing_surface.h"
22 #include "drawing_canvas.h"
23 #include "drawing_rect.h"
24 #include "gtest/gtest.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace Drawing {
32 class DrawingNativeSurFaceTest : public testing::Test {
33   public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38 
39   protected:
40     EGLDisplay eglDisplay_ = EGL_NO_DISPLAY;
41     EGLConfig eglConfig_ = EGL_NO_CONFIG_KHR;
42     EGLContext eglContext_ = EGL_NO_CONTEXT;
43     EGLSurface eglSurface_ = EGL_NO_SURFACE;
44     OH_Drawing_GpuContext *gpuContext_ = nullptr;
45     OH_Drawing_Surface *surface_ = nullptr;
46     OH_Drawing_Canvas *canvas_ = nullptr;
47 };
48 
SetUpTestCase()49 void DrawingNativeSurFaceTest::SetUpTestCase() {}
TearDownTestCase()50 void DrawingNativeSurFaceTest::TearDownTestCase() {}
SetUp()51 void DrawingNativeSurFaceTest::SetUp()
52 {
53     eglDisplay_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
54     EXPECT_NE(eglDisplay_, EGL_NO_DISPLAY);
55 
56     EGLint eglMajVers;
57     EGLint eglMinVers;
58     EGLBoolean ret = eglInitialize(eglDisplay_, &eglMajVers, &eglMinVers);
59     EXPECT_EQ(ret, EGL_TRUE);
60 
61     EGLint count;
62     EGLint configAttribs[] = {
63         EGL_SURFACE_TYPE,
64         EGL_WINDOW_BIT,
65         EGL_RED_SIZE,
66         8,
67         EGL_GREEN_SIZE,
68         8,
69         EGL_BLUE_SIZE,
70         8,
71         EGL_ALPHA_SIZE,
72         8,
73         EGL_RENDERABLE_TYPE,
74         EGL_OPENGL_ES3_BIT,
75         EGL_NONE,
76     };
77     ret = eglChooseConfig(eglDisplay_, configAttribs, &eglConfig_, 1, &count);
78     EXPECT_EQ(ret, EGL_TRUE);
79     EXPECT_GE(count, 1);
80 
81     const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
82     eglContext_ = eglCreateContext(eglDisplay_, eglConfig_, EGL_NO_CONTEXT, contextAttribs);
83     EXPECT_NE(eglContext_, EGL_NO_CONTEXT);
84 
85     EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
86     eglSurface_ = eglCreatePbufferSurface(eglDisplay_, eglConfig_, attribs);
87     EXPECT_NE(eglSurface_, EGL_NO_SURFACE);
88 
89     ret = eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_);
90     EXPECT_EQ(ret, EGL_TRUE);
91     // 初始化errorCode
92     std::cout << "DrawingNativeSurFaceTest Setup code called before each test case." << std::endl;
93     OH_Drawing_ErrorCodeReset();
94     std::cout << "DrawingNativeSurFaceTest errorCodeReset before each test case." << std::endl;
95 }
96 
TearDown()97 void DrawingNativeSurFaceTest::TearDown()
98 {
99     EGLBoolean ret = eglDestroySurface(eglDisplay_, eglSurface_);
100     EXPECT_EQ(ret, EGL_TRUE);
101 
102     ret = eglDestroyContext(eglDisplay_, eglContext_);
103     EXPECT_EQ(ret, EGL_TRUE);
104 
105     ret = eglTerminate(eglDisplay_);
106     EXPECT_EQ(ret, EGL_TRUE);
107 
108     eglSurface_ = EGL_NO_SURFACE;
109     eglContext_ = EGL_NO_CONTEXT;
110     eglDisplay_ = EGL_NO_DISPLAY;
111     std::cout << "DrawingNativeSurFaceTest Setup code called after each test case." << std::endl;
112     OH_Drawing_ErrorCodeReset();
113     std::cout << "DrawingNativeSurFaceTest errorCodeReset after each test case." << std::endl;
114 }
115 
116 /*
117  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0100
118  * @tc.name: testSurfaceCreateFromGpuContextNormal
119  * @tc.desc: test for testSurfaceCreateFromGpuContextNormal.
120  * @tc.size  : SmallTest
121  * @tc.type  : Function
122  * @tc.level : Level 0
123  */
124 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceCreateFromGpuContextNormal, Function | SmallTest | Level0) {
125     OH_Drawing_GpuContextOptions options{true};
126     gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options);
127     EXPECT_NE(gpuContext_, nullptr);
128     const int32_t width = 500;
129     const int32_t height = 500;
130     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
131     surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, true, imageInfo);
132     // add assert
133     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS);
134     EXPECT_NE(surface_, nullptr);
135     OH_Drawing_SurfaceDestroy(surface_);
136     surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, false, imageInfo);
137     // add assert
138     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS);
139     EXPECT_NE(surface_, nullptr);
140     OH_Drawing_SurfaceDestroy(surface_);
141     OH_Drawing_GpuContextDestroy(gpuContext_);
142 }
143 
144 /*
145  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0101
146  * @tc.name: testSurfaceCreateFromGpuContextNull
147  * @tc.desc: test for testSurfaceCreateFromGpuContextNull.
148  * @tc.size  : SmallTest
149  * @tc.type  : Function
150  * @tc.level : Level 3
151  */
152 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceCreateFromGpuContextNull, Function | SmallTest | Level3) {
153     OH_Drawing_GpuContextOptions options{true};
154     gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options);
155     EXPECT_NE(gpuContext_, nullptr);
156     const int32_t width = 500;
157     const int32_t height = 500;
158     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
159     // OH_Drawing_GpuContext is NULL, check error code using OH_Drawing_ErrorCodeGet
160     surface_ = OH_Drawing_SurfaceCreateFromGpuContext(nullptr, true, imageInfo);
161     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
162     // Exceptional parameter passing for OH_Drawing_Image_Info
163     OH_Drawing_Image_Info imageInfo2 = {0, 0, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
164     surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, false, imageInfo2);
165     EXPECT_EQ(surface_, nullptr);
166     OH_Drawing_SurfaceDestroy(surface_);
167     OH_Drawing_GpuContextDestroy(gpuContext_);
168 }
169 
170 /*
171  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0102
172  * @tc.name: testSurfaceCreateFromGpuContextBoundary
173  * @tc.desc: test for testSurfaceCreateFromGpuContextBoundary.
174  * @tc.size  : SmallTest
175  * @tc.type  : Function
176  * @tc.level : Level 0
177  */
178 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceCreateFromGpuContextBoundary, Function | SmallTest | Level0) {
179     OH_Drawing_GpuContextOptions options{true};
180     gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options);
181     EXPECT_NE(gpuContext_, nullptr);
182     const int32_t width = 4096;
183     const int32_t height = 2160;
184     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
185     surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, true, imageInfo);
186     EXPECT_NE(surface_, nullptr);
187     OH_Drawing_SurfaceDestroy(surface_);
188     surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, false, imageInfo);
189     EXPECT_NE(surface_, nullptr);
190     OH_Drawing_SurfaceDestroy(surface_);
191     OH_Drawing_GpuContextDestroy(gpuContext_);
192 }
193 
194 /*
195  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0200
196  * @tc.name: testSurfaceDestroyNormal
197  * @tc.desc: test for testSurfaceDestroyNormal.
198  * @tc.size  : SmallTest
199  * @tc.type  : Function
200  * @tc.level : Level 0
201  */
202 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceDestroyNormal, Function | SmallTest | Level0) {
203     OH_Drawing_GpuContextOptions options{true};
204     gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options);
205     EXPECT_NE(gpuContext_, nullptr);
206     const int32_t width = 500;
207     const int32_t height = 500;
208     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
209     surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, true, imageInfo);
210     EXPECT_NE(surface_, nullptr);
211     OH_Drawing_SurfaceDestroy(surface_);
212     OH_Drawing_GpuContextDestroy(gpuContext_);
213 }
214 
215 /*
216  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0201
217  * @tc.name: testSurfaceDestroyNull
218  * @tc.desc: test for testSurfaceDestroyNull.
219  * @tc.size  : SmallTest
220  * @tc.type  : Function
221  * @tc.level : Level 3
222  */
223 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceDestroyNull, Function | SmallTest | Level3) {
224     // free
225     OH_Drawing_SurfaceDestroy(nullptr);
226     // add assert
227     EXPECT_TRUE(true);
228 }
229 
230 /*
231  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0300
232  * @tc.name: testSurfaceGetCanvasNormal
233  * @tc.desc: test for testSurfaceGetCanvasNormal.
234  * @tc.size  : SmallTest
235  * @tc.type  : Function
236  * @tc.level : Level 0
237  */
238 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceGetCanvasNormal, Function | SmallTest | Level0) {
239     OH_Drawing_GpuContextOptions options{true};
240     gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options);
241     EXPECT_NE(gpuContext_, nullptr);
242     // 1. OH_Drawing_SurfaceCreateFromGpuContext
243     const int32_t width = 500;
244     const int32_t height = 500;
245     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
246     surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, true, imageInfo);
247     EXPECT_NE(surface_, nullptr);
248     //2.OH_Drawing_SurfaceGetCanvas, get the canvas object from the surface object,a pointer to the surface object
249     // and call the drawing interface
250     canvas_ = OH_Drawing_SurfaceGetCanvas(surface_);
251     // add assert
252     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS);
253     EXPECT_NE(canvas_, nullptr);
254     // 3. Free memory
255     OH_Drawing_SurfaceDestroy(surface_);
256     OH_Drawing_GpuContextDestroy(gpuContext_);
257 }
258 
259 /*
260  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0301
261  * @tc.name: testSurfaceGetCanvasNull
262  * @tc.desc: test for testSurfaceGetCanvasNull.
263  * @tc.size  : SmallTest
264  * @tc.type  : Function
265  * @tc.level : Level 3
266  */
267 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceGetCanvasNull, Function | SmallTest | Level3) {
268     OH_Drawing_GpuContextOptions options{true};
269     gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options);
270     EXPECT_NE(gpuContext_, nullptr);
271     // 1. OH_Drawing_SurfaceCreateFromGpuContext
272     const int32_t width = 500;
273     const int32_t height = 500;
274     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
275     surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, true, imageInfo);
276     EXPECT_NE(surface_, nullptr);
277     // 2. OH_Drawing_SurfaceGetCanvas with null parameter, check error code using OH_Drawing_ErrorCodeGet
278     canvas_ = OH_Drawing_SurfaceGetCanvas(nullptr);
279     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
280     OH_Drawing_SurfaceDestroy(surface_);
281     OH_Drawing_GpuContextDestroy(gpuContext_);
282 }
283 
284 /*
285  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0302
286  * @tc.name: testSurfaceGetCanvasBoundary
287  * @tc.desc: test for testSurfaceGetCanvasBoundary.
288  * @tc.size  : SmallTest
289  * @tc.type  : Function
290  * @tc.level : Level 0
291  */
292 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceGetCanvasBoundary, Function | SmallTest | Level0) {
293     OH_Drawing_GpuContextOptions options{true};
294     gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options);
295     EXPECT_NE(gpuContext_, nullptr);
296     // 1. OH_Drawing_SurfaceCreateFromGpuContext
297     const int32_t width = 4096;
298     const int32_t height = 2160;
299     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
300     surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, true, imageInfo);
301     EXPECT_NE(surface_, nullptr);
302     //2. OH_Drawing_SurfaceGetCanvas, get the canvas object from the surface object,a pointer to the surface object
303     // and call the drawing interface
304     canvas_ = OH_Drawing_SurfaceGetCanvas(surface_);
305     EXPECT_NE(canvas_, nullptr);
306     // 3. Free memory
307     OH_Drawing_SurfaceDestroy(surface_);
308     OH_Drawing_GpuContextDestroy(gpuContext_);
309 }
310 
311 /*
312  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0400
313  * @tc.name: testSurfaceCreateOnScreenNormal
314  * @tc.desc: test for testSurfaceCreateOnScreenNormal.window
315  * @tc.size  : SmallTest
316  * @tc.type  : Function
317  * @tc.level : Level 0
318  */
319 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceCreateOnScreenNormal, Function | SmallTest | Level0) {
320     // 1、OH_Drawing_SurfaceCreateOnScreen正常入参调用
321     gpuContext_ = OH_Drawing_GpuContextCreate();
322     EXPECT_NE(gpuContext_, nullptr);
323     const int32_t width = 4096;
324     const int32_t height = 2160;
325     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
326     // 1. OH_Drawing_SurfaceCreateOnScreen
327     surface_ = OH_Drawing_SurfaceCreateOnScreen(gpuContext_, imageInfo, nullptr);
328     canvas_ = OH_Drawing_SurfaceGetCanvas(surface_);
329     // 2. Free memory
330     OH_Drawing_SurfaceDestroy(surface_);
331     OH_Drawing_GpuContextDestroy(gpuContext_);
332 }
333 
334 /*
335  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0401
336  * @tc.name: testSurfaceCreateOnScreenNull
337  * @tc.desc: test for testSurfaceCreateOnScreenNull.
338  * @tc.size  : SmallTest
339  * @tc.type  : Function
340  * @tc.level : Level 3
341  */
342 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceCreateOnScreenNull, Function | SmallTest | Level3) {
343     // 1. OH_Drawing_SurfaceCreateOnScreen第一个参数传空
344     const int32_t width = 4096;
345     const int32_t height = 2160;
346     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
347     surface_ = OH_Drawing_SurfaceCreateOnScreen(nullptr, imageInfo, nullptr);
348     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
349     // 2. Free memory
350     OH_Drawing_SurfaceDestroy(surface_);
351 }
352 
353 /*
354  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0402
355  * @tc.name: testSurfaceCreateOnScreenMultipleCalls
356  * @tc.desc: test for testSurfaceCreateOnScreenMultipleCalls.
357  * @tc.size  : SmallTest
358  * @tc.type  : Function
359  * @tc.level : Level 3
360  */
361 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceCreateOnScreenMultipleCalls, Function | SmallTest | Level3) {
362     gpuContext_ = OH_Drawing_GpuContextCreate();
363     EXPECT_NE(gpuContext_, nullptr);
364     const int32_t width = 4096;
365     const int32_t height = 2160;
366     OH_Drawing_ColorFormat formats[] = {
367         COLOR_FORMAT_ALPHA_8,   COLOR_FORMAT_RGB_565,
368         COLOR_FORMAT_ARGB_4444, COLOR_FORMAT_RGBA_8888, COLOR_FORMAT_BGRA_8888,
369     };
370     OH_Drawing_AlphaFormat alphaFormats[] = {
371         ALPHA_FORMAT_OPAQUE,
372         ALPHA_FORMAT_PREMUL,
373         ALPHA_FORMAT_UNPREMUL,
374     };
375 
376     std::vector<OH_Drawing_Image_Info> imageInfos;
377     // Loop to create different imageInfo structures
378     for (int i = 0; i < 5; ++i) { // Loop through formats
379         for (int j = 0; j < 3; ++j) { // Loop through alphaFormats
380             OH_Drawing_Image_Info imageInfo = {width, height, formats[i], alphaFormats[j]};
381             imageInfos.push_back(imageInfo);
382         }
383     }
384 
385     for (int index = 0; index < 10; ++index) {
386         surface_ = OH_Drawing_SurfaceCreateOnScreen(gpuContext_, imageInfos[index], nullptr);
387         EXPECT_EQ(surface_, nullptr);
388         // Free memory
389         OH_Drawing_SurfaceDestroy(surface_);
390     }
391     OH_Drawing_GpuContextDestroy(gpuContext_);
392 }
393 
394 /*
395  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0500
396  * @tc.name: testSurfaceFlushNormal
397  * @tc.desc: test for testSurfaceFlushNormal.
398  * @tc.size  : SmallTest
399  * @tc.type  : Function
400  * @tc.level : Level 0
401  */
402 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceFlushNormal, Function | SmallTest | Level0) {
403     gpuContext_ = OH_Drawing_GpuContextCreate();
404     EXPECT_NE(gpuContext_, nullptr);
405     // 1. OH_Drawing_SurfaceCreateFromGpuContext
406     const int32_t width = 4096;
407     const int32_t height = 2160;
408     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
409     surface_ = OH_Drawing_SurfaceCreateOnScreen(gpuContext_, imageInfo, nullptr);
410     EXPECT_EQ(surface_, nullptr);
411     // 2. OH_Drawing_SurfaceFlush
412     auto result = OH_Drawing_SurfaceFlush(surface_);
413     EXPECT_EQ(result, OH_DRAWING_ERROR_INVALID_PARAMETER);
414     // 3. Free memory
415     OH_Drawing_SurfaceDestroy(surface_);
416     OH_Drawing_GpuContextDestroy(gpuContext_);
417 }
418 
419 /*
420  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0501
421  * @tc.name: testSurfaceFlushNull
422  * @tc.desc: test for testSurfaceFlushNull.
423  * @tc.size  : SmallTest
424  * @tc.type  : Function
425  * @tc.level : Level 3
426  */
427 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceFlushNull, Function | SmallTest | Level3) {
428     OH_Drawing_ErrorCode errorCode = OH_Drawing_SurfaceFlush(nullptr);
429     EXPECT_EQ(errorCode, OH_DRAWING_ERROR_INVALID_PARAMETER);
430 }
431 
432 /*
433  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0502
434  * @tc.name: testSurfaceFlushAbnormal
435  * @tc.desc: test for testSurfaceFlushAbnormal.
436  * @tc.size  : SmallTest
437  * @tc.type  : Function
438  * @tc.level : Level 3
439  */
440 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceFlushAbnormal, Function | SmallTest | Level3) {
441     OH_Drawing_GpuContextOptions options{true};
442     // 1. OH_Drawing_GPUContextCreateFromGL
443     gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options);
444     EXPECT_NE(gpuContext_, nullptr);
445     const int32_t width = 4096;
446     const int32_t height = 2160;
447     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
448     // 2. OH_Drawing_SurfaceCreateOnScreen
449     surface_ = OH_Drawing_SurfaceCreateOnScreen(gpuContext_, imageInfo, nullptr);
450     // 3. OH_Drawing_SurfaceFlush
451     auto result = OH_Drawing_SurfaceFlush(surface_);
452     EXPECT_NE(result, OH_DRAWING_SUCCESS);
453     // 4. Free memory
454     OH_Drawing_SurfaceDestroy(surface_);
455     OH_Drawing_GpuContextDestroy(gpuContext_);
456 }
457 
458 /*
459  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0503
460  * @tc.name: testSurfaceFlushMultipleCalls
461  * @tc.desc: test for testSurfaceFlushMultipleCalls.
462  * @tc.size  : SmallTest
463  * @tc.type  : Function
464  * @tc.level : Level 3
465  */
466 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceFlushMultipleCalls, Function | SmallTest | Level3) {
467     gpuContext_ = OH_Drawing_GpuContextCreate();
468     EXPECT_NE(gpuContext_, nullptr);
469     const int32_t width = 4096;
470     const int32_t height = 2160;
471     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
472     surface_ = OH_Drawing_SurfaceCreateOnScreen(gpuContext_, imageInfo, nullptr);
473 
474     OH_Drawing_Canvas *canvas = OH_Drawing_CanvasCreate();
475     EXPECT_NE(canvas, nullptr);
476     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(10, 100, 200, 300);
477     EXPECT_NE(rect, nullptr);
478 
479     // 1. OH_Drawing_CanvasDrawRect-OH_Drawing_SurfaceFlush循环调用10次
480     for (int i = 0; i < 10; ++i) {
481         OH_Drawing_CanvasDrawRect(canvas, rect);
482         auto result1 = OH_Drawing_SurfaceFlush(surface_);
483         EXPECT_EQ(result1, OH_DRAWING_ERROR_INVALID_PARAMETER);
484     }
485 
486     // 2. OH_Drawing_SurfaceFlush直接循环调用10次
487     for (int i = 0; i < 10; ++i) {
488         auto result2 = OH_Drawing_SurfaceFlush(surface_);
489         EXPECT_EQ(result2, OH_DRAWING_ERROR_INVALID_PARAMETER);
490     }
491     // 3. 创建不同surface(通过创建不同imageinfo)-OH_Drawing_SurfaceFlush循环调用10次
492     OH_Drawing_ColorFormat formats[] = {
493         COLOR_FORMAT_ALPHA_8,   COLOR_FORMAT_RGB_565,
494         COLOR_FORMAT_ARGB_4444, COLOR_FORMAT_RGBA_8888, COLOR_FORMAT_BGRA_8888,
495     };
496     OH_Drawing_AlphaFormat alphaFormats[] = {
497         ALPHA_FORMAT_OPAQUE,
498         ALPHA_FORMAT_PREMUL,
499         ALPHA_FORMAT_UNPREMUL,
500     };
501 
502     std::vector<OH_Drawing_Image_Info> imageInfos;
503     // Loop to create different imageInfo structures
504     for (int i = 0; i < 5; ++i) { // Loop through formats
505         for (int j = 0; j < 3; ++j) { // Loop through alphaFormats
506             OH_Drawing_Image_Info imageInfo = {width, height, formats[i], alphaFormats[j]};
507             imageInfos.push_back(imageInfo);
508         }
509     }
510 
511     for (int index = 0; index < 10; ++index) {
512         surface_ = OH_Drawing_SurfaceCreateOnScreen(gpuContext_, imageInfos[index], nullptr);
513         auto result3 = OH_Drawing_SurfaceFlush(surface_);
514         EXPECT_EQ(result3, OH_DRAWING_ERROR_INVALID_PARAMETER);
515     }
516 
517     OH_Drawing_SurfaceDestroy(surface_);
518     OH_Drawing_GpuContextDestroy(gpuContext_);
519 }
520 
521 /*
522  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SURFACE_0504
523  * @tc.name: testSurfaceFlushTiming
524  * @tc.desc: test for testSurfaceFlushTiming.
525  * @tc.size  : SmallTest
526  * @tc.type  : Function
527  * @tc.level : Level 3
528  */
529 HWTEST_F(DrawingNativeSurFaceTest, testSurfaceFlushTiming, Function | SmallTest | Level3) {
530     OH_Drawing_GpuContextOptions options{true};
531     gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options);
532     EXPECT_NE(gpuContext_, nullptr);
533     const int32_t width = 4096;
534     const int32_t height = 2160;
535     OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888,
536         ALPHA_FORMAT_OPAQUE};
537 
538     OH_Drawing_Canvas *canvas = OH_Drawing_CanvasCreate();
539     EXPECT_NE(canvas, nullptr);
540     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(10, 100, 200, 300);
541     EXPECT_NE(rect, nullptr);
542     // 1. OH_Drawing_SurfaceCreateOnScreen-OH_Drawing_CanvasDrawRect-OH_Drawing_SurfaceFlush正常时序
543     surface_ = OH_Drawing_SurfaceCreateOnScreen(gpuContext_, imageInfo, nullptr);
544     OH_Drawing_CanvasDrawRect(canvas, rect);
545     OH_Drawing_SurfaceFlush(surface_);
546 
547     // 2. OH_Drawing_SurfaceCreateOnScreen-OH_Drawing_SurfaceFlush创建surface之后直接调用flush
548     surface_ = OH_Drawing_SurfaceCreateOnScreen(gpuContext_, imageInfo, nullptr);
549     OH_Drawing_SurfaceFlush(surface_);
550 
551     // 3. 创建两个canvas-创建两个surface-各自进行绘制-各自flush
552     OH_Drawing_Canvas *canvas1 = OH_Drawing_CanvasCreate();
553     OH_Drawing_Rect *rect1 = OH_Drawing_RectCreate(10, 100, 200, 300);
554     OH_Drawing_CanvasDrawRect(canvas1, rect1);
555     OH_Drawing_Surface* surface1 = OH_Drawing_SurfaceCreateOnScreen(gpuContext_, imageInfo, nullptr);
556     OH_Drawing_Canvas *canvas2 = OH_Drawing_CanvasCreate();
557     OH_Drawing_Rect *rect2 = OH_Drawing_RectCreate(10, 100, 200, 300);
558     OH_Drawing_CanvasDrawRect(canvas2, rect2);
559     OH_Drawing_Surface* surface2 = OH_Drawing_SurfaceCreateOnScreen(gpuContext_, imageInfo, nullptr);
560 
561     OH_Drawing_SurfaceDestroy(surface_);
562     OH_Drawing_SurfaceDestroy(surface1);
563     OH_Drawing_SurfaceDestroy(surface2);
564     OH_Drawing_GpuContextDestroy(gpuContext_);
565 }
566 
567 } // namespace Drawing
568 } // namespace Rosen
569 } // namespace OHOS