xref: /aosp_15_r20/external/angle/src/tests/egl_tests/EGLContextCompatibilityTest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker 
7*8975f5c5SAndroid Build Coastguard Worker // EGLContextCompatibilityTest.cpp:
8*8975f5c5SAndroid Build Coastguard Worker //   This test will try to use all combinations of context configs and
9*8975f5c5SAndroid Build Coastguard Worker //   surface configs. If the configs are compatible, it checks that simple
10*8975f5c5SAndroid Build Coastguard Worker //   rendering works, otherwise it checks an error is generated one MakeCurrent.
11*8975f5c5SAndroid Build Coastguard Worker //
12*8975f5c5SAndroid Build Coastguard Worker 
13*8975f5c5SAndroid Build Coastguard Worker #include <gtest/gtest.h>
14*8975f5c5SAndroid Build Coastguard Worker 
15*8975f5c5SAndroid Build Coastguard Worker #include <unordered_set>
16*8975f5c5SAndroid Build Coastguard Worker #include <vector>
17*8975f5c5SAndroid Build Coastguard Worker 
18*8975f5c5SAndroid Build Coastguard Worker #include "common/debug.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/ANGLETest.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/angle_test_configs.h"
21*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/angle_test_instantiate.h"
22*8975f5c5SAndroid Build Coastguard Worker #include "util/OSWindow.h"
23*8975f5c5SAndroid Build Coastguard Worker #include "util/random_utils.h"
24*8975f5c5SAndroid Build Coastguard Worker 
25*8975f5c5SAndroid Build Coastguard Worker using namespace angle;
26*8975f5c5SAndroid Build Coastguard Worker 
27*8975f5c5SAndroid Build Coastguard Worker namespace
28*8975f5c5SAndroid Build Coastguard Worker {
29*8975f5c5SAndroid Build Coastguard Worker // The only configs with 16-bits for each of red, green, blue, and alpha is GL_RGBA16F
IsRGBA16FConfig(EGLDisplay display,EGLConfig config)30*8975f5c5SAndroid Build Coastguard Worker bool IsRGBA16FConfig(EGLDisplay display, EGLConfig config)
31*8975f5c5SAndroid Build Coastguard Worker {
32*8975f5c5SAndroid Build Coastguard Worker     EGLint red, green, blue, alpha;
33*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_RED_SIZE, &red);
34*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &green);
35*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blue);
36*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alpha);
37*8975f5c5SAndroid Build Coastguard Worker     return ((red == 16) && (green == 16) && (blue == 16) && (alpha == 16));
38*8975f5c5SAndroid Build Coastguard Worker }
39*8975f5c5SAndroid Build Coastguard Worker 
IsRGB10_A2Config(EGLDisplay display,EGLConfig config)40*8975f5c5SAndroid Build Coastguard Worker bool IsRGB10_A2Config(EGLDisplay display, EGLConfig config)
41*8975f5c5SAndroid Build Coastguard Worker {
42*8975f5c5SAndroid Build Coastguard Worker     EGLint red, green, blue, alpha;
43*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_RED_SIZE, &red);
44*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &green);
45*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blue);
46*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alpha);
47*8975f5c5SAndroid Build Coastguard Worker     return ((red == 10) && (green == 10) && (blue == 10) && (alpha == 2));
48*8975f5c5SAndroid Build Coastguard Worker }
49*8975f5c5SAndroid Build Coastguard Worker 
50*8975f5c5SAndroid Build Coastguard Worker // Queries EGL config to determine if multisampled or not
IsMultisampledConfig(EGLDisplay display,EGLConfig config)51*8975f5c5SAndroid Build Coastguard Worker bool IsMultisampledConfig(EGLDisplay display, EGLConfig config)
52*8975f5c5SAndroid Build Coastguard Worker {
53*8975f5c5SAndroid Build Coastguard Worker     EGLint samples = 0;
54*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_SAMPLES, &samples);
55*8975f5c5SAndroid Build Coastguard Worker     return (samples > 1);
56*8975f5c5SAndroid Build Coastguard Worker }
57*8975f5c5SAndroid Build Coastguard Worker 
ShouldSkipConfig(EGLDisplay display,EGLConfig config,bool windowSurfaceTest)58*8975f5c5SAndroid Build Coastguard Worker bool ShouldSkipConfig(EGLDisplay display, EGLConfig config, bool windowSurfaceTest)
59*8975f5c5SAndroid Build Coastguard Worker {
60*8975f5c5SAndroid Build Coastguard Worker     // Skip multisampled configurations due to test instability.
61*8975f5c5SAndroid Build Coastguard Worker     if (IsMultisampledConfig(display, config))
62*8975f5c5SAndroid Build Coastguard Worker         return true;
63*8975f5c5SAndroid Build Coastguard Worker 
64*8975f5c5SAndroid Build Coastguard Worker     // Disable RGBA16F/RGB10_A2 on Android due to OSWindow on Android not providing compatible
65*8975f5c5SAndroid Build Coastguard Worker     // windows (http://anglebug.com/42261830)
66*8975f5c5SAndroid Build Coastguard Worker     if (IsAndroid())
67*8975f5c5SAndroid Build Coastguard Worker     {
68*8975f5c5SAndroid Build Coastguard Worker         if (IsRGB10_A2Config(display, config))
69*8975f5c5SAndroid Build Coastguard Worker             return true;
70*8975f5c5SAndroid Build Coastguard Worker 
71*8975f5c5SAndroid Build Coastguard Worker         if (IsRGBA16FConfig(display, config))
72*8975f5c5SAndroid Build Coastguard Worker             return windowSurfaceTest;
73*8975f5c5SAndroid Build Coastguard Worker     }
74*8975f5c5SAndroid Build Coastguard Worker 
75*8975f5c5SAndroid Build Coastguard Worker     return false;
76*8975f5c5SAndroid Build Coastguard Worker }
77*8975f5c5SAndroid Build Coastguard Worker 
GetConfigs(EGLDisplay display)78*8975f5c5SAndroid Build Coastguard Worker std::vector<EGLConfig> GetConfigs(EGLDisplay display)
79*8975f5c5SAndroid Build Coastguard Worker {
80*8975f5c5SAndroid Build Coastguard Worker     int nConfigs = 0;
81*8975f5c5SAndroid Build Coastguard Worker     if (eglGetConfigs(display, nullptr, 0, &nConfigs) != EGL_TRUE)
82*8975f5c5SAndroid Build Coastguard Worker     {
83*8975f5c5SAndroid Build Coastguard Worker         std::cerr << "EGLContextCompatibilityTest: eglGetConfigs error\n";
84*8975f5c5SAndroid Build Coastguard Worker         return {};
85*8975f5c5SAndroid Build Coastguard Worker     }
86*8975f5c5SAndroid Build Coastguard Worker     if (nConfigs == 0)
87*8975f5c5SAndroid Build Coastguard Worker     {
88*8975f5c5SAndroid Build Coastguard Worker         std::cerr << "EGLContextCompatibilityTest: no configs\n";
89*8975f5c5SAndroid Build Coastguard Worker         return {};
90*8975f5c5SAndroid Build Coastguard Worker     }
91*8975f5c5SAndroid Build Coastguard Worker 
92*8975f5c5SAndroid Build Coastguard Worker     std::vector<EGLConfig> configs;
93*8975f5c5SAndroid Build Coastguard Worker 
94*8975f5c5SAndroid Build Coastguard Worker     int nReturnedConfigs = 0;
95*8975f5c5SAndroid Build Coastguard Worker     configs.resize(nConfigs);
96*8975f5c5SAndroid Build Coastguard Worker     if (eglGetConfigs(display, configs.data(), nConfigs, &nReturnedConfigs) != EGL_TRUE)
97*8975f5c5SAndroid Build Coastguard Worker     {
98*8975f5c5SAndroid Build Coastguard Worker         std::cerr << "EGLContextCompatibilityTest: eglGetConfigs error\n";
99*8975f5c5SAndroid Build Coastguard Worker         return {};
100*8975f5c5SAndroid Build Coastguard Worker     }
101*8975f5c5SAndroid Build Coastguard Worker     if (nConfigs != nReturnedConfigs)
102*8975f5c5SAndroid Build Coastguard Worker     {
103*8975f5c5SAndroid Build Coastguard Worker         std::cerr << "EGLContextCompatibilityTest: eglGetConfigs returned wrong count\n";
104*8975f5c5SAndroid Build Coastguard Worker         return {};
105*8975f5c5SAndroid Build Coastguard Worker     }
106*8975f5c5SAndroid Build Coastguard Worker 
107*8975f5c5SAndroid Build Coastguard Worker     return configs;
108*8975f5c5SAndroid Build Coastguard Worker }
109*8975f5c5SAndroid Build Coastguard Worker 
FromRenderer(EGLint renderer)110*8975f5c5SAndroid Build Coastguard Worker PlatformParameters FromRenderer(EGLint renderer)
111*8975f5c5SAndroid Build Coastguard Worker {
112*8975f5c5SAndroid Build Coastguard Worker     return WithNoFixture(PlatformParameters(2, 0, EGLPlatformParameters(renderer)));
113*8975f5c5SAndroid Build Coastguard Worker }
114*8975f5c5SAndroid Build Coastguard Worker 
EGLConfigName(EGLDisplay display,EGLConfig config)115*8975f5c5SAndroid Build Coastguard Worker std::string EGLConfigName(EGLDisplay display, EGLConfig config)
116*8975f5c5SAndroid Build Coastguard Worker {
117*8975f5c5SAndroid Build Coastguard Worker     EGLint red;
118*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_RED_SIZE, &red);
119*8975f5c5SAndroid Build Coastguard Worker     EGLint green;
120*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &green);
121*8975f5c5SAndroid Build Coastguard Worker     EGLint blue;
122*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blue);
123*8975f5c5SAndroid Build Coastguard Worker     EGLint alpha;
124*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alpha);
125*8975f5c5SAndroid Build Coastguard Worker     EGLint depth;
126*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depth);
127*8975f5c5SAndroid Build Coastguard Worker     EGLint stencil;
128*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencil);
129*8975f5c5SAndroid Build Coastguard Worker     EGLint samples;
130*8975f5c5SAndroid Build Coastguard Worker     eglGetConfigAttrib(display, config, EGL_SAMPLES, &samples);
131*8975f5c5SAndroid Build Coastguard Worker 
132*8975f5c5SAndroid Build Coastguard Worker     std::stringstream strstr;
133*8975f5c5SAndroid Build Coastguard Worker     if (red > 0)
134*8975f5c5SAndroid Build Coastguard Worker     {
135*8975f5c5SAndroid Build Coastguard Worker         strstr << "R" << red;
136*8975f5c5SAndroid Build Coastguard Worker     }
137*8975f5c5SAndroid Build Coastguard Worker     if (green > 0)
138*8975f5c5SAndroid Build Coastguard Worker     {
139*8975f5c5SAndroid Build Coastguard Worker         strstr << "G" << green;
140*8975f5c5SAndroid Build Coastguard Worker     }
141*8975f5c5SAndroid Build Coastguard Worker     if (blue > 0)
142*8975f5c5SAndroid Build Coastguard Worker     {
143*8975f5c5SAndroid Build Coastguard Worker         strstr << "B" << blue;
144*8975f5c5SAndroid Build Coastguard Worker     }
145*8975f5c5SAndroid Build Coastguard Worker     if (alpha > 0)
146*8975f5c5SAndroid Build Coastguard Worker     {
147*8975f5c5SAndroid Build Coastguard Worker         strstr << "A" << alpha;
148*8975f5c5SAndroid Build Coastguard Worker     }
149*8975f5c5SAndroid Build Coastguard Worker     if (depth > 0)
150*8975f5c5SAndroid Build Coastguard Worker     {
151*8975f5c5SAndroid Build Coastguard Worker         strstr << "D" << depth;
152*8975f5c5SAndroid Build Coastguard Worker     }
153*8975f5c5SAndroid Build Coastguard Worker     if (stencil > 0)
154*8975f5c5SAndroid Build Coastguard Worker     {
155*8975f5c5SAndroid Build Coastguard Worker         strstr << "S" << stencil;
156*8975f5c5SAndroid Build Coastguard Worker     }
157*8975f5c5SAndroid Build Coastguard Worker     if (samples > 0)
158*8975f5c5SAndroid Build Coastguard Worker     {
159*8975f5c5SAndroid Build Coastguard Worker         strstr << "MS" << samples;
160*8975f5c5SAndroid Build Coastguard Worker     }
161*8975f5c5SAndroid Build Coastguard Worker     return strstr.str();
162*8975f5c5SAndroid Build Coastguard Worker }
163*8975f5c5SAndroid Build Coastguard Worker 
164*8975f5c5SAndroid Build Coastguard Worker const std::array<EGLint, 3> kContextAttribs = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
165*8975f5c5SAndroid Build Coastguard Worker 
166*8975f5c5SAndroid Build Coastguard Worker class EGLContextCompatibilityTest : public ANGLETestBase, public testing::Test
167*8975f5c5SAndroid Build Coastguard Worker {
168*8975f5c5SAndroid Build Coastguard Worker   public:
EGLContextCompatibilityTest(EGLint renderer)169*8975f5c5SAndroid Build Coastguard Worker     EGLContextCompatibilityTest(EGLint renderer)
170*8975f5c5SAndroid Build Coastguard Worker         : ANGLETestBase(FromRenderer(renderer)), mRenderer(renderer)
171*8975f5c5SAndroid Build Coastguard Worker     {}
172*8975f5c5SAndroid Build Coastguard Worker 
SetUp()173*8975f5c5SAndroid Build Coastguard Worker     void SetUp() final
174*8975f5c5SAndroid Build Coastguard Worker     {
175*8975f5c5SAndroid Build Coastguard Worker         ANGLETestBase::ANGLETestSetUp();
176*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(eglGetPlatformDisplayEXT != nullptr);
177*8975f5c5SAndroid Build Coastguard Worker 
178*8975f5c5SAndroid Build Coastguard Worker         EGLint dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, mRenderer, EGL_NONE};
179*8975f5c5SAndroid Build Coastguard Worker         mDisplay           = eglGetPlatformDisplayEXT(
180*8975f5c5SAndroid Build Coastguard Worker             EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
181*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(mDisplay != EGL_NO_DISPLAY);
182*8975f5c5SAndroid Build Coastguard Worker 
183*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(eglInitialize(mDisplay, nullptr, nullptr) == EGL_TRUE);
184*8975f5c5SAndroid Build Coastguard Worker 
185*8975f5c5SAndroid Build Coastguard Worker         int nConfigs = 0;
186*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(eglGetConfigs(mDisplay, nullptr, 0, &nConfigs) == EGL_TRUE);
187*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(nConfigs != 0);
188*8975f5c5SAndroid Build Coastguard Worker 
189*8975f5c5SAndroid Build Coastguard Worker         int nReturnedConfigs = 0;
190*8975f5c5SAndroid Build Coastguard Worker         mConfigs.resize(nConfigs);
191*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(eglGetConfigs(mDisplay, mConfigs.data(), nConfigs, &nReturnedConfigs) ==
192*8975f5c5SAndroid Build Coastguard Worker                     EGL_TRUE);
193*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(nConfigs == nReturnedConfigs);
194*8975f5c5SAndroid Build Coastguard Worker     }
195*8975f5c5SAndroid Build Coastguard Worker 
TearDown()196*8975f5c5SAndroid Build Coastguard Worker     void TearDown() final
197*8975f5c5SAndroid Build Coastguard Worker     {
198*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
199*8975f5c5SAndroid Build Coastguard Worker         eglTerminate(mDisplay);
200*8975f5c5SAndroid Build Coastguard Worker         ANGLETestBase::ANGLETestTearDown();
201*8975f5c5SAndroid Build Coastguard Worker     }
202*8975f5c5SAndroid Build Coastguard Worker 
203*8975f5c5SAndroid Build Coastguard Worker   protected:
areConfigsCompatible(EGLConfig c1,EGLConfig c2,EGLint surfaceBit)204*8975f5c5SAndroid Build Coastguard Worker     bool areConfigsCompatible(EGLConfig c1, EGLConfig c2, EGLint surfaceBit)
205*8975f5c5SAndroid Build Coastguard Worker     {
206*8975f5c5SAndroid Build Coastguard Worker         EGLint colorBufferType1, colorBufferType2;
207*8975f5c5SAndroid Build Coastguard Worker         EGLint red1, red2, green1, green2, blue1, blue2, alpha1, alpha2;
208*8975f5c5SAndroid Build Coastguard Worker         EGLint depth1, depth2, stencil1, stencil2;
209*8975f5c5SAndroid Build Coastguard Worker         EGLint surfaceType1, surfaceType2;
210*8975f5c5SAndroid Build Coastguard Worker 
211*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c1, EGL_COLOR_BUFFER_TYPE, &colorBufferType1);
212*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c2, EGL_COLOR_BUFFER_TYPE, &colorBufferType2);
213*8975f5c5SAndroid Build Coastguard Worker 
214*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c1, EGL_RED_SIZE, &red1);
215*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c2, EGL_RED_SIZE, &red2);
216*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c1, EGL_GREEN_SIZE, &green1);
217*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c2, EGL_GREEN_SIZE, &green2);
218*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c1, EGL_BLUE_SIZE, &blue1);
219*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c2, EGL_BLUE_SIZE, &blue2);
220*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c1, EGL_ALPHA_SIZE, &alpha1);
221*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c2, EGL_ALPHA_SIZE, &alpha2);
222*8975f5c5SAndroid Build Coastguard Worker 
223*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c1, EGL_DEPTH_SIZE, &depth1);
224*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c2, EGL_DEPTH_SIZE, &depth2);
225*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c1, EGL_STENCIL_SIZE, &stencil1);
226*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c2, EGL_STENCIL_SIZE, &stencil2);
227*8975f5c5SAndroid Build Coastguard Worker 
228*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c1, EGL_SURFACE_TYPE, &surfaceType1);
229*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, c2, EGL_SURFACE_TYPE, &surfaceType2);
230*8975f5c5SAndroid Build Coastguard Worker 
231*8975f5c5SAndroid Build Coastguard Worker         EGLint colorComponentType1 = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
232*8975f5c5SAndroid Build Coastguard Worker         EGLint colorComponentType2 = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
233*8975f5c5SAndroid Build Coastguard Worker         if (IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_pixel_format_float"))
234*8975f5c5SAndroid Build Coastguard Worker         {
235*8975f5c5SAndroid Build Coastguard Worker             eglGetConfigAttrib(mDisplay, c1, EGL_COLOR_COMPONENT_TYPE_EXT, &colorComponentType1);
236*8975f5c5SAndroid Build Coastguard Worker             eglGetConfigAttrib(mDisplay, c2, EGL_COLOR_COMPONENT_TYPE_EXT, &colorComponentType2);
237*8975f5c5SAndroid Build Coastguard Worker         }
238*8975f5c5SAndroid Build Coastguard Worker 
239*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_SUCCESS();
240*8975f5c5SAndroid Build Coastguard Worker 
241*8975f5c5SAndroid Build Coastguard Worker         return colorBufferType1 == colorBufferType2 && red1 == red2 && green1 == green2 &&
242*8975f5c5SAndroid Build Coastguard Worker                blue1 == blue2 && alpha1 == alpha2 && colorComponentType1 == colorComponentType2 &&
243*8975f5c5SAndroid Build Coastguard Worker                depth1 == depth2 && stencil1 == stencil2 && (surfaceType1 & surfaceBit) != 0 &&
244*8975f5c5SAndroid Build Coastguard Worker                (surfaceType2 & surfaceBit) != 0;
245*8975f5c5SAndroid Build Coastguard Worker     }
246*8975f5c5SAndroid Build Coastguard Worker 
testWindowCompatibility(EGLConfig windowConfig,EGLConfig contextConfig,bool compatible) const247*8975f5c5SAndroid Build Coastguard Worker     void testWindowCompatibility(EGLConfig windowConfig,
248*8975f5c5SAndroid Build Coastguard Worker                                  EGLConfig contextConfig,
249*8975f5c5SAndroid Build Coastguard Worker                                  bool compatible) const
250*8975f5c5SAndroid Build Coastguard Worker     {
251*8975f5c5SAndroid Build Coastguard Worker         OSWindow *osWindow = OSWindow::New();
252*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(osWindow != nullptr);
253*8975f5c5SAndroid Build Coastguard Worker         osWindow->initialize("EGLContextCompatibilityTest", 500, 500);
254*8975f5c5SAndroid Build Coastguard Worker 
255*8975f5c5SAndroid Build Coastguard Worker         EGLContext context =
256*8975f5c5SAndroid Build Coastguard Worker             eglCreateContext(mDisplay, contextConfig, EGL_NO_CONTEXT, kContextAttribs.data());
257*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(context != EGL_NO_CONTEXT);
258*8975f5c5SAndroid Build Coastguard Worker 
259*8975f5c5SAndroid Build Coastguard Worker         EGLSurface window =
260*8975f5c5SAndroid Build Coastguard Worker             eglCreateWindowSurface(mDisplay, windowConfig, osWindow->getNativeWindow(), nullptr);
261*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
262*8975f5c5SAndroid Build Coastguard Worker 
263*8975f5c5SAndroid Build Coastguard Worker         if (compatible)
264*8975f5c5SAndroid Build Coastguard Worker         {
265*8975f5c5SAndroid Build Coastguard Worker             testClearSurface(window, windowConfig, context);
266*8975f5c5SAndroid Build Coastguard Worker         }
267*8975f5c5SAndroid Build Coastguard Worker         else
268*8975f5c5SAndroid Build Coastguard Worker         {
269*8975f5c5SAndroid Build Coastguard Worker             testMakeCurrentFails(window, context);
270*8975f5c5SAndroid Build Coastguard Worker         }
271*8975f5c5SAndroid Build Coastguard Worker 
272*8975f5c5SAndroid Build Coastguard Worker         eglDestroySurface(mDisplay, window);
273*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
274*8975f5c5SAndroid Build Coastguard Worker 
275*8975f5c5SAndroid Build Coastguard Worker         eglDestroyContext(mDisplay, context);
276*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
277*8975f5c5SAndroid Build Coastguard Worker 
278*8975f5c5SAndroid Build Coastguard Worker         OSWindow::Delete(&osWindow);
279*8975f5c5SAndroid Build Coastguard Worker     }
280*8975f5c5SAndroid Build Coastguard Worker 
testPbufferCompatibility(EGLConfig pbufferConfig,EGLConfig contextConfig,bool compatible) const281*8975f5c5SAndroid Build Coastguard Worker     void testPbufferCompatibility(EGLConfig pbufferConfig,
282*8975f5c5SAndroid Build Coastguard Worker                                   EGLConfig contextConfig,
283*8975f5c5SAndroid Build Coastguard Worker                                   bool compatible) const
284*8975f5c5SAndroid Build Coastguard Worker     {
285*8975f5c5SAndroid Build Coastguard Worker         EGLContext context =
286*8975f5c5SAndroid Build Coastguard Worker             eglCreateContext(mDisplay, contextConfig, EGL_NO_CONTEXT, kContextAttribs.data());
287*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(context != EGL_NO_CONTEXT);
288*8975f5c5SAndroid Build Coastguard Worker 
289*8975f5c5SAndroid Build Coastguard Worker         const EGLint pBufferAttribs[] = {
290*8975f5c5SAndroid Build Coastguard Worker             EGL_WIDTH, 500, EGL_HEIGHT, 500, EGL_NONE,
291*8975f5c5SAndroid Build Coastguard Worker         };
292*8975f5c5SAndroid Build Coastguard Worker         EGLSurface pbuffer = eglCreatePbufferSurface(mDisplay, pbufferConfig, pBufferAttribs);
293*8975f5c5SAndroid Build Coastguard Worker         ASSERT_TRUE(pbuffer != EGL_NO_SURFACE);
294*8975f5c5SAndroid Build Coastguard Worker 
295*8975f5c5SAndroid Build Coastguard Worker         if (compatible)
296*8975f5c5SAndroid Build Coastguard Worker         {
297*8975f5c5SAndroid Build Coastguard Worker             testClearSurface(pbuffer, pbufferConfig, context);
298*8975f5c5SAndroid Build Coastguard Worker         }
299*8975f5c5SAndroid Build Coastguard Worker         else
300*8975f5c5SAndroid Build Coastguard Worker         {
301*8975f5c5SAndroid Build Coastguard Worker             testMakeCurrentFails(pbuffer, context);
302*8975f5c5SAndroid Build Coastguard Worker         }
303*8975f5c5SAndroid Build Coastguard Worker 
304*8975f5c5SAndroid Build Coastguard Worker         eglDestroySurface(mDisplay, pbuffer);
305*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
306*8975f5c5SAndroid Build Coastguard Worker 
307*8975f5c5SAndroid Build Coastguard Worker         eglDestroyContext(mDisplay, context);
308*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
309*8975f5c5SAndroid Build Coastguard Worker     }
310*8975f5c5SAndroid Build Coastguard Worker 
311*8975f5c5SAndroid Build Coastguard Worker     std::vector<EGLConfig> mConfigs;
312*8975f5c5SAndroid Build Coastguard Worker     EGLDisplay mDisplay = EGL_NO_DISPLAY;
313*8975f5c5SAndroid Build Coastguard Worker     EGLint mRenderer    = 0;
314*8975f5c5SAndroid Build Coastguard Worker 
315*8975f5c5SAndroid Build Coastguard Worker   private:
testClearSurface(EGLSurface surface,EGLConfig surfaceConfig,EGLContext context) const316*8975f5c5SAndroid Build Coastguard Worker     void testClearSurface(EGLSurface surface, EGLConfig surfaceConfig, EGLContext context) const
317*8975f5c5SAndroid Build Coastguard Worker     {
318*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, surface, surface, context);
319*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
320*8975f5c5SAndroid Build Coastguard Worker 
321*8975f5c5SAndroid Build Coastguard Worker         glViewport(0, 0, 500, 500);
322*8975f5c5SAndroid Build Coastguard Worker         glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
323*8975f5c5SAndroid Build Coastguard Worker         glClear(GL_COLOR_BUFFER_BIT);
324*8975f5c5SAndroid Build Coastguard Worker         ASSERT_GL_NO_ERROR();
325*8975f5c5SAndroid Build Coastguard Worker 
326*8975f5c5SAndroid Build Coastguard Worker         EGLint surfaceCompontentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
327*8975f5c5SAndroid Build Coastguard Worker         if (IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_pixel_format_float"))
328*8975f5c5SAndroid Build Coastguard Worker         {
329*8975f5c5SAndroid Build Coastguard Worker             eglGetConfigAttrib(mDisplay, surfaceConfig, EGL_COLOR_COMPONENT_TYPE_EXT,
330*8975f5c5SAndroid Build Coastguard Worker                                &surfaceCompontentType);
331*8975f5c5SAndroid Build Coastguard Worker         }
332*8975f5c5SAndroid Build Coastguard Worker 
333*8975f5c5SAndroid Build Coastguard Worker         if (surfaceCompontentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT)
334*8975f5c5SAndroid Build Coastguard Worker         {
335*8975f5c5SAndroid Build Coastguard Worker             EXPECT_PIXEL_EQ(250, 250, 0, 0, 255, 255);
336*8975f5c5SAndroid Build Coastguard Worker         }
337*8975f5c5SAndroid Build Coastguard Worker         else
338*8975f5c5SAndroid Build Coastguard Worker         {
339*8975f5c5SAndroid Build Coastguard Worker             EXPECT_PIXEL_32F_EQ(250, 250, 0, 0, 1.0f, 1.0f);
340*8975f5c5SAndroid Build Coastguard Worker         }
341*8975f5c5SAndroid Build Coastguard Worker 
342*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
343*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
344*8975f5c5SAndroid Build Coastguard Worker     }
345*8975f5c5SAndroid Build Coastguard Worker 
testMakeCurrentFails(EGLSurface surface,EGLContext context) const346*8975f5c5SAndroid Build Coastguard Worker     void testMakeCurrentFails(EGLSurface surface, EGLContext context) const
347*8975f5c5SAndroid Build Coastguard Worker     {
348*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, surface, surface, context);
349*8975f5c5SAndroid Build Coastguard Worker         EXPECT_EGL_ERROR(EGL_BAD_MATCH);
350*8975f5c5SAndroid Build Coastguard Worker     }
351*8975f5c5SAndroid Build Coastguard Worker };
352*8975f5c5SAndroid Build Coastguard Worker 
353*8975f5c5SAndroid Build Coastguard Worker // The test is split in several subtest so that simple cases
354*8975f5c5SAndroid Build Coastguard Worker // are tested separately. Also each surface types are not tested
355*8975f5c5SAndroid Build Coastguard Worker // together.
356*8975f5c5SAndroid Build Coastguard Worker 
357*8975f5c5SAndroid Build Coastguard Worker // Basic test checking contexts and windows created with the
358*8975f5c5SAndroid Build Coastguard Worker // same config can render.
359*8975f5c5SAndroid Build Coastguard Worker class EGLContextCompatibilityTest_WindowSameConfig : public EGLContextCompatibilityTest
360*8975f5c5SAndroid Build Coastguard Worker {
361*8975f5c5SAndroid Build Coastguard Worker   public:
EGLContextCompatibilityTest_WindowSameConfig(EGLint renderer,size_t configIndex)362*8975f5c5SAndroid Build Coastguard Worker     EGLContextCompatibilityTest_WindowSameConfig(EGLint renderer, size_t configIndex)
363*8975f5c5SAndroid Build Coastguard Worker         : EGLContextCompatibilityTest(renderer), mConfigIndex(configIndex)
364*8975f5c5SAndroid Build Coastguard Worker     {}
365*8975f5c5SAndroid Build Coastguard Worker 
TestBody()366*8975f5c5SAndroid Build Coastguard Worker     void TestBody() override
367*8975f5c5SAndroid Build Coastguard Worker     {
368*8975f5c5SAndroid Build Coastguard Worker         EGLConfig config = mConfigs[mConfigIndex];
369*8975f5c5SAndroid Build Coastguard Worker 
370*8975f5c5SAndroid Build Coastguard Worker         EGLint surfaceType;
371*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, config, EGL_SURFACE_TYPE, &surfaceType);
372*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
373*8975f5c5SAndroid Build Coastguard Worker 
374*8975f5c5SAndroid Build Coastguard Worker         ANGLE_SKIP_TEST_IF((surfaceType & EGL_WINDOW_BIT) == 0);
375*8975f5c5SAndroid Build Coastguard Worker 
376*8975f5c5SAndroid Build Coastguard Worker         testWindowCompatibility(config, config, true);
377*8975f5c5SAndroid Build Coastguard Worker     }
378*8975f5c5SAndroid Build Coastguard Worker 
379*8975f5c5SAndroid Build Coastguard Worker     EGLint mConfigIndex;
380*8975f5c5SAndroid Build Coastguard Worker };
381*8975f5c5SAndroid Build Coastguard Worker 
382*8975f5c5SAndroid Build Coastguard Worker // Basic test checking contexts and pbuffers created with the
383*8975f5c5SAndroid Build Coastguard Worker // same config can render.
384*8975f5c5SAndroid Build Coastguard Worker class EGLContextCompatibilityTest_PbufferSameConfig : public EGLContextCompatibilityTest
385*8975f5c5SAndroid Build Coastguard Worker {
386*8975f5c5SAndroid Build Coastguard Worker   public:
EGLContextCompatibilityTest_PbufferSameConfig(EGLint renderer,size_t configIndex)387*8975f5c5SAndroid Build Coastguard Worker     EGLContextCompatibilityTest_PbufferSameConfig(EGLint renderer, size_t configIndex)
388*8975f5c5SAndroid Build Coastguard Worker         : EGLContextCompatibilityTest(renderer), mConfigIndex(configIndex)
389*8975f5c5SAndroid Build Coastguard Worker     {}
390*8975f5c5SAndroid Build Coastguard Worker 
TestBody()391*8975f5c5SAndroid Build Coastguard Worker     void TestBody() override
392*8975f5c5SAndroid Build Coastguard Worker     {
393*8975f5c5SAndroid Build Coastguard Worker         EGLConfig config = mConfigs[mConfigIndex];
394*8975f5c5SAndroid Build Coastguard Worker 
395*8975f5c5SAndroid Build Coastguard Worker         EGLint surfaceType;
396*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, config, EGL_SURFACE_TYPE, &surfaceType);
397*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
398*8975f5c5SAndroid Build Coastguard Worker 
399*8975f5c5SAndroid Build Coastguard Worker         ANGLE_SKIP_TEST_IF((surfaceType & EGL_PBUFFER_BIT) == 0);
400*8975f5c5SAndroid Build Coastguard Worker 
401*8975f5c5SAndroid Build Coastguard Worker         testPbufferCompatibility(config, config, true);
402*8975f5c5SAndroid Build Coastguard Worker     }
403*8975f5c5SAndroid Build Coastguard Worker 
404*8975f5c5SAndroid Build Coastguard Worker     EGLint mConfigIndex;
405*8975f5c5SAndroid Build Coastguard Worker };
406*8975f5c5SAndroid Build Coastguard Worker 
407*8975f5c5SAndroid Build Coastguard Worker // Check that a context rendering to a window with a different
408*8975f5c5SAndroid Build Coastguard Worker // config works or errors according to the EGL compatibility rules
409*8975f5c5SAndroid Build Coastguard Worker class EGLContextCompatibilityTest_WindowDifferentConfig : public EGLContextCompatibilityTest
410*8975f5c5SAndroid Build Coastguard Worker {
411*8975f5c5SAndroid Build Coastguard Worker   public:
EGLContextCompatibilityTest_WindowDifferentConfig(EGLint renderer,size_t configIndexA,size_t configIndexB)412*8975f5c5SAndroid Build Coastguard Worker     EGLContextCompatibilityTest_WindowDifferentConfig(EGLint renderer,
413*8975f5c5SAndroid Build Coastguard Worker                                                       size_t configIndexA,
414*8975f5c5SAndroid Build Coastguard Worker                                                       size_t configIndexB)
415*8975f5c5SAndroid Build Coastguard Worker         : EGLContextCompatibilityTest(renderer),
416*8975f5c5SAndroid Build Coastguard Worker           mConfigIndexA(configIndexA),
417*8975f5c5SAndroid Build Coastguard Worker           mConfigIndexB(configIndexB)
418*8975f5c5SAndroid Build Coastguard Worker     {}
419*8975f5c5SAndroid Build Coastguard Worker 
TestBody()420*8975f5c5SAndroid Build Coastguard Worker     void TestBody() override
421*8975f5c5SAndroid Build Coastguard Worker     {
422*8975f5c5SAndroid Build Coastguard Worker         EGLConfig config1 = mConfigs[mConfigIndexA];
423*8975f5c5SAndroid Build Coastguard Worker         EGLConfig config2 = mConfigs[mConfigIndexB];
424*8975f5c5SAndroid Build Coastguard Worker 
425*8975f5c5SAndroid Build Coastguard Worker         EGLint surfaceType;
426*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, config1, EGL_SURFACE_TYPE, &surfaceType);
427*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
428*8975f5c5SAndroid Build Coastguard Worker 
429*8975f5c5SAndroid Build Coastguard Worker         ANGLE_SKIP_TEST_IF((surfaceType & EGL_WINDOW_BIT) == 0);
430*8975f5c5SAndroid Build Coastguard Worker 
431*8975f5c5SAndroid Build Coastguard Worker         testWindowCompatibility(config1, config2,
432*8975f5c5SAndroid Build Coastguard Worker                                 areConfigsCompatible(config1, config2, EGL_WINDOW_BIT));
433*8975f5c5SAndroid Build Coastguard Worker     }
434*8975f5c5SAndroid Build Coastguard Worker 
435*8975f5c5SAndroid Build Coastguard Worker     EGLint mConfigIndexA;
436*8975f5c5SAndroid Build Coastguard Worker     EGLint mConfigIndexB;
437*8975f5c5SAndroid Build Coastguard Worker };
438*8975f5c5SAndroid Build Coastguard Worker 
439*8975f5c5SAndroid Build Coastguard Worker // Check that a context rendering to a pbuffer with a different
440*8975f5c5SAndroid Build Coastguard Worker // config works or errors according to the EGL compatibility rules
441*8975f5c5SAndroid Build Coastguard Worker class EGLContextCompatibilityTest_PbufferDifferentConfig : public EGLContextCompatibilityTest
442*8975f5c5SAndroid Build Coastguard Worker {
443*8975f5c5SAndroid Build Coastguard Worker   public:
EGLContextCompatibilityTest_PbufferDifferentConfig(EGLint renderer,size_t configIndexA,size_t configIndexB)444*8975f5c5SAndroid Build Coastguard Worker     EGLContextCompatibilityTest_PbufferDifferentConfig(EGLint renderer,
445*8975f5c5SAndroid Build Coastguard Worker                                                        size_t configIndexA,
446*8975f5c5SAndroid Build Coastguard Worker                                                        size_t configIndexB)
447*8975f5c5SAndroid Build Coastguard Worker         : EGLContextCompatibilityTest(renderer),
448*8975f5c5SAndroid Build Coastguard Worker           mConfigIndexA(configIndexA),
449*8975f5c5SAndroid Build Coastguard Worker           mConfigIndexB(configIndexB)
450*8975f5c5SAndroid Build Coastguard Worker     {}
451*8975f5c5SAndroid Build Coastguard Worker 
TestBody()452*8975f5c5SAndroid Build Coastguard Worker     void TestBody() override
453*8975f5c5SAndroid Build Coastguard Worker     {
454*8975f5c5SAndroid Build Coastguard Worker         EGLConfig config1 = mConfigs[mConfigIndexA];
455*8975f5c5SAndroid Build Coastguard Worker         EGLConfig config2 = mConfigs[mConfigIndexB];
456*8975f5c5SAndroid Build Coastguard Worker 
457*8975f5c5SAndroid Build Coastguard Worker         EGLint surfaceType;
458*8975f5c5SAndroid Build Coastguard Worker         eglGetConfigAttrib(mDisplay, config1, EGL_SURFACE_TYPE, &surfaceType);
459*8975f5c5SAndroid Build Coastguard Worker         ASSERT_EGL_SUCCESS();
460*8975f5c5SAndroid Build Coastguard Worker 
461*8975f5c5SAndroid Build Coastguard Worker         ANGLE_SKIP_TEST_IF((surfaceType & EGL_PBUFFER_BIT) == 0);
462*8975f5c5SAndroid Build Coastguard Worker 
463*8975f5c5SAndroid Build Coastguard Worker         testPbufferCompatibility(config1, config2,
464*8975f5c5SAndroid Build Coastguard Worker                                  areConfigsCompatible(config1, config2, EGL_PBUFFER_BIT));
465*8975f5c5SAndroid Build Coastguard Worker     }
466*8975f5c5SAndroid Build Coastguard Worker 
467*8975f5c5SAndroid Build Coastguard Worker     EGLint mConfigIndexA;
468*8975f5c5SAndroid Build Coastguard Worker     EGLint mConfigIndexB;
469*8975f5c5SAndroid Build Coastguard Worker };
470*8975f5c5SAndroid Build Coastguard Worker }  // namespace
471*8975f5c5SAndroid Build Coastguard Worker 
RegisterContextCompatibilityTests()472*8975f5c5SAndroid Build Coastguard Worker void RegisterContextCompatibilityTests()
473*8975f5c5SAndroid Build Coastguard Worker {
474*8975f5c5SAndroid Build Coastguard Worker     // Linux failures: http://anglebug.com/42263563
475*8975f5c5SAndroid Build Coastguard Worker     // Also wrong drivers loaded under xvfb due to egl* calls: https://anglebug.com/42266535
476*8975f5c5SAndroid Build Coastguard Worker     if (IsLinux())
477*8975f5c5SAndroid Build Coastguard Worker     {
478*8975f5c5SAndroid Build Coastguard Worker         std::cerr << "EGLContextCompatibilityTest: skipped on Linux\n";
479*8975f5c5SAndroid Build Coastguard Worker         return;
480*8975f5c5SAndroid Build Coastguard Worker     }
481*8975f5c5SAndroid Build Coastguard Worker 
482*8975f5c5SAndroid Build Coastguard Worker     std::vector<EGLint> renderers = {{
483*8975f5c5SAndroid Build Coastguard Worker         EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE,
484*8975f5c5SAndroid Build Coastguard Worker         EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
485*8975f5c5SAndroid Build Coastguard Worker         EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE,
486*8975f5c5SAndroid Build Coastguard Worker         EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE,
487*8975f5c5SAndroid Build Coastguard Worker         EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE,
488*8975f5c5SAndroid Build Coastguard Worker         EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE,
489*8975f5c5SAndroid Build Coastguard Worker     }};
490*8975f5c5SAndroid Build Coastguard Worker 
491*8975f5c5SAndroid Build Coastguard Worker     LoadEntryPointsWithUtilLoader(angle::GLESDriverType::AngleEGL);
492*8975f5c5SAndroid Build Coastguard Worker 
493*8975f5c5SAndroid Build Coastguard Worker     if (eglGetPlatformDisplayEXT == nullptr)
494*8975f5c5SAndroid Build Coastguard Worker     {
495*8975f5c5SAndroid Build Coastguard Worker         std::cerr << "EGLContextCompatibilityTest: missing eglGetPlatformDisplayEXT\n";
496*8975f5c5SAndroid Build Coastguard Worker         return;
497*8975f5c5SAndroid Build Coastguard Worker     }
498*8975f5c5SAndroid Build Coastguard Worker 
499*8975f5c5SAndroid Build Coastguard Worker     for (EGLint renderer : renderers)
500*8975f5c5SAndroid Build Coastguard Worker     {
501*8975f5c5SAndroid Build Coastguard Worker         PlatformParameters params = FromRenderer(renderer);
502*8975f5c5SAndroid Build Coastguard Worker         if (!IsPlatformAvailable(params))
503*8975f5c5SAndroid Build Coastguard Worker             continue;
504*8975f5c5SAndroid Build Coastguard Worker 
505*8975f5c5SAndroid Build Coastguard Worker         EGLint dispattrs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, renderer, EGL_NONE};
506*8975f5c5SAndroid Build Coastguard Worker         EGLDisplay display = eglGetPlatformDisplayEXT(
507*8975f5c5SAndroid Build Coastguard Worker             EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(EGL_DEFAULT_DISPLAY), dispattrs);
508*8975f5c5SAndroid Build Coastguard Worker         if (display == EGL_NO_DISPLAY)
509*8975f5c5SAndroid Build Coastguard Worker         {
510*8975f5c5SAndroid Build Coastguard Worker             std::cerr << "EGLContextCompatibilityTest: eglGetPlatformDisplayEXT error\n";
511*8975f5c5SAndroid Build Coastguard Worker             return;
512*8975f5c5SAndroid Build Coastguard Worker         }
513*8975f5c5SAndroid Build Coastguard Worker 
514*8975f5c5SAndroid Build Coastguard Worker         if (eglInitialize(display, nullptr, nullptr) != EGL_TRUE)
515*8975f5c5SAndroid Build Coastguard Worker         {
516*8975f5c5SAndroid Build Coastguard Worker             std::cerr << "EGLContextCompatibilityTest: eglInitialize error\n";
517*8975f5c5SAndroid Build Coastguard Worker             return;
518*8975f5c5SAndroid Build Coastguard Worker         }
519*8975f5c5SAndroid Build Coastguard Worker 
520*8975f5c5SAndroid Build Coastguard Worker         std::vector<EGLConfig> configs;
521*8975f5c5SAndroid Build Coastguard Worker         std::vector<std::string> configNames;
522*8975f5c5SAndroid Build Coastguard Worker         std::string rendererName = GetRendererName(renderer);
523*8975f5c5SAndroid Build Coastguard Worker 
524*8975f5c5SAndroid Build Coastguard Worker         {
525*8975f5c5SAndroid Build Coastguard Worker             std::unordered_set<std::string> configNameSet;
526*8975f5c5SAndroid Build Coastguard Worker 
527*8975f5c5SAndroid Build Coastguard Worker             for (EGLConfig config : GetConfigs(display))
528*8975f5c5SAndroid Build Coastguard Worker             {
529*8975f5c5SAndroid Build Coastguard Worker                 std::string configName = EGLConfigName(display, config);
530*8975f5c5SAndroid Build Coastguard Worker                 // Skip configs with duplicate names
531*8975f5c5SAndroid Build Coastguard Worker                 if (configNameSet.count(configName) == 0)
532*8975f5c5SAndroid Build Coastguard Worker                 {
533*8975f5c5SAndroid Build Coastguard Worker                     configNames.push_back(configName);
534*8975f5c5SAndroid Build Coastguard Worker                     configNameSet.insert(configName);
535*8975f5c5SAndroid Build Coastguard Worker                     configs.push_back(config);
536*8975f5c5SAndroid Build Coastguard Worker                 }
537*8975f5c5SAndroid Build Coastguard Worker             }
538*8975f5c5SAndroid Build Coastguard Worker         }
539*8975f5c5SAndroid Build Coastguard Worker 
540*8975f5c5SAndroid Build Coastguard Worker         for (size_t configIndex = 0; configIndex < configs.size(); ++configIndex)
541*8975f5c5SAndroid Build Coastguard Worker         {
542*8975f5c5SAndroid Build Coastguard Worker             if (ShouldSkipConfig(display, configs[configIndex], true))
543*8975f5c5SAndroid Build Coastguard Worker                 continue;
544*8975f5c5SAndroid Build Coastguard Worker 
545*8975f5c5SAndroid Build Coastguard Worker             std::stringstream nameStr;
546*8975f5c5SAndroid Build Coastguard Worker             nameStr << "WindowSameConfig/" << rendererName << "_" << configNames[configIndex];
547*8975f5c5SAndroid Build Coastguard Worker             std::string name = nameStr.str();
548*8975f5c5SAndroid Build Coastguard Worker 
549*8975f5c5SAndroid Build Coastguard Worker             testing::RegisterTest(
550*8975f5c5SAndroid Build Coastguard Worker                 "EGLContextCompatibilityTest", name.c_str(), nullptr, nullptr, __FILE__, __LINE__,
551*8975f5c5SAndroid Build Coastguard Worker                 [renderer, configIndex]() -> EGLContextCompatibilityTest * {
552*8975f5c5SAndroid Build Coastguard Worker                     return new EGLContextCompatibilityTest_WindowSameConfig(renderer, configIndex);
553*8975f5c5SAndroid Build Coastguard Worker                 });
554*8975f5c5SAndroid Build Coastguard Worker         }
555*8975f5c5SAndroid Build Coastguard Worker 
556*8975f5c5SAndroid Build Coastguard Worker         for (size_t configIndex = 0; configIndex < configs.size(); ++configIndex)
557*8975f5c5SAndroid Build Coastguard Worker         {
558*8975f5c5SAndroid Build Coastguard Worker             if (ShouldSkipConfig(display, configs[configIndex], false))
559*8975f5c5SAndroid Build Coastguard Worker                 continue;
560*8975f5c5SAndroid Build Coastguard Worker 
561*8975f5c5SAndroid Build Coastguard Worker             std::stringstream nameStr;
562*8975f5c5SAndroid Build Coastguard Worker             nameStr << "PbufferSameConfig/" << rendererName << "_" << configNames[configIndex];
563*8975f5c5SAndroid Build Coastguard Worker             std::string name = nameStr.str();
564*8975f5c5SAndroid Build Coastguard Worker 
565*8975f5c5SAndroid Build Coastguard Worker             testing::RegisterTest(
566*8975f5c5SAndroid Build Coastguard Worker                 "EGLContextCompatibilityTest", name.c_str(), nullptr, nullptr, __FILE__, __LINE__,
567*8975f5c5SAndroid Build Coastguard Worker                 [renderer, configIndex]() -> EGLContextCompatibilityTest * {
568*8975f5c5SAndroid Build Coastguard Worker                     return new EGLContextCompatibilityTest_PbufferSameConfig(renderer, configIndex);
569*8975f5c5SAndroid Build Coastguard Worker                 });
570*8975f5c5SAndroid Build Coastguard Worker         }
571*8975f5c5SAndroid Build Coastguard Worker 
572*8975f5c5SAndroid Build Coastguard Worker         // Because there are so many permutations, we skip some configs randomly.
573*8975f5c5SAndroid Build Coastguard Worker         // Attempt to run at most 100 tests per renderer.
574*8975f5c5SAndroid Build Coastguard Worker         RNG rng(0);
575*8975f5c5SAndroid Build Coastguard Worker         constexpr uint32_t kMaximumTestsPerRenderer = 100;
576*8975f5c5SAndroid Build Coastguard Worker         const uint32_t kTestCount = static_cast<uint32_t>(configs.size() * configs.size());
577*8975f5c5SAndroid Build Coastguard Worker         const float kSkipP =
578*8975f5c5SAndroid Build Coastguard Worker             1.0f - (static_cast<float>(std::min(kMaximumTestsPerRenderer, kTestCount)) /
579*8975f5c5SAndroid Build Coastguard Worker                     static_cast<float>(kTestCount));
580*8975f5c5SAndroid Build Coastguard Worker 
581*8975f5c5SAndroid Build Coastguard Worker         for (size_t configIndexA = 0; configIndexA < configs.size(); ++configIndexA)
582*8975f5c5SAndroid Build Coastguard Worker         {
583*8975f5c5SAndroid Build Coastguard Worker             if (ShouldSkipConfig(display, configs[configIndexA], true))
584*8975f5c5SAndroid Build Coastguard Worker                 continue;
585*8975f5c5SAndroid Build Coastguard Worker 
586*8975f5c5SAndroid Build Coastguard Worker             std::string configNameA = configNames[configIndexA];
587*8975f5c5SAndroid Build Coastguard Worker 
588*8975f5c5SAndroid Build Coastguard Worker             for (size_t configIndexB = 0; configIndexB < configs.size(); ++configIndexB)
589*8975f5c5SAndroid Build Coastguard Worker             {
590*8975f5c5SAndroid Build Coastguard Worker                 if (ShouldSkipConfig(display, configs[configIndexB], true))
591*8975f5c5SAndroid Build Coastguard Worker                     continue;
592*8975f5c5SAndroid Build Coastguard Worker 
593*8975f5c5SAndroid Build Coastguard Worker                 if (rng.randomFloat() < kSkipP)
594*8975f5c5SAndroid Build Coastguard Worker                     continue;
595*8975f5c5SAndroid Build Coastguard Worker 
596*8975f5c5SAndroid Build Coastguard Worker                 std::string configNameB = configNames[configIndexB];
597*8975f5c5SAndroid Build Coastguard Worker 
598*8975f5c5SAndroid Build Coastguard Worker                 std::stringstream nameStr;
599*8975f5c5SAndroid Build Coastguard Worker                 nameStr << "WindowDifferentConfig/" << rendererName << "_" << configNameA << "_"
600*8975f5c5SAndroid Build Coastguard Worker                         << configNameB;
601*8975f5c5SAndroid Build Coastguard Worker                 std::string name = nameStr.str();
602*8975f5c5SAndroid Build Coastguard Worker 
603*8975f5c5SAndroid Build Coastguard Worker                 testing::RegisterTest(
604*8975f5c5SAndroid Build Coastguard Worker                     "EGLContextCompatibilityTest", name.c_str(), nullptr, nullptr, __FILE__,
605*8975f5c5SAndroid Build Coastguard Worker                     __LINE__,
606*8975f5c5SAndroid Build Coastguard Worker                     [renderer, configIndexA, configIndexB]() -> EGLContextCompatibilityTest * {
607*8975f5c5SAndroid Build Coastguard Worker                         return new EGLContextCompatibilityTest_WindowDifferentConfig(
608*8975f5c5SAndroid Build Coastguard Worker                             renderer, configIndexA, configIndexB);
609*8975f5c5SAndroid Build Coastguard Worker                     });
610*8975f5c5SAndroid Build Coastguard Worker             }
611*8975f5c5SAndroid Build Coastguard Worker         }
612*8975f5c5SAndroid Build Coastguard Worker 
613*8975f5c5SAndroid Build Coastguard Worker         for (size_t configIndexA = 0; configIndexA < configs.size(); ++configIndexA)
614*8975f5c5SAndroid Build Coastguard Worker         {
615*8975f5c5SAndroid Build Coastguard Worker             if (ShouldSkipConfig(display, configs[configIndexA], false))
616*8975f5c5SAndroid Build Coastguard Worker                 continue;
617*8975f5c5SAndroid Build Coastguard Worker 
618*8975f5c5SAndroid Build Coastguard Worker             std::string configNameA = configNames[configIndexA];
619*8975f5c5SAndroid Build Coastguard Worker 
620*8975f5c5SAndroid Build Coastguard Worker             for (size_t configIndexB = 0; configIndexB < configs.size(); ++configIndexB)
621*8975f5c5SAndroid Build Coastguard Worker             {
622*8975f5c5SAndroid Build Coastguard Worker                 if (ShouldSkipConfig(display, configs[configIndexB], false))
623*8975f5c5SAndroid Build Coastguard Worker                     continue;
624*8975f5c5SAndroid Build Coastguard Worker 
625*8975f5c5SAndroid Build Coastguard Worker                 if (rng.randomFloat() < kSkipP)
626*8975f5c5SAndroid Build Coastguard Worker                     continue;
627*8975f5c5SAndroid Build Coastguard Worker 
628*8975f5c5SAndroid Build Coastguard Worker                 std::string configNameB = configNames[configIndexB];
629*8975f5c5SAndroid Build Coastguard Worker 
630*8975f5c5SAndroid Build Coastguard Worker                 std::stringstream nameStr;
631*8975f5c5SAndroid Build Coastguard Worker                 nameStr << "PbufferDifferentConfig/" << rendererName << "_" << configNameA << "_"
632*8975f5c5SAndroid Build Coastguard Worker                         << configNameB;
633*8975f5c5SAndroid Build Coastguard Worker                 std::string name = nameStr.str();
634*8975f5c5SAndroid Build Coastguard Worker 
635*8975f5c5SAndroid Build Coastguard Worker                 testing::RegisterTest(
636*8975f5c5SAndroid Build Coastguard Worker                     "EGLContextCompatibilityTest", name.c_str(), nullptr, nullptr, __FILE__,
637*8975f5c5SAndroid Build Coastguard Worker                     __LINE__,
638*8975f5c5SAndroid Build Coastguard Worker                     [renderer, configIndexA, configIndexB]() -> EGLContextCompatibilityTest * {
639*8975f5c5SAndroid Build Coastguard Worker                         return new EGLContextCompatibilityTest_PbufferDifferentConfig(
640*8975f5c5SAndroid Build Coastguard Worker                             renderer, configIndexA, configIndexB);
641*8975f5c5SAndroid Build Coastguard Worker                     });
642*8975f5c5SAndroid Build Coastguard Worker             }
643*8975f5c5SAndroid Build Coastguard Worker         }
644*8975f5c5SAndroid Build Coastguard Worker 
645*8975f5c5SAndroid Build Coastguard Worker         if (eglTerminate(display) == EGL_FALSE)
646*8975f5c5SAndroid Build Coastguard Worker         {
647*8975f5c5SAndroid Build Coastguard Worker             std::cerr << "EGLContextCompatibilityTest: eglTerminate error\n";
648*8975f5c5SAndroid Build Coastguard Worker             return;
649*8975f5c5SAndroid Build Coastguard Worker         }
650*8975f5c5SAndroid Build Coastguard Worker     }
651*8975f5c5SAndroid Build Coastguard Worker }
652