diff options
author | culler <culler> | 2019-11-04 15:33:24 (GMT) |
---|---|---|
committer | culler <culler> | 2019-11-04 15:33:24 (GMT) |
commit | fdc8805fa4d1297735e0bf313941ce3c40a9855c (patch) | |
tree | a82f62a86d208cf5113458274522b7967e4c7276 /macosx | |
parent | 5ad049760c08cb41250b778342c54c5a897cdcde (diff) | |
parent | 9f79252321f5466fa985cae48515e2b21c883bbf (diff) | |
download | tk-fdc8805fa4d1297735e0bf313941ce3c40a9855c.zip tk-fdc8805fa4d1297735e0bf313941ce3c40a9855c.tar.gz tk-fdc8805fa4d1297735e0bf313941ce3c40a9855c.tar.bz2 |
Fix [8793e78bf0]: High CPU usage due to unnecessary redraws of the entire window.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXDraw.c | 23 |
1 files 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]); |