11//! Everything related to `NSOpenGLPixelFormat`.
22
3+ use std:: ptr:: NonNull ;
34use std:: sync:: Arc ;
45use std:: { fmt, iter} ;
56
7+ use objc2:: AllocAnyThread ;
68use objc2:: rc:: Retained ;
79#[ allow( deprecated) ]
810use objc2_app_kit:: {
911 NSOpenGLPFAAccelerated , NSOpenGLPFAAllowOfflineRenderers , NSOpenGLPFAAlphaSize ,
1012 NSOpenGLPFAColorFloat , NSOpenGLPFAColorSize , NSOpenGLPFADepthSize , NSOpenGLPFADoubleBuffer ,
1113 NSOpenGLPFAMinimumPolicy , NSOpenGLPFAMultisample , NSOpenGLPFAOpenGLProfile ,
1214 NSOpenGLPFASampleBuffers , NSOpenGLPFASamples , NSOpenGLPFAStencilSize , NSOpenGLPFAStereo ,
13- NSOpenGLPFATripleBuffer , NSOpenGLPixelFormatAttribute , NSOpenGLProfileVersion3_2Core ,
14- NSOpenGLProfileVersion4_1Core , NSOpenGLProfileVersionLegacy ,
15+ NSOpenGLPFATripleBuffer , NSOpenGLPixelFormat , NSOpenGLPixelFormatAttribute ,
16+ NSOpenGLProfileVersion3_2Core , NSOpenGLProfileVersion4_1Core , NSOpenGLProfileVersionLegacy ,
1517} ;
1618
1719use crate :: config:: {
@@ -21,7 +23,6 @@ use crate::display::GetGlDisplay;
2123use crate :: error:: { ErrorKind , Result } ;
2224use crate :: private:: Sealed ;
2325
24- use super :: appkit:: NSOpenGLPixelFormat ;
2526use super :: display:: Display ;
2627
2728impl Display {
@@ -47,9 +48,10 @@ impl Display {
4748 attrs. push ( ( r_size + g_size + b_size + template. alpha_size ) as u32 ) ;
4849 } ,
4950 _ => {
50- return Err (
51- ErrorKind :: NotSupported ( "luminance buffers are not supported with CGL" ) . into ( )
51+ return Err ( ErrorKind :: NotSupported (
52+ "luminance buffers are not supported with CGL" ,
5253 )
54+ . into ( ) ) ;
5355 } ,
5456 }
5557
@@ -113,7 +115,12 @@ impl Display {
113115 . find_map ( |profile| {
114116 attrs[ profile_attr_pos] = profile;
115117 // initWithAttributes returns None if the attributes were invalid
116- unsafe { NSOpenGLPixelFormat :: newWithAttributes ( & attrs) }
118+ unsafe {
119+ NSOpenGLPixelFormat :: initWithAttributes (
120+ <NSOpenGLPixelFormat as AllocAnyThread >:: alloc ( ) ,
121+ NonNull :: new ( attrs. as_ptr ( ) . cast_mut ( ) ) . unwrap ( ) ,
122+ )
123+ }
117124 } )
118125 . ok_or ( ErrorKind :: BadConfig ) ?;
119126
@@ -135,11 +142,13 @@ pub struct Config {
135142}
136143
137144impl Config {
145+ #[ allow( deprecated) ]
138146 fn raw_attribute ( & self , attrib : NSOpenGLPixelFormatAttribute ) -> i32 {
139147 unsafe {
140148 let mut value = 0 ;
141149 self . inner . raw . getValues_forAttribute_forVirtualScreen (
142- & mut value, attrib,
150+ NonNull :: from ( & mut value) ,
151+ attrib,
143152 // They do differ per monitor and require context. Which is kind of insane, but
144153 // whatever. Zero is a primary monitor.
145154 0 ,
@@ -228,9 +237,13 @@ impl Sealed for Config {}
228237pub ( crate ) struct ConfigInner {
229238 display : Display ,
230239 pub ( crate ) transparency : bool ,
240+ #[ allow( deprecated) ]
231241 pub ( crate ) raw : Retained < NSOpenGLPixelFormat > ,
232242}
233243
244+ unsafe impl Send for ConfigInner { }
245+ unsafe impl Sync for ConfigInner { }
246+
234247impl PartialEq for ConfigInner {
235248 fn eq ( & self , other : & Self ) -> bool {
236249 self . raw == other. raw
0 commit comments