• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // EGLBackwardsCompatibleContextTest.cpp.cpp:
8 //   Coverage of the EGL_ANGLE_create_context_backwards_compatible extension
9 
10 #include <vector>
11 
12 #include "test_utils/ANGLETest.h"
13 #include "test_utils/angle_test_configs.h"
14 #include "test_utils/angle_test_instantiate.h"
15 
16 namespace angle
17 {
18 
19 namespace
20 {
GetCurrentContextVersion()21 std::pair<EGLint, EGLint> GetCurrentContextVersion()
22 {
23     const char *versionString = reinterpret_cast<const char *>(glGetString(GL_VERSION));
24     EXPECT_TRUE(strstr(versionString, "OpenGL ES") != nullptr);
25     return {versionString[10] - '0', versionString[12] - '0'};
26 }
27 }  // anonymous namespace
28 
29 class EGLBackwardsCompatibleContextTest : public ANGLETest
30 {
31   public:
EGLBackwardsCompatibleContextTest()32     EGLBackwardsCompatibleContextTest() : mDisplay(0) {}
33 
testSetUp()34     void testSetUp() override
35     {
36         EGLint dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, GetParam().getRenderer(), EGL_NONE};
37         mDisplay           = eglGetPlatformDisplayEXT(
38             EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
39         ASSERT_TRUE(mDisplay != EGL_NO_DISPLAY);
40 
41         ASSERT_EGL_TRUE(eglInitialize(mDisplay, nullptr, nullptr));
42 
43         int configsCount = 0;
44         ASSERT_EGL_TRUE(eglGetConfigs(mDisplay, nullptr, 0, &configsCount));
45         ASSERT_TRUE(configsCount != 0);
46 
47         std::vector<EGLConfig> configs(configsCount);
48         ASSERT_EGL_TRUE(eglGetConfigs(mDisplay, configs.data(), configsCount, &configsCount));
49 
50         for (auto config : configs)
51         {
52             EGLint surfaceType;
53             eglGetConfigAttrib(mDisplay, config, EGL_SURFACE_TYPE, &surfaceType);
54             if (surfaceType & EGL_PBUFFER_BIT)
55             {
56                 mConfig = config;
57                 break;
58             }
59         }
60         ASSERT_NE(nullptr, mConfig);
61 
62         const EGLint pbufferAttribs[] = {
63             EGL_WIDTH, 500, EGL_HEIGHT, 500, EGL_NONE,
64         };
65         mPbuffer = eglCreatePbufferSurface(mDisplay, mConfig, pbufferAttribs);
66         EXPECT_TRUE(mPbuffer != EGL_NO_SURFACE);
67     }
68 
testTearDown()69     void testTearDown() override
70     {
71         eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
72 
73         if (mPbuffer != EGL_NO_SURFACE)
74         {
75             eglDestroySurface(mDisplay, mPbuffer);
76         }
77 
78         eglTerminate(mDisplay);
79     }
80 
81     EGLDisplay mDisplay = EGL_NO_DISPLAY;
82     EGLSurface mPbuffer = EGL_NO_SURFACE;
83     EGLConfig mConfig   = 0;
84 };
85 
86 // Test extension presence.  All backends should expose this extension
TEST_P(EGLBackwardsCompatibleContextTest,PbufferDifferentConfig)87 TEST_P(EGLBackwardsCompatibleContextTest, PbufferDifferentConfig)
88 {
89     EXPECT_TRUE(
90         IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_create_context_backwards_compatible"));
91 }
92 
93 // Test that disabling backwards compatibility will always return the expected context version
TEST_P(EGLBackwardsCompatibleContextTest,BackwardsCompatibleDisbled)94 TEST_P(EGLBackwardsCompatibleContextTest, BackwardsCompatibleDisbled)
95 {
96     ANGLE_SKIP_TEST_IF(
97         !IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_create_context_backwards_compatible"));
98 
99     std::pair<EGLint, EGLint> testVersions[] = {
100         {1, 0}, {1, 1}, {2, 0}, {3, 0}, {3, 1}, {3, 2},
101     };
102 
103     for (const auto &version : testVersions)
104     {
105         EGLint attribs[] = {EGL_CONTEXT_MAJOR_VERSION,
106                             version.first,
107                             EGL_CONTEXT_MINOR_VERSION,
108                             version.second,
109                             EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE,
110                             EGL_FALSE,
111                             EGL_NONE,
112                             EGL_NONE};
113 
114         EGLContext context = eglCreateContext(mDisplay, mConfig, nullptr, attribs);
115         if (context == EGL_NO_CONTEXT)
116         {
117             // Context version not supported
118             continue;
119         }
120 
121         ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, mPbuffer, mPbuffer, context));
122 
123         auto contextVersion = GetCurrentContextVersion();
124         EXPECT_EQ(version, contextVersion);
125 
126         eglDestroyContext(mDisplay, context);
127     }
128 }
129 
130 // Test that if it's possible to create an ES3 context, requesting an ES2 context should return an
131 // ES3 context as well
TEST_P(EGLBackwardsCompatibleContextTest,BackwardsCompatibleEnabledES3)132 TEST_P(EGLBackwardsCompatibleContextTest, BackwardsCompatibleEnabledES3)
133 {
134     ANGLE_SKIP_TEST_IF(
135         !IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_create_context_backwards_compatible"));
136 
137     EGLint es3ContextAttribs[] = {
138         EGL_CONTEXT_MAJOR_VERSION, 3, EGL_CONTEXT_MINOR_VERSION, 0, EGL_NONE, EGL_NONE};
139 
140     EGLContext es3Context = eglCreateContext(mDisplay, mConfig, nullptr, es3ContextAttribs);
141     ANGLE_SKIP_TEST_IF(es3Context == EGL_NO_CONTEXT);
142 
143     ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, mPbuffer, mPbuffer, es3Context));
144     auto es3ContextVersion = GetCurrentContextVersion();
145     eglDestroyContext(mDisplay, es3Context);
146 
147     EGLint es2ContextAttribs[] = {
148         EGL_CONTEXT_MAJOR_VERSION, 2, EGL_CONTEXT_MINOR_VERSION, 0, EGL_NONE, EGL_NONE};
149 
150     EGLContext es2Context = eglCreateContext(mDisplay, mConfig, nullptr, es2ContextAttribs);
151     EXPECT_NE(es2Context, EGL_NO_CONTEXT);
152 
153     ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, mPbuffer, mPbuffer, es2Context));
154     auto es2ContextVersion = GetCurrentContextVersion();
155     eglDestroyContext(mDisplay, es2Context);
156 
157     EXPECT_EQ(es3ContextVersion, es2ContextVersion);
158 }
159 
160 // Test that if ES1.1 is supported and a 1.0 context is requested, an ES 1.1 context is returned
TEST_P(EGLBackwardsCompatibleContextTest,BackwardsCompatibleEnabledES1)161 TEST_P(EGLBackwardsCompatibleContextTest, BackwardsCompatibleEnabledES1)
162 {
163     ANGLE_SKIP_TEST_IF(
164         !IsEGLDisplayExtensionEnabled(mDisplay, "EGL_ANGLE_create_context_backwards_compatible"));
165 
166     EGLint es11ContextAttribs[] = {
167         EGL_CONTEXT_MAJOR_VERSION, 1, EGL_CONTEXT_MINOR_VERSION, 1, EGL_NONE, EGL_NONE};
168 
169     EGLContext es11Context = eglCreateContext(mDisplay, mConfig, nullptr, es11ContextAttribs);
170     ANGLE_SKIP_TEST_IF(es11Context == EGL_NO_CONTEXT);
171 
172     ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, mPbuffer, mPbuffer, es11Context));
173     auto es11ContextVersion = GetCurrentContextVersion();
174     ASSERT_EQ(std::make_pair(1, 1), es11ContextVersion);
175     eglDestroyContext(mDisplay, es11Context);
176 
177     EGLint es10ContextAttribs[] = {
178         EGL_CONTEXT_MAJOR_VERSION, 1, EGL_CONTEXT_MINOR_VERSION, 0, EGL_NONE, EGL_NONE};
179 
180     EGLContext es10Context = eglCreateContext(mDisplay, mConfig, nullptr, es10ContextAttribs);
181     EXPECT_NE(es10Context, EGL_NO_CONTEXT);
182 
183     ASSERT_EGL_TRUE(eglMakeCurrent(mDisplay, mPbuffer, mPbuffer, es10Context));
184     auto es10ContextVersion = GetCurrentContextVersion();
185     ASSERT_EQ(std::make_pair(1, 1), es10ContextVersion);
186     eglDestroyContext(mDisplay, es10Context);
187 }
188 
189 ANGLE_INSTANTIATE_TEST(EGLBackwardsCompatibleContextTest,
190                        WithNoFixture(ES2_D3D9()),
191                        WithNoFixture(ES2_D3D11()),
192                        WithNoFixture(ES2_OPENGL()),
193                        WithNoFixture(ES2_OPENGLES()),
194                        WithNoFixture(ES2_VULKAN()));
195 
196 }  // namespace angle
197