From e19d4d21dc5c3bf45032cfb6d69a51a1bf39f522 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 14 Mar 2020 17:28:32 +0100 Subject: Cocoa: Use window scale factor when rendering UI buffer. --- plugingui/nativewindow_cocoa.h | 1 + plugingui/nativewindow_cocoa.mm | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugingui/nativewindow_cocoa.h b/plugingui/nativewindow_cocoa.h index 74eb2f4..8dc73e6 100644 --- a/plugingui/nativewindow_cocoa.h +++ b/plugingui/nativewindow_cocoa.h @@ -72,6 +72,7 @@ private: EventQueue event_queue; void* native_window{nullptr}; bool first{true}; + float scale{1.0}; }; } // GUI:: diff --git a/plugingui/nativewindow_cocoa.mm b/plugingui/nativewindow_cocoa.mm index 90b5c70..37fae88 100644 --- a/plugingui/nativewindow_cocoa.mm +++ b/plugingui/nativewindow_cocoa.mm @@ -528,6 +528,8 @@ NativeWindowCocoa::NativeWindowCocoa(void* native_window, Window& window) [priv->window setContentView:priv->view]; } + scale = [[NSScreen mainScreen] backingScaleFactor]; + [priv->view setWantsLayer:YES]; [priv->view setLayerContentsPlacement:NSViewLayerContentsPlacementTopLeft]; [priv->view updateTrackingAreas]; @@ -697,9 +699,12 @@ void NativeWindowCocoa::redraw(const Rect& dirty_rect) CGImageRef image = CGBitmapContextCreateImage(gc); CGContextRelease(gc); - [[priv->view layer] setContents:(__bridge id)image]; + auto nsImage = [[NSImage alloc] initWithCGImage:image size:NSZeroSize]; + id layerContents = [nsImage layerContentsForContentsScale:scale]; + [[priv->view layer] setContents:layerContents]; updateLayerOffset(); + [[priv->view layer] setContentsScale:scale]; } void NativeWindowCocoa::setCaption(const std::string &caption) -- cgit v1.2.3