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