egl: Updated EGL samples to use new i915 EGL winsys
[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
28 #include <GLES/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, i;
47
48 eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
49
50 printf("Configurations:\n");
51 printf(" bf lv d st colorbuffer dp st supported\n");
52 printf(" id sz l b ro r g b a th cl 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 char surfString[100] = "";
61
62 eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
63 eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size);
64 eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level);
65
66 eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
67 eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green);
68 eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue);
69 eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha);
70 eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
71 eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil);
72 eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces);
73
74 if (surfaces & EGL_WINDOW_BIT)
75 strcat(surfString, "win,");
76 if (surfaces & EGL_PBUFFER_BIT)
77 strcat(surfString, "pb,");
78 if (surfaces & EGL_PIXMAP_BIT)
79 strcat(surfString, "pix,");
80 #ifdef EGL_MESA_screen_surface
81 if (surfaces & EGL_SCREEN_BIT_MESA)
82 strcat(surfString, "scrn,");
83 #endif
84 if (strlen(surfString) > 0)
85 surfString[strlen(surfString) - 1] = 0;
86
87 printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %-12s\n",
88 id, size, level,
89 doubleBuf ? 'y' : '.',
90 stereo ? 'y' : '.',
91 red, green, blue, alpha,
92 depth, stencil, surfString);
93 }
94 }
95
96
97 /**
98 * Print table of all available configurations.
99 */
100 static void
101 PrintModes(EGLDisplay d)
102 {
103 #ifdef EGL_MESA_screen_surface
104 const char *extensions = eglQueryString(d, EGL_EXTENSIONS);
105 if (strstr(extensions, "EGL_MESA_screen_surface")) {
106 EGLScreenMESA screens[MAX_SCREENS];
107 EGLint numScreens = 1, scrn;
108 EGLModeMESA modes[MAX_MODES];
109
110 eglGetScreensMESA(d, screens, MAX_SCREENS, &numScreens);
111 printf("Number of Screens: %d\n\n", numScreens);
112
113 for (scrn = 0; scrn < numScreens; scrn++) {
114 EGLint numModes, i;
115
116 eglGetModesMESA(d, screens[scrn], modes, MAX_MODES, &numModes);
117
118 printf("Screen %d Modes:\n", scrn);
119 printf(" id width height refresh name\n");
120 printf("-----------------------------------------\n");
121 for (i = 0; i < numModes; i++) {
122 EGLint id, w, h, r;
123 const char *str;
124 eglGetModeAttribMESA(d, modes[i], EGL_MODE_ID_MESA, &id);
125 eglGetModeAttribMESA(d, modes[i], EGL_WIDTH, &w);
126 eglGetModeAttribMESA(d, modes[i], EGL_HEIGHT, &h);
127 eglGetModeAttribMESA(d, modes[i], EGL_REFRESH_RATE_MESA, &r);
128 str = eglQueryModeStringMESA(d, modes[i]);
129 printf("0x%02x %5d %5d %.3f %s\n", id, w, h, r / 1000.0, str);
130 }
131 }
132 }
133 #endif
134 }
135
136
137
138 int
139 main(int argc, char *argv[])
140 {
141 int maj, min;
142 /*EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);*/
143 EGLDisplay d = eglGetDisplay("!EGL_i915");
144
145 if (!eglInitialize(d, &maj, &min)) {
146 printf("eglinfo: eglInitialize failed\n");
147 exit(1);
148 }
149
150 printf("EGL API version: %d.%d\n", maj, min);
151 printf("EGL vendor string: %s\n", eglQueryString(d, EGL_VENDOR));
152 printf("EGL version string: %s\n", eglQueryString(d, EGL_VERSION));
153 printf("EGL extensions string:\n");
154 printf(" %s\n", eglQueryString(d, EGL_EXTENSIONS));
155 printf("\n");
156
157 PrintConfigs(d);
158
159 printf("\n");
160
161 PrintModes(d);
162
163 eglTerminate(d);
164
165 return 0;
166 }