@@ -656,11 +656,6 @@ impl crate::Instance<super::Api> for Instance {
656
656
}
657
657
} ;
658
658
659
- let enable_srgb = match inner. srgb_kind {
660
- SrgbFrameBufferKind :: Core | SrgbFrameBufferKind :: Khr => true ,
661
- SrgbFrameBufferKind :: None => false ,
662
- } ;
663
-
664
659
inner
665
660
. egl
666
661
. make_current ( inner. display , None , None , None )
@@ -676,7 +671,7 @@ impl crate::Instance<super::Api> for Instance {
676
671
pbuffer : inner. pbuffer ,
677
672
raw_window_handle,
678
673
swapchain : None ,
679
- enable_srgb ,
674
+ srgb_kind : inner . srgb_kind ,
680
675
} )
681
676
}
682
677
unsafe fn destroy_surface ( & self , _surface : Surface ) { }
@@ -756,7 +751,7 @@ pub struct Surface {
756
751
pub ( super ) presentable : bool ,
757
752
raw_window_handle : RawWindowHandle ,
758
753
swapchain : Option < Swapchain > ,
759
- pub ( super ) enable_srgb : bool ,
754
+ srgb_kind : SrgbFrameBufferKind ,
760
755
}
761
756
762
757
unsafe impl Send for Surface { }
@@ -834,6 +829,13 @@ impl Surface {
834
829
None => None ,
835
830
}
836
831
}
832
+
833
+ pub fn supports_srgb ( & self ) -> bool {
834
+ match self . srgb_kind {
835
+ SrgbFrameBufferKind :: None => false ,
836
+ _ => true ,
837
+ }
838
+ }
837
839
}
838
840
839
841
impl crate :: Surface < super :: Api > for Surface {
@@ -891,58 +893,55 @@ impl crate::Surface<super::Api> for Surface {
891
893
_ => unreachable ! ( ) ,
892
894
} ;
893
895
894
- let raw = if let Some ( egl) = self . egl . upcast :: < egl:: EGL1_5 > ( ) {
895
- let attributes = [
896
- egl:: RENDER_BUFFER as usize ,
897
- if cfg ! ( target_os = "android" ) {
898
- egl:: BACK_BUFFER as usize
899
- } else {
900
- egl:: SINGLE_BUFFER as usize
901
- } ,
902
- // Always enable sRGB in EGL 1.5
903
- egl:: GL_COLORSPACE as usize ,
904
- egl:: GL_COLORSPACE_SRGB as usize ,
905
- egl:: ATTRIB_NONE ,
906
- ] ;
907
-
896
+ let mut attributes = vec ! [
897
+ egl:: RENDER_BUFFER ,
898
+ if cfg!( target_os = "android" ) {
899
+ egl:: BACK_BUFFER
900
+ } else {
901
+ egl:: SINGLE_BUFFER
902
+ } ,
903
+ ] ;
904
+ match self . srgb_kind {
905
+ SrgbFrameBufferKind :: None => { }
906
+ SrgbFrameBufferKind :: Core => {
907
+ attributes. push ( egl:: GL_COLORSPACE ) ;
908
+ attributes. push ( egl:: GL_COLORSPACE_SRGB ) ;
909
+ }
910
+ SrgbFrameBufferKind :: Khr => {
911
+ attributes. push ( EGL_GL_COLORSPACE_KHR as i32 ) ;
912
+ attributes. push ( EGL_GL_COLORSPACE_SRGB_KHR as i32 ) ;
913
+ }
914
+ }
915
+ attributes. push ( egl:: ATTRIB_NONE as i32 ) ;
916
+
917
+ // Careful, we can still be in 1.4 version even if `upcast` succeeds
918
+ let raw_result = if let Some ( egl) = self . egl . upcast :: < egl:: EGL1_5 > ( ) {
919
+ let attributes_usize = attributes
920
+ . into_iter ( )
921
+ . map ( |v| v as usize )
922
+ . collect :: < Vec < _ > > ( ) ;
908
923
egl. create_platform_window_surface (
909
924
self . display ,
910
925
self . config ,
911
926
native_window_ptr,
912
- & attributes ,
927
+ & attributes_usize ,
913
928
)
914
- . map_err ( |e| {
915
- log:: warn!( "Error in create_platform_window_surface: {:?}" , e) ;
916
- crate :: SurfaceError :: Lost
917
- } )
918
929
} else {
919
- let mut attributes = vec ! [
920
- egl:: RENDER_BUFFER ,
921
- if cfg!( target_os = "android" ) {
922
- egl:: BACK_BUFFER
923
- } else {
924
- egl:: SINGLE_BUFFER
925
- } ,
926
- ] ;
927
- if self . enable_srgb {
928
- attributes. push ( EGL_GL_COLORSPACE_KHR as i32 ) ;
929
- attributes. push ( EGL_GL_COLORSPACE_SRGB_KHR as i32 ) ;
930
- }
931
- attributes. push ( egl:: ATTRIB_NONE as i32 ) ;
932
- self . egl
933
- . create_window_surface (
934
- self . display ,
935
- self . config ,
936
- native_window_ptr,
937
- Some ( & attributes) ,
938
- )
939
- . map_err ( |e| {
940
- log:: warn!( "Error in create_platform_window_surface: {:?}" , e) ;
941
- crate :: SurfaceError :: Lost
942
- } )
943
- } ?;
930
+ self . egl . create_window_surface (
931
+ self . display ,
932
+ self . config ,
933
+ native_window_ptr,
934
+ Some ( & attributes) ,
935
+ )
936
+ } ;
944
937
945
- ( raw, wl_window)
938
+ match raw_result {
939
+ Ok ( raw) => ( raw, wl_window) ,
940
+ Err ( e) => {
941
+ log:: warn!( "Error in create_platform_window_surface: {:?}" , e) ;
942
+ return Err ( crate :: SurfaceError :: Lost ) ;
943
+ }
944
+ }
946
945
}
947
946
} ;
948
947
0 commit comments