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")) {
102 "Test requires GLX_EXT_import_context.\n");
103 piglit_report_result(PIGLIT_SKIP
);
106 piglit_require_glx_extension(dpy
, "GLX_EXT_import_context");
109 piglit_glx_get_all_proc_addresses(procedures
, ARRAY_SIZE(procedures
));
111 visinfo
= piglit_get_glx_visual(dpy
);
113 directCtx
= glXCreateContext(dpy
, visinfo
, NULL
, True
);
114 if (directCtx
== NULL
) {
116 "Could not create initial direct-rendering context.\n");
117 piglit_report_result(PIGLIT_FAIL
);
120 if (!glXIsDirect(dpy
, directCtx
)) {
121 glXDestroyContext(dpy
, directCtx
);
125 indirectCtx
= glXCreateContext(dpy
, visinfo
, NULL
, False
);
126 if (indirectCtx
== NULL
) {
128 "Could not create initial indirect-rendering "
130 piglit_report_result(PIGLIT_FAIL
);
133 piglit_glx_get_error(dpy
, NULL
);
134 old_handler
= XSetErrorHandler(x_error_handler
);
137 void GLX_EXT_import_context_teardown(void)
139 if (directCtx
!= NULL
) {
140 glXDestroyContext(dpy
, directCtx
);
144 if (indirectCtx
!= NULL
) {
145 glXDestroyContext(dpy
, indirectCtx
);
152 XSetErrorHandler(old_handler
);
155 void get_context_IDs(void)
158 if (directCtx
!= NULL
) {
159 directID
= glXGetContextIDEXT(directCtx
);
163 if (indirectCtx
!= NULL
) {
164 indirectID
= glXGetContextIDEXT(indirectCtx
);
168 const char *context_mode_name(enum context_mode mode
)
171 case direct_rendering
:
172 return "direct-rendering";
173 case indirect_rendering
:
174 return "indirect-rendering";
178 assert(!"Should not get here.");
179 piglit_report_result(PIGLIT_FAIL
);
185 bool try_import_context(GLXContextID id
, enum context_mode mode
)
187 const int expected_glx_error
= (mode
== invalid
) ? GLXBadContext
: -1;
189 GLXContext ctx
= glXImportContextEXT(dpy
, id
);
194 case direct_rendering
:
197 "Could import direct-rendering context, "
198 "but should have failed.\n");
203 case indirect_rendering
:
206 "Could not import indirect-rendering context, "
207 "but should have succeeded.\n");
215 "Could import invalid context (0x%08x), "
216 "but should have failed.\n",
223 assert(mode
!= invalid
|| expected_glx_error
!= -1);
224 pass
= validate_glx_error_code(Success
, expected_glx_error
) && pass
;
227 fprintf(stderr
, "Context ID = 0x%08x.\n", (int) id
);
230 glXFreeContextEXT(dpy
, ctx
);
235 bool validate_glx_error_code(int expected_x_error
, int expected_glx_error
)
239 if (expected_glx_error
== -1
240 && expected_x_error
== Success
241 && (glx_error_code
!= -1 || x_error_code
!= Success
)) {
243 "X error %d (%s (%d)) was generated, but "
244 "no error was expected.\n",
246 piglit_glx_error_string(glx_error_code
),
251 if (expected_glx_error
!= -1
252 && glx_error_code
!= expected_glx_error
) {
254 "X error %d (%s (%d)) was generated, but "
255 "%s (%d) was expected.\n",
257 piglit_glx_error_string(glx_error_code
),
259 piglit_glx_error_string(expected_glx_error
),
262 } else if (expected_x_error
!= Success
263 && x_error_code
!= expected_x_error
) {
265 "X error %d (%s (%d)) was generated, but "
266 "X error %d was expected.\n",
268 piglit_glx_error_string(glx_error_code
),
274 x_error_code
= Success
;