2 * Copyright (C) 2010 LunarG Inc.
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 shall be included
12 * in all copies or substantial portions of the Software.
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
20 * DEALINGS IN THE SOFTWARE.
23 * Chia-I Wu <olv@lunarg.com>
30 #define EGL_EGLEXT_PROTOTYPES
32 #include "EGL/eglext.h"
38 static EGLScreenMESA kms_screen;
39 static EGLModeMESA kms_mode;
40 static EGLint kms_width, kms_height;
43 _eglutNativeInitDisplay(void)
45 _eglut->native_dpy = EGL_DEFAULT_DISPLAY;
46 _eglut->surface_type = EGL_SCREEN_BIT_MESA;
50 _eglutNativeFiniDisplay(void)
61 EGLModeMESA modes[MAX_MODES];
62 EGLint num_screens, num_modes;
63 EGLint width, height, best_mode;
66 if (!eglGetScreensMESA(_eglut->dpy, &kms_screen, 1, &num_screens) ||
68 _eglutFatal("eglGetScreensMESA failed\n");
70 if (!eglGetModesMESA(_eglut->dpy, kms_screen,
71 modes, MAX_MODES, &num_modes) || !num_modes)
72 _eglutFatal("eglGetModesMESA failed!\n");
74 printf("Found %d modes:\n", num_modes);
79 for (i = 0; i < num_modes; i++) {
81 eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_WIDTH, &w);
82 eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_HEIGHT, &h);
83 printf("%3d: %d x %d\n", i, w, h);
84 if (w > width && h > height) {
91 printf("Will use screen size: %d x %d\n", width, height);
93 kms_mode = modes[best_mode];
99 _eglutNativeInitWindow(struct eglut_window *win, const char *title,
100 int x, int y, int w, int h)
102 EGLint surf_attribs[16];
106 exts = eglQueryString(_eglut->dpy, EGL_EXTENSIONS);
107 if (!exts || !strstr(exts, "EGL_MESA_screen_surface"))
108 _eglutFatal("EGL_MESA_screen_surface is not supported\n");
113 surf_attribs[i++] = EGL_WIDTH;
114 surf_attribs[i++] = kms_width;
115 surf_attribs[i++] = EGL_HEIGHT;
116 surf_attribs[i++] = kms_height;
117 surf_attribs[i++] = EGL_NONE;
120 win->native.u.surface = eglCreateScreenSurfaceMESA(_eglut->dpy,
121 win->config, surf_attribs);
122 if (win->native.u.surface == EGL_NO_SURFACE)
123 _eglutFatal("eglCreateScreenSurfaceMESA failed\n");
125 if (!eglShowScreenSurfaceMESA(_eglut->dpy, kms_screen,
126 win->native.u.surface, kms_mode))
127 _eglutFatal("eglShowScreenSurfaceMESA failed\n");
129 win->native.width = kms_width;
130 win->native.height = kms_height;
134 _eglutNativeFiniWindow(struct eglut_window *win)
136 eglShowScreenSurfaceMESA(_eglut->dpy,
137 kms_screen, EGL_NO_SURFACE, 0);
138 eglDestroySurface(_eglut->dpy, win->native.u.surface);
142 _eglutNativeEventLoop(void)
144 int start = _eglutNow();
147 _eglut->redisplay = 1;
150 struct eglut_window *win = _eglut->current;
151 int now = _eglutNow();
153 if (now - start > 5000) {
154 double elapsed = (double) (now - start) / 1000.0;
156 printf("%d frames in %3.1f seconds = %6.3f FPS\n",
157 frames, elapsed, frames / elapsed);
164 if (win->keyboard_cb)
165 win->keyboard_cb(27);
171 if (_eglut->redisplay) {
172 _eglut->redisplay = 0;
176 eglSwapBuffers(_eglut->dpy, win->surface);