From b72055d1222164d4c6535e124a18fb82bf608a1f Mon Sep 17 00:00:00 2001 From: Emil Loer Date: Thu, 5 Jan 2023 22:07:21 +0100 Subject: [PATCH] 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. --- src/cg.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cg.rs b/src/cg.rs index ffba09a..2910372 100644 --- a/src/cg.rs +++ b/src/cg.rs @@ -9,7 +9,7 @@ use raw_window_handle::AppKitWindowHandle; use cocoa::appkit::{NSView, NSViewHeightSizable, NSViewWidthSizable, NSWindow}; use cocoa::base::{id, nil}; -use cocoa::quartzcore::{CALayer, ContentsGravity}; +use cocoa::quartzcore::{transaction, CALayer, ContentsGravity}; use foreign_types::ForeignType; use std::sync::Arc; @@ -55,6 +55,15 @@ impl CGImpl { false, kCGRenderingIntentDefault, ); + + // The CALayer has a default action associated with a change in the layer contents, causing + // a quarter second fade transition to happen every time a new buffer is applied. This can + // be mitigated by wrapping the operation in a transaction and disabling all actions. + transaction::begin(); + transaction::set_disable_actions(true); + unsafe { self.layer.set_contents(image.as_ptr() as id) }; + + transaction::commit(); } }