1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
4 *
5 * Copyright (c) 2016 Google Inc.
6 * Copyright (c) 2016 The Khronos Group Inc.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */ /*!
21 * \file
22 * \brief CTS rendering configuration list utility.
23 */ /*-------------------------------------------------------------------*/
24
25 #include "glcConfigListEGL.hpp"
26
27 #include "deUniquePtr.hpp"
28 #include "glcConfigList.hpp"
29
30 #include <typeinfo>
31
32 #include "deUniquePtr.hpp"
33 #include "egluNativeDisplay.hpp"
34 #include "egluPlatform.hpp"
35 #include "egluUtil.hpp"
36 #include "eglwDefs.hpp"
37 #include "eglwEnums.hpp"
38 #include "tcuPlatform.hpp"
39
40 #if !defined(EGL_OPENGL_ES3_BIT_KHR)
41 #define EGL_OPENGL_ES3_BIT_KHR 0x0040
42 #endif
43
44 #if !defined(EGL_COLOR_COMPONENT_TYPE_EXT)
45 #define EGL_COLOR_COMPONENT_TYPE_EXT 0x3339
46 #endif
47
48 #if !defined(EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT)
49 #define EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT 0x333B
50 #endif
51
52 #if !defined(EGL_YUV_BUFFER_EXT)
53 #define EGL_YUV_BUFFER_EXT 0x3300
54 #endif
55
56 namespace glcts
57 {
58
getDefaultEglConfigList(tcu::Platform & eglPlatform,glu::ApiType type,ConfigList & configList)59 static void getDefaultEglConfigList(tcu::Platform& eglPlatform, glu::ApiType type, ConfigList& configList)
60 {
61 deUint32 renderableMask = 0;
62 deUint32 conformantMask = 0;
63
64 if (type == glu::ApiType::es(2, 0))
65 {
66 renderableMask = EGL_OPENGL_ES2_BIT;
67 conformantMask = EGL_OPENGL_ES2_BIT;
68 }
69 else if (type == glu::ApiType::es(3, 0))
70 {
71 renderableMask = EGL_OPENGL_ES3_BIT_KHR;
72 conformantMask = EGL_OPENGL_ES3_BIT_KHR;
73 }
74 else if (type == glu::ApiType::es(3, 1))
75 {
76 renderableMask = EGL_OPENGL_ES3_BIT_KHR;
77 conformantMask = EGL_OPENGL_ES3_BIT_KHR;
78 }
79 else if (type == glu::ApiType::es(3, 2))
80 {
81 renderableMask = EGL_OPENGL_ES3_BIT_KHR;
82 conformantMask = EGL_OPENGL_ES3_BIT_KHR;
83 }
84 else if (type.getProfile() == glu::PROFILE_CORE)
85 {
86 renderableMask = EGL_OPENGL_BIT;
87 conformantMask = EGL_OPENGL_BIT;
88 }
89 else
90 {
91 throw tcu::Exception("Unsupported context type");
92 }
93
94 de::UniquePtr<eglu::NativeDisplay> nativeDisplay(
95 eglPlatform.getEGLPlatform().getNativeDisplayFactoryRegistry().getDefaultFactory()->createDisplay());
96 const eglw::Library& library = nativeDisplay->getLibrary();
97 eglw::EGLDisplay display = eglu::getAndInitDisplay(*nativeDisplay);
98 std::vector<eglw::EGLConfig> configs = eglu::getConfigs(library, display);
99 bool supportFloatConfigs = eglu::hasExtension(library, display, "EGL_EXT_pixel_format_float");
100 bool supportYUVConfigs = eglu::hasExtension(library, display, "EGL_EXT_yuv_surface");
101
102 for (std::vector<eglw::EGLConfig>::iterator cfgIter = configs.begin(); cfgIter != configs.end(); cfgIter++)
103 {
104 int id = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_CONFIG_ID);
105 deUint32 renderableBits = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_RENDERABLE_TYPE);
106 deUint32 conformantBits = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_CONFORMANT);
107 deInt32 redSize = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_RED_SIZE);
108 deInt32 greenSize = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_GREEN_SIZE);
109 deInt32 blueSize = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_BLUE_SIZE);
110 deInt32 alphaSize = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_ALPHA_SIZE);
111 deInt32 depthSize = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_DEPTH_SIZE);
112 deInt32 stencilSize = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_STENCIL_SIZE);
113 deInt32 numSamples = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_SAMPLES);
114
115 bool isRenderable = (renderableBits & renderableMask) == renderableMask;
116 bool isConformant = (conformantBits & conformantMask) == conformantMask;
117 bool isAOSPOk = isRenderable && isConformant;
118 bool isFloatType = supportFloatConfigs ?
119 (eglu::getConfigAttribInt(library, display, *cfgIter, EGL_COLOR_COMPONENT_TYPE_EXT) ==
120 EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT) :
121 false;
122 bool isYUV =
123 supportYUVConfigs ?
124 (eglu::getConfigAttribInt(library, display, *cfgIter, EGL_COLOR_BUFFER_TYPE) == EGL_YUV_BUFFER_EXT) :
125 false;
126 bool isOk = isRenderable && isConformant && (numSamples == 0) && !isFloatType && !isYUV;
127
128 deUint32 surfaceBits = eglu::getConfigAttribInt(library, display, *cfgIter, EGL_SURFACE_TYPE);
129 deUint32 surfaceTypes = ((surfaceBits & EGL_WINDOW_BIT) ? SURFACETYPE_WINDOW : 0) |
130 ((surfaceBits & EGL_PIXMAP_BIT) ? SURFACETYPE_PIXMAP : 0) |
131 ((surfaceBits & EGL_PBUFFER_BIT) ? SURFACETYPE_PBUFFER : 0);
132
133 if (isAOSPOk)
134 {
135 configList.aospConfigs.push_back(AOSPConfig(CONFIGTYPE_EGL, id, surfaceTypes, redSize, greenSize, blueSize,
136 alphaSize, depthSize, stencilSize, numSamples));
137 }
138
139 if (isOk)
140 {
141 configList.configs.push_back(Config(CONFIGTYPE_EGL, id, surfaceTypes));
142 }
143 else
144 {
145 DE_ASSERT(!isRenderable || !isConformant || (numSamples != 0) || isFloatType || isYUV);
146 configList.excludedConfigs.push_back(
147 ExcludedConfig(CONFIGTYPE_EGL, id,
148 !isRenderable ? EXCLUDEREASON_NOT_COMPATIBLE :
149 !isConformant ? EXCLUDEREASON_NOT_CONFORMANT :
150 (numSamples != 0) ?
151 EXCLUDEREASON_MSAA :
152 isFloatType ? EXCLUDEREASON_FLOAT : EXCLUDEREASON_YUV));
153 }
154 }
155 eglu::terminateDisplay(library, display);
156 }
157
getConfigListEGL(tcu::Platform & platform,glu::ApiType type,ConfigList & configList)158 void getConfigListEGL(tcu::Platform& platform, glu::ApiType type, ConfigList& configList)
159 {
160 try
161 {
162 getDefaultEglConfigList(platform, type, configList);
163 }
164 catch (const std::bad_cast&)
165 {
166 throw tcu::Exception("Platform is not tcu::EglPlatform");
167 }
168 }
169
170 } // glcts
171