Merge branch 'mesa_7_6_branch' into mesa_7_7_branch
[mesa.git] / progs / egl / eglscreen.c
1 /*
2 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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 shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22 /*
23 * Stolen from eglgears
24 *
25 * Creates a surface and show that on the first screen
26 */
27
28 #define EGL_EGLEXT_PROTOTYPES
29
30 #include <assert.h>
31 #include <math.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <unistd.h>
36 #include <GL/gl.h>
37 #include <EGL/egl.h>
38 #include <EGL/eglext.h>
39
40 #define MAX_CONFIGS 10
41 #define MAX_MODES 100
42
43 int
44 main(int argc, char *argv[])
45 {
46 int maj, min;
47 EGLSurface screen_surf;
48 EGLConfig configs[MAX_CONFIGS];
49 EGLint numConfigs, i;
50 EGLBoolean b;
51 EGLDisplay d;
52 EGLint screenAttribs[10];
53 EGLModeMESA mode[MAX_MODES];
54 EGLScreenMESA screen;
55 EGLint count, chosenMode;
56 EGLint width = 0, height = 0;
57
58 d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
59 assert(d);
60
61 if (!eglInitialize(d, &maj, &min)) {
62 printf("eglscreen: eglInitialize failed\n");
63 exit(1);
64 }
65
66 printf("eglscreen: EGL version = %d.%d\n", maj, min);
67 printf("eglscreen: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
68
69 /* XXX use ChooseConfig */
70 eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
71 eglGetScreensMESA(d, &screen, 1, &count);
72
73 if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) {
74 printf("eglscreen: eglGetModesMESA failed!\n");
75 return 0;
76 }
77
78 /* Print list of modes, and find the one to use */
79 printf("eglscreen: Found %d modes:\n", count);
80 for (i = 0; i < count; i++) {
81 EGLint w, h;
82 eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w);
83 eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h);
84 printf("%3d: %d x %d\n", i, w, h);
85 if (w > width && h > height) {
86 width = w;
87 height = h;
88 chosenMode = i;
89 }
90 }
91 printf("eglscreen: Using screen mode/size %d: %d x %d\n", chosenMode, width, height);
92
93 /* build up screenAttribs array */
94 i = 0;
95 screenAttribs[i++] = EGL_WIDTH;
96 screenAttribs[i++] = width;
97 screenAttribs[i++] = EGL_HEIGHT;
98 screenAttribs[i++] = height;
99 screenAttribs[i++] = EGL_NONE;
100
101 screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
102 if (screen_surf == EGL_NO_SURFACE) {
103 printf("eglscreen: Failed to create screen surface\n");
104 return 0;
105 }
106
107 b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]);
108 if (!b) {
109 printf("eglscreen: Show surface failed\n");
110 return 0;
111 }
112
113 usleep(5000000);
114
115 eglDestroySurface(d, screen_surf);
116 eglTerminate(d);
117
118 return 0;
119 }