| 1 | /** |
| 2 | * test_egl_configs: List available EGL configurations |
| 3 | * Copyright (c) 2013 Thomas Perl <m@thp.io> |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | **/ |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <unistd.h> |
| 21 | #include <string.h> |
| 22 | #include <assert.h> |
| 23 | |
| 24 | #include <EGL/egl.h> |
| 25 | #include <EGL/eglext.h> |
| 26 | |
| 27 | |
| 28 | #define FAIL_WITH(...) do { fprintf(stderr, __VA_ARGS__); exit(1); } while (0) |
| 29 | #define TEST_LOG(...) fprintf(stderr, __VA_ARGS__) |
| 30 | |
| 31 | #define TEST_ASSERT(x) do { \ |
| 32 | int error = eglGetError(); \ |
| 33 | if (error != EGL_SUCCESS) { \ |
| 34 | FAIL_WITH("EGL Error %x at %s:%d\n", error, __FILE__, __LINE__); \ |
| 35 | } \ |
| 36 | if (!(x)) { \ |
| 37 | FAIL_WITH("Assertion failed: %s at %s:%d\n", (#x), __FILE__, __LINE__); \ |
| 38 | } \ |
| 39 | } while (0) |
| 40 | |
| 41 | |
| 42 | static EGLDisplay display; |
| 43 | static EGLConfig config; |
| 44 | |
| 45 | int |
| 46 | ATTRIB(EGLint attribute) |
| 47 | { |
| 48 | EGLint value; |
| 49 | EGLBoolean result; |
| 50 | |
| 51 | result = eglGetConfigAttrib(display, config, attribute, &value); |
| 52 | if (result != EGL_TRUE) { |
| 53 | TEST_LOG("For attribute: %d\n", attribute); |
| 54 | TEST_ASSERT(result == EGL_TRUE); // this makes sure we exit() |
| 55 | } |
| 56 | |
| 57 | return value; |
| 58 | } |
| 59 | |
| 60 | #define TEST_LOG_FEATURE(x) TEST_LOG(" %s: %s\n", (#x), ATTRIB(x) ? "yes" : "no") |
| 61 | #define TEST_LOG_VALUE(x) TEST_LOG(" %s: %d\n", (#x), ATTRIB(x)) |
| 62 | #define TEST_LOG_VALUE_HEX(x) TEST_LOG(" %s: %x\n", (#x), ATTRIB(x)) |
| 63 | |
| 64 | #define SINCE_EGL_VERSION(maj, min) (major >= (maj) && minor >= (min)) |
| 65 | |
| 66 | /* Syntactic sugar for decoding one-of-many option fields */ |
| 67 | #define ATTRIB_SWITCH(x) TEST_LOG(" %s: ", (#x)); switch (ATTRIB(x)) |
| 68 | #define ATTRIB_CASE(x) case x: TEST_LOG("%s\n", (#x)); break |
| 69 | #define ATTRIB_SWITCH_DEFAULT(x) default: TEST_LOG("%x\n", ATTRIB(x)); break |
| 70 | |
| 71 | /* Syntactic sugar for decoding bitfields */ |
| 72 | #define START_DECODE_BITFIELD(x) value = ATTRIB(x); TEST_LOG(" %s: %x (", (#x), value); |
| 73 | #define TEST_BITFIELD_VALUE(x) if (value & (x)) TEST_LOG(" %s ", (#x)) |
| 74 | #define END_DECODE_BITFIELD(x) TEST_LOG(")\n") |
| 75 | |
| 76 | |
| 77 | /** |
| 78 | * For reference, the values tested below have been obtained from: |
| 79 | * http://www.khronos.org/registry/egl/sdk/docs/man/xhtml/eglGetConfigAttrib.html |
| 80 | * http://www.khronos.org/registry/egl/sdk/docs/man/xhtml/eglChooseConfig.html |
| 81 | **/ |
| 82 | |
| 83 | int |
| 84 | main(int argc, char *argv[]) |
| 85 | { |
| 86 | EGLBoolean result; |
| 87 | EGLint major, minor; |
| 88 | EGLint num_config; |
| 89 | EGLint num_config_result; |
| 90 | EGLConfig *configs; |
| 91 | EGLint value; |
| 92 | int i; |
| 93 | |
| 94 | TEST_LOG("Starting test (EGL_PLATFORM=%s)\n", getenv("EGL_PLATFORM")); |
| 95 | |
| 96 | display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 97 | TEST_ASSERT(display != EGL_NO_DISPLAY); |
| 98 | |
| 99 | result = eglInitialize(display, &major, &minor); |
| 100 | TEST_ASSERT(result == EGL_TRUE); |
| 101 | |
| 102 | TEST_LOG("EGL Version %d.%d\n", major, minor); |
| 103 | TEST_LOG("Extensions: %s\n", eglQueryString(display, EGL_EXTENSIONS)); |
| 104 | |
| 105 | result = eglGetConfigs(display, NULL, 0, &num_config); |
| 106 | TEST_ASSERT(result == EGL_TRUE); |
| 107 | |
| 108 | TEST_LOG("Available configurations: %d\n", num_config); |
| 109 | configs = (EGLConfig *)calloc(num_config, sizeof(EGLConfig)); |
| 110 | |
| 111 | result = eglGetConfigs(display, configs, num_config, &num_config_result); |
| 112 | TEST_ASSERT(result == EGL_TRUE); |
| 113 | |
| 114 | for (i=0; i<num_config_result; i++) { |
| 115 | config = configs[i]; |
| 116 | |
| 117 | TEST_LOG("===== Configuration #%d =====\n", i); |
| 118 | |
| 119 | TEST_LOG_VALUE(EGL_RED_SIZE); |
| 120 | TEST_LOG_VALUE(EGL_GREEN_SIZE); |
| 121 | TEST_LOG_VALUE(EGL_BLUE_SIZE); |
| 122 | TEST_LOG_VALUE(EGL_ALPHA_SIZE); |
| 123 | TEST_LOG_VALUE(EGL_BUFFER_SIZE); |
| 124 | TEST_LOG_VALUE(EGL_DEPTH_SIZE); |
| 125 | TEST_LOG_VALUE(EGL_STENCIL_SIZE); |
| 126 | |
| 127 | TEST_LOG_VALUE(EGL_CONFIG_ID); |
| 128 | TEST_LOG_VALUE(EGL_LEVEL); |
| 129 | TEST_LOG_VALUE(EGL_SAMPLE_BUFFERS); |
| 130 | TEST_LOG_VALUE(EGL_SAMPLES); |
| 131 | |
| 132 | TEST_LOG_VALUE(EGL_MAX_PBUFFER_WIDTH); |
| 133 | TEST_LOG_VALUE(EGL_MAX_PBUFFER_HEIGHT); |
| 134 | TEST_LOG_VALUE(EGL_MAX_PBUFFER_PIXELS); |
| 135 | |
| 136 | TEST_LOG_VALUE(EGL_MIN_SWAP_INTERVAL); |
| 137 | TEST_LOG_VALUE(EGL_MAX_SWAP_INTERVAL); |
| 138 | |
| 139 | TEST_LOG_VALUE(EGL_NATIVE_VISUAL_ID); |
| 140 | TEST_LOG_VALUE(EGL_NATIVE_VISUAL_TYPE); |
| 141 | |
| 142 | ATTRIB_SWITCH(EGL_CONFIG_CAVEAT) { |
| 143 | ATTRIB_CASE(EGL_NONE); |
| 144 | ATTRIB_CASE(EGL_SLOW_CONFIG); |
| 145 | ATTRIB_CASE(EGL_NON_CONFORMANT_CONFIG); |
| 146 | ATTRIB_SWITCH_DEFAULT(EGL_CONFIG_CAVEAT); |
| 147 | } |
| 148 | |
| 149 | TEST_LOG_FEATURE(EGL_BIND_TO_TEXTURE_RGB); |
| 150 | TEST_LOG_FEATURE(EGL_BIND_TO_TEXTURE_RGBA); |
| 151 | TEST_LOG_FEATURE(EGL_NATIVE_RENDERABLE); |
| 152 | |
| 153 | START_DECODE_BITFIELD(EGL_SURFACE_TYPE) { |
| 154 | TEST_BITFIELD_VALUE(EGL_MULTISAMPLE_RESOLVE_BOX_BIT); |
| 155 | TEST_BITFIELD_VALUE(EGL_PBUFFER_BIT); |
| 156 | TEST_BITFIELD_VALUE(EGL_PIXMAP_BIT); |
| 157 | TEST_BITFIELD_VALUE(EGL_SWAP_BEHAVIOR_PRESERVED_BIT); |
| 158 | TEST_BITFIELD_VALUE(EGL_VG_ALPHA_FORMAT_PRE_BIT); |
| 159 | TEST_BITFIELD_VALUE(EGL_VG_COLORSPACE_LINEAR_BIT); |
| 160 | TEST_BITFIELD_VALUE(EGL_WINDOW_BIT); |
| 161 | } END_DECODE_BITFIELD(EGL_SURFACE_TYPE); |
| 162 | |
| 163 | TEST_LOG_VALUE_HEX(EGL_TRANSPARENT_RED_VALUE); |
| 164 | TEST_LOG_VALUE_HEX(EGL_TRANSPARENT_GREEN_VALUE); |
| 165 | TEST_LOG_VALUE_HEX(EGL_TRANSPARENT_BLUE_VALUE); |
| 166 | |
| 167 | ATTRIB_SWITCH(EGL_TRANSPARENT_TYPE) { |
| 168 | ATTRIB_CASE(EGL_NONE); |
| 169 | ATTRIB_CASE(EGL_TRANSPARENT_RGB); |
| 170 | ATTRIB_SWITCH_DEFAULT(EGL_TRANSPARENT_TYPE); |
| 171 | } |
| 172 | |
| 173 | // New features introduced in EGL 1.2 |
| 174 | if (SINCE_EGL_VERSION(1, 2)) { |
| 175 | #ifdef EGL_LUMINANCE_SIZE |
| 176 | TEST_LOG_VALUE(EGL_LUMINANCE_SIZE); |
| 177 | #endif /* EGL_LUMINANCE_SIZE */ |
| 178 | |
| 179 | #ifdef EGL_COLOR_BUFFER_TYPE |
| 180 | ATTRIB_SWITCH(EGL_COLOR_BUFFER_TYPE) { |
| 181 | ATTRIB_CASE(EGL_RGB_BUFFER); |
| 182 | ATTRIB_CASE(EGL_LUMINANCE_BUFFER); |
| 183 | ATTRIB_SWITCH_DEFAULT(EGL_COLOR_BUFFER_TYPE); |
| 184 | } |
| 185 | #endif /* EGL_COLOR_BUFFER_TYPE */ |
| 186 | |
| 187 | #ifdef EGL_RENDERABLE_TYPE |
| 188 | START_DECODE_BITFIELD(EGL_RENDERABLE_TYPE) { |
| 189 | TEST_BITFIELD_VALUE(EGL_OPENGL_BIT); |
| 190 | TEST_BITFIELD_VALUE(EGL_OPENGL_ES_BIT); |
| 191 | TEST_BITFIELD_VALUE(EGL_OPENGL_ES2_BIT); |
| 192 | TEST_BITFIELD_VALUE(EGL_OPENVG_BIT); |
| 193 | } END_DECODE_BITFIELD(EGL_RENDERABLE_TYPE); |
| 194 | #endif /* EGL_RENDERABLE_TYPE */ |
| 195 | } |
| 196 | |
| 197 | // New features introduced in EGL 1.3 |
| 198 | if (SINCE_EGL_VERSION(1, 3)) { |
| 199 | #ifdef EGL_CONFORMANT |
| 200 | START_DECODE_BITFIELD(EGL_CONFORMANT) { |
| 201 | TEST_BITFIELD_VALUE(EGL_OPENGL_BIT); |
| 202 | TEST_BITFIELD_VALUE(EGL_OPENGL_ES_BIT); |
| 203 | TEST_BITFIELD_VALUE(EGL_OPENGL_ES2_BIT); |
| 204 | TEST_BITFIELD_VALUE(EGL_OPENVG_BIT); |
| 205 | } END_DECODE_BITFIELD(EGL_CONFORMANT); |
| 206 | #endif /* EGL_CONFORMANT */ |
| 207 | } |
| 208 | |
| 209 | TEST_LOG("\n\n"); |
| 210 | } |
| 211 | |
| 212 | free(configs); |
| 213 | |
| 214 | result = eglTerminate(display); |
| 215 | TEST_ASSERT(result == EGL_TRUE); |
| 216 | |
| 217 | return 0; |
| 218 | } |