@@ -100,7 +100,7 @@ impl Observer {
100100}
101101
102102#[ derive( Debug ) ]
103- pub struct CGImpl < D , W > {
103+ struct CGResources < D > {
104104 /// Our layer.
105105 layer : SendCALayer ,
106106 /// The layer that our layer was created from.
@@ -118,11 +118,18 @@ pub struct CGImpl<D, W> {
118118 width : u32 ,
119119 /// The height of the buffer.
120120 height : u32 ,
121- window_handle : W ,
122121 _display : PhantomData < D > ,
123122}
124123
125- impl < D , W > Drop for CGImpl < D , W > {
124+ #[ derive( Debug ) ]
125+ pub struct CGImpl < D , W > {
126+ /// Resources needed for the surface.
127+ resources : CGResources < D > ,
128+ /// The window associated with the surface.
129+ window_handle : W ,
130+ }
131+
132+ impl < D > Drop for CGResources < D > {
126133 fn drop ( & mut self ) {
127134 // SAFETY: Registered in `new`, must be removed before the observer is deallocated.
128135 unsafe {
@@ -265,7 +272,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for CGImpl<
265272 let width = ( size. width * scale_factor) as u32 ;
266273 let height = ( size. height * scale_factor) as u32 ;
267274
268- Ok ( Self {
275+ let resources = CGResources {
269276 layer : SendCALayer ( layer) ,
270277 root_layer : SendCALayer ( root_layer) ,
271278 observer,
@@ -274,6 +281,10 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for CGImpl<
274281 width,
275282 height,
276283 _display : PhantomData ,
284+ } ;
285+
286+ Ok ( Self {
287+ resources,
277288 window_handle : window_src,
278289 } )
279290 }
@@ -283,6 +294,11 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for CGImpl<
283294 & self . window_handle
284295 }
285296
297+ #[ inline]
298+ fn into_window ( self ) -> W {
299+ self . window_handle
300+ }
301+
286302 #[ inline]
287303 fn supports_alpha_mode ( & self , alpha_mode : AlphaMode ) -> bool {
288304 // Premultiplied doesn't seem to work, at least not with transparent windows.
@@ -299,36 +315,36 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for CGImpl<
299315 alpha_mode : AlphaMode ,
300316 ) -> Result < ( ) , SoftBufferError > {
301317 let opaque = matches ! ( alpha_mode, AlphaMode :: Opaque | AlphaMode :: Ignored ) ;
302- self . layer . setOpaque ( opaque) ;
318+ self . resources . layer . setOpaque ( opaque) ;
303319 // TODO: Set opaque-ness on root layer too? Is that our responsibility, or Winit's?
304- // self.root_layer.setOpaque(opaque);
320+ // self.resources. root_layer.setOpaque(opaque);
305321
306322 let width = width. get ( ) ;
307323 let height = height. get ( ) ;
308324
309325 // TODO: Is this check desirable?
310- if self . width == width && self . height == height {
326+ if self . resources . width == width && self . resources . height == height {
311327 return Ok ( ( ) ) ;
312328 }
313329
314330 // Recreate buffer. It's fine to release the old one, `CALayer.contents` is going to keep
315331 // a reference to it around as long as it's still in use.
316- self . buffer = Buffer :: new ( width, height) ;
317- self . width = width;
318- self . height = height;
332+ self . resources . buffer = Buffer :: new ( width, height) ;
333+ self . resources . width = width;
334+ self . resources . height = height;
319335
320336 Ok ( ( ) )
321337 }
322338
323339 fn next_buffer ( & mut self , alpha_mode : AlphaMode ) -> Result < BufferImpl < ' _ > , SoftBufferError > {
324340 // Unlocked in `present_with_damage` or the buffer's `Drop`.
325- self . buffer . info ( ) . lock ( ) ;
341+ self . resources . buffer . info ( ) . lock ( ) ;
326342
327343 Ok ( BufferImpl {
328- buffer : & mut self . buffer ,
329- width : self . width ,
330- height : self . height ,
331- color_space : & self . color_space ,
344+ buffer : & mut self . resources . buffer ,
345+ width : self . resources . width ,
346+ height : self . resources . height ,
347+ color_space : & self . resources . color_space ,
332348 alpha_info : match ( alpha_mode, cfg ! ( target_endian = "little" ) ) {
333349 ( AlphaMode :: Opaque | AlphaMode :: Ignored , true ) => CGImageAlphaInfo :: NoneSkipFirst ,
334350 ( AlphaMode :: Opaque | AlphaMode :: Ignored , false ) => CGImageAlphaInfo :: NoneSkipLast ,
@@ -337,7 +353,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for CGImpl<
337353 ( AlphaMode :: Postmultiplied , true ) => CGImageAlphaInfo :: First ,
338354 ( AlphaMode :: Postmultiplied , false ) => CGImageAlphaInfo :: Last ,
339355 } ,
340- layer : & mut self . layer ,
356+ layer : & mut self . resources . layer ,
341357 } )
342358 }
343359}
0 commit comments