2 * Copyright (c) Intel 2011
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "piglit-util-egl.h"
26 const char* piglit_get_egl_error_name(EGLint error
) {
27 #define CASE(x) case x: return #x;
33 CASE(EGL_BAD_ATTRIBUTE
)
36 CASE(EGL_BAD_CURRENT_SURFACE
)
39 CASE(EGL_BAD_NATIVE_PIXMAP
)
40 CASE(EGL_BAD_NATIVE_WINDOW
)
41 CASE(EGL_BAD_PARAMETER
)
43 CASE(EGL_CONTEXT_LOST
)
44 CASE(EGL_NOT_INITIALIZED
)
46 return "(unrecognized error)";
52 piglit_check_egl_error(EGLint expected_error
)
56 actual_error
= eglGetError();
57 if (actual_error
== expected_error
) {
62 * If the lookup of the error's name is successful, then print
63 * Unexpected EGL error: NAME 0xHEX
65 * Unexpected EGL error: 0xHEX
67 printf("Unexpected EGL error: %s 0x%x\n",
68 piglit_get_egl_error_name(actual_error
), actual_error
);
70 /* Print the expected error, but only if an error was really expected. */
71 if (expected_error
!= EGL_SUCCESS
) {
72 printf("Expected EGL error: %s 0x%x\n",
73 piglit_get_egl_error_name(expected_error
), expected_error
);
80 piglit_egl_get_default_display(EGLenum platform
)
82 return piglit_egl_get_display(platform
, EGL_DEFAULT_DISPLAY
);
86 piglit_egl_get_display(EGLenum platform
, void *native_display
)
88 static bool once
= true;
90 static bool has_base
= false;
91 static bool has_x11
= false;
92 static bool has_wayland
= false;
93 static bool has_gbm
= false;
94 static bool has_surfaceless_mesa
= false;
96 static EGLDisplay (*peglGetPlatformDisplayEXT
)(EGLenum platform
, void *native_display
, const EGLint
*attrib_list
);
98 if (platform
== EGL_NONE
) {
99 return eglGetDisplay(native_display
);
105 has_base
= piglit_is_egl_extension_supported(EGL_NO_DISPLAY
, "EGL_EXT_platform_base");
106 has_x11
= piglit_is_egl_extension_supported(EGL_NO_DISPLAY
, "EGL_EXT_platform_x11");
107 has_wayland
= piglit_is_egl_extension_supported(EGL_NO_DISPLAY
, "EGL_EXT_platform_wayland");
108 has_gbm
= piglit_is_egl_extension_supported(EGL_NO_DISPLAY
, "EGL_EXT_platform_gbm");
109 has_surfaceless_mesa
= piglit_is_egl_extension_supported(EGL_NO_DISPLAY
, "EGL_MESA_platform_surfaceless");
111 peglGetPlatformDisplayEXT
= (void*) eglGetProcAddress("eglGetPlatformDisplayEXT");
115 return EGL_NO_DISPLAY
;
119 case EGL_PLATFORM_X11_EXT
:
121 return EGL_NO_DISPLAY
;
124 case EGL_PLATFORM_WAYLAND_EXT
:
126 return EGL_NO_DISPLAY
;
129 case EGL_PLATFORM_GBM_MESA
:
131 return EGL_NO_DISPLAY
;
134 case EGL_PLATFORM_SURFACELESS_MESA
:
135 if (!has_surfaceless_mesa
) {
136 return EGL_NO_DISPLAY
;
140 fprintf(stderr
, "%s: unrecognized platform %#x\n", __func__
, platform
);
141 return EGL_NO_DISPLAY
;
144 return peglGetPlatformDisplayEXT(platform
, native_display
, NULL
);
148 piglit_is_egl_extension_supported(EGLDisplay egl_dpy
, const char *name
)
150 const char *const egl_extension_list
=
151 eglQueryString(egl_dpy
, EGL_EXTENSIONS
);
154 * If EGL does not support EGL_EXT_client_extensions, then
155 * eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS) returns NULL and
156 * generates EGL_BAD_DISPLAY. In this case, just report that the
157 * requested (client) extension is not supported.
159 if (!egl_extension_list
&& egl_dpy
== EGL_NO_DISPLAY
&&
160 piglit_check_egl_error(EGL_BAD_DISPLAY
))
163 return piglit_is_extension_in_string(egl_extension_list
, name
);
166 void piglit_require_egl_extension(EGLDisplay dpy
, const char *name
)
168 if (!piglit_is_egl_extension_supported(dpy
, name
)) {
169 printf("Test requires %s\n", name
);
170 piglit_report_result(PIGLIT_SKIP
);
175 piglit_egl_bind_api(EGLenum api
)
177 const char *api_string
= "";
182 if (api
== EGL_OPENGL_API
)
183 api_string
= "EGL_OPENGL_API";
184 else if (api
== EGL_OPENGL_ES_API
)
185 api_string
= "EGL_OPENGL_ES_API";
189 if (piglit_check_egl_error(EGL_BAD_PARAMETER
)) {
190 fprintf(stderr
, "eglBindAPI(%s) failed because EGL "
191 "does not support the API\n",
195 fprintf(stderr
, "unexpected error for "
198 piglit_report_result(PIGLIT_FAIL
);