2 * Copyright © 2013 Intel Corporation
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 #include "weston-test-client-helper.h"
31 #include <wayland-egl.h>
32 #include <GLES2/gl2.h>
35 struct client *client;
40 EGLSurface egl_surface;
44 init_egl(struct test_data *test_data)
46 struct wl_egl_window *native_window;
47 struct surface *surface = test_data->client->surface;
48 const char *str, *mesa;
50 static const EGLint context_attribs[] = {
51 EGL_CONTEXT_CLIENT_VERSION, 2,
55 EGLint config_attribs[] = {
56 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
61 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
65 EGLint major, minor, n;
68 test_data->egl_dpy = eglGetDisplay((EGLNativeDisplayType)
69 test_data->client->wl_display);
70 assert(test_data->egl_dpy);
72 ret = eglInitialize(test_data->egl_dpy, &major, &minor);
73 assert(ret == EGL_TRUE);
74 ret = eglBindAPI(EGL_OPENGL_ES_API);
75 assert(ret == EGL_TRUE);
77 ret = eglChooseConfig(test_data->egl_dpy, config_attribs,
78 &test_data->egl_conf, 1, &n);
79 assert(ret && n == 1);
81 test_data->egl_ctx = eglCreateContext(test_data->egl_dpy,
83 EGL_NO_CONTEXT, context_attribs);
84 assert(test_data->egl_ctx);
87 wl_egl_window_create(surface->wl_surface,
90 test_data->egl_surface =
91 eglCreateWindowSurface(test_data->egl_dpy,
93 (EGLNativeWindowType) native_window,
96 ret = eglMakeCurrent(test_data->egl_dpy, test_data->egl_surface,
97 test_data->egl_surface, test_data->egl_ctx);
98 assert(ret == EGL_TRUE);
100 /* This test is specific to mesa 10.0 and later, which is the
101 * first release that doesn't accidentally triple-buffer. */
102 str = (const char *) glGetString(GL_VERSION);
103 mesa = strstr(str, "Mesa ");
105 skip("unknown EGL implementation (%s)\n", str);
106 if (sscanf(mesa + 5, "%d.%d", &major, &minor) != 2)
107 skip("unrecognized mesa version (%s)\n", str);
109 skip("mesa version too old (%s)\n", str);
113 TEST(test_buffer_count)
115 struct test_data test_data;
116 uint32_t buffer_count;
119 test_data.client = client_create(10, 10, 10, 10);
120 init_egl(&test_data);
122 /* This is meant to represent a typical game loop which is
123 * expecting eglSwapBuffers to block and throttle the
124 * rendering to a sensible frame rate. Therefore it doesn't
125 * expect to have to install a frame callback itself. I'd
126 * imagine this is what a typical SDL game would end up
129 for (i = 0; i < 10; i++) {
130 glClear(GL_COLOR_BUFFER_BIT);
131 eglSwapBuffers(test_data.egl_dpy, test_data.egl_surface);
134 buffer_count = get_n_egl_buffers(test_data.client);
136 printf("buffers used = %i\n", buffer_count);
138 /* The implementation should only end up creating two buffers
139 * and cycling between them */
140 assert(buffer_count == 2);