1 /* Copyright © 2011 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "piglit-util-gl.h"
25 #include "piglit-glx-util.h"
28 PFNGLXGETCURRENTDISPLAYEXTPROC __piglit_glXGetCurrentDisplayEXT
= NULL
;
29 PFNGLXQUERYCONTEXTINFOEXTPROC __piglit_glXQueryContextInfoEXT
= NULL
;
30 PFNGLXGETCONTEXTIDEXTPROC __piglit_glXGetContextIDEXT
= NULL
;
31 PFNGLXIMPORTCONTEXTEXTPROC __piglit_glXImportContextEXT
= NULL
;
32 PFNGLXFREECONTEXTEXTPROC __piglit_glXFreeContextEXT
= NULL
;
34 #define ADD_FUNC(name) PIGLIT_GLX_PROC(__piglit_##name, name)
35 static const struct piglit_glx_proc_reference procedures
[] = {
36 ADD_FUNC(glXGetCurrentDisplayEXT
),
37 ADD_FUNC(glXQueryContextInfoEXT
),
38 ADD_FUNC(glXGetContextIDEXT
),
39 ADD_FUNC(glXImportContextEXT
),
40 ADD_FUNC(glXFreeContextEXT
),
44 XVisualInfo
*visinfo
= NULL
;
45 GLXContext directCtx
= NULL
;
46 GLXContextID directID
= None
;
47 GLXContext indirectCtx
= NULL
;
48 GLXContextID indirectID
= None
;
50 int glx_error_code
= -1;
51 int x_error_code
= Success
;
53 int piglit_height
= 50;
54 int piglit_width
= 50;
56 static int (*old_handler
)(Display
*, XErrorEvent
*);
58 static int x_error_handler(Display
*dpy
, XErrorEvent
*e
)
61 x_error_code
= e
->error_code
;
62 glx_error_code
= piglit_glx_get_error(dpy
, e
);
67 void GLX_EXT_import_context_setup_for_child(void)
69 dpy
= piglit_get_glx_display();
70 old_handler
= XSetErrorHandler(x_error_handler
);
73 void GLX_EXT_import_context_setup(void)
77 dpy
= piglit_get_glx_display();
79 /* NVIDIA incorrectly only list the extension in the client
80 * extensions list. If the extension is available for applications
81 * to use, it is supposed to be included in the list returned by
82 * glXQueryExtensionsString.
84 * The glXImportContextEXT manual page is somewhat clear on this
87 * "If _glxextstring(EXT_import_context) is included in the string
88 * returned by glXQueryExtensionsString, when called with argument
89 * GLX_EXTENSIONS, extension EXT_import_context is supported."
91 * The text is a little weird because the only parameters to
92 * glXQueryExtensionsString are the display and the screen.
94 vendor
= glXGetClientString(dpy
, GLX_VENDOR
);
95 if (strcmp("NVIDIA Corporation", vendor
) == 0) {
96 const char *const client_extensions
=
97 glXGetClientString(dpy
, GLX_EXTENSIONS
);
99 if (!piglit_is_extension_in_string(client_extensions
,
100 "GLX_EXT_import_context")) {
101 printf("Test requires GLX_EXT_import_context.\n");
102 piglit_report_result(PIGLIT_SKIP
);
105 piglit_require_glx_extension(dpy
, "GLX_EXT_import_context");
108 piglit_glx_get_all_proc_addresses(procedures
, ARRAY_SIZE(procedures
));
110 visinfo
= piglit_get_glx_visual(dpy
);
112 directCtx
= glXCreateContext(dpy
, visinfo
, NULL
, True
);
113 if (directCtx
== NULL
) {
115 "Could not create initial direct-rendering context.\n");
116 piglit_report_result(PIGLIT_FAIL
);
119 if (!glXIsDirect(dpy
, directCtx
)) {
120 glXDestroyContext(dpy
, directCtx
);
124 indirectCtx
= glXCreateContext(dpy
, visinfo
, NULL
, False
);
125 if (indirectCtx
== NULL
) {
127 "Could not create initial indirect-rendering "
129 piglit_report_result(PIGLIT_FAIL
);
132 piglit_glx_get_error(dpy
, NULL
);
133 old_handler
= XSetErrorHandler(x_error_handler
);
136 void GLX_EXT_import_context_teardown(void)
138 if (directCtx
!= NULL
) {
139 glXDestroyContext(dpy
, directCtx
);
143 if (indirectCtx
!= NULL
) {
144 glXDestroyContext(dpy
, indirectCtx
);
151 XSetErrorHandler(old_handler
);
154 void get_context_IDs(void)
157 if (directCtx
!= NULL
) {
158 directID
= glXGetContextIDEXT(directCtx
);
162 if (indirectCtx
!= NULL
) {
163 indirectID
= glXGetContextIDEXT(indirectCtx
);
167 const char *context_mode_name(enum context_mode mode
)
170 case direct_rendering
:
171 return "direct-rendering";
172 case indirect_rendering
:
173 return "indirect-rendering";
177 assert(!"Should not get here.");
178 piglit_report_result(PIGLIT_FAIL
);
184 bool try_import_context(GLXContextID id
, enum context_mode mode
)
186 const int expected_glx_error
= (mode
== invalid
) ? GLXBadContext
: -1;
188 GLXContext ctx
= glXImportContextEXT(dpy
, id
);
193 case direct_rendering
:
196 "Could import direct-rendering context, "
197 "but should have failed.\n");
202 case indirect_rendering
:
205 "Could not import indirect-rendering context, "
206 "but should have succeeded.\n");
214 "Could import invalid context (0x%08x), "
215 "but should have failed.\n",
222 assert(mode
!= invalid
|| expected_glx_error
!= -1);
223 pass
= validate_glx_error_code(Success
, expected_glx_error
) && pass
;
226 fprintf(stderr
, "Context ID = 0x%08x.\n", (int) id
);
229 glXFreeContextEXT(dpy
, ctx
);
234 bool validate_glx_error_code(int expected_x_error
, int expected_glx_error
)
238 if (expected_glx_error
== -1
239 && expected_x_error
== Success
240 && (glx_error_code
!= -1 || x_error_code
!= Success
)) {
242 "X error %d (%s (%d)) was generated, but "
243 "no error was expected.\n",
245 piglit_glx_error_string(glx_error_code
),
250 if (expected_glx_error
!= -1
251 && glx_error_code
!= expected_glx_error
) {
253 "X error %d (%s (%d)) was generated, but "
254 "%s (%d) was expected.\n",
256 piglit_glx_error_string(glx_error_code
),
258 piglit_glx_error_string(expected_glx_error
),
261 } else if (expected_x_error
!= Success
262 && x_error_code
!= expected_x_error
) {
264 "X error %d (%s (%d)) was generated, but "
265 "X error %d was expected.\n",
267 piglit_glx_error_string(glx_error_code
),
273 x_error_code
= Success
;