summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorculler <culler>2019-10-30 15:30:20 (GMT)
committerculler <culler>2019-10-30 15:30:20 (GMT)
commit9f79252321f5466fa985cae48515e2b21c883bbf (patch)
tree83f3d52ce8c6ebb96784d5e42b7e4049142bac1d /macosx
parentab6d53027cf2347ee194bed0cb5ce40564f50558 (diff)
downloadtk-9f79252321f5466fa985cae48515e2b21c883bbf.zip
tk-9f79252321f5466fa985cae48515e2b21c883bbf.tar.gz
tk-9f79252321f5466fa985cae48515e2b21c883bbf.tar.bz2
Fix [8793e78bf0]: High CPU usage due to unnecessary redraws of the entire window.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/tkMacOSXDraw.c23
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]);