1 /*
2  * Copyright © 2010 Intel Corporation
3  *
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  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
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
13  * Software.
14  *
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 NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Eric Anholt <eric@anholt.net>
25  *
26  */
27 
28 /** @file glx-destroycontext-2.c
29  *
30  * Test that MakeCurrent after destroying a context bound to the
31  * current thread works correctly.
32  */
33 
34 #include "piglit-util-gl.h"
35 #include "piglit-glx-util.h"
36 
37 int piglit_width = 50, piglit_height = 50;
38 static Display *dpy;
39 static Window win;
40 static XVisualInfo *visinfo;
41 
42 enum piglit_result
draw(Display * dpy)43 draw(Display *dpy)
44 {
45 	GLboolean pass = GL_TRUE;
46 	float green[] = {0.0, 1.0, 0.0, 0.0};
47 	GLXContext ctx;
48 
49 	ctx = piglit_get_glx_context(dpy, visinfo);
50 	glXMakeCurrent(dpy, win, ctx);
51 	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
52 	glClearColor(1.0, 0.0, 0.0, 1.0);
53 	glClear(GL_COLOR_BUFFER_BIT);
54 	glXDestroyContext(dpy, ctx);
55 
56 	ctx = piglit_get_glx_context(dpy, visinfo);
57 	glXMakeCurrent(dpy, win, ctx);
58 
59 	glClearColor(0.0, 1.0, 0.0, 1.0);
60 	glClear(GL_COLOR_BUFFER_BIT);
61 
62 	pass &= piglit_probe_pixel_rgb(1, 1, green);
63 
64 	glXSwapBuffers(dpy, win);
65 
66 	/* Free our resources when we're done. */
67 	glXMakeCurrent(dpy, None, NULL);
68 	glXDestroyContext(dpy, ctx);
69 
70 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
71 }
72 
73 int
main(int argc,char ** argv)74 main(int argc, char **argv)
75 {
76 	int i;
77 
78 	for(i = 1; i < argc; ++i) {
79 		if (!strcmp(argv[i], "-auto"))
80 			piglit_automatic = 1;
81 		else
82 			fprintf(stderr, "Unknown option: %s\n", argv[i]);
83 	}
84 
85 	dpy = XOpenDisplay(NULL);
86 	if (dpy == NULL) {
87 		fprintf(stderr, "couldn't open display\n");
88 		piglit_report_result(PIGLIT_FAIL);
89 	}
90 	visinfo = piglit_get_glx_visual(dpy);
91 	win = piglit_get_glx_window(dpy, visinfo);
92 
93 	XMapWindow(dpy, win);
94 
95 	piglit_glx_event_loop(dpy, draw);
96 
97 	return 0;
98 }
99