Skip to content

Commit 34ce03b

Browse files
authored
Remove CATransaction::setDisableActions(true) call (#349)
This is more cleanly handled by disabling the transition upon creating the layer instead.
1 parent cadb780 commit 34ce03b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ objc2-foundation = { version = "0.3.2", default-features = false, features = [
117117
"NSString",
118118
"NSThread",
119119
"NSValue",
120+
"NSNull",
120121
] }
121122
objc2-quartz-core = { version = "0.3.2", default-features = false, features = [
122123
"std",

src/backends/cg.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::error::InitError;
33
use crate::{backend_interface::*, AlphaMode};
44
use crate::{util, Pixel, Rect, SoftBufferError};
55
use objc2::rc::Retained;
6-
use objc2::runtime::{AnyObject, Bool};
6+
use objc2::runtime::{AnyObject, Bool, ProtocolObject};
77
use objc2::{define_class, msg_send, AllocAnyThread, DefinedClass, MainThreadMarker, Message};
88
use objc2_core_foundation::{CFRetained, CGPoint};
99
use objc2_core_graphics::{
@@ -13,7 +13,7 @@ use objc2_core_graphics::{
1313
};
1414
use objc2_foundation::{
1515
ns_string, NSDictionary, NSKeyValueChangeKey, NSKeyValueChangeNewKey,
16-
NSKeyValueObservingOptions, NSNumber, NSObject, NSObjectNSKeyValueObserverRegistration,
16+
NSKeyValueObservingOptions, NSNull, NSNumber, NSObject, NSObjectNSKeyValueObserverRegistration,
1717
NSString, NSValue,
1818
};
1919
use 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

Comments
 (0)