Created
February 8, 2014 11:02
-
-
Save anonymous/8881954 to your computer and use it in GitHub Desktop.
eglinfo.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * eglinfo - like glxinfo but for EGL | |
| * | |
| * Brian Paul | |
| * 11 March 2005 | |
| * | |
| * Copyright (C) 2005 Brian Paul All Rights Reserved. | |
| * | |
| * Permission is hereby granted, free of charge, to any person obtaining a | |
| * copy of this software and associated documentation files (the "Software"), | |
| * to deal in the Software without restriction, including without limitation | |
| * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
| * and/or sell copies of the Software, and to permit persons to whom the | |
| * Software is furnished to do so, subject to the following conditions: | |
| * | |
| * The above copyright notice and this permission notice shall be included | |
| * in all copies or substantial portions of the Software. | |
| * | |
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
| * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
| * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | |
| * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
| * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| */ | |
| #define EGL_EGLEXT_PROTOTYPES | |
| #include <EGL/egl.h> | |
| #include <EGL/eglext.h> | |
| #include <assert.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #define MAX_CONFIGS 1000 | |
| #define MAX_MODES 1000 | |
| #define MAX_SCREENS 10 | |
| /* These are X visual types, so if you're running eglinfo under | |
| * something not X, they probably don't make sense. */ | |
| static const char *vnames[] = { "SG", "GS", "SC", "PC", "TC", "DC" }; | |
| static const char* getErrorString(EGLint error) | |
| { | |
| switch (error) | |
| { | |
| case EGL_SUCCESS: | |
| return "Success"; | |
| case EGL_NOT_INITIALIZED: | |
| return "EGL is not or could not be initialized"; | |
| case EGL_BAD_ACCESS: | |
| return "EGL cannot access a requested resource"; | |
| case EGL_BAD_ALLOC: | |
| return "EGL failed to allocate resources for the requested operation"; | |
| case EGL_BAD_ATTRIBUTE: | |
| return "An unrecognized attribute or attribute value was passed " | |
| "in the attribute list"; | |
| case EGL_BAD_CONTEXT: | |
| return "An EGLContext argument does not name a valid EGL " | |
| "rendering context"; | |
| case EGL_BAD_CONFIG: | |
| return "An EGLConfig argument does not name a valid EGL frame " | |
| "buffer configuration"; | |
| case EGL_BAD_CURRENT_SURFACE: | |
| return "The current surface of the calling thread is a window, pixel " | |
| "buffer or pixmap that is no longer valid"; | |
| case EGL_BAD_DISPLAY: | |
| return "An EGLDisplay argument does not name a valid EGL display " | |
| "connection"; | |
| case EGL_BAD_SURFACE: | |
| return "An EGLSurface argument does not name a valid surface " | |
| "configured for GL rendering"; | |
| case EGL_BAD_MATCH: | |
| return "Arguments are inconsistent"; | |
| case EGL_BAD_PARAMETER: | |
| return "One or more argument values are invalid"; | |
| case EGL_BAD_NATIVE_PIXMAP: | |
| return "A NativePixmapType argument does not refer to a valid " | |
| "native pixmap"; | |
| case EGL_BAD_NATIVE_WINDOW: | |
| return "A NativeWindowType argument does not refer to a valid " | |
| "native window"; | |
| case EGL_CONTEXT_LOST: | |
| return "The application must destroy all contexts and reinitialise"; | |
| } | |
| return "UNKNOWN EGL ERROR"; | |
| } | |
| /** | |
| * Print table of all available configurations. | |
| */ | |
| static void | |
| PrintConfigs(EGLDisplay d) | |
| { | |
| EGLConfig configs[MAX_CONFIGS]; | |
| EGLint numConfigs, i; | |
| eglBindAPI(EGL_OPENGL_ES_API); | |
| eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); | |
| printf("Configurations:\n"); | |
| printf(" bf lv colorbuffer dp st ms vis cav bi renderable supported supported\n"); | |
| printf(" id sz l r g b a th cl ns b id eat nd gl es es2 vg config surfaces \n"); | |
| printf("----------------------------------------------------------------------------------\n"); | |
| for (i = 0; i < numConfigs; i++) { | |
| EGLint id, size, level; | |
| EGLint red, green, blue, alpha; | |
| EGLint depth, stencil; | |
| EGLint renderable, surfaces; | |
| EGLint vid, vtype, caveat, bindRgb, bindRgba; | |
| EGLint samples, sampleBuffers; | |
| EGLint attribs [] = { | |
| EGL_CONTEXT_CLIENT_VERSION, 2, | |
| EGL_NONE | |
| }; | |
| EGLContext context; | |
| EGLint context_error = EGL_SUCCESS; | |
| char surfString[100] = ""; | |
| eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); | |
| eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size); | |
| eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level); | |
| eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red); | |
| eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green); | |
| eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue); | |
| eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha); | |
| eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth); | |
| eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil); | |
| eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_ID, &vid); | |
| eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_TYPE, &vtype); | |
| eglGetConfigAttrib(d, configs[i], EGL_CONFIG_CAVEAT, &caveat); | |
| eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGB, &bindRgb); | |
| eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGBA, &bindRgba); | |
| eglGetConfigAttrib(d, configs[i], EGL_RENDERABLE_TYPE, &renderable); | |
| eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces); | |
| eglGetConfigAttrib(d, configs[i], EGL_SAMPLES, &samples); | |
| eglGetConfigAttrib(d, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers); | |
| if (surfaces & EGL_WINDOW_BIT) | |
| strcat(surfString, "win,"); | |
| if (surfaces & EGL_PBUFFER_BIT) | |
| strcat(surfString, "pb,"); | |
| if (surfaces & EGL_PIXMAP_BIT) | |
| strcat(surfString, "pix,"); | |
| #ifdef EGL_MESA_screen_surface | |
| if (surfaces & EGL_SCREEN_BIT_MESA) | |
| strcat(surfString, "scrn,"); | |
| #endif | |
| if (strlen(surfString) > 0) | |
| surfString[strlen(surfString) - 1] = 0; | |
| context = eglCreateContext(d, configs[i], EGL_NO_CONTEXT, attribs); | |
| context_error = eglGetError(); | |
| printf("0x%02x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%02x%s ", | |
| id, size, level, | |
| red, green, blue, alpha, | |
| depth, stencil, | |
| samples, sampleBuffers, vid, vtype < 6 ? vnames[vtype] : "--"); | |
| printf(" %c %c %c %c %c %c %c %s ", | |
| (caveat != EGL_NONE) ? 'y' : 'n', | |
| (bindRgba) ? 'a' : (bindRgb) ? 'y' : 'n', | |
| (renderable & EGL_OPENGL_BIT) ? 'y' : 'n', | |
| (renderable & EGL_OPENGL_ES_BIT) ? 'y' : 'n', | |
| (renderable & EGL_OPENGL_ES2_BIT) ? 'y' : 'n', | |
| (renderable & EGL_OPENVG_BIT) ? 'y' : 'n', | |
| (context != EGL_NO_CONTEXT) ? 'y' : 'n', | |
| surfString); | |
| if (context != EGL_NO_CONTEXT) | |
| { | |
| printf("\n"); | |
| eglDestroyContext(d, context); | |
| } else | |
| { | |
| printf(" eglCreateContext: %s\n", getErrorString(context_error)); | |
| } | |
| } | |
| } | |
| /** | |
| * Print table of all available configurations. | |
| */ | |
| static void | |
| PrintModes(EGLDisplay d) | |
| { | |
| } | |
| static void | |
| PrintExtensions(EGLDisplay d) | |
| { | |
| const char *extensions, *p, *end, *next; | |
| int column; | |
| printf("EGL extensions string:\n"); | |
| extensions = eglQueryString(d, EGL_EXTENSIONS); | |
| column = 0; | |
| end = extensions + strlen(extensions); | |
| for (p = extensions; p < end; p = next + 1) { | |
| next = strchr(p, ' '); | |
| if (next == NULL) | |
| next = end; | |
| if (column > 0 && column + next - p + 1 > 70) { | |
| printf("\n"); | |
| column = 0; | |
| } | |
| if (column == 0) | |
| printf(" "); | |
| else | |
| printf(" "); | |
| column += next - p + 1; | |
| printf("%.*s", (int) (next - p), p); | |
| p = next + 1; | |
| } | |
| if (column > 0) | |
| printf("\n"); | |
| } | |
| int | |
| main(int argc, char *argv[]) | |
| { | |
| int maj, min; | |
| EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); | |
| if (!eglInitialize(d, &maj, &min)) { | |
| printf("eglinfo: eglInitialize failed\n"); | |
| exit(1); | |
| } | |
| printf("EGL API version: %d.%d\n", maj, min); | |
| printf("EGL vendor string: %s\n", eglQueryString(d, EGL_VENDOR)); | |
| printf("EGL version string: %s\n", eglQueryString(d, EGL_VERSION)); | |
| #ifdef EGL_VERSION_1_2 | |
| printf("EGL client APIs: %s\n", eglQueryString(d, EGL_CLIENT_APIS)); | |
| #endif | |
| PrintExtensions(d); | |
| PrintConfigs(d); | |
| PrintModes(d); | |
| eglTerminate(d); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment