mac: Fix layer scale not being updated when contents is updated and window is on a new screen

cc #67
This commit is contained in:
Simon Hausmann 2023-01-15 09:09:12 +01:00
parent 33a4c3741b
commit 2832a6e42b

View file

@ -16,6 +16,7 @@ use std::sync::Arc;
pub struct CGImpl {
layer: CALayer,
window: id,
}
impl CGImpl {
@ -27,14 +28,13 @@ impl CGImpl {
let subview: id = NSView::alloc(nil).initWithFrame_(NSView::frame(view));
layer.set_contents_gravity(ContentsGravity::TopLeft);
layer.set_needs_display_on_bounds_change(false);
layer.set_contents_scale(window.backingScaleFactor());
subview.setLayer(layer.id());
subview.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable);
view.addSubview_(subview); // retains subview (+1) = 2
let _: () = msg_send![subview, release]; // releases subview (-1) = 1
}
Ok(Self { layer })
Ok(Self { layer, window })
}
pub(crate) unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16) {
@ -62,7 +62,11 @@ impl CGImpl {
transaction::begin();
transaction::set_disable_actions(true);
unsafe { self.layer.set_contents(image.as_ptr() as id) };
unsafe {
self.layer
.set_contents_scale(self.window.backingScaleFactor());
self.layer.set_contents(image.as_ptr() as id);
};
transaction::commit();
}