11b5d61b8Smrg/* 21b5d61b8Smrg * Copyright © 2016 Red Hat, Inc. 31b5d61b8Smrg * 41b5d61b8Smrg * Permission is hereby granted, free of charge, to any person obtaining a 51b5d61b8Smrg * copy of this software and associated documentation files (the "Software"), 61b5d61b8Smrg * to deal in the Software without restriction, including without limitation 71b5d61b8Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 81b5d61b8Smrg * and/or sell copies of the Software, and to permit persons to whom the 91b5d61b8Smrg * Software is furnished to do so, subject to the following conditions: 101b5d61b8Smrg * 111b5d61b8Smrg * The above copyright notice and this permission notice (including the next 121b5d61b8Smrg * paragraph) shall be included in all copies or substantial portions of the 131b5d61b8Smrg * Software. 141b5d61b8Smrg * 151b5d61b8Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 161b5d61b8Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 171b5d61b8Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 181b5d61b8Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 191b5d61b8Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 201b5d61b8Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 211b5d61b8Smrg * DEALINGS IN THE SOFTWARE. 221b5d61b8Smrg * 231b5d61b8Smrg * Authors: 241b5d61b8Smrg * Adam Jackson <ajax@redhat.com> 251b5d61b8Smrg */ 261b5d61b8Smrg 271b5d61b8Smrg#ifndef GLAMOR_EGL_H 281b5d61b8Smrg#define GLAMOR_EGL_H 291b5d61b8Smrg 301b5d61b8Smrg#define MESA_EGL_NO_X11_HEADERS 3125da500fSmrg#define EGL_NO_X11 321b5d61b8Smrg#include <epoxy/gl.h> 331b5d61b8Smrg#include <epoxy/egl.h> 341b5d61b8Smrg#include <glamor_egl_ext.h> 351b5d61b8Smrg 361b5d61b8Smrg/* 371b5d61b8Smrg * Create an EGLDisplay from a native display type. This is a little quirky 381b5d61b8Smrg * for a few reasons. 391b5d61b8Smrg * 401b5d61b8Smrg * 1: GetPlatformDisplayEXT and GetPlatformDisplay are the API you want to 411b5d61b8Smrg * use, but have different function signatures in the third argument; this 421b5d61b8Smrg * happens not to matter for us, at the moment, but it means epoxy won't alias 431b5d61b8Smrg * them together. 441b5d61b8Smrg * 451b5d61b8Smrg * 2: epoxy 1.3 and earlier don't understand EGL client extensions, which 461b5d61b8Smrg * means you can't call "eglGetPlatformDisplayEXT" directly, as the resolver 471b5d61b8Smrg * will crash. 481b5d61b8Smrg * 491b5d61b8Smrg * 3: You can't tell whether you have EGL 1.5 at this point, because 501b5d61b8Smrg * eglQueryString(EGL_VERSION) is a property of the display, which we don't 511b5d61b8Smrg * have yet. So you have to query for extensions no matter what. Fortunately 521b5d61b8Smrg * epoxy_has_egl_extension _does_ let you query for client extensions, so 531b5d61b8Smrg * we don't have to write our own extension string parsing. 541b5d61b8Smrg * 551b5d61b8Smrg * 4. There is no EGL_KHR_platform_base to complement the EXT one, thus one 561b5d61b8Smrg * needs to know EGL 1.5 is supported in order to use the eglGetPlatformDisplay 571b5d61b8Smrg * function pointer. 581b5d61b8Smrg * We can workaround this (circular dependency) by probing for the EGL 1.5 591b5d61b8Smrg * platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't seem 601b5d61b8Smrg * like mesa will be able to adverise these (even though it can do EGL 1.5). 611b5d61b8Smrg */ 621b5d61b8Smrgstatic inline EGLDisplay 631b5d61b8Smrgglamor_egl_get_display(EGLint type, void *native) 641b5d61b8Smrg{ 651b5d61b8Smrg /* In practise any EGL 1.5 implementation would support the EXT extension */ 661b5d61b8Smrg if (epoxy_has_egl_extension(NULL, "EGL_EXT_platform_base")) { 671b5d61b8Smrg PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT = 681b5d61b8Smrg (void *) eglGetProcAddress("eglGetPlatformDisplayEXT"); 691b5d61b8Smrg if (getPlatformDisplayEXT) 701b5d61b8Smrg return getPlatformDisplayEXT(type, native, NULL); 711b5d61b8Smrg } 721b5d61b8Smrg 731b5d61b8Smrg /* Welp, everything is awful. */ 741b5d61b8Smrg return eglGetDisplay(native); 751b5d61b8Smrg} 761b5d61b8Smrg 771b5d61b8Smrg#endif 78