@@ -63,9 +63,8 @@ impl HalManagedMetalLayerDelegate {
6363}
6464
6565impl super :: Surface {
66- fn new ( view : Option < NonNull < Object > > , layer : metal:: MetalLayer ) -> Self {
66+ fn new ( layer : metal:: MetalLayer ) -> Self {
6767 Self {
68- view,
6968 render_layer : Mutex :: new ( layer) ,
7069 swapchain_format : RwLock :: new ( None ) ,
7170 extent : RwLock :: new ( wgt:: Extent3d :: default ( ) ) ,
@@ -85,16 +84,14 @@ impl super::Surface {
8584 // SAFETY: The layer is an initialized instance of `CAMetalLayer`, and
8685 // we transfer the retain count to `MetalLayer` using `ManuallyDrop`.
8786 let layer = unsafe { metal:: MetalLayer :: from_ptr ( layer. cast ( ) ) } ;
88- let view: * mut Object = msg_send ! [ view. as_ptr( ) , retain] ;
89- let view = NonNull :: new ( view) . expect ( "retain should return the same object" ) ;
90- Self :: new ( Some ( view) , layer)
87+ Self :: new ( layer)
9188 }
9289
9390 pub unsafe fn from_layer ( layer : & metal:: MetalLayerRef ) -> Self {
9491 let class = class ! ( CAMetalLayer ) ;
9592 let proper_kind: BOOL = msg_send ! [ layer, isKindOfClass: class] ;
9693 assert_eq ! ( proper_kind, YES ) ;
97- Self :: new ( None , layer. to_owned ( ) )
94+ Self :: new ( layer. to_owned ( ) )
9895 }
9996
10097 /// Get or create a new `CAMetalLayer` associated with the given `NSView`
@@ -278,16 +275,6 @@ impl super::Surface {
278275 }
279276}
280277
281- impl Drop for super :: Surface {
282- fn drop ( & mut self ) {
283- if let Some ( view) = self . view {
284- unsafe {
285- let ( ) = msg_send ! [ view. as_ptr( ) , release] ;
286- }
287- }
288- }
289- }
290-
291278impl crate :: Surface for super :: Surface {
292279 type A = super :: Api ;
293280
@@ -319,21 +306,23 @@ impl crate::Surface for super::Surface {
319306
320307 // AppKit / UIKit automatically sets the correct scale factor for
321308 // layers attached to a view. Our layer, however, may not be directly
322- // attached to the view; in those cases, we need to set the scale
309+ // attached to a view; in those cases, we need to set the scale
323310 // factor ourselves.
324311 //
325312 // For AppKit, we do so by adding a delegate on the layer with the
326313 // `layer:shouldInheritContentsScale:fromWindow:` method returning
327314 // `true` - this tells the system to automatically update the scale
328315 // factor when it changes.
329316 //
330- // For UIKit, we manually update the scale factor here.
317+ // For UIKit, we manually update the scale factor from the super layer
318+ // here, if there is one.
331319 //
332320 // TODO: Is there a way that we could listen to such changes instead?
333321 #[ cfg( not( target_os = "macos" ) ) ]
334322 {
335- if let Some ( view) = self . view {
336- 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] ;
337326 let ( ) = msg_send ! [ render_layer. as_ptr( ) , setContentsScale: scale_factor] ;
338327 }
339328 }
0 commit comments