1 | /* |
2 | * Copyright © 2013 Intel Corporation |
3 | * |
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
5 | * copy of this software and associated documentation files (the "Software"), |
6 | * to deal in the Software without restriction, including without limitation |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
8 | * and/or sell copies of the Software, and to permit persons to whom the |
9 | * Software is furnished to do so, subject to the following conditions: |
10 | * |
11 | * The above copyright notice and this permission notice (including the next |
12 | * paragraph) shall be included in all copies or substantial portions of the |
13 | * Software. |
14 | * |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
21 | * IN THE SOFTWARE. |
22 | */ |
23 | |
24 | #include <assert.h> |
25 | #include <string.h> |
26 | #include <stdio.h> |
27 | |
28 | #include "dispatch_common.h" |
29 | |
30 | int |
31 | epoxy_conservative_egl_version(void) |
32 | { |
33 | EGLDisplay dpy = eglGetCurrentDisplay(); |
34 | |
35 | if (!dpy) |
36 | return 14; |
37 | |
38 | return epoxy_egl_version(dpy); |
39 | } |
40 | |
41 | /** |
42 | * @brief Returns the version of OpenGL we are using |
43 | * |
44 | * The version is encoded as: |
45 | * |
46 | * ``` |
47 | * |
48 | * version = major * 10 + minor |
49 | * |
50 | * ``` |
51 | * |
52 | * So it can be easily used for version comparisons. |
53 | * |
54 | * @param The EGL display |
55 | * |
56 | * @return The encoded version of EGL we are using |
57 | * |
58 | * @see epoxy_gl_version() |
59 | */ |
60 | int |
61 | epoxy_egl_version(EGLDisplay dpy) |
62 | { |
63 | int major, minor; |
64 | const char *version_string; |
65 | int ret; |
66 | |
67 | version_string = eglQueryString(dpy, EGL_VERSION); |
68 | if (!version_string) |
69 | return 0; |
70 | |
71 | ret = sscanf(s: version_string, format: "%d.%d" , &major, &minor); |
72 | assert(ret == 2); |
73 | return major * 10 + minor; |
74 | } |
75 | |
76 | bool |
77 | epoxy_conservative_has_egl_extension(const char *ext) |
78 | { |
79 | return epoxy_has_egl_extension(eglGetCurrentDisplay(), extension: ext); |
80 | } |
81 | |
82 | /** |
83 | * @brief Returns true if the given EGL extension is supported in the current context. |
84 | * |
85 | * @param dpy The EGL display |
86 | * @param extension The name of the EGL extension |
87 | * |
88 | * @return `true` if the extension is available |
89 | * |
90 | * @see epoxy_has_gl_extension() |
91 | * @see epoxy_has_glx_extension() |
92 | */ |
93 | bool |
94 | epoxy_has_egl_extension(EGLDisplay dpy, const char *ext) |
95 | { |
96 | return epoxy_extension_in_string(eglQueryString(dpy, EGL_EXTENSIONS), ext) || epoxy_extension_in_string(eglQueryString(NULL, EGL_EXTENSIONS), ext); |
97 | } |
98 | |
99 | /** |
100 | * @brief Checks whether EGL is available. |
101 | * |
102 | * @return `true` if EGL is available |
103 | * |
104 | * @newin{1,4} |
105 | */ |
106 | bool |
107 | epoxy_has_egl(void) |
108 | { |
109 | #if !PLATFORM_HAS_EGL |
110 | return false; |
111 | #else |
112 | if (epoxy_load_egl(false, true)) { |
113 | EGLDisplay* (* pf_eglGetCurrentDisplay) (void); |
114 | |
115 | pf_eglGetCurrentDisplay = epoxy_conservative_egl_dlsym(name: "eglGetCurrentDisplay" , false); |
116 | if (pf_eglGetCurrentDisplay) |
117 | return true; |
118 | } |
119 | |
120 | return false; |
121 | #endif /* PLATFORM_HAS_EGL */ |
122 | } |
123 | |