From 29ba1095370abcdc341086b258bfe046f50100fc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 8 Apr 2020 13:41:35 +0200 Subject: Mac: Use high-resolution backing surfaces --- pugl/detail/mac_cairo.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'pugl/detail/mac_cairo.m') diff --git a/pugl/detail/mac_cairo.m b/pugl/detail/mac_cairo.m index 51c1c13..ccce14e 100644 --- a/pugl/detail/mac_cairo.m +++ b/pugl/detail/mac_cairo.m @@ -43,7 +43,9 @@ - (id) initWithFrame:(NSRect)frame { - return (self = [super initWithFrame:frame]); + self = [super initWithFrame:frame]; + + return self; } - (void) resizeWithOldSuperviewSize:(NSSize)oldSize @@ -69,7 +71,7 @@ puglMacCairoCreate(PuglView* view) PuglCairoView* drawView = [PuglCairoView alloc]; drawView->puglview = view; - [drawView initWithFrame:NSMakeRect(0, 0, view->frame.width, view->frame.height)]; + [drawView initWithFrame:[impl->wrapperView bounds]]; if (view->hints[PUGL_RESIZABLE]) { [drawView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; } else { @@ -103,10 +105,17 @@ puglMacCairoEnter(PuglView* view, const PuglEventExpose* expose) assert(!drawView->surface); assert(!drawView->cr); + const double scale = 1.0 / [[NSScreen mainScreen] backingScaleFactor]; CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; + const CGSize sizePx = {view->frame.width, view->frame.height}; + const CGSize sizePt = CGContextConvertSizeToUserSpace(context, sizePx); + + // Convert coordinates to standard Cairo space + CGContextTranslateCTM(context, 0.0, -sizePt.height); + CGContextScaleCTM(context, scale, -scale); drawView->surface = cairo_quartz_surface_create_for_cg_context( - context, view->frame.width, view->frame.height); + context, sizePx.width, sizePx.height); drawView->cr = cairo_create(drawView->surface); -- cgit v1.2.1