eglinfo.c revision 32001f49
132001f49Smrg/*
232001f49Smrg * eglinfo - like glxinfo but for EGL
332001f49Smrg *
432001f49Smrg * Brian Paul
532001f49Smrg * 11 March 2005
632001f49Smrg *
732001f49Smrg * Copyright (C) 2005  Brian Paul   All Rights Reserved.
832001f49Smrg *
932001f49Smrg * Permission is hereby granted, free of charge, to any person obtaining a
1032001f49Smrg * copy of this software and associated documentation files (the "Software"),
1132001f49Smrg * to deal in the Software without restriction, including without limitation
1232001f49Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1332001f49Smrg * and/or sell copies of the Software, and to permit persons to whom the
1432001f49Smrg * Software is furnished to do so, subject to the following conditions:
1532001f49Smrg *
1632001f49Smrg * The above copyright notice and this permission notice shall be included
1732001f49Smrg * in all copies or substantial portions of the Software.
1832001f49Smrg *
1932001f49Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2032001f49Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2132001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2232001f49Smrg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2332001f49Smrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2432001f49Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2532001f49Smrg */
2632001f49Smrg
2732001f49Smrg#define EGL_EGLEXT_PROTOTYPES
2832001f49Smrg
2932001f49Smrg#include <EGL/egl.h>
3032001f49Smrg#include <EGL/eglext.h>
3132001f49Smrg#include <assert.h>
3232001f49Smrg#include <stdio.h>
3332001f49Smrg#include <stdlib.h>
3432001f49Smrg#include <string.h>
3532001f49Smrg
3632001f49Smrg#define MAX_CONFIGS 1000
3732001f49Smrg#define MAX_MODES 1000
3832001f49Smrg#define MAX_SCREENS 10
3932001f49Smrg
4032001f49Smrg/* These are X visual types, so if you're running eglinfo under
4132001f49Smrg * something not X, they probably don't make sense. */
4232001f49Smrgstatic const char *vnames[] = { "SG", "GS", "SC", "PC", "TC", "DC" };
4332001f49Smrg
4432001f49Smrg/**
4532001f49Smrg * Print table of all available configurations.
4632001f49Smrg */
4732001f49Smrgstatic void
4832001f49SmrgPrintConfigs(EGLDisplay d)
4932001f49Smrg{
5032001f49Smrg   EGLConfig configs[MAX_CONFIGS];
5132001f49Smrg   EGLint numConfigs, i;
5232001f49Smrg
5332001f49Smrg   eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
5432001f49Smrg
5532001f49Smrg   printf("Configurations:\n");
5632001f49Smrg   printf("     bf lv colorbuffer dp st  ms    vis   cav bi  renderable  supported\n");
5732001f49Smrg   printf("  id sz  l  r  g  b  a th cl ns b    id   eat nd gl es es2 vg surfaces \n");
5832001f49Smrg   printf("---------------------------------------------------------------------\n");
5932001f49Smrg   for (i = 0; i < numConfigs; i++) {
6032001f49Smrg      EGLint id, size, level;
6132001f49Smrg      EGLint red, green, blue, alpha;
6232001f49Smrg      EGLint depth, stencil;
6332001f49Smrg      EGLint renderable, surfaces;
6432001f49Smrg      EGLint vid, vtype, caveat, bindRgb, bindRgba;
6532001f49Smrg      EGLint samples, sampleBuffers;
6632001f49Smrg      char surfString[100] = "";
6732001f49Smrg
6832001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
6932001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size);
7032001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level);
7132001f49Smrg
7232001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
7332001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green);
7432001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue);
7532001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha);
7632001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
7732001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil);
7832001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_ID, &vid);
7932001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_TYPE, &vtype);
8032001f49Smrg
8132001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_CONFIG_CAVEAT, &caveat);
8232001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGB, &bindRgb);
8332001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGBA, &bindRgba);
8432001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_RENDERABLE_TYPE, &renderable);
8532001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces);
8632001f49Smrg
8732001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_SAMPLES, &samples);
8832001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers);
8932001f49Smrg
9032001f49Smrg      if (surfaces & EGL_WINDOW_BIT)
9132001f49Smrg         strcat(surfString, "win,");
9232001f49Smrg      if (surfaces & EGL_PBUFFER_BIT)
9332001f49Smrg         strcat(surfString, "pb,");
9432001f49Smrg      if (surfaces & EGL_PIXMAP_BIT)
9532001f49Smrg         strcat(surfString, "pix,");
9632001f49Smrg#ifdef EGL_MESA_screen_surface
9732001f49Smrg      if (surfaces & EGL_SCREEN_BIT_MESA)
9832001f49Smrg         strcat(surfString, "scrn,");
9932001f49Smrg#endif
10032001f49Smrg      if (strlen(surfString) > 0)
10132001f49Smrg         surfString[strlen(surfString) - 1] = 0;
10232001f49Smrg
10332001f49Smrg      printf("0x%02x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%02x%s ",
10432001f49Smrg             id, size, level,
10532001f49Smrg             red, green, blue, alpha,
10632001f49Smrg             depth, stencil,
10732001f49Smrg             samples, sampleBuffers, vid, vtype < 6 ? vnames[vtype] : "--");
10832001f49Smrg      printf("  %c  %c  %c  %c  %c   %c %s\n",
10932001f49Smrg             (caveat != EGL_NONE) ? 'y' : ' ',
11032001f49Smrg             (bindRgba) ? 'a' : (bindRgb) ? 'y' : ' ',
11132001f49Smrg             (renderable & EGL_OPENGL_BIT) ? 'y' : ' ',
11232001f49Smrg             (renderable & EGL_OPENGL_ES_BIT) ? 'y' : ' ',
11332001f49Smrg             (renderable & EGL_OPENGL_ES2_BIT) ? 'y' : ' ',
11432001f49Smrg             (renderable & EGL_OPENVG_BIT) ? 'y' : ' ',
11532001f49Smrg             surfString);
11632001f49Smrg   }
11732001f49Smrg}
11832001f49Smrg
11932001f49Smrg
12032001f49Smrg/**
12132001f49Smrg * Print table of all available configurations.
12232001f49Smrg */
12332001f49Smrgstatic void
12432001f49SmrgPrintModes(EGLDisplay d)
12532001f49Smrg{
12632001f49Smrg#ifdef EGL_MESA_screen_surface
12732001f49Smrg   const char *extensions = eglQueryString(d, EGL_EXTENSIONS);
12832001f49Smrg   if (strstr(extensions, "EGL_MESA_screen_surface")) {
12932001f49Smrg      EGLScreenMESA screens[MAX_SCREENS];
13032001f49Smrg      EGLint numScreens = 1, scrn;
13132001f49Smrg      EGLModeMESA modes[MAX_MODES];
13232001f49Smrg
13332001f49Smrg      eglGetScreensMESA(d, screens, MAX_SCREENS, &numScreens);
13432001f49Smrg      printf("Number of Screens: %d\n\n", numScreens);
13532001f49Smrg
13632001f49Smrg      for (scrn = 0; scrn < numScreens; scrn++) {
13732001f49Smrg         EGLint numModes, i;
13832001f49Smrg
13932001f49Smrg         eglGetModesMESA(d, screens[scrn], modes, MAX_MODES, &numModes);
14032001f49Smrg
14132001f49Smrg         printf("Screen %d Modes:\n", scrn);
14232001f49Smrg         printf("  id  width height refresh  name\n");
14332001f49Smrg         printf("-----------------------------------------\n");
14432001f49Smrg         for (i = 0; i < numModes; i++) {
14532001f49Smrg            EGLint id, w, h, r;
14632001f49Smrg            const char *str;
14732001f49Smrg            eglGetModeAttribMESA(d, modes[i], EGL_MODE_ID_MESA, &id);
14832001f49Smrg            eglGetModeAttribMESA(d, modes[i], EGL_WIDTH, &w);
14932001f49Smrg            eglGetModeAttribMESA(d, modes[i], EGL_HEIGHT, &h);
15032001f49Smrg            eglGetModeAttribMESA(d, modes[i], EGL_REFRESH_RATE_MESA, &r);
15132001f49Smrg            str = eglQueryModeStringMESA(d, modes[i]);
15232001f49Smrg            printf("0x%02x %5d  %5d   %.3f  %s\n", id, w, h, r / 1000.0, str);
15332001f49Smrg         }
15432001f49Smrg      }
15532001f49Smrg   }
15632001f49Smrg#endif
15732001f49Smrg}
15832001f49Smrg
15932001f49Smrgstatic void
16032001f49SmrgPrintExtensions(EGLDisplay d)
16132001f49Smrg{
16232001f49Smrg   const char *extensions, *p, *end, *next;
16332001f49Smrg   int column;
16432001f49Smrg
16532001f49Smrg   printf("EGL extensions string:\n");
16632001f49Smrg
16732001f49Smrg   extensions = eglQueryString(d, EGL_EXTENSIONS);
16832001f49Smrg
16932001f49Smrg   column = 0;
17032001f49Smrg   end = extensions + strlen(extensions);
17132001f49Smrg
17232001f49Smrg   for (p = extensions; p < end; p = next + 1) {
17332001f49Smrg      next = strchr(p, ' ');
17432001f49Smrg      if (next == NULL)
17532001f49Smrg         next = end;
17632001f49Smrg
17732001f49Smrg      if (column > 0 && column + next - p + 1 > 70) {
17832001f49Smrg	 printf("\n");
17932001f49Smrg	 column = 0;
18032001f49Smrg      }
18132001f49Smrg      if (column == 0)
18232001f49Smrg	 printf("    ");
18332001f49Smrg      else
18432001f49Smrg	 printf(" ");
18532001f49Smrg      column += next - p + 1;
18632001f49Smrg
18732001f49Smrg      printf("%.*s", (int) (next - p), p);
18832001f49Smrg
18932001f49Smrg      p = next + 1;
19032001f49Smrg   }
19132001f49Smrg
19232001f49Smrg   if (column > 0)
19332001f49Smrg      printf("\n");
19432001f49Smrg}
19532001f49Smrg
19632001f49Smrgint
19732001f49Smrgmain(int argc, char *argv[])
19832001f49Smrg{
19932001f49Smrg   int maj, min;
20032001f49Smrg   EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
20132001f49Smrg
20232001f49Smrg   if (!eglInitialize(d, &maj, &min)) {
20332001f49Smrg      printf("eglinfo: eglInitialize failed\n");
20432001f49Smrg      exit(1);
20532001f49Smrg   }
20632001f49Smrg
20732001f49Smrg   printf("EGL API version: %d.%d\n", maj, min);
20832001f49Smrg   printf("EGL vendor string: %s\n", eglQueryString(d, EGL_VENDOR));
20932001f49Smrg   printf("EGL version string: %s\n", eglQueryString(d, EGL_VERSION));
21032001f49Smrg#ifdef EGL_VERSION_1_2
21132001f49Smrg   printf("EGL client APIs: %s\n", eglQueryString(d, EGL_CLIENT_APIS));
21232001f49Smrg#endif
21332001f49Smrg
21432001f49Smrg   PrintExtensions(d);
21532001f49Smrg
21632001f49Smrg   PrintConfigs(d);
21732001f49Smrg
21832001f49Smrg   PrintModes(d);
21932001f49Smrg
22032001f49Smrg   eglTerminate(d);
22132001f49Smrg
22232001f49Smrg   return 0;
22332001f49Smrg}
224