Path: blob/main_old/src/tests/egl_tests/EGLBackwardsCompatibleContextTest.cpp
1693 views
//1// Copyright 2015 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//56// EGLBackwardsCompatibleContextTest.cpp.cpp:7// Coverage of the EGL_ANGLE_create_context_backwards_compatible extension89#include <vector>1011#include "test_utils/ANGLETest.h"12#include "test_utils/angle_test_configs.h"13#include "test_utils/angle_test_instantiate.h"1415namespace angle16{1718namespace19{20std::pair<EGLint, EGLint> GetCurrentContextVersion()21{22const char *versionString = reinterpret_cast<const char *>(glGetString(GL_VERSION));23EXPECT_TRUE(strstr(versionString, "OpenGL ES") != nullptr);24return {versionString[10] - '0', versionString[12] - '0'};25}26} // anonymous namespace2728class EGLBackwardsCompatibleContextTest : public ANGLETest29{30public:31EGLBackwardsCompatibleContextTest() : mDisplay(0) {}3233void testSetUp() override34{35EGLint dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(), EGL_NONE};36mDisplay = eglGetPlatformDisplayEXT(37EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);38ASSERT_TRUE(mDisplay != EGL_NO_DISPLAY);3940ASSERT_EGL_TRUE(eglInitialize(mDisplay, nullptr, nullptr));4142int configsCount = 0;43ASSERT_EGL_TRUE(eglGetConfigs(mDisplay, nullptr, 0, &configsCount));44ASSERT_TRUE(configsCount != 0);4546std::vector<EGLConfig> configs(configsCount);47ASSERT_EGL_TRUE(eglGetConfigs(mDisplay, configs.data(), configsCount, &configsCount));4849for (auto config : configs)50{51EGLint surfaceType;52eglGetConfigAttrib(mDisplay, config, EGL_SURFACE_TYPE, &surfaceType);53if (surfaceType & EGL_PBUFFER_BIT)54{55mConfig = config;56break;57}58}59if (!mConfig)60{61mConfig = configs[0];62}63ASSERT_NE(nullptr, mConfig);6465EGLint surfaceType = EGL_NONE;66eglGetConfigAttrib(mDisplay, mConfig, EGL_SURFACE_TYPE, &surfaceType);67if (surfaceType & EGL_PBUFFER_BIT)68{69const EGLint pbufferAttribs[] = {70EGL_WIDTH, 500, EGL_HEIGHT, 500, EGL_NONE,71};72mPbuffer = eglCreatePbufferSurface(mDisplay, mConfig, pbufferAttribs);73EXPECT_TRUE(mPbuffer != EGL_NO_SURFACE);74}75}7677void testTearDown() override78{79eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);8081if (mPbuffer != EGL_NO_SURFACE)82{83eglDestroySurface(mDisplay, mPbuffer);84}8586eglTerminate(mDisplay);87}8889EGLDisplay mDisplay = EGL_NO_DISPLAY;90EGLSurface mPbuffer = EGL_NO_SURFACE;91EGLConfig mConfig = 0;92};9394// Test extension presence. All backends should expose this extension95TEST_P(EGLBackwardsCompatibleContextTest, PbufferDifferentConfig)96{97EXPECT_TRUE(98IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_create_context_backwards_compatible"));99}100101// Test that disabling backwards compatibility will always return the expected context version102TEST_P(EGLBackwardsCompatibleContextTest, BackwardsCompatibleDisbled)103{104ANGLE_SKIP_TEST_IF(105!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_create_context_backwards_compatible"));106ANGLE_SKIP_TEST_IF(!mPbuffer);107108std::pair<EGLint, EGLint> testVersions[] = {109{1, 0}, {1, 1}, {2, 0}, {3, 0}, {3, 1}, {3, 2},110};111112for (const auto &version : testVersions)113{114EGLint attribs[] = {EGL_CONTEXT_MAJOR_VERSION,115version.first,116EGL_CONTEXT_MINOR_VERSION,117version.second,118EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE,119EGL_FALSE,120EGL_NONE,121EGL_NONE};122123EGLContext context = eglCreateContext(mDisplay, mConfig, nullptr, attribs);124if (context == EGL_NO_CONTEXT)125{126// Context version not supported127continue;128}129130ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, mPbuffer, mPbuffer, context));131132auto contextVersion = GetCurrentContextVersion();133EXPECT_EQ(version, contextVersion);134135ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));136eglDestroyContext(mDisplay, context);137}138}139140// Test that if it's possible to create an ES3 context, requesting an ES2 context should return an141// ES3 context as well142TEST_P(EGLBackwardsCompatibleContextTest, BackwardsCompatibleEnabledES3)143{144ANGLE_SKIP_TEST_IF(145!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_create_context_backwards_compatible"));146ANGLE_SKIP_TEST_IF(!mPbuffer);147148EGLint es3ContextAttribs[] = {149EGL_CONTEXT_MAJOR_VERSION, 3, EGL_CONTEXT_MINOR_VERSION, 0, EGL_NONE, EGL_NONE};150151EGLContext es3Context = eglCreateContext(mDisplay, mConfig, nullptr, es3ContextAttribs);152ANGLE_SKIP_TEST_IF(es3Context == EGL_NO_CONTEXT);153154ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, mPbuffer, mPbuffer, es3Context));155auto es3ContextVersion = GetCurrentContextVersion();156eglDestroyContext(mDisplay, es3Context);157158EGLint es2ContextAttribs[] = {159EGL_CONTEXT_MAJOR_VERSION, 2, EGL_CONTEXT_MINOR_VERSION, 0, EGL_NONE, EGL_NONE};160161EGLContext es2Context = eglCreateContext(mDisplay, mConfig, nullptr, es2ContextAttribs);162EXPECT_NE(es2Context, EGL_NO_CONTEXT);163164ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, mPbuffer, mPbuffer, es2Context));165auto es2ContextVersion = GetCurrentContextVersion();166ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));167eglDestroyContext(mDisplay, es2Context);168169EXPECT_EQ(es3ContextVersion, es2ContextVersion);170}171172// Test that if ES1.1 is supported and a 1.0 context is requested, an ES 1.1 context is returned173TEST_P(EGLBackwardsCompatibleContextTest, BackwardsCompatibleEnabledES1)174{175ANGLE_SKIP_TEST_IF(176!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_create_context_backwards_compatible"));177ANGLE_SKIP_TEST_IF(!mPbuffer);178179EGLint es11ContextAttribs[] = {180EGL_CONTEXT_MAJOR_VERSION, 1, EGL_CONTEXT_MINOR_VERSION, 1, EGL_NONE, EGL_NONE};181182EGLContext es11Context = eglCreateContext(mDisplay, mConfig, nullptr, es11ContextAttribs);183ANGLE_SKIP_TEST_IF(es11Context == EGL_NO_CONTEXT);184185ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, mPbuffer, mPbuffer, es11Context));186auto es11ContextVersion = GetCurrentContextVersion();187ASSERT_EQ(std::make_pair(1, 1), es11ContextVersion);188ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));189eglDestroyContext(mDisplay, es11Context);190191EGLint es10ContextAttribs[] = {192EGL_CONTEXT_MAJOR_VERSION, 1, EGL_CONTEXT_MINOR_VERSION, 0, EGL_NONE, EGL_NONE};193194EGLContext es10Context = eglCreateContext(mDisplay, mConfig, nullptr, es10ContextAttribs);195EXPECT_NE(es10Context, EGL_NO_CONTEXT);196197ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, mPbuffer, mPbuffer, es10Context));198auto es10ContextVersion = GetCurrentContextVersion();199ASSERT_EQ(std::make_pair(1, 1), es10ContextVersion);200ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));201eglDestroyContext(mDisplay, es10Context);202}203204ANGLE_INSTANTIATE_TEST(EGLBackwardsCompatibleContextTest,205WithNoFixture(ES2_D3D9()),206WithNoFixture(ES2_D3D11()),207WithNoFixture(ES2_OPENGL()),208WithNoFixture(ES2_OPENGLES()),209WithNoFixture(ES2_VULKAN()));210211} // namespace angle212213214