Skip to content

Commit b72055d

Browse files
committed
Disable CALayer fade action when setting buffers
This commit fixes a bug in the Core Graphics backend that causes a new buffer not be shown immediately but instead use a quarter second fade transition. This happens because the CALayer has a default action associated with a change in the layer contents. The problem was mitigated by wrapping the contents change in a transaction and disabling all actions for the duration of this transaction.
1 parent a78becd commit b72055d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/cg.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use raw_window_handle::AppKitWindowHandle;
99

1010
use cocoa::appkit::{NSView, NSViewHeightSizable, NSViewWidthSizable, NSWindow};
1111
use cocoa::base::{id, nil};
12-
use cocoa::quartzcore::{CALayer, ContentsGravity};
12+
use cocoa::quartzcore::{transaction, CALayer, ContentsGravity};
1313
use foreign_types::ForeignType;
1414

1515
use std::sync::Arc;
@@ -55,6 +55,15 @@ impl CGImpl {
5555
false,
5656
kCGRenderingIntentDefault,
5757
);
58+
59+
// The CALayer has a default action associated with a change in the layer contents, causing
60+
// a quarter second fade transition to happen every time a new buffer is applied. This can
61+
// be mitigated by wrapping the operation in a transaction and disabling all actions.
62+
transaction::begin();
63+
transaction::set_disable_actions(true);
64+
5865
unsafe { self.layer.set_contents(image.as_ptr() as id) };
66+
67+
transaction::commit();
5968
}
6069
}

0 commit comments

Comments
 (0)