fix build
[gltest.git] / eglinfo.c
1 /*
2  * eglinfo - like glxinfo but for EGL
3  *
4  * Brian Paul
5  * 11 March 2005
6  *
7  * Copyright (C) 2005  Brian Paul   All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26
27
28 #include <EGL/egl.h>
29 #include <assert.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #define MAX_CONFIGS 1000
35 #define MAX_MODES 1000
36 #define MAX_SCREENS 10
37
38
39 /**
40  * Print table of all available configurations.
41  */
42 static void
43 PrintConfigs(EGLDisplay d)
44 {
45    EGLConfig configs[MAX_CONFIGS];
46    EGLint numConfigs=0, i;
47
48    eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
49
50    printf("Configurations (%i):\n", numConfigs);
51    printf("     bf lv d st colorbuffer dp st  ms    vis   supported\n");
52    printf("  id sz  l b ro  r  g  b  a th cl ns b    id   surfaces \n");
53    printf("--------------------------------------------------------\n");
54    for (i = 0; i < numConfigs; i++) {
55       EGLint id, size, level;
56       EGLint red, green, blue, alpha;
57       EGLint depth, stencil;
58       EGLint surfaces;
59       EGLint doubleBuf = 1, stereo = 0;
60       EGLint vid;
61       EGLint samples, sampleBuffers;
62       char surfString[100] = "";
63
64       eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
65       eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size);
66       eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level);
67
68       eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
69       eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green);
70       eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue);
71       eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha);
72       eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
73       eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil);
74       eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_ID, &vid);
75       eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces);
76
77       eglGetConfigAttrib(d, configs[i], EGL_SAMPLES, &samples);
78       eglGetConfigAttrib(d, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers);
79
80       if (surfaces & EGL_WINDOW_BIT)
81          strcat(surfString, "win,");
82       if (surfaces & EGL_PBUFFER_BIT)
83          strcat(surfString, "pb,");
84       if (surfaces & EGL_PIXMAP_BIT)
85          strcat(surfString, "pix,");
86 #ifdef EGL_MESA_screen_surface
87       if (surfaces & EGL_SCREEN_BIT_MESA)
88          strcat(surfString, "scrn,");
89 #endif
90       if (strlen(surfString) > 0)
91          surfString[strlen(surfString) - 1] = 0;
92
93       printf("0x%02x %2d %2d %c  %c %2d %2d %2d %2d %2d %2d %2d%2d  0x%02x   %-12s\n",
94              id, size, level,
95              doubleBuf ? 'y' : '.',
96              stereo ? 'y' : '.',
97              red, green, blue, alpha,
98              depth, stencil,
99              samples, sampleBuffers, vid, surfString);
100    }
101 }
102
103
104 /**
105  * If possible, irint table of all available configurations.
106  */
107 static void
108 PrintModes(EGLDisplay d)
109 {
110 #ifdef EGL_MESA_screen_surface
111    const char *extensions = eglQueryString(d, EGL_EXTENSIONS);
112    if (strstr(extensions, "EGL_MESA_screen_surface")) {
113       EGLScreenMESA screens[MAX_SCREENS];
114       EGLint numScreens = 1, scrn;
115       EGLModeMESA modes[MAX_MODES];
116
117       eglGetScreensMESA(d, screens, MAX_SCREENS, &numScreens);
118       printf("Number of Screens: %d\n\n", numScreens);
119
120       for (scrn = 0; scrn < numScreens; scrn++) {
121          EGLint numModes, i;
122
123          eglGetModesMESA(d, screens[scrn], modes, MAX_MODES, &numModes);
124
125          printf("Screen %d Modes:\n", scrn);
126          printf("  id  width height refresh  name\n");
127          printf("-----------------------------------------\n");
128          for (i = 0; i < numModes; i++) {
129             EGLint id, w, h, r;
130             const char *str;
131             eglGetModeAttribMESA(d, modes[i], EGL_MODE_ID_MESA, &id);
132             eglGetModeAttribMESA(d, modes[i], EGL_WIDTH, &w);
133             eglGetModeAttribMESA(d, modes[i], EGL_HEIGHT, &h);
134             eglGetModeAttribMESA(d, modes[i], EGL_REFRESH_RATE_MESA, &r);
135             str = eglQueryModeStringMESA(d, modes[i]);
136             printf("0x%02x %5d  %5d   %.3f  %s\n", id, w, h, r / 1000.0, str);
137          }
138       }
139    }
140 #else
141         (void)d; /* mark d as unused */
142 #endif
143 }
144
145
146
147 int
148 main(void)
149 {
150    int maj, min;
151    EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
152
153    if (!eglInitialize(d, &maj, &min)) {
154       printf("eglinfo: eglInitialize failed\n");
155       exit(1);
156    }
157
158    printf("EGL API version: %d.%d\n", maj, min);
159    printf("EGL vendor string: %s\n", eglQueryString(d, EGL_VENDOR));
160    printf("EGL version string: %s\n", eglQueryString(d, EGL_VERSION));
161 #ifdef EGL_VERSION_1_2
162    printf("EGL client APIs: %s\n", eglQueryString(d, EGL_CLIENT_APIS));
163 #endif
164    printf("EGL extensions string:\n");
165    printf("    %s\n", eglQueryString(d, EGL_EXTENSIONS));
166
167    PrintConfigs(d);
168
169    PrintModes(d);
170
171    eglTerminate(d);
172
173    return 0;
174 }