Merge branch '7.8'
[mesa.git] / progs / egl / opengl / 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;
56 EGLint chosenMode = 0;
57 EGLint width = 0, height = 0;
58
59 d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
60 assert(d);
61
62 if (!eglInitialize(d, &maj, &min)) {
63 printf("eglscreen: eglInitialize failed\n");
64 exit(1);
65 }
66
67 printf("eglscreen: EGL version = %d.%d\n", maj, min);
68 printf("eglscreen: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
69
70 /* XXX use ChooseConfig */
71 eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
72 eglGetScreensMESA(d, &screen, 1, &count);
73
74 if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) {
75 printf("eglscreen: eglGetModesMESA failed!\n");
76 return 0;
77 }
78
79 /* Print list of modes, and find the one to use */
80 printf("eglscreen: Found %d modes:\n", count);
81 for (i = 0; i < count; i++) {
82 EGLint w, h;
83 eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w);
84 eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h);
85 printf("%3d: %d x %d\n", i, w, h);
86 if (w > width && h > height) {
87 width = w;
88 height = h;
89 chosenMode = i;
90 }
91 }
92 printf("eglscreen: Using screen mode/size %d: %d x %d\n", chosenMode, width, height);
93
94 /* build up screenAttribs array */
95 i = 0;
96 screenAttribs[i++] = EGL_WIDTH;
97 screenAttribs[i++] = width;
98 screenAttribs[i++] = EGL_HEIGHT;
99 screenAttribs[i++] = height;
100 screenAttribs[i++] = EGL_NONE;
101
102 screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
103 if (screen_surf == EGL_NO_SURFACE) {
104 printf("eglscreen: Failed to create screen surface\n");
105 return 0;
106 }
107
108 b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]);
109 if (!b) {
110 printf("eglscreen: Show surface failed\n");
111 return 0;
112 }
113
114 usleep(5000000);
115
116 eglDestroySurface(d, screen_surf);
117 eglTerminate(d);
118
119 return 0;
120 }