X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=jwxyz%2Fjwxyz-cocoa.m;h=96d54b88ef4ffc3c2f8afebb6579a406db5b8cb3;hb=c85f503f5793839a6be4c818332aca4a96927bb2;hp=4585e6584ce231202379e5ef32a529bf0ea6d9f9;hpb=4361b69d3178d7fc98d0388f9a223af6c2651aba;p=xscreensaver diff --git a/jwxyz/jwxyz-cocoa.m b/jwxyz/jwxyz-cocoa.m index 4585e658..96d54b88 100644 --- a/jwxyz/jwxyz-cocoa.m +++ b/jwxyz/jwxyz-cocoa.m @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1991-2017 Jamie Zawinski +/* xscreensaver, Copyright (c) 1991-2018 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -41,6 +41,8 @@ #import #import +#define VTBL JWXYZ_VTBL(dpy) + /* OS X/iOS-specific JWXYZ implementation. */ void @@ -109,7 +111,13 @@ jwxyz_scale (Window main_window) scale = main_window->window.view.hackedContentScaleFactor; if (scale < 1) // iPad Pro magnifies the backbuffer by 3x, which makes text scale = 1; // excessively blurry in BSOD. -# endif + +# else // !USE_IPHONE + + /* Desktop retina displays also need fonts doubled. */ + scale = main_window->window.view.hackedContentScaleFactor; + +# endif // !USE_IPHONE return scale; } @@ -451,6 +459,8 @@ jwxyz_load_native_font (Window main_window, int traits_jwxyz, int mask_jwxyz, } } + [font_name release]; + if (nsfont) { if (family_name_ret) @@ -528,7 +538,7 @@ nsstring_from(const char *str, size_t len, int utf8_p) void jwxyz_render_text (Display *dpy, void *native_font, - const char *str, size_t len, int utf8_p, + const char *str, size_t len, Bool utf8_p, Bool antialias_p, XCharStruct *cs_ret, char **pixmap_ret) { utf8_metrics (dpy, (NSFont *)native_font, nsstring_from (str, len, utf8_p), @@ -560,6 +570,7 @@ jwxyz_get_pos (Window w, XPoint *xvpos, XPoint *xp) # if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6) NSRect rr1 = [w->window.view convertRect: NSMakeRect(0,0,0,0) toView:nil]; NSRect rr2 = [nsw convertRectToScreen: rr1]; + NSPoint wpos = NSMakePoint (rr2.origin.x - rr1.origin.x, rr2.origin.y - rr1.origin.y); # else @@ -578,7 +589,8 @@ jwxyz_get_pos (Window w, XPoint *xvpos, XPoint *xp) vpos.y += wpos.y; // get top left of view on screen, from bottom left - vpos.y += w->frame.height; + double s = [w->window.view hackedContentScaleFactor]; + vpos.y += w->frame.height / s; // get top left of view on screen, from top left NSArray *screens = [NSScreen screens]; @@ -679,19 +691,19 @@ create_framebuffer (GLuint *gl_framebuffer, GLuint *gl_renderbuffer) static void push_bg_gc (Display *dpy, Drawable d, GC gc, Bool fill_p) { - XGCValues *gcv = jwxyz_gc_gcv (gc); + XGCValues *gcv = VTBL->gc_gcv (gc); push_color_gc (dpy, d, gc, gcv->background, gcv->antialias_p, fill_p); } void -jwxyz_copy_area (Display *dpy, Drawable src, Drawable dst, GC gc, - int src_x, int src_y, - unsigned int width, unsigned int height, - int dst_x, int dst_y) +jwxyz_quartz_copy_area (Display *dpy, Drawable src, Drawable dst, GC gc, + int src_x, int src_y, + unsigned int width, unsigned int height, + int dst_x, int dst_y) { XRectangle src_frame = src->frame, dst_frame = dst->frame; - XGCValues *gcv = jwxyz_gc_gcv (gc); + XGCValues *gcv = VTBL->gc_gcv (gc); BOOL mask_p = src->type == PIXMAP && src->pixmap.depth == 1; @@ -710,30 +722,12 @@ jwxyz_copy_area (Display *dpy, Drawable src, Drawable dst, GC gc, !dst_frame.y, "unexpected non-zero origin"); - ptrdiff_t src_pitch = CGBitmapContextGetBytesPerRow(src->cgc); - ptrdiff_t dst_pitch = CGBitmapContextGetBytesPerRow(dst->cgc); - char *src_data = seek_xy (CGBitmapContextGetData (src->cgc), src_pitch, - src_x, src_y); - char *dst_data = seek_xy (CGBitmapContextGetData (dst->cgc), dst_pitch, - dst_x, dst_y); - - size_t bytes = width * 4; - - if (src == dst && dst_y > src_y) { - // Copy upwards if the areas might overlap. - src_data += src_pitch * (height - 1); - dst_data += dst_pitch * (height - 1); - src_pitch = -src_pitch; - dst_pitch = -dst_pitch; - } + jwxyz_blit (CGBitmapContextGetData (src->cgc), + CGBitmapContextGetBytesPerRow (src->cgc), src_x, src_y, + CGBitmapContextGetData (dst->cgc), + CGBitmapContextGetBytesPerRow (dst->cgc), dst_x, dst_y, + width, height); - while (height) { - // memcpy is an alias for memmove on OS X. - memmove(dst_data, src_data, bytes); - src_data += src_pitch; - dst_data += dst_pitch; - --height; - } } else { CGRect src_rect = CGRectMake(src_x, src_y, width, height), @@ -787,7 +781,7 @@ jwxyz_copy_area (Display *dpy, Drawable src, Drawable dst, GC gc, // then fill in a solid rectangle of the fg color, using the image as an // alpha mask. (the image has only values of BlackPixel or WhitePixel.) - set_color (dpy, cgc, gcv->foreground, jwxyz_gc_depth (gc), + set_color (dpy, cgc, gcv->foreground, VTBL->gc_depth (gc), gcv->alpha_allowed_p, YES); CGContextClipToMask (cgc, dst_rect, cgi); CGContextFillRect (cgc, dst_rect);