@@ -64,6 +64,7 @@ use crate::{
64
64
Api , ContextError , CreationError , GlAttributes , GlRequest , PixelFormat ,
65
65
PixelFormatRequirements , ReleaseBehavior , Robustness ,
66
66
} ;
67
+ use crate :: platform_impl:: PlatformAttributes ;
67
68
68
69
use glutin_egl_sys as ffi;
69
70
use parking_lot:: Mutex ;
@@ -156,11 +157,11 @@ fn get_egl_version(
156
157
}
157
158
158
159
unsafe fn bind_and_get_api < ' a > (
159
- opengl : & ' a GlAttributes < & ' a Context > ,
160
+ gl_attr : & ' a GlAttributes < & ' a Context > ,
160
161
egl_version : ( ffi:: egl:: types:: EGLint , ffi:: egl:: types:: EGLint ) ,
161
162
) -> Result < ( Option < ( u8 , u8 ) > , Api ) , CreationError > {
162
163
let egl = EGL . as_ref ( ) . unwrap ( ) ;
163
- match opengl . version {
164
+ match gl_attr . version {
164
165
GlRequest :: Latest => {
165
166
if egl_version >= ( 1 , 4 ) {
166
167
if egl. BindAPI ( ffi:: egl:: OPENGL_API ) != 0 {
@@ -390,7 +391,8 @@ impl Context {
390
391
/// `ContextPrototype`.
391
392
pub fn new < ' a , F > (
392
393
pf_reqs : & PixelFormatRequirements ,
393
- opengl : & ' a GlAttributes < & ' a Context > ,
394
+ gl_attr : & ' a GlAttributes < & ' a Context > ,
395
+ plat_attr : & PlatformAttributes ,
394
396
native_display : NativeDisplay ,
395
397
surface_type : SurfaceType ,
396
398
config_selector : F ,
@@ -429,7 +431,7 @@ impl Context {
429
431
} ;
430
432
431
433
// binding the right API and choosing the version
432
- let ( version, api) = unsafe { bind_and_get_api ( & opengl , egl_version) ? } ;
434
+ let ( version, api) = unsafe { bind_and_get_api ( & gl_attr , egl_version) ? } ;
433
435
434
436
let ( config_id, pixel_format) = unsafe {
435
437
choose_fbconfig (
@@ -438,13 +440,14 @@ impl Context {
438
440
api,
439
441
version,
440
442
pf_reqs,
443
+ plat_attr,
441
444
surface_type,
442
445
config_selector,
443
446
) ?
444
447
} ;
445
448
446
449
Ok ( ContextPrototype {
447
- opengl ,
450
+ gl_attr ,
448
451
display,
449
452
egl_version,
450
453
extensions,
@@ -475,6 +478,13 @@ impl Context {
475
478
476
479
pub unsafe fn make_current ( & self ) -> Result < ( ) , ContextError > {
477
480
let egl = EGL . as_ref ( ) . unwrap ( ) ;
481
+ // FIXME: Possible race condition: we lock the mutex, grab the surface,
482
+ // unlock it. Then the other thread on android destroys the surface,
483
+ // then we try to use the surface.
484
+ //
485
+ // Problem is rare enough, and can only possibly happen on android.
486
+ //
487
+ // Is it okay to use a drestroyed surface? I can't imagine so.
478
488
let surface = self
479
489
. surface
480
490
. as_ref ( )
@@ -731,7 +741,7 @@ impl Drop for Context {
731
741
732
742
#[ derive( Debug ) ]
733
743
pub struct ContextPrototype < ' a > {
734
- opengl : & ' a GlAttributes < & ' a Context > ,
744
+ gl_attr : & ' a GlAttributes < & ' a Context > ,
735
745
display : ffi:: egl:: types:: EGLDisplay ,
736
746
egl_version : ( ffi:: egl:: types:: EGLint , ffi:: egl:: types:: EGLint ) ,
737
747
extensions : Vec < String > ,
@@ -881,7 +891,7 @@ impl<'a> ContextPrototype<'a> {
881
891
self ,
882
892
surface : Option < ffi:: egl:: types:: EGLSurface > ,
883
893
) -> Result < Context , CreationError > {
884
- let share = match self . opengl . sharing {
894
+ let share = match self . gl_attr . sharing {
885
895
Some ( ctx) => ctx. context ,
886
896
None => std:: ptr:: null ( ) ,
887
897
} ;
@@ -895,8 +905,8 @@ impl<'a> ContextPrototype<'a> {
895
905
self . api ,
896
906
version,
897
907
self . config_id ,
898
- self . opengl . debug ,
899
- self . opengl . robustness ,
908
+ self . gl_attr . debug ,
909
+ self . gl_attr . robustness ,
900
910
share,
901
911
) ?
902
912
} else if self . api == Api :: OpenGlEs {
@@ -907,8 +917,8 @@ impl<'a> ContextPrototype<'a> {
907
917
self . api ,
908
918
( 2 , 0 ) ,
909
919
self . config_id ,
910
- self . opengl . debug ,
911
- self . opengl . robustness ,
920
+ self . gl_attr . debug ,
921
+ self . gl_attr . robustness ,
912
922
share,
913
923
) {
914
924
ctx
@@ -919,8 +929,8 @@ impl<'a> ContextPrototype<'a> {
919
929
self . api ,
920
930
( 1 , 0 ) ,
921
931
self . config_id ,
922
- self . opengl . debug ,
923
- self . opengl . robustness ,
932
+ self . gl_attr . debug ,
933
+ self . gl_attr . robustness ,
924
934
share,
925
935
) {
926
936
ctx
@@ -935,8 +945,8 @@ impl<'a> ContextPrototype<'a> {
935
945
self . api ,
936
946
( 3 , 2 ) ,
937
947
self . config_id ,
938
- self . opengl . debug ,
939
- self . opengl . robustness ,
948
+ self . gl_attr . debug ,
949
+ self . gl_attr . robustness ,
940
950
share,
941
951
) {
942
952
ctx
@@ -947,8 +957,8 @@ impl<'a> ContextPrototype<'a> {
947
957
self . api ,
948
958
( 3 , 1 ) ,
949
959
self . config_id ,
950
- self . opengl . debug ,
951
- self . opengl . robustness ,
960
+ self . gl_attr . debug ,
961
+ self . gl_attr . robustness ,
952
962
share,
953
963
) {
954
964
ctx
@@ -959,8 +969,8 @@ impl<'a> ContextPrototype<'a> {
959
969
self . api ,
960
970
( 1 , 0 ) ,
961
971
self . config_id ,
962
- self . opengl . debug ,
963
- self . opengl . robustness ,
972
+ self . gl_attr . debug ,
973
+ self . gl_attr . robustness ,
964
974
share,
965
975
) {
966
976
ctx
@@ -988,6 +998,7 @@ unsafe fn choose_fbconfig<F>(
988
998
api : Api ,
989
999
version : Option < ( u8 , u8 ) > ,
990
1000
pf_reqs : & PixelFormatRequirements ,
1001
+ plat_attr : & PlatformAttributes ,
991
1002
surface_type : SurfaceType ,
992
1003
mut config_selector : F ,
993
1004
) -> Result < ( ffi:: egl:: types:: EGLConfig , PixelFormat ) , CreationError >
@@ -1105,7 +1116,7 @@ where
1105
1116
return Err ( CreationError :: NoAvailablePixelFormat ) ;
1106
1117
}
1107
1118
1108
- if let Some ( xid) = pf_reqs . x11_visual_xid {
1119
+ if let Some ( xid) = plat_attr . x11_visual_xid {
1109
1120
out. push ( ffi:: egl:: NATIVE_VISUAL_ID as raw:: c_int ) ;
1110
1121
out. push ( xid as raw:: c_int ) ;
1111
1122
}
0 commit comments