1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License. 5f6603c60Sopenharmony_ci * You may obtain a copy of the License at 6f6603c60Sopenharmony_ci * 7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f6603c60Sopenharmony_ci * 9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, Hardware 10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and 13f6603c60Sopenharmony_ci * limitations under the License. 14f6603c60Sopenharmony_ci */ 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci#include "gtest/gtest.h" 17f6603c60Sopenharmony_ci#include "EGL/egl.h" 18f6603c60Sopenharmony_ci#include "EGL/eglext.h" 19f6603c60Sopenharmony_ci#include "GLES3/gl32.h" 20f6603c60Sopenharmony_ci#include "drawing_canvas.h" 21f6603c60Sopenharmony_ci#include "drawing_gpu_context.h" 22f6603c60Sopenharmony_ci#include "drawing_surface.h" 23f6603c60Sopenharmony_ci 24f6603c60Sopenharmony_ciusing namespace testing; 25f6603c60Sopenharmony_ciusing namespace testing::ext; 26f6603c60Sopenharmony_ci 27f6603c60Sopenharmony_cinamespace OHOS { 28f6603c60Sopenharmony_cinamespace Rosen { 29f6603c60Sopenharmony_cinamespace Drawing { 30f6603c60Sopenharmony_ciclass NativeDrawingSurfaceLargeValueTest : public testing::Test { 31f6603c60Sopenharmony_cipublic: 32f6603c60Sopenharmony_ci static void SetUpTestCase(); 33f6603c60Sopenharmony_ci static void TearDownTestCase(); 34f6603c60Sopenharmony_ci void SetUp() override; 35f6603c60Sopenharmony_ci void TearDown() override; 36f6603c60Sopenharmony_ciprotected: 37f6603c60Sopenharmony_ci EGLDisplay eglDisplay_ = EGL_NO_DISPLAY; 38f6603c60Sopenharmony_ci EGLConfig eglConfig_ = EGL_NO_CONFIG_KHR; 39f6603c60Sopenharmony_ci EGLContext eglContext_ = EGL_NO_CONTEXT; 40f6603c60Sopenharmony_ci EGLSurface eglSurface_ = EGL_NO_SURFACE; 41f6603c60Sopenharmony_ci OH_Drawing_GpuContext* gpuContext_ = nullptr; 42f6603c60Sopenharmony_ci OH_Drawing_Surface* surface_ = nullptr; 43f6603c60Sopenharmony_ci OH_Drawing_Canvas* canvas_ = nullptr; 44f6603c60Sopenharmony_ci}; 45f6603c60Sopenharmony_ci 46f6603c60Sopenharmony_civoid NativeDrawingSurfaceLargeValueTest::SetUpTestCase() {} 47f6603c60Sopenharmony_civoid NativeDrawingSurfaceLargeValueTest::TearDownTestCase() {} 48f6603c60Sopenharmony_civoid NativeDrawingSurfaceLargeValueTest::SetUp() 49f6603c60Sopenharmony_ci{ 50f6603c60Sopenharmony_ci eglDisplay_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); 51f6603c60Sopenharmony_ci EXPECT_NE(eglDisplay_, EGL_NO_DISPLAY); 52f6603c60Sopenharmony_ci 53f6603c60Sopenharmony_ci EGLint eglMajVers; 54f6603c60Sopenharmony_ci EGLint eglMinVers; 55f6603c60Sopenharmony_ci EGLBoolean ret = eglInitialize(eglDisplay_, &eglMajVers, &eglMinVers); 56f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 57f6603c60Sopenharmony_ci 58f6603c60Sopenharmony_ci EGLint count; 59f6603c60Sopenharmony_ci EGLint configAttribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, 60f6603c60Sopenharmony_ci EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, 61f6603c60Sopenharmony_ci EGL_ALPHA_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, EGL_NONE }; 62f6603c60Sopenharmony_ci ret = eglChooseConfig(eglDisplay_, configAttribs, &eglConfig_, 1, &count); 63f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 64f6603c60Sopenharmony_ci EXPECT_GE(count, 1); 65f6603c60Sopenharmony_ci 66f6603c60Sopenharmony_ci const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; 67f6603c60Sopenharmony_ci eglContext_ = eglCreateContext(eglDisplay_, eglConfig_, EGL_NO_CONTEXT, contextAttribs); 68f6603c60Sopenharmony_ci EXPECT_NE(eglContext_, EGL_NO_CONTEXT); 69f6603c60Sopenharmony_ci 70f6603c60Sopenharmony_ci EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE}; 71f6603c60Sopenharmony_ci eglSurface_ = eglCreatePbufferSurface(eglDisplay_, eglConfig_, attribs); 72f6603c60Sopenharmony_ci EXPECT_NE(eglSurface_, EGL_NO_SURFACE); 73f6603c60Sopenharmony_ci 74f6603c60Sopenharmony_ci ret = eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_); 75f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 76f6603c60Sopenharmony_ci} 77f6603c60Sopenharmony_ci 78f6603c60Sopenharmony_civoid NativeDrawingSurfaceLargeValueTest::TearDown() 79f6603c60Sopenharmony_ci{ 80f6603c60Sopenharmony_ci EGLBoolean ret = eglDestroySurface(eglDisplay_, eglSurface_); 81f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 82f6603c60Sopenharmony_ci 83f6603c60Sopenharmony_ci ret = eglDestroyContext(eglDisplay_, eglContext_); 84f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 85f6603c60Sopenharmony_ci 86f6603c60Sopenharmony_ci ret = eglTerminate(eglDisplay_); 87f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 88f6603c60Sopenharmony_ci 89f6603c60Sopenharmony_ci eglSurface_ = EGL_NO_SURFACE; 90f6603c60Sopenharmony_ci eglContext_ = EGL_NO_CONTEXT; 91f6603c60Sopenharmony_ci eglDisplay_ = EGL_NO_DISPLAY; 92f6603c60Sopenharmony_ci} 93f6603c60Sopenharmony_ci 94f6603c60Sopenharmony_ci/* 95f6603c60Sopenharmony_ci * @tc.name : NativeDrawingSurfaceLargeValueTest_CreateFromGpuContext 96f6603c60Sopenharmony_ci * @tc.desc : test for CreateFromGpuContext. 97f6603c60Sopenharmony_ci * @tc.size : MediumTest 98f6603c60Sopenharmony_ci * @tc.type : Function 99f6603c60Sopenharmony_ci * @tc.level : Level 1 100f6603c60Sopenharmony_ci */ 101f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingSurfaceLargeValueTest, NativeDrawingSurfaceLargeValueTest_CreateFromGpuContext, TestSize.Level1) 102f6603c60Sopenharmony_ci{ 103f6603c60Sopenharmony_ci OH_Drawing_GpuContextOptions options {true}; 104f6603c60Sopenharmony_ci gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options); 105f6603c60Sopenharmony_ci EXPECT_NE(gpuContext_, nullptr); 106f6603c60Sopenharmony_ci 107f6603c60Sopenharmony_ci const int32_t width = 2160; 108f6603c60Sopenharmony_ci const int32_t height = 4096; 109f6603c60Sopenharmony_ci OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 110f6603c60Sopenharmony_ci surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, true, imageInfo); 111f6603c60Sopenharmony_ci EXPECT_NE(surface_, nullptr); 112f6603c60Sopenharmony_ci OH_Drawing_SurfaceDestroy(surface_); 113f6603c60Sopenharmony_ci 114f6603c60Sopenharmony_ci surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, false, imageInfo); 115f6603c60Sopenharmony_ci EXPECT_NE(surface_, nullptr); 116f6603c60Sopenharmony_ci OH_Drawing_SurfaceDestroy(surface_); 117f6603c60Sopenharmony_ci 118f6603c60Sopenharmony_ci surface_ = OH_Drawing_SurfaceCreateFromGpuContext(nullptr, false, imageInfo); 119f6603c60Sopenharmony_ci EXPECT_EQ(surface_, nullptr); 120f6603c60Sopenharmony_ci OH_Drawing_SurfaceDestroy(surface_); 121f6603c60Sopenharmony_ci OH_Drawing_GpuContextDestroy(gpuContext_); 122f6603c60Sopenharmony_ci} 123f6603c60Sopenharmony_ci 124f6603c60Sopenharmony_ci/* 125f6603c60Sopenharmony_ci * @tc.name : NativeDrawingSurfaceLargeValueTest_GetCanvas 126f6603c60Sopenharmony_ci * @tc.desc : test for GetCanvas. 127f6603c60Sopenharmony_ci * @tc.size : MediumTest 128f6603c60Sopenharmony_ci * @tc.type : Function 129f6603c60Sopenharmony_ci * @tc.level : Level 1 130f6603c60Sopenharmony_ci */ 131f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingSurfaceLargeValueTest, NativeDrawingSurfaceLargeValueTest_GetCanvas, TestSize.Level1) 132f6603c60Sopenharmony_ci{ 133f6603c60Sopenharmony_ci OH_Drawing_GpuContextOptions options {true}; 134f6603c60Sopenharmony_ci gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options); 135f6603c60Sopenharmony_ci EXPECT_NE(gpuContext_, nullptr); 136f6603c60Sopenharmony_ci 137f6603c60Sopenharmony_ci const int32_t width = 2160; 138f6603c60Sopenharmony_ci const int32_t height = 4096; 139f6603c60Sopenharmony_ci OH_Drawing_Image_Info imageInfo = {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 140f6603c60Sopenharmony_ci surface_ = OH_Drawing_SurfaceCreateFromGpuContext(gpuContext_, true, imageInfo); 141f6603c60Sopenharmony_ci EXPECT_NE(surface_, nullptr); 142f6603c60Sopenharmony_ci 143f6603c60Sopenharmony_ci canvas_ = OH_Drawing_SurfaceGetCanvas(surface_); 144f6603c60Sopenharmony_ci EXPECT_NE(canvas_, nullptr); 145f6603c60Sopenharmony_ci 146f6603c60Sopenharmony_ci canvas_ = OH_Drawing_SurfaceGetCanvas(nullptr); 147f6603c60Sopenharmony_ci EXPECT_EQ(canvas_, nullptr); 148f6603c60Sopenharmony_ci OH_Drawing_SurfaceDestroy(surface_); 149f6603c60Sopenharmony_ci OH_Drawing_GpuContextDestroy(gpuContext_); 150f6603c60Sopenharmony_ci} 151f6603c60Sopenharmony_ci} // namespace Drawing 152f6603c60Sopenharmony_ci} // namespace Rosen 153f6603c60Sopenharmony_ci} // namespace OHOS