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.
This commit is contained in:
Emil Loer 2023-01-05 22:07:21 +01:00
parent a78becd316
commit b72055d122
No known key found for this signature in database
GPG key ID: F74006FC8A2A183E

View file

@ -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();
}
}