Merge commit 'origin/gallium-master-merge'
[mesa.git] / progs / egl / 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 /**
41 * Print table of all available configurations.
42 */
43 static void
44 PrintConfigs(EGLDisplay d)
45 {
46 EGLConfig configs[MAX_CONFIGS];
47 EGLint numConfigs, i;
48
49 eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
50
51 printf("Configurations:\n");
52 printf(" bf lv d st colorbuffer dp st ms vis supported\n");
53 printf(" id sz l b ro r g b a th cl ns b id surfaces \n");
54 printf("--------------------------------------------------------\n");
55 for (i = 0; i < numConfigs; i++) {
56 EGLint id, size, level;
57 EGLint red, green, blue, alpha;
58 EGLint depth, stencil;
59 EGLint surfaces;
60 EGLint doubleBuf = 1, stereo = 0;
61 EGLint vid;
62 EGLint samples, sampleBuffers;
63 char surfString[100] = "";
64
65 eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
66 eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size);
67 eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level);
68
69 eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
70 eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green);
71 eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue);
72 eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha);
73 eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
74 eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil);
75 eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_ID, &vid);
76 eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces);
77
78 eglGetConfigAttrib(d, configs[i], EGL_SAMPLES, &samples);
79 eglGetConfigAttrib(d, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers);
80
81 if (surfaces & EGL_WINDOW_BIT)
82 strcat(surfString, "win,");
83 if (surfaces & EGL_PBUFFER_BIT)
84 strcat(surfString, "pb,");
85 if (surfaces & EGL_PIXMAP_BIT)
86 strcat(surfString, "pix,");
87 #ifdef EGL_MESA_screen_surface
88 if (surfaces & EGL_SCREEN_BIT_MESA)
89 strcat(surfString, "scrn,");
90 #endif
91 if (strlen(surfString) > 0)
92 surfString[strlen(surfString) - 1] = 0;
93
94 printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %2d%2d 0x%02x %-12s\n",
95 id, size, level,
96 doubleBuf ? 'y' : '.',
97 stereo ? 'y' : '.',
98 red, green, blue, alpha,
99 depth, stencil,
100 samples, sampleBuffers, vid, surfString);
101 }
102 }
103
104
105 /**
106 * Print table of all available configurations.
107 */
108 static void
109 PrintModes(EGLDisplay d)
110 {
111 #ifdef EGL_MESA_screen_surface
112 const char *extensions = eglQueryString(d, EGL_EXTENSIONS);
113 if (strstr(extensions, "EGL_MESA_screen_surface")) {
114 EGLScreenMESA screens[MAX_SCREENS];
115 EGLint numScreens = 1, scrn;
116 EGLModeMESA modes[MAX_MODES];
117
118 eglGetScreensMESA(d, screens, MAX_SCREENS, &numScreens);
119 printf("Number of Screens: %d\n\n", numScreens);
120
121 for (scrn = 0; scrn < numScreens; scrn++) {
122 EGLint numModes, i;
123
124 eglGetModesMESA(d, screens[scrn], modes, MAX_MODES, &numModes);
125
126 printf("Screen %d Modes:\n", scrn);
127 printf(" id width height refresh name\n");
128 printf("-----------------------------------------\n");
129 for (i = 0; i < numModes; i++) {
130 EGLint id, w, h, r;
131 const char *str;
132 eglGetModeAttribMESA(d, modes[i], EGL_MODE_ID_MESA, &id);
133 eglGetModeAttribMESA(d, modes[i], EGL_WIDTH, &w);
134 eglGetModeAttribMESA(d, modes[i], EGL_HEIGHT, &h);
135 eglGetModeAttribMESA(d, modes[i], EGL_REFRESH_RATE_MESA, &r);
136 str = eglQueryModeStringMESA(d, modes[i]);
137 printf("0x%02x %5d %5d %.3f %s\n", id, w, h, r / 1000.0, str);
138 }
139 }
140 }
141 #endif
142 }
143
144
145
146 int
147 main(int argc, char *argv[])
148 {
149 int maj, min;
150 //EGLDisplay d = eglGetDisplay((EGLNativeDisplayType)"!EGL_i915");
151 EGLDisplay d = eglGetDisplay((EGLNativeDisplayType)"!EGL_i915");
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 }