Merge branch '7.8'
[mesa.git] / progs / egl / opengl / 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 #define EGL_EGLEXT_PROTOTYPES
28
29 #include <EGL/egl.h>
30 #include <EGL/eglext.h>
31 #include <assert.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #define MAX_CONFIGS 1000
37 #define MAX_MODES 1000
38 #define MAX_SCREENS 10
39
40 /* These are X visual types, so if you're running eglinfo under
41 * something not X, they probably don't make sense. */
42 static const char *vnames[] = { "SG", "GS", "SC", "PC", "TC", "DC" };
43
44 /**
45 * Print table of all available configurations.
46 */
47 static void
48 PrintConfigs(EGLDisplay d)
49 {
50 EGLConfig configs[MAX_CONFIGS];
51 EGLint numConfigs, i;
52
53 eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
54
55 printf("Configurations:\n");
56 printf(" bf lv colorbuffer dp st ms vis cav bi renderable supported\n");
57 printf(" id sz l r g b a th cl ns b id eat nd gl es es2 vg surfaces \n");
58 printf("---------------------------------------------------------------------\n");
59 for (i = 0; i < numConfigs; i++) {
60 EGLint id, size, level;
61 EGLint red, green, blue, alpha;
62 EGLint depth, stencil;
63 EGLint renderable, surfaces;
64 EGLint vid, vtype, caveat, bindRgb, bindRgba;
65 EGLint samples, sampleBuffers;
66 char surfString[100] = "";
67
68 eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
69 eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size);
70 eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level);
71
72 eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
73 eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green);
74 eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue);
75 eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha);
76 eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
77 eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil);
78 eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_ID, &vid);
79 eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_TYPE, &vtype);
80
81 eglGetConfigAttrib(d, configs[i], EGL_CONFIG_CAVEAT, &caveat);
82 eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGB, &bindRgb);
83 eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGBA, &bindRgba);
84 eglGetConfigAttrib(d, configs[i], EGL_RENDERABLE_TYPE, &renderable);
85 eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces);
86
87 eglGetConfigAttrib(d, configs[i], EGL_SAMPLES, &samples);
88 eglGetConfigAttrib(d, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers);
89
90 if (surfaces & EGL_WINDOW_BIT)
91 strcat(surfString, "win,");
92 if (surfaces & EGL_PBUFFER_BIT)
93 strcat(surfString, "pb,");
94 if (surfaces & EGL_PIXMAP_BIT)
95 strcat(surfString, "pix,");
96 #ifdef EGL_MESA_screen_surface
97 if (surfaces & EGL_SCREEN_BIT_MESA)
98 strcat(surfString, "scrn,");
99 #endif
100 if (strlen(surfString) > 0)
101 surfString[strlen(surfString) - 1] = 0;
102
103 printf("0x%02x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%02x%s ",
104 id, size, level,
105 red, green, blue, alpha,
106 depth, stencil,
107 samples, sampleBuffers, vid, vtype < 6 ? vnames[vtype] : "--");
108 printf(" %c %c %c %c %c %c %s\n",
109 (caveat != EGL_NONE) ? 'y' : ' ',
110 (bindRgba) ? 'a' : (bindRgb) ? 'y' : ' ',
111 (renderable & EGL_OPENGL_BIT) ? 'y' : ' ',
112 (renderable & EGL_OPENGL_ES_BIT) ? 'y' : ' ',
113 (renderable & EGL_OPENGL_ES2_BIT) ? 'y' : ' ',
114 (renderable & EGL_OPENVG_BIT) ? 'y' : ' ',
115 surfString);
116 }
117 }
118
119
120 /**
121 * Print table of all available configurations.
122 */
123 static void
124 PrintModes(EGLDisplay d)
125 {
126 #ifdef EGL_MESA_screen_surface
127 const char *extensions = eglQueryString(d, EGL_EXTENSIONS);
128 if (strstr(extensions, "EGL_MESA_screen_surface")) {
129 EGLScreenMESA screens[MAX_SCREENS];
130 EGLint numScreens = 1, scrn;
131 EGLModeMESA modes[MAX_MODES];
132
133 eglGetScreensMESA(d, screens, MAX_SCREENS, &numScreens);
134 printf("Number of Screens: %d\n\n", numScreens);
135
136 for (scrn = 0; scrn < numScreens; scrn++) {
137 EGLint numModes, i;
138
139 eglGetModesMESA(d, screens[scrn], modes, MAX_MODES, &numModes);
140
141 printf("Screen %d Modes:\n", scrn);
142 printf(" id width height refresh name\n");
143 printf("-----------------------------------------\n");
144 for (i = 0; i < numModes; i++) {
145 EGLint id, w, h, r;
146 const char *str;
147 eglGetModeAttribMESA(d, modes[i], EGL_MODE_ID_MESA, &id);
148 eglGetModeAttribMESA(d, modes[i], EGL_WIDTH, &w);
149 eglGetModeAttribMESA(d, modes[i], EGL_HEIGHT, &h);
150 eglGetModeAttribMESA(d, modes[i], EGL_REFRESH_RATE_MESA, &r);
151 str = eglQueryModeStringMESA(d, modes[i]);
152 printf("0x%02x %5d %5d %.3f %s\n", id, w, h, r / 1000.0, str);
153 }
154 }
155 }
156 #endif
157 }
158
159 static void
160 PrintExtensions(EGLDisplay d)
161 {
162 const char *extensions, *p, *end, *next;
163 int column;
164
165 printf("EGL extensions string:\n");
166
167 extensions = eglQueryString(d, EGL_EXTENSIONS);
168
169 column = 0;
170 end = extensions + strlen(extensions);
171
172 for (p = extensions; p < end; p = next + 1) {
173 next = strchr(p, ' ');
174 if (next == NULL)
175 next = end;
176
177 if (column > 0 && column + next - p + 1 > 70) {
178 printf("\n");
179 column = 0;
180 }
181 if (column == 0)
182 printf(" ");
183 else
184 printf(" ");
185 column += next - p + 1;
186
187 printf("%.*s", (int) (next - p), p);
188
189 p = next + 1;
190 }
191
192 if (column > 0)
193 printf("\n");
194 }
195
196 int
197 main(int argc, char *argv[])
198 {
199 int maj, min;
200 EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
201
202 if (!eglInitialize(d, &maj, &min)) {
203 printf("eglinfo: eglInitialize failed\n");
204 exit(1);
205 }
206
207 printf("EGL API version: %d.%d\n", maj, min);
208 printf("EGL vendor string: %s\n", eglQueryString(d, EGL_VENDOR));
209 printf("EGL version string: %s\n", eglQueryString(d, EGL_VERSION));
210 #ifdef EGL_VERSION_1_2
211 printf("EGL client APIs: %s\n", eglQueryString(d, EGL_CLIENT_APIS));
212 #endif
213
214 PrintExtensions(d);
215
216 PrintConfigs(d);
217
218 PrintModes(d);
219
220 eglTerminate(d);
221
222 return 0;
223 }