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_gpu_context.h" 21f6603c60Sopenharmony_ci 22f6603c60Sopenharmony_ciusing namespace testing; 23f6603c60Sopenharmony_ciusing namespace testing::ext; 24f6603c60Sopenharmony_ci 25f6603c60Sopenharmony_cinamespace OHOS { 26f6603c60Sopenharmony_cinamespace Rosen { 27f6603c60Sopenharmony_cinamespace Drawing { 28f6603c60Sopenharmony_ciclass NativeDrawingGpuContextTest : public testing::Test { 29f6603c60Sopenharmony_cipublic: 30f6603c60Sopenharmony_ci static void SetUpTestCase(); 31f6603c60Sopenharmony_ci static void TearDownTestCase(); 32f6603c60Sopenharmony_ci void SetUp() override; 33f6603c60Sopenharmony_ci void TearDown() override; 34f6603c60Sopenharmony_ciprotected: 35f6603c60Sopenharmony_ci EGLDisplay eglDisplay_ = EGL_NO_DISPLAY; 36f6603c60Sopenharmony_ci EGLConfig eglConfig_ = EGL_NO_CONFIG_KHR; 37f6603c60Sopenharmony_ci EGLContext eglContext_ = EGL_NO_CONTEXT; 38f6603c60Sopenharmony_ci EGLSurface eglSurface_ = EGL_NO_SURFACE; 39f6603c60Sopenharmony_ci OH_Drawing_GpuContext* gpuContext_ = nullptr; 40f6603c60Sopenharmony_ci}; 41f6603c60Sopenharmony_ci 42f6603c60Sopenharmony_civoid NativeDrawingGpuContextTest::SetUpTestCase() {} 43f6603c60Sopenharmony_civoid NativeDrawingGpuContextTest::TearDownTestCase() {} 44f6603c60Sopenharmony_civoid NativeDrawingGpuContextTest::SetUp() 45f6603c60Sopenharmony_ci{ 46f6603c60Sopenharmony_ci eglDisplay_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); 47f6603c60Sopenharmony_ci EXPECT_NE(eglDisplay_, EGL_NO_DISPLAY); 48f6603c60Sopenharmony_ci 49f6603c60Sopenharmony_ci EGLint eglMajVers; 50f6603c60Sopenharmony_ci EGLint eglMinVers; 51f6603c60Sopenharmony_ci EGLBoolean ret = eglInitialize(eglDisplay_, &eglMajVers, &eglMinVers); 52f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 53f6603c60Sopenharmony_ci 54f6603c60Sopenharmony_ci EGLint count; 55f6603c60Sopenharmony_ci EGLint configAttribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, 56f6603c60Sopenharmony_ci EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, 57f6603c60Sopenharmony_ci EGL_ALPHA_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, EGL_NONE }; 58f6603c60Sopenharmony_ci ret = eglChooseConfig(eglDisplay_, configAttribs, &eglConfig_, 1, &count); 59f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 60f6603c60Sopenharmony_ci EXPECT_GE(count, 1); 61f6603c60Sopenharmony_ci 62f6603c60Sopenharmony_ci const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; 63f6603c60Sopenharmony_ci eglContext_ = eglCreateContext(eglDisplay_, eglConfig_, EGL_NO_CONTEXT, contextAttribs); 64f6603c60Sopenharmony_ci EXPECT_NE(eglContext_, EGL_NO_CONTEXT); 65f6603c60Sopenharmony_ci 66f6603c60Sopenharmony_ci EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE}; 67f6603c60Sopenharmony_ci eglSurface_ = eglCreatePbufferSurface(eglDisplay_, eglConfig_, attribs); 68f6603c60Sopenharmony_ci EXPECT_NE(eglSurface_, EGL_NO_SURFACE); 69f6603c60Sopenharmony_ci 70f6603c60Sopenharmony_ci ret = eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_); 71f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 72f6603c60Sopenharmony_ci} 73f6603c60Sopenharmony_ci 74f6603c60Sopenharmony_civoid NativeDrawingGpuContextTest::TearDown() 75f6603c60Sopenharmony_ci{ 76f6603c60Sopenharmony_ci EGLBoolean ret = eglDestroySurface(eglDisplay_, eglSurface_); 77f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 78f6603c60Sopenharmony_ci 79f6603c60Sopenharmony_ci ret = eglDestroyContext(eglDisplay_, eglContext_); 80f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 81f6603c60Sopenharmony_ci 82f6603c60Sopenharmony_ci ret = eglTerminate(eglDisplay_); 83f6603c60Sopenharmony_ci EXPECT_EQ(ret, EGL_TRUE); 84f6603c60Sopenharmony_ci 85f6603c60Sopenharmony_ci eglSurface_ = EGL_NO_SURFACE; 86f6603c60Sopenharmony_ci eglContext_ = EGL_NO_CONTEXT; 87f6603c60Sopenharmony_ci eglDisplay_ = EGL_NO_DISPLAY; 88f6603c60Sopenharmony_ci} 89f6603c60Sopenharmony_ci 90f6603c60Sopenharmony_ci/* 91f6603c60Sopenharmony_ci * @tc.name : NativeDrawingGpuContextTest_CreateFromGL 92f6603c60Sopenharmony_ci * @tc.desc : test for CreateFromGL. 93f6603c60Sopenharmony_ci * @tc.size : MediumTest 94f6603c60Sopenharmony_ci * @tc.type : Function 95f6603c60Sopenharmony_ci * @tc.level : Level 1 96f6603c60Sopenharmony_ci */ 97f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingGpuContextTest, NativeDrawingGpuContextTest_CreateFromGL, TestSize.Level1) 98f6603c60Sopenharmony_ci{ 99f6603c60Sopenharmony_ci OH_Drawing_GpuContextOptions options; 100f6603c60Sopenharmony_ci options.allowPathMaskCaching = true; 101f6603c60Sopenharmony_ci gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options); 102f6603c60Sopenharmony_ci EXPECT_NE(gpuContext_, nullptr); 103f6603c60Sopenharmony_ci OH_Drawing_GpuContextDestroy(gpuContext_); 104f6603c60Sopenharmony_ci 105f6603c60Sopenharmony_ci options.allowPathMaskCaching = false; 106f6603c60Sopenharmony_ci gpuContext_ = OH_Drawing_GpuContextCreateFromGL(options); 107f6603c60Sopenharmony_ci EXPECT_NE(gpuContext_, nullptr); 108f6603c60Sopenharmony_ci OH_Drawing_GpuContextDestroy(gpuContext_); 109f6603c60Sopenharmony_ci} 110f6603c60Sopenharmony_ci} // namespace Drawing 111f6603c60Sopenharmony_ci} // namespace Rosen 112f6603c60Sopenharmony_ci} // namespace OHOS