1 // Copyright 2012 Intel Corporation 2 // 3 // All rights reserved. 4 // 5 // Redistribution and use in source and binary forms, with or without 6 // modification, are permitted provided that the following conditions are met: 7 // 8 // - Redistributions of source code must retain the above copyright notice, this 9 // list of conditions and the following disclaimer. 10 // 11 // - Redistributions in binary form must reproduce the above copyright notice, 12 // this list of conditions and the following disclaimer in the documentation 13 // and/or other materials provided with the distribution. 14 // 15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26 #pragma once 27 28 #include <stdbool.h> 29 #include <stddef.h> 30 #include <stdint.h> 31 #include <stdlib.h> 32 33 #include "waffle_version.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 301) 40 # define WAFFLE_DEPRECATED __attribute__((deprecated)) 41 #elif defined(_MSC_VER) 42 # define WAFFLE_DEPRECATED __declspec(deprecated) 43 #else 44 # define WAFFLE_DEPRECATED 45 #endif 46 47 #if WAFFLE_API_VERSION >= 0x0106 48 # define WAFFLE_DEPRECATED_1_06 WAFFLE_DEPRECATED 49 #else 50 # define WAFFLE_DEPRECATED_1_06 51 #endif 52 53 struct waffle_display; 54 struct waffle_config; 55 struct waffle_context; 56 struct waffle_window; 57 58 union waffle_native_display; 59 union waffle_native_config; 60 union waffle_native_context; 61 union waffle_native_window; 62 63 // --------------------------------------------------------------------------- 64 // waffle_error 65 // --------------------------------------------------------------------------- 66 67 enum waffle_error { 68 WAFFLE_NO_ERROR = 0x00, 69 WAFFLE_ERROR_FATAL = 0x01, 70 WAFFLE_ERROR_UNKNOWN = 0x02, 71 WAFFLE_ERROR_INTERNAL = 0x03, 72 WAFFLE_ERROR_BAD_ALLOC = 0x04, 73 WAFFLE_ERROR_NOT_INITIALIZED = 0x05, 74 WAFFLE_ERROR_ALREADY_INITIALIZED = 0x06, 75 WAFFLE_ERROR_BAD_ATTRIBUTE = 0x08, 76 WAFFLE_ERROR_BAD_PARAMETER = 0x10, 77 WAFFLE_ERROR_BAD_DISPLAY_MATCH = 0x11, 78 WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM = 0x12, 79 WAFFLE_ERROR_BUILT_WITHOUT_SUPPORT = 0x13, 80 }; 81 82 struct waffle_error_info { 83 enum waffle_error code; 84 const char *message; 85 size_t message_length; 86 }; 87 88 enum waffle_error 89 waffle_error_get_code(void); 90 91 const struct waffle_error_info* 92 waffle_error_get_info(void); 93 94 const char* 95 waffle_error_to_string(enum waffle_error e); 96 97 // --------------------------------------------------------------------------- 98 // waffle_enum 99 // --------------------------------------------------------------------------- 100 101 enum waffle_enum { 102 // ------------------------------------------------------------------ 103 // Generic 104 // ------------------------------------------------------------------ 105 106 WAFFLE_DONT_CARE = -1, 107 WAFFLE_NONE = 0, 108 109 // ------------------------------------------------------------------ 110 // For waffle_init() 111 // ------------------------------------------------------------------ 112 113 WAFFLE_PLATFORM = 0x0010, 114 WAFFLE_PLATFORM_ANDROID = 0x0011, 115 WAFFLE_PLATFORM_CGL = 0x0012, 116 WAFFLE_PLATFORM_GLX = 0x0013, 117 WAFFLE_PLATFORM_WAYLAND = 0x0014, 118 WAFFLE_PLATFORM_X11_EGL = 0x0015, 119 WAFFLE_PLATFORM_GBM = 0x0016, 120 WAFFLE_PLATFORM_WGL = 0x0017, 121 WAFFLE_PLATFORM_NACL = 0x0018, 122 WAFFLE_PLATFORM_SURFACELESS_EGL = 0x0019, 123 124 // ------------------------------------------------------------------ 125 // For waffle_config_choose() 126 // ------------------------------------------------------------------ 127 128 WAFFLE_CONTEXT_API = 0x020a, 129 WAFFLE_CONTEXT_OPENGL = 0x020b, 130 WAFFLE_CONTEXT_OPENGL_ES1 = 0x020c, 131 WAFFLE_CONTEXT_OPENGL_ES2 = 0x020d, 132 WAFFLE_CONTEXT_OPENGL_ES3 = 0x0214, 133 134 WAFFLE_CONTEXT_MAJOR_VERSION = 0x020e, 135 WAFFLE_CONTEXT_MINOR_VERSION = 0x020f, 136 137 WAFFLE_CONTEXT_PROFILE = 0x0210, 138 WAFFLE_CONTEXT_CORE_PROFILE = 0x0211, 139 WAFFLE_CONTEXT_COMPATIBILITY_PROFILE = 0x0212, 140 141 WAFFLE_CONTEXT_FORWARD_COMPATIBLE = 0x0215, 142 WAFFLE_CONTEXT_DEBUG = 0x0216, 143 WAFFLE_CONTEXT_ROBUST_ACCESS = 0x0217, 144 145 WAFFLE_RED_SIZE = 0x0201, 146 WAFFLE_GREEN_SIZE = 0x0202, 147 WAFFLE_BLUE_SIZE = 0x0203, 148 WAFFLE_ALPHA_SIZE = 0x0204, 149 150 WAFFLE_DEPTH_SIZE = 0x0205, 151 WAFFLE_STENCIL_SIZE = 0x0206, 152 153 WAFFLE_SAMPLE_BUFFERS = 0x0207, 154 WAFFLE_SAMPLES = 0x0208, 155 156 WAFFLE_DOUBLE_BUFFERED = 0x0209, 157 158 WAFFLE_ACCUM_BUFFER = 0x0213, 159 160 // ------------------------------------------------------------------ 161 // For waffle_dl_sym() 162 // ------------------------------------------------------------------ 163 164 WAFFLE_DL_OPENGL = 0x0301, 165 WAFFLE_DL_OPENGL_ES1 = 0x0302, 166 WAFFLE_DL_OPENGL_ES2 = 0x0303, 167 WAFFLE_DL_OPENGL_ES3 = 0x0304, 168 169 // ------------------------------------------------------------------ 170 // For waffle_window 171 // ------------------------------------------------------------------ 172 173 WAFFLE_WINDOW_WIDTH = 0x0310, 174 WAFFLE_WINDOW_HEIGHT = 0x0311, 175 WAFFLE_WINDOW_FULLSCREEN = 0x0312, 176 }; 177 178 const char* 179 waffle_enum_to_string(int32_t e); 180 181 // --------------------------------------------------------------------------- 182 183 bool 184 waffle_init(const int32_t *attrib_list); 185 186 #if WAFFLE_API_VERSION >= 0x0106 187 bool 188 waffle_teardown(void); 189 #endif 190 191 bool 192 waffle_make_current(struct waffle_display *dpy, 193 struct waffle_window *window, 194 struct waffle_context *ctx); 195 196 #if WAFFLE_API_VERSION >= 0x0106 197 struct waffle_display * 198 waffle_get_current_display(void); 199 200 struct waffle_window * 201 waffle_get_current_window(void); 202 203 struct waffle_context * 204 waffle_get_current_context(void); 205 #endif 206 207 void* 208 waffle_get_proc_address(const char *name); 209 210 bool 211 waffle_is_extension_in_string(const char *extension_string, 212 const char *extension_name); 213 214 // --------------------------------------------------------------------------- 215 // waffle_display 216 // --------------------------------------------------------------------------- 217 218 struct waffle_display* 219 waffle_display_connect(const char *name); 220 221 bool 222 waffle_display_disconnect(struct waffle_display *self); 223 224 bool 225 waffle_display_supports_context_api(struct waffle_display *self, 226 int32_t context_api); 227 228 union waffle_native_display* 229 waffle_display_get_native(struct waffle_display *self); 230 231 // --------------------------------------------------------------------------- 232 // waffle_config 233 // --------------------------------------------------------------------------- 234 235 struct waffle_config* 236 waffle_config_choose(struct waffle_display *dpy, 237 const int32_t attrib_list[]); 238 239 bool 240 waffle_config_destroy(struct waffle_config *self); 241 242 union waffle_native_config* 243 waffle_config_get_native(struct waffle_config *self); 244 245 // --------------------------------------------------------------------------- 246 // waffle_context 247 // --------------------------------------------------------------------------- 248 249 struct waffle_context* 250 waffle_context_create(struct waffle_config *config, 251 struct waffle_context *shared_ctx); 252 253 bool 254 waffle_context_destroy(struct waffle_context *self); 255 256 union waffle_native_context* 257 waffle_context_get_native(struct waffle_context *self); 258 259 // --------------------------------------------------------------------------- 260 // waffle_window 261 // --------------------------------------------------------------------------- 262 263 #if WAFFLE_API_VERSION >= 0x0106 264 struct waffle_window* 265 waffle_window_create2( 266 struct waffle_config *config, 267 const intptr_t attrib_list[]); 268 #endif 269 270 struct waffle_window* 271 waffle_window_create( 272 struct waffle_config *config, 273 int32_t width, 274 int32_t height); 275 276 bool 277 waffle_window_destroy(struct waffle_window *self); 278 279 bool 280 waffle_window_show(struct waffle_window *self); 281 282 bool 283 waffle_window_swap_buffers(struct waffle_window *self); 284 285 union waffle_native_window* 286 waffle_window_get_native(struct waffle_window *self); 287 288 #if defined(WAFFLE_API_EXPERIMENTAL) && WAFFLE_API_VERSION >= 0x0103 289 bool 290 waffle_window_resize( 291 struct waffle_window *self, 292 int32_t width, 293 int32_t height); 294 #endif 295 296 // --------------------------------------------------------------------------- 297 // waffle_dl 298 // --------------------------------------------------------------------------- 299 300 bool 301 waffle_dl_can_open(int32_t dl); 302 303 void* 304 waffle_dl_sym(int32_t dl, const char *name); 305 306 // --------------------------------------------------------------------------- 307 // waffle_native 308 // --------------------------------------------------------------------------- 309 310 struct waffle_gbm_config; 311 struct waffle_gbm_context; 312 struct waffle_gbm_display; 313 struct waffle_gbm_window; 314 struct waffle_glx_config; 315 struct waffle_glx_context; 316 struct waffle_glx_display; 317 struct waffle_glx_window; 318 struct waffle_wayland_config; 319 struct waffle_wayland_context; 320 struct waffle_wayland_display; 321 struct waffle_wayland_window; 322 struct waffle_x11_egl_config; 323 struct waffle_x11_egl_context; 324 struct waffle_x11_egl_display; 325 struct waffle_x11_egl_window; 326 327 union waffle_native_display { 328 struct waffle_gbm_display *gbm; 329 struct waffle_glx_display *glx; 330 struct waffle_x11_egl_display *x11_egl; 331 struct waffle_wayland_display *wayland; 332 }; 333 334 union waffle_native_config { 335 struct waffle_gbm_config *gbm; 336 struct waffle_glx_config *glx; 337 struct waffle_x11_egl_config *x11_egl; 338 struct waffle_wayland_config *wayland; 339 }; 340 341 union waffle_native_context { 342 struct waffle_gbm_context *gbm; 343 struct waffle_glx_context *glx; 344 struct waffle_x11_egl_context *x11_egl; 345 struct waffle_wayland_context *wayland; 346 }; 347 348 union waffle_native_window { 349 struct waffle_gbm_window *gbm; 350 struct waffle_glx_window *glx; 351 struct waffle_x11_egl_window *x11_egl; 352 struct waffle_wayland_window *wayland; 353 }; 354 355 // --------------------------------------------------------------------------- 356 // waffle_attrib_list 357 // --------------------------------------------------------------------------- 358 359 WAFFLE_DEPRECATED_1_06 int32_t 360 waffle_attrib_list_length(const int32_t attrib_list[]); 361 362 WAFFLE_DEPRECATED_1_06 bool 363 waffle_attrib_list_get( 364 const int32_t attrib_list[], 365 int32_t key, 366 int32_t *value); 367 368 WAFFLE_DEPRECATED_1_06 bool 369 waffle_attrib_list_get_with_default( 370 const int32_t attrib_list[], 371 int32_t key, 372 int32_t *value, 373 int32_t default_value); 374 375 WAFFLE_DEPRECATED_1_06 bool 376 waffle_attrib_list_update( 377 int32_t *attrib_list, 378 int32_t key, 379 int32_t value); 380 381 #ifdef __cplusplus 382 } // end extern "C" 383 #endif 384