From 9f79252321f5466fa985cae48515e2b21c883bbf Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 30 Oct 2019 15:30:20 +0000 Subject: Fix [8793e78bf0]: High CPU usage due to unnecessary redraws of the entire window. --- macosx/tkMacOSXDraw.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index 314ca35..5714bf4 100644 --- a/macosx/tkMacOSXDraw.c +++ b/macosx/tkMacOSXDraw.c @@ -1632,16 +1632,27 @@ TkMacOSXSetupDrawingContext( * a view's drawRect or setFrame methods. The isDrawing attribute * tells us whether we are being called from one of those methods. * - * If the CGContext is not valid, or belongs to a different View, then - * we mark our view as needing display and return failure. It should - * get drawn in a later call to drawRect. + * If the CGContext is not valid then we mark our view as needing + * display in the bounding rectangle of the clipping region and + * return failure. That rectangle should get drawn in a later call + * to drawRect. */ - - if (view != [NSView focusView]) { - [view setNeedsDisplay:YES]; + + if (![NSApp isDrawing] || view != [NSView focusView]) { + NSRect bounds = [view bounds]; + NSRect dirtyNS = bounds; + CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0, + .ty = dirtyNS.size.height}; + if (dc.clipRgn) { + CGRect dirtyCG = NSRectToCGRect(dirtyNS); + HIShapeGetBounds(dc.clipRgn, &dirtyCG); + dirtyNS = NSRectToCGRect(CGRectApplyAffineTransform(dirtyCG, t)); + } + [view setNeedsDisplayInRect:dirtyNS]; canDraw = false; goto end; } + dc.view = view; dc.context = GET_CGCONTEXT; dc.portBounds = NSRectToCGRect([view bounds]); -- cgit v0.12 From d815697b8593d92960f651b6b69e3ac18561bd00 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Fri, 1 Nov 2019 18:44:14 +0000 Subject: Work around a bug in [NSFont familyName] which Apple introduced in macOS 10.15.1 --- macosx/tkMacOSXFont.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index fb71e85..a0da3a9 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -128,11 +128,24 @@ GetTkFontAttributesForNSFont( { NSFontTraitMask traits = [[NSFontManager sharedFontManager] traitsOfFont:nsFont]; + char *family = [[nsFont familyName] UTF8String]; + + /* + * Workaround for a bug in Catalina 15.1. The familyName method can prefix + * the font name with ".SF " and the font manager will refuse to accept + * that name when searching for the font. As a workaround, if the name + * starts with ".SF " we remove that prefix. + */ - faPtr->family = Tk_GetUid([[nsFont familyName] UTF8String]); + if (strncmp(family, ".SF ", 4) == 0) { + faPtr->family = Tk_GetUid(family + 4); + } else { + faPtr->family = Tk_GetUid([[nsFont familyName] UTF8String]); + } faPtr->size = [nsFont pointSize]; faPtr->weight = (traits & NSBoldFontMask ? TK_FW_BOLD : TK_FW_NORMAL); faPtr->slant = (traits & NSItalicFontMask ? TK_FS_ITALIC : TK_FS_ROMAN); + } /* -- cgit v0.12 From 09fe4a9aaf45f55440dcd7af939040cc492c8acc Mon Sep 17 00:00:00 2001 From: marc_culler Date: Sun, 3 Nov 2019 23:02:04 +0000 Subject: Use [NSFont userFixedPitchFontOfSize:11] instead of CTFontCreateUIFontForLanguage(fixedPitch, 11, NULL) to get a valid fixed pitch font. --- macosx/tkMacOSXFont.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index a0da3a9..b11794a 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -128,20 +128,7 @@ GetTkFontAttributesForNSFont( { NSFontTraitMask traits = [[NSFontManager sharedFontManager] traitsOfFont:nsFont]; - char *family = [[nsFont familyName] UTF8String]; - - /* - * Workaround for a bug in Catalina 15.1. The familyName method can prefix - * the font name with ".SF " and the font manager will refuse to accept - * that name when searching for the font. As a workaround, if the name - * starts with ".SF " we remove that prefix. - */ - - if (strncmp(family, ".SF ", 4) == 0) { - faPtr->family = Tk_GetUid(family + 4); - } else { - faPtr->family = Tk_GetUid([[nsFont familyName] UTF8String]); - } + faPtr->family = Tk_GetUid([[nsFont familyName] UTF8String]); faPtr->size = [nsFont pointSize]; faPtr->weight = (traits & NSBoldFontMask ? TK_FW_BOLD : TK_FW_NORMAL); faPtr->slant = (traits & NSItalicFontMask ? TK_FS_ITALIC : TK_FS_ROMAN); @@ -407,7 +394,17 @@ TkpFontPkgInit( systemFont++; } TkInitFontAttributes(&fa); +#if 0 + /* + * In macOS 10.15.1 a bug was introduced which caused the call below to + * return a font with the invalid familyName ".SF NS Mono" instead of the + * valid familyName "NS Mono". Calling [NSFont userFixedPitchFontOfSize:11] + * returns a font in the "Menlo" family which has a valid familyName. + */ nsFont = (NSFont*) CTFontCreateUIFontForLanguage(fixedPitch, 11, NULL); +#else + nsFont = [NSFont userFixedPitchFontOfSize:11]; +#endif if (nsFont) { GetTkFontAttributesForNSFont(nsFont, &fa); CFRelease(nsFont); -- cgit v0.12 From d6ff843f2a143394e4c24f8502d9b1fdc17e6ebb Mon Sep 17 00:00:00 2001 From: culler Date: Mon, 4 Nov 2019 16:09:33 +0000 Subject: But we shouldn't call CFRelease on the font returned by [NSFont userFixedPitchFontOfSize:11] --- macosx/tkMacOSXFont.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index 23a3cb8..bc1edff 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -407,7 +407,9 @@ TkpFontPkgInit( #endif if (nsFont) { GetTkFontAttributesForNSFont(nsFont, &fa); +#if 0 CFRelease(nsFont); +#endif } else { fa.family = Tk_GetUid("Monaco"); fa.size = 11; -- cgit v0.12 From 36766607d76fdb1ffc103c4f6e0f0527a7e840bd Mon Sep 17 00:00:00 2001 From: culler Date: Mon, 4 Nov 2019 16:21:40 +0000 Subject: Edit a comment. --- macosx/tkMacOSXFont.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index bc1edff..d6429ed 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -396,9 +396,9 @@ TkpFontPkgInit( TkInitFontAttributes(&fa); #if 0 /* - * In macOS 10.15.1 a bug was introduced which caused the call below to - * return a font with the invalid familyName ".SF NS Mono" instead of the - * valid familyName "NS Mono". Calling [NSFont userFixedPitchFontOfSize:11] + * In macOS 10.15.1 Apple introduced a bug which caused the call below to + * return a font with the invalid familyName ".SF NSMono" instead of the + * valid familyName "NSMono". Calling [NSFont userFixedPitchFontOfSize:11] * returns a font in the "Menlo" family which has a valid familyName. */ nsFont = (NSFont*) CTFontCreateUIFontForLanguage(fixedPitch, 11, NULL); -- cgit v0.12