@@ -3,7 +3,7 @@ use crate::error::InitError;
33use crate :: { backend_interface:: * , AlphaMode } ;
44use crate :: { util, Pixel , Rect , SoftBufferError } ;
55use objc2:: rc:: Retained ;
6- use objc2:: runtime:: { AnyObject , Bool } ;
6+ use objc2:: runtime:: { AnyObject , Bool , ProtocolObject } ;
77use objc2:: { define_class, msg_send, AllocAnyThread , DefinedClass , MainThreadMarker , Message } ;
88use objc2_core_foundation:: { CFRetained , CGPoint } ;
99use objc2_core_graphics:: {
@@ -13,7 +13,7 @@ use objc2_core_graphics::{
1313} ;
1414use objc2_foundation:: {
1515 ns_string, NSDictionary , NSKeyValueChangeKey , NSKeyValueChangeNewKey ,
16- NSKeyValueObservingOptions , NSNumber , NSObject , NSObjectNSKeyValueObserverRegistration ,
16+ NSKeyValueObservingOptions , NSNull , NSNumber , NSObject , NSObjectNSKeyValueObserverRegistration ,
1717 NSString , NSValue ,
1818} ;
1919use objc2_quartz_core:: { kCAGravityTopLeft, CALayer , CATransaction } ;
@@ -238,6 +238,17 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for CGImpl<
238238 // Default alpha mode is opaque.
239239 layer. setOpaque ( true ) ;
240240
241+ // The CALayer has a default action associated with a change in the layer contents, causing
242+ // a quarter second fade transition to happen every time a new buffer is applied.
243+ //
244+ // We avoid this by setting the action for the "contents" key to NULL.
245+ //
246+ // TODO(madsmtm): Do we want to do the same for bounds/contentsScale for smoother resizing?
247+ layer. setActions ( Some ( & NSDictionary :: from_slices (
248+ & [ ns_string ! ( "contents" ) ] ,
249+ & [ ProtocolObject :: from_ref ( & * NSNull :: null ( ) ) ] ,
250+ ) ) ) ;
251+
241252 // The color space we're using. Initialize it here to reduce work later on.
242253 // TODO: Allow setting this to something else?
243254 let color_space = CGColorSpace :: new_device_rgb ( ) . unwrap ( ) ;
@@ -407,11 +418,9 @@ impl BufferInterface for BufferImpl<'_> {
407418 }
408419 . unwrap ( ) ;
409420
410- // The CALayer has a default action associated with a change in the layer contents, causing
411- // a quarter second fade transition to happen every time a new buffer is applied. This can
412- // be avoided by wrapping the operation in a transaction and disabling all actions.
421+ // Wrap layer modifications in a transaction. Unclear if we should keep doing this, see
422+ // <https://github.com/rust-windowing/softbuffer/pull/275> for discussion about this.
413423 CATransaction :: begin ( ) ;
414- CATransaction :: setDisableActions ( true ) ;
415424
416425 // SAFETY: The contents is `CGImage`, which is a valid class for `contents`.
417426 unsafe { layer. setContents ( Some ( image. as_ref ( ) ) ) } ;
0 commit comments