blob: ad2bceebe5364deaff0fbc22fa87ca11ffe06ce6 [file] [log] [blame]
Neil Roberts40c0c3f2013-10-29 20:13:45 +00001/*
2 * Copyright © 2013 Intel Corporation
3 *
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.
13 *
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.
21 */
22
23#include <string.h>
24
25#include "weston-test-client-helper.h"
26#include <stdio.h>
27#include <poll.h>
28#include <time.h>
29
30#include <EGL/egl.h>
31#include <wayland-egl.h>
32#include <GLES2/gl2.h>
33
34struct test_data {
35 struct client *client;
36
37 EGLDisplay egl_dpy;
38 EGLContext egl_ctx;
39 EGLConfig egl_conf;
40 EGLSurface egl_surface;
41};
42
43static void
44init_egl(struct test_data *test_data)
45{
46 struct wl_egl_window *native_window;
47 struct surface *surface = test_data->client->surface;
48
49 static const EGLint context_attribs[] = {
50 EGL_CONTEXT_CLIENT_VERSION, 2,
51 EGL_NONE
52 };
53
54 EGLint config_attribs[] = {
55 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
56 EGL_RED_SIZE, 1,
57 EGL_GREEN_SIZE, 1,
58 EGL_BLUE_SIZE, 1,
59 EGL_ALPHA_SIZE, 0,
60 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
61 EGL_NONE
62 };
63
64 EGLint major, minor, n;
65 EGLBoolean ret;
66
67 test_data->egl_dpy = eglGetDisplay((EGLNativeDisplayType)
68 test_data->client->wl_display);
69 assert(test_data->egl_dpy);
70
71 ret = eglInitialize(test_data->egl_dpy, &major, &minor);
72 assert(ret == EGL_TRUE);
73 ret = eglBindAPI(EGL_OPENGL_ES_API);
74 assert(ret == EGL_TRUE);
75
76 ret = eglChooseConfig(test_data->egl_dpy, config_attribs,
77 &test_data->egl_conf, 1, &n);
78 assert(ret && n == 1);
79
80 test_data->egl_ctx = eglCreateContext(test_data->egl_dpy,
81 test_data->egl_conf,
82 EGL_NO_CONTEXT, context_attribs);
83 assert(test_data->egl_ctx);
84
85 native_window =
86 wl_egl_window_create(surface->wl_surface,
87 surface->width,
88 surface->height);
89 test_data->egl_surface =
90 eglCreateWindowSurface(test_data->egl_dpy,
91 test_data->egl_conf,
92 (EGLNativeWindowType) native_window,
93 NULL);
94
95 ret = eglMakeCurrent(test_data->egl_dpy, test_data->egl_surface,
96 test_data->egl_surface, test_data->egl_ctx);
97 assert(ret == EGL_TRUE);
98}
99
100TEST(test_buffer_count)
101{
102 struct test_data test_data;
103 uint32_t buffer_count;
104 int i;
105
106 test_data.client = client_create(10, 10, 10, 10);
107 init_egl(&test_data);
108
109 /* This is meant to represent a typical game loop which is
110 * expecting eglSwapBuffers to block and throttle the
111 * rendering to a sensible frame rate. Therefore it doesn't
112 * expect to have to install a frame callback itself. I'd
113 * imagine this is what a typical SDL game would end up
114 * doing */
115
116 for (i = 0; i < 10; i++) {
117 glClear(GL_COLOR_BUFFER_BIT);
118 eglSwapBuffers(test_data.egl_dpy, test_data.egl_surface);
119 }
120
121 buffer_count = get_n_egl_buffers(test_data.client);
122
123 printf("buffers used = %i\n", buffer_count);
124
125 /* The implementation should only end up creating two buffers
126 * and cycling between them */
127 assert(buffer_count == 2);
128}