@@ -64,9 +64,8 @@ impl HalManagedMetalLayerDelegate {
64
64
}
65
65
66
66
impl super :: Surface {
67
- fn new ( view : Option < NonNull < Object > > , layer : metal:: MetalLayer ) -> Self {
67
+ fn new ( layer : metal:: MetalLayer ) -> Self {
68
68
Self {
69
- view,
70
69
render_layer : Mutex :: new ( layer) ,
71
70
swapchain_format : RwLock :: new ( None ) ,
72
71
extent : RwLock :: new ( wgt:: Extent3d :: default ( ) ) ,
@@ -86,16 +85,14 @@ impl super::Surface {
86
85
// SAFETY: The layer is an initialized instance of `CAMetalLayer`, and
87
86
// we transfer the retain count to `MetalLayer` using `ManuallyDrop`.
88
87
let layer = unsafe { metal:: MetalLayer :: from_ptr ( layer. cast ( ) ) } ;
89
- let view: * mut Object = msg_send ! [ view. as_ptr( ) , retain] ;
90
- let view = NonNull :: new ( view) . expect ( "retain should return the same object" ) ;
91
- Self :: new ( Some ( view) , layer)
88
+ Self :: new ( layer)
92
89
}
93
90
94
91
pub unsafe fn from_layer ( layer : & metal:: MetalLayerRef ) -> Self {
95
92
let class = class ! ( CAMetalLayer ) ;
96
93
let proper_kind: BOOL = msg_send ! [ layer, isKindOfClass: class] ;
97
94
assert_eq ! ( proper_kind, YES ) ;
98
- Self :: new ( None , layer. to_owned ( ) )
95
+ Self :: new ( layer. to_owned ( ) )
99
96
}
100
97
101
98
/// Get or create a new `CAMetalLayer` associated with the given `NSView`
@@ -279,16 +276,6 @@ impl super::Surface {
279
276
}
280
277
}
281
278
282
- impl Drop for super :: Surface {
283
- fn drop ( & mut self ) {
284
- if let Some ( view) = self . view {
285
- unsafe {
286
- let ( ) = msg_send ! [ view. as_ptr( ) , release] ;
287
- }
288
- }
289
- }
290
- }
291
-
292
279
impl crate :: Surface for super :: Surface {
293
280
type A = super :: Api ;
294
281
@@ -320,8 +307,8 @@ impl crate::Surface for super::Surface {
320
307
321
308
// AppKit / UIKit automatically sets the correct scale factor for
322
309
// layers attached to a view. Our layer, however, may not be directly
323
- // attached to the view; in those cases, we need to set the scale
324
- // factor ourselves.
310
+ // attached to a view; in those cases, we need to set the scale
311
+ // factor ourselves from the super layer, if there is one .
325
312
//
326
313
// For AppKit, we do so by adding a delegate on the layer with the
327
314
// `layer:shouldInheritContentsScale:fromWindow:` method returning
@@ -333,8 +320,9 @@ impl crate::Surface for super::Surface {
333
320
// TODO: Is there a way that we could listen to such changes instead?
334
321
#[ cfg( not( target_os = "macos" ) ) ]
335
322
{
336
- if let Some ( view) = self . view {
337
- let scale_factor: CGFloat = msg_send ! [ view. as_ptr( ) , contentScaleFactor] ;
323
+ let superlayer: * mut Object = msg_send ! [ render_layer. as_ptr( ) , superlayer] ;
324
+ if !superlayer. is_null ( ) {
325
+ let scale_factor: CGFloat = msg_send ! [ superlayer, contentsScale] ;
338
326
let ( ) = msg_send ! [ render_layer. as_ptr( ) , setContentsScale: scale_factor] ;
339
327
}
340
328
}
0 commit comments