1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2019 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 // EGLChooseConfigTest.cpp:
7*8975f5c5SAndroid Build Coastguard Worker // Tests of proper default-value semantics for eglChooseConfig
8*8975f5c5SAndroid Build Coastguard Worker
9*8975f5c5SAndroid Build Coastguard Worker #include <gtest/gtest.h>
10*8975f5c5SAndroid Build Coastguard Worker
11*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/ANGLETest.h"
12*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/angle_test_configs.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "util/EGLWindow.h"
14*8975f5c5SAndroid Build Coastguard Worker
15*8975f5c5SAndroid Build Coastguard Worker using namespace angle;
16*8975f5c5SAndroid Build Coastguard Worker
17*8975f5c5SAndroid Build Coastguard Worker namespace angle
18*8975f5c5SAndroid Build Coastguard Worker {
19*8975f5c5SAndroid Build Coastguard Worker class EGLChooseConfigTest : public ANGLETest<>
20*8975f5c5SAndroid Build Coastguard Worker {
21*8975f5c5SAndroid Build Coastguard Worker protected:
EGLChooseConfigTest()22*8975f5c5SAndroid Build Coastguard Worker EGLChooseConfigTest() {}
23*8975f5c5SAndroid Build Coastguard Worker };
24*8975f5c5SAndroid Build Coastguard Worker
25*8975f5c5SAndroid Build Coastguard Worker // Test that the EGL_COLOR_BUFFER_TYPE is defaulted to EGL_RGB_BUFFER
TEST_P(EGLChooseConfigTest,Defaults)26*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLChooseConfigTest, Defaults)
27*8975f5c5SAndroid Build Coastguard Worker {
28*8975f5c5SAndroid Build Coastguard Worker EGLDisplay display = getEGLWindow()->getDisplay();
29*8975f5c5SAndroid Build Coastguard Worker
30*8975f5c5SAndroid Build Coastguard Worker EGLint nConfigs = 0;
31*8975f5c5SAndroid Build Coastguard Worker EGLint allConfigCount = 0;
32*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglGetConfigs(display, nullptr, 0, &nConfigs));
33*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(nConfigs, 0);
34*8975f5c5SAndroid Build Coastguard Worker
35*8975f5c5SAndroid Build Coastguard Worker std::vector<EGLConfig> allConfigs(nConfigs);
36*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglGetConfigs(display, allConfigs.data(), nConfigs, &allConfigCount));
37*8975f5c5SAndroid Build Coastguard Worker ASSERT_EQ(nConfigs, allConfigCount);
38*8975f5c5SAndroid Build Coastguard Worker
39*8975f5c5SAndroid Build Coastguard Worker // Choose configs that have the default attribute values:
40*8975f5c5SAndroid Build Coastguard Worker const EGLint defaultConfigAttributes[] = {EGL_NONE};
41*8975f5c5SAndroid Build Coastguard Worker EGLint defaultConfigCount;
42*8975f5c5SAndroid Build Coastguard Worker std::vector<EGLConfig> defaultConfigs(allConfigCount);
43*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_TRUE(eglChooseConfig(display, defaultConfigAttributes, defaultConfigs.data(),
44*8975f5c5SAndroid Build Coastguard Worker defaultConfigs.size(), &defaultConfigCount));
45*8975f5c5SAndroid Build Coastguard Worker ASSERT_EGL_SUCCESS();
46*8975f5c5SAndroid Build Coastguard Worker ASSERT_LE(defaultConfigCount, allConfigCount);
47*8975f5c5SAndroid Build Coastguard Worker defaultConfigs.resize(defaultConfigCount);
48*8975f5c5SAndroid Build Coastguard Worker
49*8975f5c5SAndroid Build Coastguard Worker // Check that the default configs all have the default attribute values we care about:
50*8975f5c5SAndroid Build Coastguard Worker for (EGLConfig config : defaultConfigs)
51*8975f5c5SAndroid Build Coastguard Worker {
52*8975f5c5SAndroid Build Coastguard Worker EGLint colorBufferType, level, renderableType, surfaceType, transparentType;
53*8975f5c5SAndroid Build Coastguard Worker EGLint colorComponentType;
54*8975f5c5SAndroid Build Coastguard Worker
55*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_COLOR_BUFFER_TYPE, &colorBufferType);
56*8975f5c5SAndroid Build Coastguard Worker ASSERT_EQ(colorBufferType, EGL_RGB_BUFFER);
57*8975f5c5SAndroid Build Coastguard Worker
58*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_LEVEL, &level);
59*8975f5c5SAndroid Build Coastguard Worker ASSERT_EQ(level, 0);
60*8975f5c5SAndroid Build Coastguard Worker
61*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType);
62*8975f5c5SAndroid Build Coastguard Worker ASSERT_EQ(renderableType & EGL_OPENGL_ES_BIT, EGL_OPENGL_ES_BIT);
63*8975f5c5SAndroid Build Coastguard Worker
64*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_SURFACE_TYPE, &surfaceType);
65*8975f5c5SAndroid Build Coastguard Worker ASSERT_EQ(surfaceType & EGL_WINDOW_BIT, EGL_WINDOW_BIT);
66*8975f5c5SAndroid Build Coastguard Worker
67*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_TRANSPARENT_TYPE, &transparentType);
68*8975f5c5SAndroid Build Coastguard Worker ASSERT_EQ(transparentType, EGL_NONE);
69*8975f5c5SAndroid Build Coastguard Worker
70*8975f5c5SAndroid Build Coastguard Worker if (IsEGLDisplayExtensionEnabled(display, "EGL_EXT_pixel_format_float"))
71*8975f5c5SAndroid Build Coastguard Worker {
72*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_COLOR_COMPONENT_TYPE_EXT, &colorComponentType);
73*8975f5c5SAndroid Build Coastguard Worker ASSERT_EQ(colorComponentType, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT);
74*8975f5c5SAndroid Build Coastguard Worker }
75*8975f5c5SAndroid Build Coastguard Worker }
76*8975f5c5SAndroid Build Coastguard Worker
77*8975f5c5SAndroid Build Coastguard Worker // Check that all of the configs that have the default attribute values are are defaultConfigs,
78*8975f5c5SAndroid Build Coastguard Worker // and all that don't aren't:
79*8975f5c5SAndroid Build Coastguard Worker for (EGLConfig config : allConfigs)
80*8975f5c5SAndroid Build Coastguard Worker {
81*8975f5c5SAndroid Build Coastguard Worker EGLint colorBufferType, level, renderableType, surfaceType, transparentType;
82*8975f5c5SAndroid Build Coastguard Worker EGLint colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
83*8975f5c5SAndroid Build Coastguard Worker
84*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_COLOR_BUFFER_TYPE, &colorBufferType);
85*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_LEVEL, &level);
86*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType);
87*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_SURFACE_TYPE, &surfaceType);
88*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_TRANSPARENT_TYPE, &transparentType);
89*8975f5c5SAndroid Build Coastguard Worker if (IsEGLDisplayExtensionEnabled(display, "EGL_EXT_pixel_format_float"))
90*8975f5c5SAndroid Build Coastguard Worker {
91*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_COLOR_COMPONENT_TYPE_EXT, &colorComponentType);
92*8975f5c5SAndroid Build Coastguard Worker }
93*8975f5c5SAndroid Build Coastguard Worker
94*8975f5c5SAndroid Build Coastguard Worker bool isADefault =
95*8975f5c5SAndroid Build Coastguard Worker ((colorBufferType == EGL_RGB_BUFFER) && (level == 0) &&
96*8975f5c5SAndroid Build Coastguard Worker ((renderableType & EGL_OPENGL_ES_BIT) == EGL_OPENGL_ES_BIT) &&
97*8975f5c5SAndroid Build Coastguard Worker ((surfaceType & EGL_WINDOW_BIT) == EGL_WINDOW_BIT) && (transparentType == EGL_NONE) &&
98*8975f5c5SAndroid Build Coastguard Worker (colorComponentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT));
99*8975f5c5SAndroid Build Coastguard Worker EGLint thisConfigID;
100*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, config, EGL_CONFIG_ID, &thisConfigID);
101*8975f5c5SAndroid Build Coastguard Worker bool foundInDefaultConfigs = false;
102*8975f5c5SAndroid Build Coastguard Worker // Attempt to find this config ID in defaultConfigs:
103*8975f5c5SAndroid Build Coastguard Worker for (EGLConfig defaultConfig : defaultConfigs)
104*8975f5c5SAndroid Build Coastguard Worker {
105*8975f5c5SAndroid Build Coastguard Worker EGLint defaultConfigID;
106*8975f5c5SAndroid Build Coastguard Worker eglGetConfigAttrib(display, defaultConfig, EGL_CONFIG_ID, &defaultConfigID);
107*8975f5c5SAndroid Build Coastguard Worker if (defaultConfigID == thisConfigID)
108*8975f5c5SAndroid Build Coastguard Worker {
109*8975f5c5SAndroid Build Coastguard Worker foundInDefaultConfigs = true;
110*8975f5c5SAndroid Build Coastguard Worker }
111*8975f5c5SAndroid Build Coastguard Worker }
112*8975f5c5SAndroid Build Coastguard Worker ASSERT_EQ(isADefault, foundInDefaultConfigs);
113*8975f5c5SAndroid Build Coastguard Worker }
114*8975f5c5SAndroid Build Coastguard Worker }
115*8975f5c5SAndroid Build Coastguard Worker
116*8975f5c5SAndroid Build Coastguard Worker } // namespace angle
117*8975f5c5SAndroid Build Coastguard Worker
118*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(EGLChooseConfigTest,
119*8975f5c5SAndroid Build Coastguard Worker ES2_D3D11(),
120*8975f5c5SAndroid Build Coastguard Worker ES2_D3D9(),
121*8975f5c5SAndroid Build Coastguard Worker ES2_METAL(),
122*8975f5c5SAndroid Build Coastguard Worker ES2_OPENGL(),
123*8975f5c5SAndroid Build Coastguard Worker ES2_OPENGLES(),
124*8975f5c5SAndroid Build Coastguard Worker ES2_VULKAN());
125