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");
587ec3b29aSmrg   /*        ^  ^   ^  ^  ^  ^  ^ ^  ^  ^  ^    ^    ^   ^  ^  ^  ^   ^  ^
597ec3b29aSmrg    *        |  |   |  |  |  |  | |  |  |  |    |    |   |  |  |  |   |  |
607ec3b29aSmrg    *        |  |   |  |  |  |  | |  |  |  |    |    |   |  |  |  |   |  EGL_SURFACE_TYPE
617ec3b29aSmrg    *        |  |   |  |  |  |  | |  |  |  |    |    |   |  EGL_RENDERABLE_TYPE
627ec3b29aSmrg    *        |  |   |  |  |  |  | |  |  |  |    |    |   EGL_BIND_TO_TEXTURE_RGB/EGL_BIND_TO_TEXTURE_RGBA
637ec3b29aSmrg    *        |  |   |  |  |  |  | |  |  |  |    |    EGL_CONFIG_CAVEAT
647ec3b29aSmrg    *        |  |   |  |  |  |  | |  |  |  |    EGL_NATIVE_VISUAL_ID/EGL_NATIVE_VISUAL_TYPE
657ec3b29aSmrg    *        |  |   |  |  |  |  | |  |  |  EGL_SAMPLE_BUFFERS
667ec3b29aSmrg    *        |  |   |  |  |  |  | |  |  EGL_SAMPLES
677ec3b29aSmrg    *        |  |   |  |  |  |  | |  EGL_STENCIL_SIZE
687ec3b29aSmrg    *        |  |   |  |  |  |  | EGL_DEPTH_SIZE
697ec3b29aSmrg    *        |  |   |  |  |  |  EGL_ALPHA_SIZE
707ec3b29aSmrg    *        |  |   |  |  |  EGL_BLUE_SIZE
717ec3b29aSmrg    *        |  |   |  |  EGL_GREEN_SIZE
727ec3b29aSmrg    *        |  |   |  EGL_RED_SIZE
737ec3b29aSmrg    *        |  |   EGL_LEVEL
747ec3b29aSmrg    *        |  EGL_BUFFER_SIZE
757ec3b29aSmrg    *        EGL_CONFIG_ID
767ec3b29aSmrg    */
7732001f49Smrg   printf("---------------------------------------------------------------------\n");
7832001f49Smrg   for (i = 0; i < numConfigs; i++) {
7932001f49Smrg      EGLint id, size, level;
8032001f49Smrg      EGLint red, green, blue, alpha;
8132001f49Smrg      EGLint depth, stencil;
8232001f49Smrg      EGLint renderable, surfaces;
8332001f49Smrg      EGLint vid, vtype, caveat, bindRgb, bindRgba;
8432001f49Smrg      EGLint samples, sampleBuffers;
8532001f49Smrg      char surfString[100] = "";
8632001f49Smrg
8732001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
8832001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size);
8932001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level);
9032001f49Smrg
9132001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
9232001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green);
9332001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue);
9432001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha);
9532001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
9632001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil);
9732001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_ID, &vid);
9832001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_TYPE, &vtype);
9932001f49Smrg
10032001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_CONFIG_CAVEAT, &caveat);
10132001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGB, &bindRgb);
10232001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGBA, &bindRgba);
10332001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_RENDERABLE_TYPE, &renderable);
10432001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces);
10532001f49Smrg
10632001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_SAMPLES, &samples);
10732001f49Smrg      eglGetConfigAttrib(d, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers);
10832001f49Smrg
10932001f49Smrg      if (surfaces & EGL_WINDOW_BIT)
11032001f49Smrg         strcat(surfString, "win,");
11132001f49Smrg      if (surfaces & EGL_PBUFFER_BIT)
11232001f49Smrg         strcat(surfString, "pb,");
11332001f49Smrg      if (surfaces & EGL_PIXMAP_BIT)
11432001f49Smrg         strcat(surfString, "pix,");
1157ec3b29aSmrg      if (surfaces & EGL_STREAM_BIT_KHR)
1167ec3b29aSmrg         strcat(surfString, "str,");
11732001f49Smrg      if (strlen(surfString) > 0)
11832001f49Smrg         surfString[strlen(surfString) - 1] = 0;
11932001f49Smrg
12032001f49Smrg      printf("0x%02x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%02x%s ",
12132001f49Smrg             id, size, level,
12232001f49Smrg             red, green, blue, alpha,
12332001f49Smrg             depth, stencil,
12432001f49Smrg             samples, sampleBuffers, vid, vtype < 6 ? vnames[vtype] : "--");
12532001f49Smrg      printf("  %c  %c  %c  %c  %c   %c %s\n",
12632001f49Smrg             (caveat != EGL_NONE) ? 'y' : ' ',
12732001f49Smrg             (bindRgba) ? 'a' : (bindRgb) ? 'y' : ' ',
12832001f49Smrg             (renderable & EGL_OPENGL_BIT) ? 'y' : ' ',
12932001f49Smrg             (renderable & EGL_OPENGL_ES_BIT) ? 'y' : ' ',
13032001f49Smrg             (renderable & EGL_OPENGL_ES2_BIT) ? 'y' : ' ',
13132001f49Smrg             (renderable & EGL_OPENVG_BIT) ? 'y' : ' ',
13232001f49Smrg             surfString);
13332001f49Smrg   }
13432001f49Smrg}
13532001f49Smrg
13632001f49Smrg
1377ec3b29aSmrgstatic const char *
13832001f49SmrgPrintExtensions(EGLDisplay d)
13932001f49Smrg{
14032001f49Smrg   const char *extensions, *p, *end, *next;
14132001f49Smrg   int column;
14232001f49Smrg
1437ec3b29aSmrg   puts(d == EGL_NO_DISPLAY ? "EGL client extensions string:" :
1447ec3b29aSmrg                              "EGL extensions string:");
14532001f49Smrg
14632001f49Smrg   extensions = eglQueryString(d, EGL_EXTENSIONS);
1477ec3b29aSmrg   if (!extensions)
1487ec3b29aSmrg      return NULL;
14932001f49Smrg
15032001f49Smrg   column = 0;
15132001f49Smrg   end = extensions + strlen(extensions);
15232001f49Smrg
15332001f49Smrg   for (p = extensions; p < end; p = next + 1) {
15432001f49Smrg      next = strchr(p, ' ');
15532001f49Smrg      if (next == NULL)
15632001f49Smrg         next = end;
15732001f49Smrg
15832001f49Smrg      if (column > 0 && column + next - p + 1 > 70) {
15932001f49Smrg	 printf("\n");
16032001f49Smrg	 column = 0;
16132001f49Smrg      }
16232001f49Smrg      if (column == 0)
16332001f49Smrg	 printf("    ");
16432001f49Smrg      else
16532001f49Smrg	 printf(" ");
16632001f49Smrg      column += next - p + 1;
16732001f49Smrg
16832001f49Smrg      printf("%.*s", (int) (next - p), p);
16932001f49Smrg
17032001f49Smrg      p = next + 1;
17132001f49Smrg   }
17232001f49Smrg
17332001f49Smrg   if (column > 0)
17432001f49Smrg      printf("\n");
1757ec3b29aSmrg
1767ec3b29aSmrg   return extensions;
17732001f49Smrg}
17832001f49Smrg
1797ec3b29aSmrgstatic int
1807ec3b29aSmrgdoOneDisplay(EGLDisplay d, const char *name)
18132001f49Smrg{
18232001f49Smrg   int maj, min;
18332001f49Smrg
1847ec3b29aSmrg   printf("%s:\n", name);
18532001f49Smrg   if (!eglInitialize(d, &maj, &min)) {
1867ec3b29aSmrg      printf("eglinfo: eglInitialize failed\n\n");
1877ec3b29aSmrg      return 1;
18832001f49Smrg   }
18932001f49Smrg
19032001f49Smrg   printf("EGL API version: %d.%d\n", maj, min);
19132001f49Smrg   printf("EGL vendor string: %s\n", eglQueryString(d, EGL_VENDOR));
19232001f49Smrg   printf("EGL version string: %s\n", eglQueryString(d, EGL_VERSION));
19332001f49Smrg#ifdef EGL_VERSION_1_2
19432001f49Smrg   printf("EGL client APIs: %s\n", eglQueryString(d, EGL_CLIENT_APIS));
19532001f49Smrg#endif
19632001f49Smrg
19732001f49Smrg   PrintExtensions(d);
19832001f49Smrg
19932001f49Smrg   PrintConfigs(d);
20032001f49Smrg   eglTerminate(d);
2017ec3b29aSmrg   printf("\n");
20232001f49Smrg   return 0;
20332001f49Smrg}
2047ec3b29aSmrg
2057ec3b29aSmrgint
2067ec3b29aSmrgmain(int argc, char *argv[])
2077ec3b29aSmrg{
2087ec3b29aSmrg   int ret = 0;
2097ec3b29aSmrg   const char *clientext;
2107ec3b29aSmrg
2117ec3b29aSmrg   clientext = PrintExtensions(EGL_NO_DISPLAY);
2127ec3b29aSmrg   printf("\n");
2137ec3b29aSmrg
2147ec3b29aSmrg   if (strstr(clientext, "EGL_EXT_platform_base")) {
2157ec3b29aSmrg       PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =
2167ec3b29aSmrg           (PFNEGLGETPLATFORMDISPLAYEXTPROC)
2177ec3b29aSmrg           eglGetProcAddress("eglGetPlatformDisplayEXT");
2187ec3b29aSmrg       if (strstr(clientext, "EGL_KHR_platform_android"))
2197ec3b29aSmrg           ret += doOneDisplay(getPlatformDisplay(EGL_PLATFORM_ANDROID_KHR,
2207ec3b29aSmrg                                                  EGL_DEFAULT_DISPLAY,
2217ec3b29aSmrg                                                  NULL), "Android platform");
2227ec3b29aSmrg       if (strstr(clientext, "EGL_MESA_platform_gbm") ||
2237ec3b29aSmrg           strstr(clientext, "EGL_KHR_platform_gbm"))
2247ec3b29aSmrg           ret += doOneDisplay(getPlatformDisplay(EGL_PLATFORM_GBM_MESA,
2257ec3b29aSmrg                                                  EGL_DEFAULT_DISPLAY,
2267ec3b29aSmrg                                                  NULL), "GBM platform");
2277ec3b29aSmrg       if (strstr(clientext, "EGL_EXT_platform_wayland") ||
2287ec3b29aSmrg           strstr(clientext, "EGL_KHR_platform_wayland"))
2297ec3b29aSmrg           ret += doOneDisplay(getPlatformDisplay(EGL_PLATFORM_WAYLAND_EXT,
2307ec3b29aSmrg                                                  EGL_DEFAULT_DISPLAY,
2317ec3b29aSmrg                                                  NULL), "Wayland platform");
2327ec3b29aSmrg       if (strstr(clientext, "EGL_EXT_platform_x11") ||
2337ec3b29aSmrg           strstr(clientext, "EGL_KHR_platform_x11"))
2347ec3b29aSmrg           ret += doOneDisplay(getPlatformDisplay(EGL_PLATFORM_X11_EXT,
2357ec3b29aSmrg                                                  EGL_DEFAULT_DISPLAY,
2367ec3b29aSmrg                                                  NULL), "X11 platform");
2377ec3b29aSmrg       if (strstr(clientext, "EGL_EXT_platform_device"))
2387ec3b29aSmrg           ret += doOneDisplay(getPlatformDisplay(EGL_PLATFORM_DEVICE_EXT,
2397ec3b29aSmrg                                                  EGL_DEFAULT_DISPLAY,
2407ec3b29aSmrg                                                  NULL), "Device platform");
2417ec3b29aSmrg   }
2427ec3b29aSmrg   else {
2437ec3b29aSmrg      ret = doOneDisplay(eglGetDisplay(EGL_DEFAULT_DISPLAY), "Default display");
2447ec3b29aSmrg   }
2457ec3b29aSmrg
2467ec3b29aSmrg   return ret;
2477ec3b29aSmrg}
248