From dc11bb18cf2ebc3f36a6d5b083a95b5639149c4f Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 21 Mar 2021 18:44:06 +0100 Subject: [PATCH] Use new CoreGraphics API to reset clipping region Since 10.13 there is available a dedicated CGContextResetClip() API to reset a clipping region so we don't need to use current workaround anymore. --- src/osx/carbon/graphics.cpp | 40 +++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 591afc715d..80f9431cf2 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -40,6 +40,7 @@ #include "wx/osx/dcmemory.h" #include "wx/osx/private.h" #include "wx/osx/core/cfdictionary.h" + #include "wx/osx/private/available.h" #else #include "CoreServices/CoreServices.h" #include "ApplicationServices/ApplicationServices.h" @@ -2052,21 +2053,30 @@ void wxMacCoreGraphicsContext::ResetClip() { if ( m_cgContext ) { - // there is no way for clearing the clip, we can only revert to the stored - // state, but then we have to make sure everything else is NOT restored - CGAffineTransform transform = CGContextGetCTM( m_cgContext ); - CGContextRestoreGState( m_cgContext ); - CGContextSaveGState( m_cgContext ); - CGAffineTransform transformNew = CGContextGetCTM( m_cgContext ); - transformNew = CGAffineTransformInvert( transformNew ) ; - CGContextConcatCTM( m_cgContext, transformNew); - CGContextConcatCTM( m_cgContext, transform); - // Retain antialiasing mode - DoSetAntialiasMode(m_antialias); - // Retain interpolation quality - DoSetInterpolationQuality(m_interpolation); - // Retain composition mode - DoSetCompositionMode(m_composition); +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13 + if ( WX_IS_MACOS_OR_IOS_AVAILABLE(10, 13, 11, 0) ) + { + CGContextResetClip(m_cgContext); + } + else +#endif + { + // there is no way for clearing the clip, we can only revert to the stored + // state, but then we have to make sure everything else is NOT restored + CGAffineTransform transform = CGContextGetCTM( m_cgContext ); + CGContextRestoreGState( m_cgContext ); + CGContextSaveGState( m_cgContext ); + CGAffineTransform transformNew = CGContextGetCTM( m_cgContext ); + transformNew = CGAffineTransformInvert( transformNew ) ; + CGContextConcatCTM( m_cgContext, transformNew); + CGContextConcatCTM( m_cgContext, transform); + // Retain antialiasing mode + DoSetAntialiasMode(m_antialias); + // Retain interpolation quality + DoSetInterpolationQuality(m_interpolation); + // Retain composition mode + DoSetCompositionMode(m_composition); + } } else {