From e0f5218121054172bf9df6474ae37c29e6d24e11 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 10 Mar 2016 11:43:51 +0000 Subject: [PATCH] Added an internal flag JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS --- .../native/juce_mac_NSViewComponentPeer.mm | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index d786ac61a4..89cda33e0c 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -69,7 +69,6 @@ public: view (nil), isSharedWindow (viewToAttachTo != nil), fullScreen (false), - insideDrawRect (false), #if USE_COREGRAPHICS_RENDERING usingCoreGraphics (true), #else @@ -793,6 +792,37 @@ public: displayScale = (float) screen.backingScaleFactor; #endif + #if USE_COREGRAPHICS_RENDERING && JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS + // This option invokes a separate paint call for each rectangle of the clip region. + // It's a long story, but this is a basically a workaround for a CGContext not having + // a way of finding whether a rectangle falls within its clip region + if (usingCoreGraphics) + { + const NSRect* rects = nullptr; + NSInteger numRects = 0; + [view getRectsBeingDrawn: &rects count: &numRects]; + + if (numRects > 1) + { + for (int i = 0; i < numRects; ++i) + { + NSRect rect = rects[i]; + CGContextSaveGState (cg); + CGContextClipToRect (cg, CGRectMake (rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)); + drawRect (cg, rect, displayScale); + CGContextRestoreGState (cg); + } + + return; + } + } + #endif + + drawRect (cg, r, displayScale); + } + + void drawRect (CGContextRef cg, NSRect r, float displayScale) + { #if USE_COREGRAPHICS_RENDERING if (usingCoreGraphics) { @@ -872,9 +902,7 @@ public: void invokePaint (LowLevelGraphicsContext& context) { lastRepaintTime = Time::getCurrentTime(); - insideDrawRect = true; handlePaint (context); - insideDrawRect = false; } void performAnyPendingRepaintsNow() override @@ -1283,7 +1311,7 @@ public: //============================================================================== NSWindow* window; NSView* view; - bool isSharedWindow, fullScreen, insideDrawRect; + bool isSharedWindow, fullScreen; bool usingCoreGraphics, isZooming, textWasInserted; String stringBeingComposed; NSNotificationCenter* notificationCenter;