Path: blob/main_old/src/tests/egl_tests/EGLNoConfigContextTest.cpp
1693 views
//1// Copyright 2019 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// EGLNoConfigContectTest.cpp:6// EGL extension EGL_KHR_no_config_context allows a context to be created7// without a config specified. This means all surfaces are compatible.8// As a result compatibility checks are circumvented.9// This test suite creates and verifies creating a configless context10// and then verifies simple rendering to ensure compatibility.11//1213#include <gtest/gtest.h>1415#include "test_utils/ANGLETest.h"1617using namespace angle;1819class EGLNoConfigContextTest : public ANGLETest20{21public:22EGLNoConfigContextTest() : mDisplay(EGL_NO_DISPLAY), mContext(EGL_NO_CONTEXT) {}2324void testSetUp() override25{26int clientVersion = GetParam().majorVersion;2728EGLint dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(), EGL_NONE};29mDisplay = eglGetPlatformDisplayEXT(30EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);31EXPECT_TRUE(mDisplay != EGL_NO_DISPLAY);32EXPECT_EGL_TRUE(eglInitialize(mDisplay, nullptr, nullptr));3334mExtensionSupported = IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_no_config_context");35if (!mExtensionSupported)36{37return; // Not supported, don't create context38}3940EGLint ctxattrs[] = {EGL_CONTEXT_CLIENT_VERSION, clientVersion, EGL_NONE};41mContext = eglCreateContext(mDisplay, EGL_NO_CONFIG_KHR, nullptr, ctxattrs);42EXPECT_TRUE(mContext != EGL_NO_CONTEXT);43}4445void testTearDown() override46{47if (mDisplay != EGL_NO_DISPLAY)48{49if (mContext != EGL_NO_CONTEXT)50{51eglDestroyContext(mDisplay, mContext);52mContext = EGL_NO_CONTEXT;53}54eglTerminate(mDisplay);55eglReleaseThread();56}57ASSERT_EGL_SUCCESS() << "Error during test TearDown";58}5960EGLDisplay mDisplay = EGL_NO_DISPLAY;61EGLContext mContext = EGL_NO_CONTEXT;62bool mExtensionSupported = false;63};6465// Check that context has no config.66TEST_P(EGLNoConfigContextTest, QueryConfigID)67{68ANGLE_SKIP_TEST_IF(!mExtensionSupported);69EXPECT_TRUE(mDisplay);70EXPECT_TRUE(mContext);7172EGLint configId = -1;73EXPECT_EGL_TRUE(eglQueryContext(mDisplay, mContext, EGL_CONFIG_ID, &configId));74EXPECT_TRUE(configId == 0);75ASSERT_EGL_SUCCESS();76}7778// Any surface should be eglMakeCurrent compatible with no-config context.79// Do a glClear and glReadPixel to verify rendering.80TEST_P(EGLNoConfigContextTest, RenderCheck)81{82ANGLE_SKIP_TEST_IF(!mExtensionSupported);8384// Get all the configs85EGLint count;86EXPECT_EGL_TRUE(eglGetConfigs(mDisplay, nullptr, 0, &count));87EXPECT_TRUE(count > 0);88std::vector<EGLConfig> configs(count);89EXPECT_EGL_TRUE(eglGetConfigs(mDisplay, configs.data(), count, &count));9091// For each config, create PbufferSurface and do a render check92EGLSurface surface = EGL_NO_SURFACE;93for (auto config : configs)94{95const uint32_t kWidth = 1;96const uint32_t kHeight = 1;9798EGLint configId;99EXPECT_EGL_TRUE(eglGetConfigAttrib(mDisplay, config, EGL_CONFIG_ID, &configId));100EGLint surfattrs[] = {EGL_WIDTH, kWidth, EGL_HEIGHT, kHeight, EGL_NONE};101surface = eglCreatePbufferSurface(mDisplay, config, surfattrs);102EXPECT_TRUE(surface != EGL_NO_SURFACE);103104EGLint bufferSize = 0;105EXPECT_EGL_TRUE(eglGetConfigAttrib(mDisplay, config, EGL_BUFFER_SIZE, &bufferSize));106107EXPECT_EGL_TRUE(eglMakeCurrent(mDisplay, surface, surface, mContext));108ASSERT_EGL_SUCCESS() << "eglMakeCurrent failed with Config: " << configId << '\n';109110// ClearColor RED111glClearColor(1.0, 0.0, 0.0, 1.0);112glClear(GL_COLOR_BUFFER_BIT);113ASSERT_GL_NO_ERROR() << "glClear failed";114115if (bufferSize > 32)116{ // GL_FLOAT configs117EXPECT_PIXEL_COLOR32F_EQ(0, 0, kFloatRed);118}119else120{ // GL_UNSIGNED_BYTE configs121EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);122}123124eglDestroySurface(mDisplay, surface);125surface = EGL_NO_SURFACE;126}127}128129GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLNoConfigContextTest);130ANGLE_INSTANTIATE_TEST(EGLNoConfigContextTest,131WithNoFixture(ES2_OPENGL()),132WithNoFixture(ES2_VULKAN()),133WithNoFixture(ES3_OPENGL()),134WithNoFixture(ES3_VULKAN()));135136137