2 * Copyright © 2010 Intel Corporation
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:
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 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
23 * Author: Kristian Høgsberg <krh@bitplanet.net>
26 /** @file egl-nok-swap-region.c
28 * Test EGL_NOK_swap_region.
31 #include "piglit-util.h"
38 static const EGLint attribs
[] = {
39 EGL_SURFACE_TYPE
, EGL_WINDOW_BIT
| EGL_PIXMAP_BIT
| EGL_PBUFFER_BIT
,
44 EGL_RENDERABLE_TYPE
, EGL_OPENGL_BIT
,
49 egl_util_create_pixmap(struct egl_state
*state
,
50 int width
, int height
, const EGLint
*attribs
)
55 pixmap
= XCreatePixmap(state
->dpy
, state
->win
,
56 width
, height
, state
->depth
);
58 surf
= eglCreatePixmapSurface(state
->egl_dpy
, state
->cfg
,
65 create_window(struct egl_state
*state
)
67 XSetWindowAttributes window_attr
;
68 XVisualInfo
template, *vinfo
;
71 int screen
= DefaultScreen(state
->dpy
);
72 Window root_win
= RootWindow(state
->dpy
, screen
);
75 if (!eglGetConfigAttrib(state
->egl_dpy
,
76 state
->cfg
, EGL_NATIVE_VISUAL_ID
, &id
)) {
77 fprintf(stderr
, "eglGetConfigAttrib() failed\n");
78 piglit_report_result(PIGLIT_FAILURE
);
81 template.visualid
= id
;
82 vinfo
= XGetVisualInfo(state
->dpy
, VisualIDMask
, &template, &count
);
84 fprintf(stderr
, "XGetVisualInfo() failed\n");
85 piglit_report_result(PIGLIT_FAILURE
);
88 state
->depth
= vinfo
->depth
;
89 window_attr
.background_pixel
= 0;
90 window_attr
.border_pixel
= 0;
91 window_attr
.colormap
= XCreateColormap(state
->dpy
, root_win
,
92 vinfo
->visual
, AllocNone
);
93 window_attr
.event_mask
=
94 StructureNotifyMask
| ExposureMask
| KeyPressMask
;
95 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
96 state
->win
= XCreateWindow(state
->dpy
, root_win
, 0, 0,
97 state
->width
, state
->height
,
98 0, vinfo
->depth
, InputOutput
,
99 vinfo
->visual
, mask
, &window_attr
);
101 XMapWindow(state
->dpy
, state
->win
);
106 static enum piglit_result
107 event_loop(struct egl_state
*state
, const struct egl_test
*test
)
110 enum piglit_result result
= PIGLIT_FAILURE
;
113 XNextEvent (state
->dpy
, &event
);
115 if (event
.type
== Expose
) {
116 result
= test
->draw(state
);
121 if (event
.type
== KeyPress
) {
122 KeySym sym
= XKeycodeToKeysym (state
->dpy
,
123 event
.xkey
.keycode
, 0);
125 if (sym
== XK_Escape
|| sym
== XK_q
|| sym
== XK_Q
)
134 check_extensions(struct egl_state
*state
, const struct egl_test
*test
)
136 const char *extensions
;
139 extensions
= eglQueryString(state
->egl_dpy
, EGL_EXTENSIONS
);
140 for (i
= 0; test
->extensions
[i
]; i
++) {
141 if (!strstr(extensions
, test
->extensions
[i
])) {
142 fprintf(stderr
, "missing extension %s\n",
143 test
->extensions
[i
]);
144 piglit_report_result(PIGLIT_SKIP
);
150 egl_util_run(const struct egl_test
*test
, int argc
, char *argv
[])
152 struct egl_state state
;
154 enum piglit_result result
;
157 for (i
= 1; i
< argc
; ++i
) {
158 if (!strcmp(argv
[i
], "-auto"))
161 fprintf(stderr
, "Unknown option: %s\n", argv
[i
]);
164 state
.dpy
= XOpenDisplay(NULL
);
165 if (state
.dpy
== NULL
) {
166 fprintf(stderr
, "couldn't open display\n");
167 piglit_report_result(PIGLIT_FAILURE
);
170 eglBindAPI(EGL_OPENGL_API
);
172 state
.egl_dpy
= eglGetDisplay(state
.dpy
);
173 if (state
.egl_dpy
== EGL_NO_DISPLAY
) {
174 fprintf(stderr
, "eglGetDisplay() failed\n");
175 piglit_report_result(PIGLIT_FAILURE
);
178 if (!eglInitialize(state
.egl_dpy
, &state
.major
, &state
.minor
)) {
179 fprintf(stderr
, "eglInitialize() failed\n");
180 piglit_report_result(PIGLIT_FAILURE
);
183 check_extensions(&state
, test
);
185 if (!eglChooseConfig(state
.egl_dpy
, attribs
, &state
.cfg
, 1, &count
) ||
187 fprintf(stderr
, "eglChooseConfig() failed\n");
188 piglit_report_result(PIGLIT_FAILURE
);
191 state
.ctx
= eglCreateContext(state
.egl_dpy
, state
.cfg
,
192 EGL_NO_CONTEXT
, NULL
);
193 if (state
.ctx
== EGL_NO_CONTEXT
) {
194 fprintf(stderr
, "eglCreateContext() failed\n");
195 piglit_report_result(PIGLIT_FAILURE
);
200 create_window(&state
);
202 state
.surf
= eglCreateWindowSurface(state
.egl_dpy
,
203 state
.cfg
, state
.win
, NULL
);
204 if (state
.surf
== EGL_NO_SURFACE
) {
205 fprintf(stderr
, "eglCreateWindowSurface() failed\n");
206 piglit_report_result(PIGLIT_FAILURE
);
209 if (!eglMakeCurrent(state
.egl_dpy
,
210 state
.surf
, state
.surf
, state
.ctx
)) {
211 fprintf(stderr
, "eglMakeCurrent() failed\n");
212 piglit_report_result(PIGLIT_FAILURE
);
215 result
= event_loop(&state
, test
);
217 eglTerminate(state
.egl_dpy
);
219 piglit_report_result(result
);