Skip to content

Commit b74047a

Browse files
committed
Fix scaling of the buffer on macOS
Currently the size of the buffer on macOS is interpreted in logical pixels, which is inconsistent with the other platforms. Instead, we should apply the same scale factor that applies to regular rendering.
1 parent fbc4851 commit b74047a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/cg.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core_graphics::data_provider::CGDataProvider;
66
use core_graphics::image::CGImage;
77

88
use cocoa::base::{id, nil};
9-
use cocoa::appkit::{NSView, NSViewWidthSizable, NSViewHeightSizable};
9+
use cocoa::appkit::{NSView, NSViewWidthSizable, NSViewHeightSizable, NSWindow};
1010
use cocoa::quartzcore::{CALayer, ContentsGravity};
1111
use foreign_types::ForeignType;
1212

@@ -18,11 +18,13 @@ pub struct CGImpl {
1818

1919
impl CGImpl {
2020
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SwBufError> {
21+
let window = handle.ns_window as id;
2122
let view = handle.ns_view as id;
2223
let layer = CALayer::new();
23-
let subview: id = NSView::alloc(nil).initWithFrame_(view.frame());
24+
let subview: id = NSView::alloc(nil).initWithFrame_(NSView::frame(view));
2425
layer.set_contents_gravity(ContentsGravity::TopLeft);
2526
layer.set_needs_display_on_bounds_change(false);
27+
layer.set_contents_scale(window.backingScaleFactor());
2628
subview.setLayer(layer.id());
2729
subview.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable);
2830

0 commit comments

Comments
 (0)