Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Commit

Permalink
Fix scaling of the buffer on macOS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tronical committed Dec 21, 2022
1 parent fbc4851 commit b74047a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core_graphics::data_provider::CGDataProvider;
use core_graphics::image::CGImage;

use cocoa::base::{id, nil};
use cocoa::appkit::{NSView, NSViewWidthSizable, NSViewHeightSizable};
use cocoa::appkit::{NSView, NSViewWidthSizable, NSViewHeightSizable, NSWindow};
use cocoa::quartzcore::{CALayer, ContentsGravity};
use foreign_types::ForeignType;

Expand All @@ -18,11 +18,13 @@ pub struct CGImpl {

impl CGImpl {
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SwBufError> {
let window = handle.ns_window as id;
let view = handle.ns_view as id;
let layer = CALayer::new();
let subview: id = NSView::alloc(nil).initWithFrame_(view.frame());
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);

Expand Down

0 comments on commit b74047a

Please sign in to comment.