1#![allow(non_upper_case_globals)]
41#![allow(non_snake_case)]
42#![allow(clippy::missing_safety_doc)]
47#![allow(clippy::missing_transmute_annotations)]
48
49extern crate libc;
50
51use std::convert::{TryFrom, TryInto};
52use std::ffi::CStr;
53use std::ffi::CString;
54use std::fmt;
55use std::ptr;
56
57use libc::{c_char, c_uint, c_void};
58
59pub trait Api {
61 fn version(&self) -> Version;
63}
64
65pub trait Downcast<V> {
66 fn downcast(&self) -> &V;
67}
68
69impl<T> Downcast<T> for T {
70 fn downcast(&self) -> &T {
71 self
72 }
73}
74
75pub trait Upcast<V> {
76 fn upcast(&self) -> Option<&V>;
77}
78
79impl<T> Upcast<T> for T {
80 fn upcast(&self) -> Option<&T> {
81 Some(self)
82 }
83}
84
85pub struct Instance<T> {
90 api: T,
91}
92
93impl<T> Instance<T> {
94 #[inline(always)]
96 pub fn cast_into<U: From<T>>(self) -> Instance<U> {
97 Instance {
98 api: self.api.into(),
99 }
100 }
101
102 #[inline(always)]
104 pub fn try_cast_into<U: TryFrom<T>>(self) -> Result<Instance<U>, Instance<U::Error>> {
105 match self.api.try_into() {
106 Ok(t) => Ok(Instance { api: t }),
107 Err(e) => Err(Instance { api: e }),
108 }
109 }
110
111 #[inline(always)]
113 pub fn version(&self) -> Version
114 where
115 T: Api,
116 {
117 self.api.version()
118 }
119}
120
121impl<T> Instance<T> {
122 #[inline(always)]
123 pub const fn new(api: T) -> Instance<T> {
124 Instance { api }
125 }
126}
127
128impl<T: fmt::Debug> fmt::Debug for Instance<T> {
129 #[inline(always)]
130 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
131 write!(f, "Instance({:?})", self.api)
132 }
133}
134
135impl<T> From<T> for Instance<T> {
136 #[inline(always)]
137 fn from(t: T) -> Instance<T> {
138 Instance::new(t)
139 }
140}
141
142#[cfg(feature = "1_0")]
147mod egl1_0 {
148 use super::*;
149
150 pub type Boolean = c_uint;
151 pub type Int = i32;
152 pub type Attrib = usize;
153 pub type EGLDisplay = *mut c_void;
154 pub type EGLConfig = *mut c_void;
155 pub type EGLContext = *mut c_void;
156 pub type EGLSurface = *mut c_void;
157 pub type NativeDisplayType = *mut c_void;
158
159 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
160 pub struct Display(EGLDisplay);
161
162 impl Display {
163 #[inline]
169 pub unsafe fn from_ptr(ptr: EGLDisplay) -> Display {
170 Display(ptr)
171 }
172
173 #[inline]
174 pub fn as_ptr(&self) -> EGLDisplay {
175 self.0
176 }
177 }
178
179 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
180 pub struct Config(pub(crate) EGLConfig);
181
182 impl Config {
183 #[inline]
189 pub unsafe fn from_ptr(ptr: EGLConfig) -> Config {
190 Config(ptr)
191 }
192
193 #[inline]
194 pub fn as_ptr(&self) -> EGLConfig {
195 self.0
196 }
197 }
198
199 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
200 pub struct Context(pub(crate) EGLContext);
201
202 impl Context {
203 #[inline]
209 pub unsafe fn from_ptr(ptr: EGLContext) -> Context {
210 Context(ptr)
211 }
212
213 #[inline]
214 pub fn as_ptr(&self) -> EGLContext {
215 self.0
216 }
217 }
218
219 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
220 pub struct Surface(EGLSurface);
221
222 impl Surface {
223 #[inline]
229 pub unsafe fn from_ptr(ptr: EGLSurface) -> Surface {
230 Surface(ptr)
231 }
232
233 #[inline]
234 pub fn as_ptr(&self) -> EGLSurface {
235 self.0
236 }
237 }
238
239 #[cfg(not(target_os = "android"))]
240 pub type NativePixmapType = *mut c_void;
241
242 #[cfg(not(target_os = "android"))]
243 pub type NativeWindowType = *mut c_void;
244
245 #[cfg(target_os = "android")]
252 pub type NativePixmapType = *mut c_void;
253
254 #[cfg(target_os = "android")]
255 pub type NativeWindowType = *mut c_void;
256
257 pub const ALPHA_SIZE: Int = 0x3021;
258 pub const BAD_ACCESS: Int = 0x3002;
259 pub const BAD_ALLOC: Int = 0x3003;
260 pub const BAD_ATTRIBUTE: Int = 0x3004;
261 pub const BAD_CONFIG: Int = 0x3005;
262 pub const BAD_CONTEXT: Int = 0x3006;
263 pub const BAD_CURRENT_SURFACE: Int = 0x3007;
264 pub const BAD_DISPLAY: Int = 0x3008;
265 pub const BAD_MATCH: Int = 0x3009;
266 pub const BAD_NATIVE_PIXMAP: Int = 0x300A;
267 pub const BAD_NATIVE_WINDOW: Int = 0x300B;
268 pub const BAD_PARAMETER: Int = 0x300C;
269 pub const BAD_SURFACE: Int = 0x300D;
270 pub const BLUE_SIZE: Int = 0x3022;
271 pub const BUFFER_SIZE: Int = 0x3020;
272 pub const CONFIG_CAVEAT: Int = 0x3027;
273 pub const CONFIG_ID: Int = 0x3028;
274 pub const CORE_NATIVE_ENGINE: Int = 0x305B;
275 pub const DEPTH_SIZE: Int = 0x3025;
276 pub const DONT_CARE: Int = -1;
277 pub const DRAW: Int = 0x3059;
278 pub const EXTENSIONS: Int = 0x3055;
279 pub const FALSE: Boolean = 0;
280 pub const GREEN_SIZE: Int = 0x3023;
281 pub const HEIGHT: Int = 0x3056;
282 pub const LARGEST_PBUFFER: Int = 0x3058;
283 pub const LEVEL: Int = 0x3029;
284 pub const MAX_PBUFFER_HEIGHT: Int = 0x302A;
285 pub const MAX_PBUFFER_PIXELS: Int = 0x302B;
286 pub const MAX_PBUFFER_WIDTH: Int = 0x302C;
287 pub const NATIVE_RENDERABLE: Int = 0x302D;
288 pub const NATIVE_VISUAL_ID: Int = 0x302E;
289 pub const NATIVE_VISUAL_TYPE: Int = 0x302F;
290 pub const NONE: Int = 0x3038;
291 pub const ATTRIB_NONE: Attrib = 0x3038;
292 pub const NON_CONFORMANT_CONFIG: Int = 0x3051;
293 pub const NOT_INITIALIZED: Int = 0x3001;
294 pub const NO_CONTEXT: EGLContext = 0 as EGLContext;
295 pub const NO_DISPLAY: EGLDisplay = 0 as EGLDisplay;
296 pub const NO_SURFACE: EGLSurface = 0 as EGLSurface;
297 pub const PBUFFER_BIT: Int = 0x0001;
298 pub const PIXMAP_BIT: Int = 0x0002;
299 pub const READ: Int = 0x305A;
300 pub const RED_SIZE: Int = 0x3024;
301 pub const SAMPLES: Int = 0x3031;
302 pub const SAMPLE_BUFFERS: Int = 0x3032;
303 pub const SLOW_CONFIG: Int = 0x3050;
304 pub const STENCIL_SIZE: Int = 0x3026;
305 pub const SUCCESS: Int = 0x3000;
306 pub const SURFACE_TYPE: Int = 0x3033;
307 pub const TRANSPARENT_BLUE_VALUE: Int = 0x3035;
308 pub const TRANSPARENT_GREEN_VALUE: Int = 0x3036;
309 pub const TRANSPARENT_RED_VALUE: Int = 0x3037;
310 pub const TRANSPARENT_RGB: Int = 0x3052;
311 pub const TRANSPARENT_TYPE: Int = 0x3034;
312 pub const TRUE: Boolean = 1;
313 pub const VENDOR: Int = 0x3053;
314 pub const VERSION: Int = 0x3054;
315 pub const WIDTH: Int = 0x3057;
316 pub const WINDOW_BIT: Int = 0x0004;
317
318 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
320 pub enum Error {
321 NotInitialized,
324
325 BadAccess,
328
329 BadAlloc,
331
332 BadAttribute,
335
336 BadContext,
338
339 BadConfig,
341
342 BadCurrentSurface,
345
346 BadDisplay,
348
349 BadSurface,
352
353 BadMatch,
356
357 BadParameter,
359
360 BadNativePixmap,
362
363 BadNativeWindow,
365
366 ContextLost,
370 }
371
372 impl std::error::Error for Error {
373 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
374 None
375 }
376 }
377
378 impl Error {
379 pub fn native(&self) -> Int {
380 use Error::*;
381 match self {
382 NotInitialized => NOT_INITIALIZED,
383 BadAccess => BAD_ACCESS,
384 BadAlloc => BAD_ALLOC,
385 BadAttribute => BAD_ATTRIBUTE,
386 BadContext => BAD_CONTEXT,
387 BadConfig => BAD_CONFIG,
388 BadCurrentSurface => BAD_CURRENT_SURFACE,
389 BadDisplay => BAD_DISPLAY,
390 BadSurface => BAD_SURFACE,
391 BadMatch => BAD_MATCH,
392 BadParameter => BAD_PARAMETER,
393 BadNativePixmap => BAD_NATIVE_PIXMAP,
394 BadNativeWindow => BAD_NATIVE_WINDOW,
395 ContextLost => CONTEXT_LOST,
396 }
397 }
398
399 fn message(&self) -> &'static str {
400 use Error::*;
401 match self {
402 NotInitialized => "EGL is not initialized, or could not be initialized, for the specified EGL display connection.",
403 BadAccess => "EGL cannot access a requested resource (for example a context is bound in another thread.",
404 BadAlloc => "EGL failed to allocate resources for the requested operation.",
405 BadAttribute => "An unrecognized attribute or attribute value was passed in the attribute list.",
406 BadContext => "An Context argument does not name a valid EGL rendering context.",
407 BadConfig => "An Config argument does not name a valid EGL frame buffer configuration.",
408 BadCurrentSurface => "The current surface of the calling thread is a window, pixel buffer or pixmap that is no longer valid.",
409 BadDisplay => "An Display argument does not name a valid EGL display connection.",
410 BadSurface => "An Surface argument does not name a valid surface (window, pixel buffer or pixmap) configured for GL rendering.",
411 BadMatch => "Arguments are inconsistent (for example, a valid context requires buffers not supplied by a valid surface.",
412 BadParameter => "One or more argument values are invalid.",
413 BadNativePixmap => "A NativePixmapType argument does not refer to a valid native pixmap.",
414 BadNativeWindow => "A NativeWindowType argument does not refer to a valid native window.",
415 ContextLost => "A power management event has occurred. The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering."
416 }
417 }
418 }
419
420 impl From<Error> for Int {
421 fn from(e: Error) -> Int {
422 e.native()
423 }
424 }
425
426 impl TryFrom<Int> for Error {
427 type Error = Int;
428
429 fn try_from(e: Int) -> Result<Error, Int> {
430 use Error::*;
431 match e {
432 NOT_INITIALIZED => Ok(NotInitialized),
433 BAD_ACCESS => Ok(BadAccess),
434 BAD_ALLOC => Ok(BadAlloc),
435 BAD_ATTRIBUTE => Ok(BadAttribute),
436 BAD_CONTEXT => Ok(BadContext),
437 BAD_CONFIG => Ok(BadConfig),
438 BAD_CURRENT_SURFACE => Ok(BadCurrentSurface),
439 BAD_DISPLAY => Ok(BadDisplay),
440 BAD_SURFACE => Ok(BadSurface),
441 BAD_MATCH => Ok(BadMatch),
442 BAD_PARAMETER => Ok(BadParameter),
443 BAD_NATIVE_PIXMAP => Ok(BadNativePixmap),
444 BAD_NATIVE_WINDOW => Ok(BadNativeWindow),
445 CONTEXT_LOST => Ok(ContextLost),
446 _ => Err(e),
447 }
448 }
449 }
450
451 impl fmt::Display for Error {
452 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
453 self.message().fmt(f)
454 }
455 }
456
457 pub fn check_int_list(attrib_list: &[Int]) -> Result<(), Error> {
458 if attrib_list.last() == Some(&NONE) {
459 Ok(())
460 } else {
461 Err(Error::BadParameter)
462 }
463 }
464
465 pub fn check_attrib_list(attrib_list: &[Attrib]) -> Result<(), Error> {
466 if attrib_list.last() == Some(&ATTRIB_NONE) {
467 Ok(())
468 } else {
469 Err(Error::BadParameter)
470 }
471 }
472
473 impl<T: api::EGL1_0> Instance<T> {
474 pub fn matching_config_count(
483 &self,
484 display: Display,
485 attrib_list: &[Int],
486 ) -> Result<usize, Error> {
487 check_int_list(attrib_list)?;
488 unsafe {
489 let mut count = 0;
490
491 if self.api.eglChooseConfig(
492 display.as_ptr(),
493 attrib_list.as_ptr(),
494 ptr::null_mut(),
495 0,
496 &mut count,
497 ) == TRUE
498 {
499 Ok(count as usize)
500 } else {
501 Err(self.get_error().unwrap())
502 }
503 }
504 }
505
506 pub fn choose_config(
536 &self,
537 display: Display,
538 attrib_list: &[Int],
539 configs: &mut Vec<Config>,
540 ) -> Result<(), Error> {
541 check_int_list(attrib_list)?;
542
543 let capacity = configs.capacity();
544 if capacity == 0 {
545 Ok(())
549 } else {
550 unsafe {
551 let mut count = 0;
552
553 if self.api.eglChooseConfig(
554 display.as_ptr(),
555 attrib_list.as_ptr(),
556 configs.as_mut_ptr() as *mut EGLConfig,
557 capacity.try_into().unwrap(),
558 &mut count,
559 ) == TRUE
560 {
561 configs.set_len(count as usize);
562 Ok(())
563 } else {
564 Err(self.get_error().unwrap())
565 }
566 }
567 }
568 }
569
570 pub fn choose_first_config(
590 &self,
591 display: Display,
592 attrib_list: &[Int],
593 ) -> Result<Option<Config>, Error> {
594 let mut configs = Vec::with_capacity(1);
595 self.choose_config(display, attrib_list, &mut configs)?;
596 Ok(configs.first().copied())
597 }
598
599 pub unsafe fn copy_buffers(
606 &self,
607 display: Display,
608 surface: Surface,
609 target: NativePixmapType,
610 ) -> Result<(), Error> {
611 unsafe {
612 if self
613 .api
614 .eglCopyBuffers(display.as_ptr(), surface.as_ptr(), target)
615 == TRUE
616 {
617 Ok(())
618 } else {
619 Err(self.get_error().unwrap())
620 }
621 }
622 }
623
624 pub fn create_context(
629 &self,
630 display: Display,
631 config: Config,
632 share_context: Option<Context>,
633 attrib_list: &[Int],
634 ) -> Result<Context, Error> {
635 check_int_list(attrib_list)?;
636 unsafe {
637 let share_context = match share_context {
638 Some(share_context) => share_context.as_ptr(),
639 None => NO_CONTEXT,
640 };
641
642 let context = self.api.eglCreateContext(
643 display.as_ptr(),
644 config.as_ptr(),
645 share_context,
646 attrib_list.as_ptr(),
647 );
648
649 if context != NO_CONTEXT {
650 Ok(Context(context))
651 } else {
652 Err(self.get_error().unwrap())
653 }
654 }
655 }
656
657 pub fn create_pbuffer_surface(
662 &self,
663 display: Display,
664 config: Config,
665 attrib_list: &[Int],
666 ) -> Result<Surface, Error> {
667 check_int_list(attrib_list)?;
668 unsafe {
669 let surface = self.api.eglCreatePbufferSurface(
670 display.as_ptr(),
671 config.as_ptr(),
672 attrib_list.as_ptr(),
673 );
674
675 if surface != NO_SURFACE {
676 Ok(Surface(surface))
677 } else {
678 Err(self.get_error().unwrap())
679 }
680 }
681 }
682
683 pub unsafe fn create_pixmap_surface(
693 &self,
694 display: Display,
695 config: Config,
696 pixmap: NativePixmapType,
697 attrib_list: &[Int],
698 ) -> Result<Surface, Error> {
699 check_int_list(attrib_list)?;
700 let surface = self.api.eglCreatePixmapSurface(
701 display.as_ptr(),
702 config.as_ptr(),
703 pixmap,
704 attrib_list.as_ptr(),
705 );
706
707 if surface != NO_SURFACE {
708 Ok(Surface(surface))
709 } else {
710 Err(self.get_error().unwrap())
711 }
712 }
713
714 pub unsafe fn create_window_surface(
724 &self,
725 display: Display,
726 config: Config,
727 window: NativeWindowType,
728 attrib_list: Option<&[Int]>,
729 ) -> Result<Surface, Error> {
730 let attrib_list = match attrib_list {
731 Some(attrib_list) => {
732 check_int_list(attrib_list)?;
733 attrib_list.as_ptr()
734 }
735 None => ptr::null(),
736 };
737
738 let surface = self.api.eglCreateWindowSurface(
739 display.as_ptr(),
740 config.as_ptr(),
741 window,
742 attrib_list,
743 );
744
745 if surface != NO_SURFACE {
746 Ok(Surface(surface))
747 } else {
748 Err(self.get_error().unwrap())
749 }
750 }
751
752 pub fn destroy_context(&self, display: Display, ctx: Context) -> Result<(), Error> {
754 unsafe {
755 if self.api.eglDestroyContext(display.as_ptr(), ctx.as_ptr()) == TRUE {
756 Ok(())
757 } else {
758 Err(self.get_error().unwrap())
759 }
760 }
761 }
762
763 pub fn destroy_surface(&self, display: Display, surface: Surface) -> Result<(), Error> {
765 unsafe {
766 if self
767 .api
768 .eglDestroySurface(display.as_ptr(), surface.as_ptr())
769 == TRUE
770 {
771 Ok(())
772 } else {
773 Err(self.get_error().unwrap())
774 }
775 }
776 }
777
778 pub fn get_config_attrib(
780 &self,
781 display: Display,
782 config: Config,
783 attribute: Int,
784 ) -> Result<Int, Error> {
785 unsafe {
786 let mut value: Int = 0;
787 if self.api.eglGetConfigAttrib(
788 display.as_ptr(),
789 config.as_ptr(),
790 attribute,
791 &mut value,
792 ) == TRUE
793 {
794 Ok(value)
795 } else {
796 Err(self.get_error().unwrap())
797 }
798 }
799 }
800
801 pub fn get_config_count(&self, display: Display) -> Result<usize, Error> {
820 unsafe {
821 let mut count = 0;
822
823 if self
824 .api
825 .eglGetConfigs(display.as_ptr(), std::ptr::null_mut(), 0, &mut count)
826 == TRUE
827 {
828 Ok(count as usize)
829 } else {
830 Err(self.get_error().unwrap())
831 }
832 }
833 }
834
835 pub fn get_configs(
855 &self,
856 display: Display,
857 configs: &mut Vec<Config>,
858 ) -> Result<(), Error> {
859 let capacity = configs.capacity();
860 if capacity == 0 {
861 Ok(())
865 } else {
866 unsafe {
867 let mut count = 0;
868
869 if self.api.eglGetConfigs(
870 display.as_ptr(),
871 configs.as_mut_ptr() as *mut EGLConfig,
872 capacity.try_into().unwrap(),
873 &mut count,
874 ) == TRUE
875 {
876 configs.set_len(count as usize);
877 Ok(())
878 } else {
879 Err(self.get_error().unwrap())
880 }
881 }
882 }
883 }
884
885 pub fn get_current_display(&self) -> Option<Display> {
887 unsafe {
888 let display = self.api.eglGetCurrentDisplay();
889
890 if display != NO_DISPLAY {
891 Some(Display(display))
892 } else {
893 None
894 }
895 }
896 }
897
898 pub fn get_current_surface(&self, readdraw: Int) -> Option<Surface> {
900 unsafe {
901 let surface = self.api.eglGetCurrentSurface(readdraw);
902
903 if surface != NO_SURFACE {
904 Some(Surface(surface))
905 } else {
906 None
907 }
908 }
909 }
910
911 pub unsafe fn get_display(&self, display_id: NativeDisplayType) -> Option<Display> {
924 let display = self.api.eglGetDisplay(display_id);
925
926 if display != NO_DISPLAY {
927 Some(Display(display))
928 } else {
929 None
930 }
931 }
932
933 pub fn get_error(&self) -> Option<Error> {
943 unsafe {
944 let e = self.api.eglGetError();
945 if e == SUCCESS {
946 None
947 } else {
948 Some(e.try_into().unwrap())
949 }
950 }
951 }
952
953 pub fn get_proc_address(&self, procname: &str) -> Option<extern "system" fn()> {
955 unsafe {
956 let string = CString::new(procname).unwrap();
957
958 let addr = self.api.eglGetProcAddress(string.as_ptr());
959 if addr as usize != 0 {
963 Some(addr)
964 } else {
965 None
966 }
967 }
968 }
969
970 pub fn initialize(&self, display: Display) -> Result<(Int, Int), Error> {
972 unsafe {
973 let mut major = 0;
974 let mut minor = 0;
975
976 if self
977 .api
978 .eglInitialize(display.as_ptr(), &mut major, &mut minor)
979 == TRUE
980 {
981 Ok((major, minor))
982 } else {
983 Err(self.get_error().unwrap())
984 }
985 }
986 }
987
988 pub fn make_current(
990 &self,
991 display: Display,
992 draw: Option<Surface>,
993 read: Option<Surface>,
994 ctx: Option<Context>,
995 ) -> Result<(), Error> {
996 unsafe {
997 let draw = match draw {
998 Some(draw) => draw.as_ptr(),
999 None => NO_SURFACE,
1000 };
1001 let read = match read {
1002 Some(read) => read.as_ptr(),
1003 None => NO_SURFACE,
1004 };
1005 let ctx = match ctx {
1006 Some(ctx) => ctx.as_ptr(),
1007 None => NO_CONTEXT,
1008 };
1009
1010 if self.api.eglMakeCurrent(display.as_ptr(), draw, read, ctx) == TRUE {
1011 Ok(())
1012 } else {
1013 Err(self.get_error().unwrap())
1014 }
1015 }
1016 }
1017
1018 pub fn query_context(
1020 &self,
1021 display: Display,
1022 ctx: Context,
1023 attribute: Int,
1024 ) -> Result<Int, Error> {
1025 unsafe {
1026 let mut value = 0;
1027 if self
1028 .api
1029 .eglQueryContext(display.as_ptr(), ctx.as_ptr(), attribute, &mut value)
1030 == TRUE
1031 {
1032 Ok(value)
1033 } else {
1034 Err(self.get_error().unwrap())
1035 }
1036 }
1037 }
1038
1039 pub fn query_string(
1042 &self,
1043 display: Option<Display>,
1044 name: Int,
1045 ) -> Result<&'static CStr, Error> {
1046 unsafe {
1047 let display_ptr = match display {
1048 Some(display) => display.as_ptr(),
1049 None => NO_DISPLAY,
1050 };
1051
1052 let c_str = self.api.eglQueryString(display_ptr, name);
1053
1054 if !c_str.is_null() {
1055 Ok(CStr::from_ptr(c_str))
1056 } else {
1057 Err(self.get_error().unwrap())
1058 }
1059 }
1060 }
1061
1062 pub fn query_surface(
1064 &self,
1065 display: Display,
1066 surface: Surface,
1067 attribute: Int,
1068 ) -> Result<Int, Error> {
1069 unsafe {
1070 let mut value = 0;
1071 if self.api.eglQuerySurface(
1072 display.as_ptr(),
1073 surface.as_ptr(),
1074 attribute,
1075 &mut value,
1076 ) == TRUE
1077 {
1078 Ok(value)
1079 } else {
1080 Err(self.get_error().unwrap())
1081 }
1082 }
1083 }
1084
1085 pub fn swap_buffers(&self, display: Display, surface: Surface) -> Result<(), Error> {
1087 unsafe {
1088 if self.api.eglSwapBuffers(display.as_ptr(), surface.as_ptr()) == TRUE {
1089 Ok(())
1090 } else {
1091 Err(self.get_error().unwrap())
1092 }
1093 }
1094 }
1095
1096 pub fn terminate(&self, display: Display) -> Result<(), Error> {
1098 unsafe {
1099 if self.api.eglTerminate(display.as_ptr()) == TRUE {
1100 Ok(())
1101 } else {
1102 Err(self.get_error().unwrap())
1103 }
1104 }
1105 }
1106
1107 pub fn wait_gl(&self) -> Result<(), Error> {
1109 unsafe {
1110 if self.api.eglWaitGL() == TRUE {
1111 Ok(())
1112 } else {
1113 Err(self.get_error().unwrap())
1114 }
1115 }
1116 }
1117
1118 pub fn wait_native(&self, engine: Int) -> Result<(), Error> {
1120 unsafe {
1121 if self.api.eglWaitNative(engine) == TRUE {
1122 Ok(())
1123 } else {
1124 Err(self.get_error().unwrap())
1125 }
1126 }
1127 }
1128 }
1129}
1130
1131#[cfg(feature = "1_0")]
1132pub use egl1_0::*;
1133
1134#[cfg(feature = "1_1")]
1139mod egl1_1 {
1140 use super::*;
1141
1142 pub const BACK_BUFFER: Int = 0x3084;
1143 pub const BIND_TO_TEXTURE_RGB: Int = 0x3039;
1144 pub const BIND_TO_TEXTURE_RGBA: Int = 0x303A;
1145 pub const CONTEXT_LOST: Int = 0x300E;
1146 pub const MIN_SWAP_INTERVAL: Int = 0x303B;
1147 pub const MAX_SWAP_INTERVAL: Int = 0x303C;
1148 pub const MIPMAP_TEXTURE: Int = 0x3082;
1149 pub const MIPMAP_LEVEL: Int = 0x3083;
1150 pub const NO_TEXTURE: Int = 0x305C;
1151 pub const TEXTURE_2D: Int = 0x305F;
1152 pub const TEXTURE_FORMAT: Int = 0x3080;
1153 pub const TEXTURE_RGB: Int = 0x305D;
1154 pub const TEXTURE_RGBA: Int = 0x305E;
1155 pub const TEXTURE_TARGET: Int = 0x3081;
1156
1157 impl<T: api::EGL1_1> Instance<T> {
1158 pub fn bind_tex_image(
1160 &self,
1161 display: Display,
1162 surface: Surface,
1163 buffer: Int,
1164 ) -> Result<(), Error> {
1165 unsafe {
1166 if self
1167 .api
1168 .eglBindTexImage(display.as_ptr(), surface.as_ptr(), buffer)
1169 == TRUE
1170 {
1171 Ok(())
1172 } else {
1173 Err(self.get_error().unwrap())
1174 }
1175 }
1176 }
1177
1178 pub fn release_tex_image(
1180 &self,
1181 display: Display,
1182 surface: Surface,
1183 buffer: Int,
1184 ) -> Result<(), Error> {
1185 unsafe {
1186 if self
1187 .api
1188 .eglReleaseTexImage(display.as_ptr(), surface.as_ptr(), buffer)
1189 == TRUE
1190 {
1191 Ok(())
1192 } else {
1193 Err(self.get_error().unwrap())
1194 }
1195 }
1196 }
1197
1198 pub fn surface_attrib(
1200 &self,
1201 display: Display,
1202 surface: Surface,
1203 attribute: Int,
1204 value: Int,
1205 ) -> Result<(), Error> {
1206 unsafe {
1207 if self
1208 .api
1209 .eglSurfaceAttrib(display.as_ptr(), surface.as_ptr(), attribute, value)
1210 == TRUE
1211 {
1212 Ok(())
1213 } else {
1214 Err(self.get_error().unwrap())
1215 }
1216 }
1217 }
1218
1219 pub fn swap_interval(&self, display: Display, interval: Int) -> Result<(), Error> {
1222 unsafe {
1223 if self.api.eglSwapInterval(display.as_ptr(), interval) == TRUE {
1224 Ok(())
1225 } else {
1226 Err(self.get_error().unwrap())
1227 }
1228 }
1229 }
1230 }
1231}
1232
1233#[cfg(feature = "1_1")]
1234pub use egl1_1::*;
1235
1236#[cfg(feature = "1_2")]
1241mod egl1_2 {
1242 use super::*;
1243
1244 pub type Enum = c_uint;
1245 pub type EGLClientBuffer = *mut c_void;
1246
1247 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1248 pub struct ClientBuffer(EGLClientBuffer);
1249
1250 impl ClientBuffer {
1251 #[inline]
1257 pub unsafe fn from_ptr(ptr: EGLClientBuffer) -> ClientBuffer {
1258 ClientBuffer(ptr)
1259 }
1260
1261 #[inline]
1262 pub fn as_ptr(&self) -> EGLClientBuffer {
1263 self.0
1264 }
1265 }
1266
1267 pub const ALPHA_FORMAT: Int = 0x3088;
1268 pub const ALPHA_FORMAT_NONPRE: Int = 0x308B;
1269 pub const ALPHA_FORMAT_PRE: Int = 0x308C;
1270 pub const ALPHA_MASK_SIZE: Int = 0x303E;
1271 pub const BUFFER_PRESERVED: Int = 0x3094;
1272 pub const BUFFER_DESTROYED: Int = 0x3095;
1273 pub const CLIENT_APIS: Int = 0x308D;
1274 pub const COLORSPACE: Int = 0x3087;
1275 pub const COLORSPACE_sRGB: Int = 0x3089;
1276 pub const COLORSPACE_LINEAR: Int = 0x308A;
1277 pub const COLOR_BUFFER_TYPE: Int = 0x303F;
1278 pub const CONTEXT_CLIENT_TYPE: Int = 0x3097;
1279 pub const DISPLAY_SCALING: Int = 10000;
1280 pub const HORIZONTAL_RESOLUTION: Int = 0x3090;
1281 pub const LUMINANCE_BUFFER: Int = 0x308F;
1282 pub const LUMINANCE_SIZE: Int = 0x303D;
1283 pub const OPENGL_ES_BIT: Int = 0x0001;
1284 pub const OPENVG_BIT: Int = 0x0002;
1285 pub const OPENGL_ES_API: Enum = 0x30A0;
1286 pub const OPENVG_API: Enum = 0x30A1;
1287 pub const OPENVG_IMAGE: Int = 0x3096;
1288 pub const PIXEL_ASPECT_RATIO: Int = 0x3092;
1289 pub const RENDERABLE_TYPE: Int = 0x3040;
1290 pub const RENDER_BUFFER: Int = 0x3086;
1291 pub const RGB_BUFFER: Int = 0x308E;
1292 pub const SINGLE_BUFFER: Int = 0x3085;
1293 pub const SWAP_BEHAVIOR: Int = 0x3093;
1294 pub const UNKNOWN: Int = -1;
1295 pub const VERTICAL_RESOLUTION: Int = 0x3091;
1296
1297 impl<T: api::EGL1_2> Instance<T> {
1298 pub fn bind_api(&self, api: Enum) -> Result<(), Error> {
1300 unsafe {
1301 if self.api.eglBindAPI(api) == TRUE {
1302 Ok(())
1303 } else {
1304 Err(self.get_error().unwrap())
1305 }
1306 }
1307 }
1308
1309 pub fn query_api(&self) -> Enum {
1311 unsafe { self.api.eglQueryAPI() }
1312 }
1313
1314 pub fn create_pbuffer_from_client_buffer(
1319 &self,
1320 display: Display,
1321 buffer_type: Enum,
1322 buffer: ClientBuffer,
1323 config: Config,
1324 attrib_list: &[Int],
1325 ) -> Result<Surface, Error> {
1326 check_int_list(attrib_list)?;
1327 unsafe {
1328 let surface = self.api.eglCreatePbufferFromClientBuffer(
1329 display.as_ptr(),
1330 buffer_type,
1331 buffer.as_ptr(),
1332 config.as_ptr(),
1333 attrib_list.as_ptr(),
1334 );
1335
1336 if surface != NO_SURFACE {
1337 Ok(Surface::from_ptr(surface))
1338 } else {
1339 Err(self.get_error().unwrap())
1340 }
1341 }
1342 }
1343
1344 pub fn release_thread(&self) -> Result<(), Error> {
1346 unsafe {
1347 if self.api.eglReleaseThread() == TRUE {
1348 Ok(())
1349 } else {
1350 Err(self.get_error().unwrap())
1351 }
1352 }
1353 }
1354
1355 pub fn wait_client(&self) -> Result<(), Error> {
1357 unsafe {
1358 if self.api.eglWaitClient() == TRUE {
1359 Ok(())
1360 } else {
1361 Err(self.get_error().unwrap())
1362 }
1363 }
1364 }
1365 }
1366}
1367
1368#[cfg(feature = "1_2")]
1369pub use egl1_2::*;
1370
1371#[cfg(feature = "1_3")]
1376mod egl1_3 {
1377 use super::*;
1378
1379 pub const CONFORMANT: Int = 0x3042;
1380 pub const CONTEXT_CLIENT_VERSION: Int = 0x3098;
1381 pub const MATCH_NATIVE_PIXMAP: Int = 0x3041;
1382 pub const OPENGL_ES2_BIT: Int = 0x0004;
1383 pub const VG_ALPHA_FORMAT: Int = 0x3088;
1384 pub const VG_ALPHA_FORMAT_NONPRE: Int = 0x308B;
1385 pub const VG_ALPHA_FORMAT_PRE: Int = 0x308C;
1386 pub const VG_ALPHA_FORMAT_PRE_BIT: Int = 0x0040;
1387 pub const VG_COLORSPACE: Int = 0x3087;
1388 pub const VG_COLORSPACE_sRGB: Int = 0x3089;
1389 pub const VG_COLORSPACE_LINEAR: Int = 0x308A;
1390 pub const VG_COLORSPACE_LINEAR_BIT: Int = 0x0020;
1391}
1392
1393#[cfg(feature = "1_3")]
1394pub use egl1_3::*;
1395
1396#[cfg(feature = "1_4")]
1401mod egl1_4 {
1402 use super::*;
1403
1404 pub const DEFAULT_DISPLAY: NativeDisplayType = 0 as NativeDisplayType;
1405 pub const MULTISAMPLE_RESOLVE_BOX_BIT: Int = 0x0200;
1406 pub const MULTISAMPLE_RESOLVE: Int = 0x3099;
1407 pub const MULTISAMPLE_RESOLVE_DEFAULT: Int = 0x309A;
1408 pub const MULTISAMPLE_RESOLVE_BOX: Int = 0x309B;
1409 pub const OPENGL_API: Enum = 0x30A2;
1410 pub const OPENGL_BIT: Int = 0x0008;
1411 pub const SWAP_BEHAVIOR_PRESERVED_BIT: Int = 0x0400;
1412
1413 impl<T: api::EGL1_4> Instance<T> {
1414 pub fn get_current_context(&self) -> Option<Context> {
1416 unsafe {
1417 let context = self.api.eglGetCurrentContext();
1418
1419 if context != NO_CONTEXT {
1420 Some(Context(context))
1421 } else {
1422 None
1423 }
1424 }
1425 }
1426 }
1427}
1428
1429#[cfg(feature = "1_4")]
1430pub use egl1_4::*;
1431
1432#[cfg(feature = "1_5")]
1437mod egl1_5 {
1438 use super::*;
1439
1440 pub type Time = u64;
1441 pub type EGLSync = *mut c_void;
1442 pub type EGLImage = *mut c_void;
1443
1444 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1445 pub struct Sync(EGLSync);
1446
1447 impl Sync {
1448 #[inline]
1454 pub unsafe fn from_ptr(ptr: EGLSync) -> Sync {
1455 Sync(ptr)
1456 }
1457
1458 #[inline]
1459 pub fn as_ptr(&self) -> EGLSync {
1460 self.0
1461 }
1462 }
1463
1464 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1465 pub struct Image(EGLImage);
1466
1467 impl Image {
1468 #[inline]
1474 pub unsafe fn from_ptr(ptr: EGLImage) -> Image {
1475 Image(ptr)
1476 }
1477
1478 #[inline]
1479 pub fn as_ptr(&self) -> EGLImage {
1480 self.0
1481 }
1482 }
1483
1484 pub const CONTEXT_MAJOR_VERSION: Int = 0x3098;
1485 pub const CONTEXT_MINOR_VERSION: Int = 0x30FB;
1486 pub const CONTEXT_OPENGL_PROFILE_MASK: Int = 0x30FD;
1487 pub const CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY: Int = 0x31BD;
1488 pub const NO_RESET_NOTIFICATION: Int = 0x31BE;
1489 pub const LOSE_CONTEXT_ON_RESET: Int = 0x31BF;
1490 pub const CONTEXT_OPENGL_CORE_PROFILE_BIT: Int = 0x00000001;
1491 pub const CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT: Int = 0x00000002;
1492 pub const CONTEXT_OPENGL_DEBUG: Int = 0x31B0;
1493 pub const CONTEXT_OPENGL_FORWARD_COMPATIBLE: Int = 0x31B1;
1494 pub const CONTEXT_OPENGL_ROBUST_ACCESS: Int = 0x31B2;
1495 pub const OPENGL_ES3_BIT: Int = 0x00000040;
1496 pub const CL_EVENT_HANDLE: Int = 0x309C;
1497 pub const SYNC_CL_EVENT: Int = 0x30FE;
1498 pub const SYNC_CL_EVENT_COMPLETE: Int = 0x30FF;
1499 pub const SYNC_PRIOR_COMMANDS_COMPLETE: Int = 0x30F0;
1500 pub const SYNC_TYPE: Int = 0x30F7;
1501 pub const SYNC_STATUS: Int = 0x30F1;
1502 pub const SYNC_CONDITION: Int = 0x30F8;
1503 pub const SIGNALED: Int = 0x30F2;
1504 pub const UNSIGNALED: Int = 0x30F3;
1505 pub const SYNC_FLUSH_COMMANDS_BIT: Int = 0x0001;
1506 pub const FOREVER: u64 = 0xFFFFFFFFFFFFFFFFu64;
1507 pub const TIMEOUT_EXPIRED: Int = 0x30F5;
1508 pub const CONDITION_SATISFIED: Int = 0x30F6;
1509 pub const NO_SYNC: EGLSync = 0 as EGLSync;
1510 pub const SYNC_FENCE: Int = 0x30F9;
1511 pub const GL_COLORSPACE: Int = 0x309D;
1512 pub const GL_COLORSPACE_SRGB: Int = 0x3089;
1513 pub const GL_COLORSPACE_LINEAR: Int = 0x308A;
1514 pub const GL_RENDERBUFFER: Int = 0x30B9;
1515 pub const GL_TEXTURE_2D: Int = 0x30B1;
1516 pub const GL_TEXTURE_LEVEL: Int = 0x30BC;
1517 pub const GL_TEXTURE_3D: Int = 0x30B2;
1518 pub const GL_TEXTURE_ZOFFSET: Int = 0x30BD;
1519 pub const GL_TEXTURE_CUBE_MAP_POSITIVE_X: Int = 0x30B3;
1520 pub const GL_TEXTURE_CUBE_MAP_NEGATIVE_X: Int = 0x30B4;
1521 pub const GL_TEXTURE_CUBE_MAP_POSITIVE_Y: Int = 0x30B5;
1522 pub const GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: Int = 0x30B6;
1523 pub const GL_TEXTURE_CUBE_MAP_POSITIVE_Z: Int = 0x30B7;
1524 pub const GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: Int = 0x30B8;
1525 pub const IMAGE_PRESERVED: Int = 0x30D2;
1526 pub const NO_IMAGE: EGLImage = 0 as EGLImage;
1527
1528 impl<T: api::EGL1_5> Instance<T> {
1529 pub unsafe fn create_sync(
1543 &self,
1544 display: Display,
1545 ty: Enum,
1546 attrib_list: &[Attrib],
1547 ) -> Result<Sync, Error> {
1548 check_attrib_list(attrib_list)?;
1549 let sync = self
1550 .api
1551 .eglCreateSync(display.as_ptr(), ty, attrib_list.as_ptr());
1552 if sync != NO_SYNC {
1553 Ok(Sync(sync))
1554 } else {
1555 Err(self.get_error().unwrap())
1556 }
1557 }
1558
1559 pub unsafe fn destroy_sync(&self, display: Display, sync: Sync) -> Result<(), Error> {
1566 if self.api.eglDestroySync(display.as_ptr(), sync.as_ptr()) == TRUE {
1567 Ok(())
1568 } else {
1569 Err(self.get_error().unwrap())
1570 }
1571 }
1572
1573 pub unsafe fn client_wait_sync(
1580 &self,
1581 display: Display,
1582 sync: Sync,
1583 flags: Int,
1584 timeout: Time,
1585 ) -> Result<Int, Error> {
1586 let status =
1587 self.api
1588 .eglClientWaitSync(display.as_ptr(), sync.as_ptr(), flags, timeout);
1589 if status != FALSE as Int {
1590 Ok(status)
1591 } else {
1592 Err(self.get_error().unwrap())
1593 }
1594 }
1595
1596 pub unsafe fn get_sync_attrib(
1603 &self,
1604 display: Display,
1605 sync: Sync,
1606 attribute: Int,
1607 ) -> Result<Attrib, Error> {
1608 let mut value = 0;
1609 if self.api.eglGetSyncAttrib(
1610 display.as_ptr(),
1611 sync.as_ptr(),
1612 attribute,
1613 &mut value as *mut Attrib,
1614 ) == TRUE
1615 {
1616 Ok(value)
1617 } else {
1618 Err(self.get_error().unwrap())
1619 }
1620 }
1621
1622 pub fn create_image(
1630 &self,
1631 display: Display,
1632 ctx: Context,
1633 target: Enum,
1634 buffer: ClientBuffer,
1635 attrib_list: &[Attrib],
1636 ) -> Result<Image, Error> {
1637 check_attrib_list(attrib_list)?;
1638 unsafe {
1639 let image = self.api.eglCreateImage(
1640 display.as_ptr(),
1641 ctx.as_ptr(),
1642 target,
1643 buffer.as_ptr(),
1644 attrib_list.as_ptr(),
1645 );
1646 if image != NO_IMAGE {
1647 Ok(Image(image))
1648 } else {
1649 Err(self.get_error().unwrap())
1650 }
1651 }
1652 }
1653
1654 pub fn destroy_image(&self, display: Display, image: Image) -> Result<(), Error> {
1656 unsafe {
1657 if self.api.eglDestroyImage(display.as_ptr(), image.as_ptr()) == TRUE {
1658 Ok(())
1659 } else {
1660 Err(self.get_error().unwrap())
1661 }
1662 }
1663 }
1664
1665 pub unsafe fn get_platform_display(
1684 &self,
1685 platform: Enum,
1686 native_display: NativeDisplayType,
1687 attrib_list: &[Attrib],
1688 ) -> Result<Display, Error> {
1689 check_attrib_list(attrib_list)?;
1690
1691 let display =
1692 self.api
1693 .eglGetPlatformDisplay(platform, native_display, attrib_list.as_ptr());
1694 if display != NO_DISPLAY {
1695 Ok(Display::from_ptr(display))
1696 } else {
1697 Err(self.get_error().unwrap())
1698 }
1699 }
1700
1701 pub unsafe fn create_platform_window_surface(
1717 &self,
1718 display: Display,
1719 config: Config,
1720 native_window: NativeWindowType,
1721 attrib_list: &[Attrib],
1722 ) -> Result<Surface, Error> {
1723 check_attrib_list(attrib_list)?;
1724
1725 let surface = self.api.eglCreatePlatformWindowSurface(
1726 display.as_ptr(),
1727 config.as_ptr(),
1728 native_window,
1729 attrib_list.as_ptr(),
1730 );
1731 if surface != NO_SURFACE {
1732 Ok(Surface::from_ptr(surface))
1733 } else {
1734 Err(self.get_error().unwrap())
1735 }
1736 }
1737
1738 pub unsafe fn create_platform_pixmap_surface(
1754 &self,
1755 display: Display,
1756 config: Config,
1757 native_pixmap: NativePixmapType,
1758 attrib_list: &[Attrib],
1759 ) -> Result<Surface, Error> {
1760 check_attrib_list(attrib_list)?;
1761
1762 let surface = self.api.eglCreatePlatformPixmapSurface(
1763 display.as_ptr(),
1764 config.as_ptr(),
1765 native_pixmap,
1766 attrib_list.as_ptr(),
1767 );
1768 if surface != NO_SURFACE {
1769 Ok(Surface::from_ptr(surface))
1770 } else {
1771 Err(self.get_error().unwrap())
1772 }
1773 }
1774
1775 pub fn wait_sync(&self, display: Display, sync: Sync, flags: Int) -> Result<(), Error> {
1780 unsafe {
1781 if self.api.eglWaitSync(display.as_ptr(), sync.as_ptr(), flags) == TRUE {
1782 Ok(())
1783 } else {
1784 Err(self.get_error().unwrap())
1785 }
1786 }
1787 }
1788 }
1789}
1790
1791#[cfg(feature = "1_5")]
1792pub use egl1_5::*;
1793
1794macro_rules! api {
1799 ($($id:ident : $version:literal { $(fn $name:ident ($($arg:ident : $atype:ty ),* ) -> $rtype:ty ;)* }),*) => {
1800 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1801 pub enum Version {
1802 $(
1803 #[cfg(feature=$version)]
1804 $id,
1805 )*
1806 }
1807
1808 impl std::fmt::Display for Version {
1809 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1810 match self {
1811 $(
1812 #[cfg(feature=$version)]
1813 Version::$id => write!(f, $version),
1814 )*
1815 }
1816 }
1817 }
1818
1819 pub mod api {
1820 use super::*;
1821
1822 api!(@api_traits () () $($id : $version { $(fn $name ($($arg : $atype ),* ) -> $rtype ;)* })*);
1823 }
1824
1825 #[cfg(feature="dynamic")]
1826 extern crate libloading;
1827
1828 api!(@dynamic_struct $($id : $version { $(fn $name ($($arg : $atype ),* ) -> $rtype ;)* })*);
1829 api!(@api_types () $($id : $version { $(fn $name ($($arg : $atype ),* ) -> $rtype ;)* })*);
1830 };
1831 (@dynamic_struct $($id:ident : $version:literal { $(fn $name:ident ($($arg:ident : $atype:ty ),* ) -> $rtype:ty ;)* })*) => {
1832 #[cfg(feature="dynamic")]
1833 #[derive(Debug)]
1834 pub enum LoadError<L> {
1835 Library(L),
1837
1838 InvalidVersion {
1840 provided: Version,
1841 required: Version
1842 }
1843 }
1844
1845 #[cfg(feature="dynamic")]
1846 impl<L: std::error::Error + 'static> std::error::Error for LoadError<L> {
1847 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
1848 match self {
1849 LoadError::Library(l) => Some(l),
1850 _ => None
1851 }
1852 }
1853 }
1854
1855 #[cfg(feature="dynamic")]
1856 impl<L: std::fmt::Display> std::fmt::Display for LoadError<L> {
1857 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1858 match self {
1859 LoadError::Library(l) => write!(f, "Load error: {}", l),
1860 LoadError::InvalidVersion { provided, required } => write!(f, "Invalid EGL API version (required {}, provided {})", required, provided)
1861 }
1862 }
1863 }
1864
1865 #[cfg(feature="dynamic")]
1866 struct RawDynamic<L> {
1867 lib: L,
1868 version: Version,
1869 $(
1870 $(
1871 #[cfg(feature=$version)]
1872 $name : std::mem::MaybeUninit<unsafe extern "system" fn($($atype ),*) -> $rtype>,
1873 )*
1874 )*
1875 }
1876
1877 #[cfg(feature="dynamic")]
1878 impl<L> RawDynamic<L> {
1879 #[inline(always)]
1880 pub fn library(&self) -> &L {
1882 &self.lib
1883 }
1884
1885 #[inline(always)]
1886 pub fn version(&self) -> Version {
1888 self.version
1889 }
1890
1891 #[inline(always)]
1892 pub unsafe fn set_version(&mut self, version: Version) {
1894 self.version = version
1895 }
1896
1897 pub unsafe fn unloaded(lib: L, version: Version) -> Self {
1899 RawDynamic {
1900 lib,
1901 version,
1902 $(
1903 $(
1904 #[cfg(feature=$version)]
1905 $name : std::mem::MaybeUninit::uninit(),
1906 )*
1907 )*
1908 }
1909 }
1910 }
1911
1912 #[cfg(feature="dynamic")]
1913 pub struct Dynamic<L, A> {
1921 raw: RawDynamic<L>,
1922 _api_version: std::marker::PhantomData<A>
1923 }
1924
1925 #[cfg(feature="dynamic")]
1926 impl<L, A> Dynamic<L, A> {
1927 #[inline(always)]
1928 pub fn library(&self) -> &L {
1930 self.raw.library()
1931 }
1932
1933 pub fn version(&self) -> Version {
1935 self.raw.version()
1936 }
1937
1938 pub(crate) unsafe fn unloaded(lib: L, version: Version) -> Self {
1940 Dynamic {
1941 raw: RawDynamic::unloaded(lib, version),
1942 _api_version: std::marker::PhantomData
1943 }
1944 }
1945 }
1946
1947 #[cfg(feature="dynamic")]
1948 impl<L, A> Api for Dynamic<L, A> {
1949 #[inline(always)]
1951 fn version(&self) -> Version {
1952 self.version()
1953 }
1954 }
1955
1956 #[cfg(feature="dynamic")]
1957 #[cfg(feature="1_0")]
1958 impl<L: std::borrow::Borrow<libloading::Library>> Dynamic<L, EGL1_0> {
1959 #[inline]
1960 pub unsafe fn load_from(lib: L) -> Result<Dynamic<L, EGL1_0>, libloading::Error> {
1970 let mut result = Dynamic::unloaded(lib, Version::EGL1_0);
1971
1972 $(
1973 match $id::load_from(&mut result.raw) {
1974 Ok(()) => result.raw.set_version(Version::$id),
1975 Err(libloading::Error::DlSymUnknown) => {
1976 if Version::$id == Version::EGL1_0 {
1977 return Err(libloading::Error::DlSymUnknown) } else {
1979 return Ok(result)
1980 }
1981 },
1982 Err(e @ libloading::Error::DlSym { .. }) => {
1983 if Version::$id == Version::EGL1_0 {
1984 return Err(e) } else {
1986 return Ok(result)
1987 }
1988 },
1989 Err(e) => return Err(e)
1990 }
1991 )*
1992
1993 Ok(result)
1994 }
1995 }
1996
1997 #[cfg(feature="dynamic")]
1998 #[cfg(feature="1_0")]
1999 impl<L: std::borrow::Borrow<libloading::Library>> Instance<Dynamic<L, EGL1_0>> {
2000 #[inline(always)]
2001 pub unsafe fn load_from(lib: L) -> Result<Instance<Dynamic<L, EGL1_0>>, libloading::Error> {
2010 Ok(Instance::new(Dynamic::<L, EGL1_0>::load_from(lib)?))
2011 }
2012 }
2013
2014 #[cfg(feature="dynamic")]
2015 impl<L, V> Instance<Dynamic<L, V>> {
2016 #[inline(always)]
2018 pub fn downcast<W>(&self) -> &Instance<Dynamic<L, W>> where Instance<Dynamic<L, V>>: Downcast<Instance<Dynamic<L, W>>> {
2019 Downcast::downcast(self)
2020 }
2021
2022 #[inline(always)]
2024 pub fn upcast<W>(&self) -> Option<&Instance<Dynamic<L, W>>> where Instance<Dynamic<L, V>>: Upcast<Instance<Dynamic<L, W>>> {
2025 Upcast::upcast(self)
2026 }
2027 }
2028
2029 #[cfg(feature="dynamic")]
2030 unsafe impl<L: std::borrow::Borrow<libloading::Library> + Send, A: Send> Send for Dynamic<L, A> {}
2031
2032 #[cfg(feature="dynamic")]
2033 unsafe impl<L: std::borrow::Borrow<libloading::Library> + std::marker::Sync, A: std::marker::Sync> std::marker::Sync for Dynamic<L, A> {}
2034
2035 #[cfg(feature="dynamic")]
2036 impl<L: std::borrow::Borrow<libloading::Library> + fmt::Debug, A> fmt::Debug for Dynamic<L, A> {
2037 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2038 write!(f, "Dynamic({:?})", self.library())
2039 }
2040 }
2041 };
2042 (@api_traits ( ) ( ) $id:ident : $version:literal { $(fn $name:ident ($($arg:ident : $atype:ty ),* ) -> $rtype:ty ;)* } $($t_id:ident : $t_version:literal { $(fn $t_name:ident ($($t_arg:ident : $t_atype:ty ),* ) -> $t_rtype:ty ;)* })*) => {
2043 api!(@api_trait ( ) ( ) $id : $version { $(fn $name ($($arg : $atype ),* ) -> $rtype ;)* });
2044 api!(@api_traits ( $id : $version ) ( : $id ) $($t_id : $t_version { $(fn $t_name ($($t_arg : $t_atype ),* ) -> $t_rtype ;)* })*);
2045 };
2046 (@api_traits ( $($pred:ident : $p_version:literal)+ ) ( $($deps:tt)+ ) $id:ident : $version:literal { $(fn $name:ident ($($arg:ident : $atype:ty ),* ) -> $rtype:ty ;)* } $($t_id:ident : $t_version:literal { $(fn $t_name:ident ($($t_arg:ident : $t_atype:ty ),* ) -> $t_rtype:ty ;)* })*) => {
2047 api!(@api_trait ( $($pred : $p_version)* ) ( $($deps)* ) $id : $version { $(fn $name ($($arg : $atype ),* ) -> $rtype ;)* });
2048 api!(@api_traits ( $($pred : $version)* $id : $version ) ( $($deps)* + $id ) $($t_id : $t_version { $(fn $t_name ($($t_arg : $t_atype ),* ) -> $t_rtype ;)* })*);
2049 };
2050 (@api_traits ( $($pred:ident : $p_version:literal)* ) ( $($deps:tt)* )) => {
2051 };
2053 (@api_trait ( $($pred:ident : $p_version:literal)* ) ( $($deps:tt)* ) $id:ident : $version:literal { $(fn $name:ident ($($arg:ident : $atype:ty ),* ) -> $rtype:ty ;)* }) => {
2054 #[cfg(feature=$version)]
2063 pub unsafe trait $id $($deps)* {
2064 $(
2065 unsafe fn $name (&self, $($arg : $atype ),* ) -> $rtype ;
2066 )*
2067 }
2068 };
2069 (@api_types ( ) $id:ident : $version:literal { $(fn $name:ident ($($arg:ident : $atype:ty ),* ) -> $rtype:ty ;)* } $($t_id:ident : $t_version:literal { $(fn $t_name:ident ($($t_arg:ident : $t_atype:ty ),* ) -> $t_rtype:ty ;)* })*) => {
2070 #[cfg(feature="dynamic")]
2071 $(
2072 #[cfg(not(feature=$t_version))]
2073 )*
2074 #[cfg(feature=$version)]
2075 pub type Latest = $id;
2077
2078 $(
2079 #[cfg(not(feature=$t_version))]
2080 )*
2081 #[cfg(feature=$version)]
2082 pub const LATEST: Version = Version::$id;
2084
2085 api!(@api_type ( ) $id : $version { $(fn $name ($($arg : $atype ),* ) -> $rtype ;)* });
2086 api!(@api_types ( $id : $version { $(fn $name ($($arg : $atype ),* ) -> $rtype ;)* } ) $($t_id : $t_version { $(fn $t_name ($($t_arg : $t_atype ),* ) -> $t_rtype ;)* })*);
2087 };
2088 (@api_types ( $($pred:ident : $p_version:literal { $(fn $p_name:ident ($($p_arg:ident : $p_atype:ty ),* ) -> $p_rtype:ty ;)* })+ ) $id:ident : $version:literal { $(fn $name:ident ($($arg:ident : $atype:ty ),* ) -> $rtype:ty ;)* } $($t_id:ident : $t_version:literal { $(fn $t_name:ident ($($t_arg:ident : $t_atype:ty ),* ) -> $t_rtype:ty ;)* })*) => {
2089 #[cfg(feature="dynamic")]
2090 $(
2091 #[cfg(not(feature=$t_version))]
2092 )*
2093 #[cfg(feature=$version)]
2094 pub type Latest = $id;
2096
2097 $(
2098 #[cfg(not(feature=$t_version))]
2099 )*
2100 #[cfg(feature=$version)]
2101 pub const LATEST: Version = Version::$id;
2103
2104 api!(@api_type ( $($pred : $p_version { $(fn $p_name ($($p_arg : $p_atype ),* ) -> $p_rtype ;)* })* ) $id : $version { $(fn $name ($($arg : $atype ),* ) -> $rtype ;)* });
2105 api!(@api_types ( $($pred : $p_version { $(fn $p_name ($($p_arg : $p_atype ),* ) -> $p_rtype ;)* })* $id : $version { $(fn $name ($($arg : $atype ),* ) -> $rtype ;)* } ) $($t_id : $t_version { $(fn $t_name ($($t_arg : $t_atype ),* ) -> $t_rtype ;)* })*);
2106 };
2107 (@api_types ( $($pred:ident : $p_version:literal { $(fn $p_name:ident ($($p_arg:ident : $p_atype:ty ),* ) -> $p_rtype:ty ;)* })+ ) ) => {
2108 #[cfg(feature="dynamic")]
2109 #[cfg(feature="1_0")]
2110 pub type DynamicInstance<V = Latest> = Instance<Dynamic<libloading::Library, V>>;
2112
2113 #[cfg(feature="dynamic")]
2114 #[cfg(feature="1_0")]
2115 impl DynamicInstance<EGL1_0> {
2116 #[inline(always)]
2117 pub unsafe fn load_from_filename<P: libloading::AsFilename>(filename: P) -> Result<DynamicInstance<EGL1_0>, libloading::Error> {
2128 #[cfg(target_os = "linux")]
2129 let lib: libloading::Library = {
2130 libloading::os::unix::Library::open(Some(filename), 0x2 | 0x1000)?.into()
2133 };
2134 #[cfg(not(target_os = "linux"))]
2135 let lib = libloading::Library::new(filename)?;
2136 Self::load_from(lib)
2137 }
2138
2139 #[inline(always)]
2140 pub unsafe fn load() -> Result<DynamicInstance<EGL1_0>, libloading::Error> {
2147 Self::load_from_filename("libEGL.so.1").or(Self::load_from_filename("libEGL.so"))
2148 }
2149 }
2150 };
2151 (@api_type ( $($pred:ident : $p_version:literal { $(fn $p_name:ident ($($p_arg:ident : $p_atype:ty ),* ) -> $p_rtype:ty ;)* })* ) $id:ident : $version:literal { $(fn $name:ident ($($arg:ident : $atype:ty ),* ) -> $rtype:ty ;)* }) => {
2152 #[cfg(feature="dynamic")]
2153 #[cfg(feature=$version)]
2154 pub struct $id;
2158
2159 #[cfg(feature="dynamic")]
2160 #[cfg(feature=$version)]
2161 impl $id {
2162 #[allow(unused_variables)]
2163 unsafe fn load_from<L: std::borrow::Borrow<libloading::Library>>(raw: &mut RawDynamic<L>) -> Result<(), libloading::Error> {
2164 let lib = raw.lib.borrow();
2165
2166 $(
2167 let name = stringify!($name).as_bytes();
2168 let symbol = lib.get::<unsafe extern "system" fn($($atype ),*) -> $rtype>(name)?;
2169 #[cfg(unix)]
2170 let ptr = (&symbol.into_raw().into_raw()) as *const *mut _ as *const unsafe extern "system" fn($($atype ),*) -> $rtype;
2171 #[cfg(windows)]
2172 let ptr = (&symbol.into_raw().into_raw()) as *const _ as *const unsafe extern "system" fn($($atype ),*) -> $rtype;
2173 assert!(!ptr.is_null());
2174 raw.$name = std::mem::MaybeUninit::new(*ptr);
2175 )*
2176
2177 Ok(())
2178 }
2179 }
2180
2181 $(
2182 #[cfg(feature="dynamic")]
2183 #[cfg(feature=$version)]
2184 unsafe impl<L: std::borrow::Borrow<libloading::Library>> api::$pred for Dynamic<L, $id> {
2185 $(
2186 #[inline(always)]
2187 unsafe fn $p_name(&self, $($p_arg : $p_atype),*) -> $p_rtype {
2188 (self.raw.$p_name.assume_init())($($p_arg),*)
2189 }
2190 )*
2191 }
2192 )*
2193
2194 #[cfg(feature="dynamic")]
2195 #[cfg(feature=$version)]
2196 unsafe impl<L: std::borrow::Borrow<libloading::Library>> api::$id for Dynamic<L, $id> {
2197 $(
2198 #[inline(always)]
2199 unsafe fn $name(&self, $($arg : $atype),*) -> $rtype {
2200 (self.raw.$name.assume_init())($($arg),*)
2201 }
2202 )*
2203 }
2204
2205 $(
2206 #[cfg(feature="dynamic")]
2207 #[cfg(feature=$version)]
2208 impl<L: std::borrow::Borrow<libloading::Library>> TryFrom<Dynamic<L, $pred>> for Dynamic<L, $id> {
2209 type Error = Dynamic<L, $pred>;
2210
2211 fn try_from(other: Dynamic<L, $pred>) -> Result<Self, Dynamic<L, $pred>> {
2212 if other.version() >= Version::$id {
2213 Ok(Dynamic {
2214 raw: other.raw,
2215 _api_version: std::marker::PhantomData
2216 })
2217 } else {
2218 Err(other)
2219 }
2220 }
2221 }
2222
2223 #[cfg(feature="dynamic")]
2224 #[cfg(feature=$version)]
2225 impl<L: std::borrow::Borrow<libloading::Library>> From<Dynamic<L, $id>> for Dynamic<L, $pred> {
2226 fn from(other: Dynamic<L, $id>) -> Self {
2227 Dynamic {
2228 raw: other.raw,
2229 _api_version: std::marker::PhantomData
2230 }
2231 }
2232 }
2233
2234 #[cfg(feature="dynamic")]
2235 #[cfg(feature=$version)]
2236 impl<L: std::borrow::Borrow<libloading::Library>> AsRef<Dynamic<L, $pred>> for Dynamic<L, $id> {
2237 fn as_ref(&self) -> &Dynamic<L, $pred> {
2238 unsafe { std::mem::transmute(self) } }
2240 }
2241
2242 #[cfg(feature="dynamic")]
2243 #[cfg(feature=$version)]
2244 impl<L: std::borrow::Borrow<libloading::Library>> Downcast<Dynamic<L, $pred>> for Dynamic<L, $id> {
2245 fn downcast(&self) -> &Dynamic<L, $pred> {
2246 unsafe { std::mem::transmute(self) } }
2248 }
2249
2250 #[cfg(feature="dynamic")]
2251 #[cfg(feature=$version)]
2252 impl<L: std::borrow::Borrow<libloading::Library>> Downcast<Instance<Dynamic<L, $pred>>> for Instance<Dynamic<L, $id>> {
2253 fn downcast(&self) -> &Instance<Dynamic<L, $pred>> {
2254 unsafe { std::mem::transmute(self) } }
2256 }
2257
2258 #[cfg(feature="dynamic")]
2259 #[cfg(feature=$version)]
2260 impl<L: std::borrow::Borrow<libloading::Library>> Upcast<Dynamic<L, $id>> for Dynamic<L, $pred> {
2261 fn upcast(&self) -> Option<&Dynamic<L, $id>> {
2262 if self.version() >= Version::$id {
2263 Some(unsafe { std::mem::transmute(self) }) } else {
2265 None
2266 }
2267 }
2268 }
2269
2270 #[cfg(feature="dynamic")]
2271 #[cfg(feature=$version)]
2272 impl<L: std::borrow::Borrow<libloading::Library>> Upcast<Instance<Dynamic<L, $id>>> for Instance<Dynamic<L, $pred>> {
2273 fn upcast(&self) -> Option<&Instance<Dynamic<L, $id>>> {
2274 if self.version() >= Version::$id {
2275 Some(unsafe { std::mem::transmute(self) }) } else {
2277 None
2278 }
2279 }
2280 }
2281 )*
2282
2283 #[cfg(feature="dynamic")]
2284 #[cfg(feature=$version)]
2285 impl<L: std::borrow::Borrow<libloading::Library>> Dynamic<L, $id> {
2286 #[inline]
2287 pub unsafe fn load_required(lib: L) -> Result<Dynamic<L, $id>, LoadError<libloading::Error>> {
2294 match Dynamic::<L, EGL1_0>::load_from(lib) {
2295 Ok(dynamic) => {
2296 let provided = dynamic.version();
2297 match dynamic.try_into() {
2298 Ok(t) => Ok(t),
2299 Err(_) => Err(LoadError::InvalidVersion {
2300 provided,
2301 required: Version::$id
2302 })
2303 }
2304 },
2305 Err(e) => Err(LoadError::Library(e))
2306 }
2307 }
2308 }
2309
2310 #[cfg(feature="dynamic")]
2311 #[cfg(feature=$version)]
2312 impl<L: std::borrow::Borrow<libloading::Library>> Instance<Dynamic<L, $id>> {
2313 #[inline(always)]
2314 pub unsafe fn load_required_from(lib: L) -> Result<Instance<Dynamic<L, $id>>, LoadError<libloading::Error>> {
2320 Ok(Instance::new(Dynamic::<L, $id>::load_required(lib)?))
2321 }
2322 }
2323
2324 #[cfg(feature="dynamic")]
2325 #[cfg(feature=$version)]
2326 impl DynamicInstance<$id> {
2327 #[inline(always)]
2328 pub unsafe fn load_required_from_filename<P: libloading::AsFilename>(filename: P) -> Result<DynamicInstance<$id>, LoadError<libloading::Error>> {
2340 #[cfg(target_os = "linux")]
2341 let lib: libloading::Library = {
2342 libloading::os::unix::Library::open(Some(filename), 0x2 | 0x1000).map_err(LoadError::Library)?.into()
2345 };
2346 #[cfg(not(target_os = "linux"))]
2347 let lib = libloading::Library::new(filename).map_err(LoadError::Library)?;
2348 Self::load_required_from(lib)
2349 }
2350
2351 #[inline(always)]
2352 pub unsafe fn load_required() -> Result<DynamicInstance<$id>, LoadError<libloading::Error>> {
2360 Self::load_required_from_filename("libEGL.so.1").or(Self::load_required_from_filename("libEGL.so"))
2361 }
2362 }
2363 }
2364}
2365
2366api! {
2367 EGL1_0 : "1_0" {
2368 fn eglChooseConfig(
2369 display: EGLDisplay,
2370 attrib_list: *const Int,
2371 configs: *mut EGLConfig,
2372 config_size: Int,
2373 num_config: *mut Int
2374 ) -> Boolean;
2375 fn eglCopyBuffers(
2376 display: EGLDisplay,
2377 surface: EGLSurface,
2378 target: NativePixmapType
2379 ) -> Boolean;
2380 fn eglCreateContext(
2381 display: EGLDisplay,
2382 config: EGLConfig,
2383 share_context: EGLContext,
2384 attrib_list: *const Int
2385 ) -> EGLContext;
2386 fn eglCreatePbufferSurface(
2387 display: EGLDisplay,
2388 config: EGLConfig,
2389 attrib_list: *const Int
2390 ) -> EGLSurface;
2391 fn eglCreatePixmapSurface(
2392 display: EGLDisplay,
2393 config: EGLConfig,
2394 pixmap: NativePixmapType,
2395 attrib_list: *const Int
2396 ) -> EGLSurface;
2397 fn eglCreateWindowSurface(
2398 display: EGLDisplay,
2399 config: EGLConfig,
2400 win: NativeWindowType,
2401 attrib_list: *const Int
2402 ) -> EGLSurface;
2403 fn eglDestroyContext(display: EGLDisplay, ctx: EGLContext) -> Boolean;
2404 fn eglDestroySurface(display: EGLDisplay, surface: EGLSurface) -> Boolean;
2405 fn eglGetConfigAttrib(
2406 display: EGLDisplay,
2407 config: EGLConfig,
2408 attribute: Int,
2409 value: *mut Int
2410 ) -> Boolean;
2411 fn eglGetConfigs(
2412 display: EGLDisplay,
2413 configs: *mut EGLConfig,
2414 config_size: Int,
2415 num_config: *mut Int
2416 ) -> Boolean;
2417 fn eglGetCurrentDisplay() -> EGLDisplay;
2418 fn eglGetCurrentSurface(readdraw: Int) -> EGLSurface;
2419 fn eglGetDisplay(display_id: NativeDisplayType) -> EGLDisplay;
2420 fn eglGetError() -> Int;
2421 fn eglGetProcAddress(procname: *const c_char) -> extern "system" fn();
2422 fn eglInitialize(display: EGLDisplay, major: *mut Int, minor: *mut Int) -> Boolean;
2423 fn eglMakeCurrent(
2424 display: EGLDisplay,
2425 draw: EGLSurface,
2426 read: EGLSurface,
2427 ctx: EGLContext
2428 ) -> Boolean;
2429 fn eglQueryContext(
2430 display: EGLDisplay,
2431 ctx: EGLContext,
2432 attribute: Int,
2433 value: *mut Int
2434 ) -> Boolean;
2435 fn eglQueryString(display: EGLDisplay, name: Int) -> *const c_char;
2436 fn eglQuerySurface(
2437 display: EGLDisplay,
2438 surface: EGLSurface,
2439 attribute: Int,
2440 value: *mut Int
2441 ) -> Boolean;
2442 fn eglSwapBuffers(display: EGLDisplay, surface: EGLSurface) -> Boolean;
2443 fn eglTerminate(display: EGLDisplay) -> Boolean;
2444 fn eglWaitGL() -> Boolean;
2445 fn eglWaitNative(engine: Int) -> Boolean;
2446 },
2447
2448 EGL1_1 : "1_1" {
2449 fn eglBindTexImage(display: EGLDisplay, surface: EGLSurface, buffer: Int) -> Boolean;
2450 fn eglReleaseTexImage(display: EGLDisplay, surface: EGLSurface, buffer: Int) -> Boolean;
2451 fn eglSurfaceAttrib(
2452 display: EGLDisplay,
2453 surface: EGLSurface,
2454 attribute: Int,
2455 value: Int
2456 ) -> Boolean;
2457 fn eglSwapInterval(display: EGLDisplay, interval: Int) -> Boolean;
2458 },
2459
2460 EGL1_2 : "1_2" {
2461 fn eglBindAPI(api: Enum) -> Boolean;
2462 fn eglQueryAPI() -> Enum;
2463 fn eglCreatePbufferFromClientBuffer(
2464 display: EGLDisplay,
2465 buftype: Enum,
2466 buffer: EGLClientBuffer,
2467 config: EGLConfig,
2468 attrib_list: *const Int
2469 ) -> EGLSurface;
2470 fn eglReleaseThread() -> Boolean;
2471 fn eglWaitClient() -> Boolean;
2472 },
2473
2474 EGL1_3 : "1_3" {
2475 },
2477
2478 EGL1_4 : "1_4" {
2479 fn eglGetCurrentContext() -> EGLContext;
2480 },
2481
2482 EGL1_5 : "1_5" {
2483 fn eglCreateSync(display: EGLDisplay, type_: Enum, attrib_list: *const Attrib) -> EGLSync;
2484 fn eglDestroySync(display: EGLDisplay, sync: EGLSync) -> Boolean;
2485 fn eglClientWaitSync(display: EGLDisplay, sync: EGLSync, flags: Int, timeout: Time) -> Int;
2486 fn eglGetSyncAttrib(
2487 display: EGLDisplay,
2488 sync: EGLSync,
2489 attribute: Int,
2490 value: *mut Attrib
2491 ) -> Boolean;
2492 fn eglCreateImage(
2493 display: EGLDisplay,
2494 ctx: EGLContext,
2495 target: Enum,
2496 buffer: EGLClientBuffer,
2497 attrib_list: *const Attrib
2498 ) -> EGLImage;
2499 fn eglDestroyImage(display: EGLDisplay, image: EGLImage) -> Boolean;
2500 fn eglGetPlatformDisplay(
2501 platform: Enum,
2502 native_display: *mut c_void,
2503 attrib_list: *const Attrib
2504 ) -> EGLDisplay;
2505 fn eglCreatePlatformWindowSurface(
2506 display: EGLDisplay,
2507 config: EGLConfig,
2508 native_window: *mut c_void,
2509 attrib_list: *const Attrib
2510 ) -> EGLSurface;
2511 fn eglCreatePlatformPixmapSurface(
2512 display: EGLDisplay,
2513 config: EGLConfig,
2514 native_pixmap: *mut c_void,
2515 attrib_list: *const Attrib
2516 ) -> EGLSurface;
2517 fn eglWaitSync(display: EGLDisplay, sync: EGLSync, flags: Int) -> Boolean;
2518 }
2519}