Keep track of graphics state stack depth

To avoid restoring graphics state from the empty stack. This
could also help in diagnosing potential problems with unbalanced
PushState()/PopState() calls.
This commit is contained in:
Artur Wieczorek
2021-07-23 18:10:59 +02:00
parent 3e7ad82016
commit 7349f138e7

View File

@@ -1543,6 +1543,7 @@ private:
CGAffineTransform m_initTransform; CGAffineTransform m_initTransform;
CGAffineTransform m_windowTransform; CGAffineTransform m_windowTransform;
bool m_invisible; bool m_invisible;
int m_stateStackLevel;
#if wxOSX_USE_COCOA_OR_CARBON #if wxOSX_USE_COCOA_OR_CARBON
wxCFRef<HIShapeRef> m_clipRgn; wxCFRef<HIShapeRef> m_clipRgn;
@@ -1817,6 +1818,7 @@ bool wxMacCoreGraphicsContext::EnsureIsValid()
CGContextSetTextMatrix( m_cgContext, CGAffineTransformIdentity ); CGContextSetTextMatrix( m_cgContext, CGAffineTransformIdentity );
m_contextSynthesized = true; m_contextSynthesized = true;
CGContextSaveGState( m_cgContext ); CGContextSaveGState( m_cgContext );
m_stateStackLevel = 0;
#if 0 // turn on for debugging of clientdc #if 0 // turn on for debugging of clientdc
static float color = 0.5 ; static float color = 0.5 ;
@@ -2375,6 +2377,7 @@ void wxMacCoreGraphicsContext::SetNativeContext( CGContextRef cg )
CGContextSaveGState( m_cgContext ); CGContextSaveGState( m_cgContext );
CGContextSetTextMatrix( m_cgContext, CGAffineTransformIdentity ); CGContextSetTextMatrix( m_cgContext, CGAffineTransformIdentity );
CGContextSaveGState( m_cgContext ); CGContextSaveGState( m_cgContext );
m_stateStackLevel = 0;
m_contextSynthesized = false; m_contextSynthesized = false;
} }
} }
@@ -2485,6 +2488,7 @@ void wxMacCoreGraphicsContext::PushState()
return; return;
CGContextSaveGState( m_cgContext ); CGContextSaveGState( m_cgContext );
m_stateStackLevel++;
} }
void wxMacCoreGraphicsContext::PopState() void wxMacCoreGraphicsContext::PopState()
@@ -2492,7 +2496,9 @@ void wxMacCoreGraphicsContext::PopState()
if (!EnsureIsValid()) if (!EnsureIsValid())
return; return;
wxCHECK_RET(m_stateStackLevel > 0, "No state to pop");
CGContextRestoreGState( m_cgContext ); CGContextRestoreGState( m_cgContext );
m_stateStackLevel--;
} }
void wxMacCoreGraphicsContext::DoDrawText( const wxString &str, wxDouble x, wxDouble y ) void wxMacCoreGraphicsContext::DoDrawText( const wxString &str, wxDouble x, wxDouble y )