summaryrefslogtreecommitdiff
path: root/vcl/quartz
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-05-06 13:57:36 +0900
committerTomaž Vajngerl <quikee@gmail.com>2019-05-17 10:38:25 +0200
commit9e35b5a70844c8a0f6bc8e9dd8e0055cf5597b07 (patch)
tree817ad5c379818e8fd165b3585511a11ad3e13001 /vcl/quartz
parent06b46104cc8b35e668e4b1a6d26a6a8e828fe373 (diff)
handle CG state save/restore in ContextHolder class
Change-Id: I44ee257a8a196e8f2372dd01776c0c7c5193ad0a Reviewed-on: https://gerrit.libreoffice.org/72436 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/quartz')
-rw-r--r--vcl/quartz/salgdi.cxx15
-rw-r--r--vcl/quartz/salgdicommon.cxx56
-rw-r--r--vcl/quartz/salgdiutils.cxx6
3 files changed, 24 insertions, 53 deletions
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 826b4bff4339..a68f9e9736ef 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -185,9 +185,6 @@ AquaSalGraphics::AquaSalGraphics()
#ifdef MACOSX
, mpFrame( nullptr )
#endif
-#if OSL_DEBUG_LEVEL > 0
- , mnContextStackDepth( 0 )
-#endif
, mpXorEmulation( nullptr )
, mnXorMode( 0 )
, mnWidth( 0 )
@@ -449,8 +446,7 @@ void AquaSalGraphics::DrawTextLayout(const GenericSalLayout& rLayout)
std::cerr << "]\n";
#endif
- SAL_INFO("vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth );
- CGContextSaveGState(maContextHolder.get());
+ maContextHolder.saveState();
// The view is vertically flipped (no idea why), flip it back.
SAL_INFO("vcl.cg", "CGContextScaleCTM(" << maContextHolder.get() << ",1,-1)");
@@ -478,8 +474,7 @@ void AquaSalGraphics::DrawTextLayout(const GenericSalLayout& rLayout)
size_t nStartIndex = std::distance(aGlyphOrientation.cbegin(), aIt);
size_t nLen = std::distance(aIt, aNext);
- SAL_INFO("vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth );
- CGContextSaveGState(maContextHolder.get());
+ maContextHolder.saveState();
if (rStyle.mfFontRotation && !bUprightGlyph)
{
SAL_INFO("vcl.cg", "CGContextRotateCTM(" << maContextHolder.get() << "," << rStyle.mfFontRotation << ")");
@@ -487,14 +482,12 @@ void AquaSalGraphics::DrawTextLayout(const GenericSalLayout& rLayout)
}
SAL_INFO("vcl.cg", "CTFontDrawGlyphs() @" << nStartIndex << ":" << nLen << "," << maContextHolder.get());
CTFontDrawGlyphs(pFont, &aGlyphIds[nStartIndex], &aGlyphPos[nStartIndex], nLen, maContextHolder.get());
- SAL_INFO("vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth-- );
- CGContextRestoreGState(maContextHolder.get());
+ maContextHolder.restoreState();
aIt = aNext;
}
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth-- );
- CGContextRestoreGState(maContextHolder.get());
+ maContextHolder.restoreState();
}
void AquaSalGraphics::SetFont(LogicalFontInstance* pReqFont, int nFallbackLevel)
diff --git a/vcl/quartz/salgdicommon.cxx b/vcl/quartz/salgdicommon.cxx
index b2c0d921d08b..dc73d3c95b28 100644
--- a/vcl/quartz/salgdicommon.cxx
+++ b/vcl/quartz/salgdicommon.cxx
@@ -629,8 +629,7 @@ bool AquaSalGraphics::drawTransformedBitmap(
// setup the image transformation
// using the rNull,rX,rY points as destinations for the (0,0),(0,Width),(Height,0) source points
- SAL_INFO( "vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth );
- CGContextSaveGState( maContextHolder.get() );
+ maContextHolder.saveState();
const basegfx::B2DVector aXRel = rX - rNull;
const basegfx::B2DVector aYRel = rY - rNull;
const CGAffineTransform aCGMat = CGAffineTransformMake(
@@ -649,8 +648,7 @@ bool AquaSalGraphics::drawTransformedBitmap(
SAL_INFO( "vcl.cg", "CGImageRelease(" << xImage << ")" );
CGImageRelease( xImage );
// restore the Quartz graphics state
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth--);
- CGContextRestoreGState(maContextHolder.get());
+ maContextHolder.restoreState();
// mark the destination as painted
const CGRect aDstRect = CGRectApplyAffineTransform( aSrcRect, aCGMat );
@@ -666,8 +664,7 @@ bool AquaSalGraphics::drawAlphaRect( long nX, long nY, long nWidth,
return true;
// save the current state
- SAL_INFO( "vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth );
- CGContextSaveGState( maContextHolder.get() );
+ maContextHolder.saveState();
SAL_INFO( "vcl.cg", "CGContextSetAlpha(" << maContextHolder.get() << "," << (100-nTransparency) * (1.0/100) << ")" );
CGContextSetAlpha( maContextHolder.get(), (100-nTransparency) * (1.0/100) );
@@ -685,9 +682,7 @@ bool AquaSalGraphics::drawAlphaRect( long nX, long nY, long nWidth,
SAL_INFO( "vcl.cg", "CGContextDrawPath(" << maContextHolder.get() << ",kCGPathFill)" );
CGContextDrawPath( maContextHolder.get(), kCGPathFill );
- // restore state
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth--);
- CGContextRestoreGState(maContextHolder.get());
+ maContextHolder.restoreState();
RefreshRect( aRect );
return true;
@@ -752,8 +747,7 @@ bool AquaSalGraphics::drawEPS( long nX, long nY, long nWidth, long nHeight,
return false;
}
// NOTE: flip drawing, else the nsimage would be drawn upside down
- SAL_INFO( "vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth );
- CGContextSaveGState( maContextHolder.get() );
+ maContextHolder.saveState();
// CGContextTranslateCTM( maContextHolder.get(), 0, +mnHeight );
SAL_INFO( "vcl.cg", "CGContextScaleCTM(" << maContextHolder.get() << ",+1,-1)" );
CGContextScaleCTM( maContextHolder.get(), +1, -1 );
@@ -776,8 +770,7 @@ bool AquaSalGraphics::drawEPS( long nX, long nY, long nWidth, long nHeight,
[NSGraphicsContext setCurrentContext: pOrigNSCtx];
[pOrigNSCtx release]; // restore the original retain count
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth--);
- CGContextRestoreGState( maContextHolder.get() );
+ maContextHolder.restoreState();
// mark the destination rectangle as updated
RefreshRect( aDstRect );
@@ -927,8 +920,7 @@ bool AquaSalGraphics::drawPolyLine(
if( ! ((aRefreshRect.size.width <= 0.125) && (aRefreshRect.size.height <= 0.125)) )
{
// use the path to prepare the graphics context
- SAL_INFO( "vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth );
- CGContextSaveGState( maContextHolder.get() );
+ maContextHolder.saveState();
SAL_INFO( "vcl.cg", "CGContextBeginPath(" << maContextHolder.get() << ")" );
CGContextBeginPath( maContextHolder.get() );
SAL_INFO( "vcl.cg", "CGContextAddPath(" << maContextHolder.get() << "," << xPath << ")" );
@@ -943,8 +935,7 @@ bool AquaSalGraphics::drawPolyLine(
CGContextSetMiterLimit(maContextHolder.get(), fCGMiterLimit);
SAL_INFO( "vcl.cg", "CGContextDrawPath(" << maContextHolder.get() << ",kCGPathStroke)" );
CGContextDrawPath( maContextHolder.get(), kCGPathStroke );
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth-- );
- CGContextRestoreGState( maContextHolder.get() );
+ maContextHolder.restoreState();
// mark modified rectangle as updated
RefreshRect( aRefreshRect );
@@ -1021,8 +1012,7 @@ bool AquaSalGraphics::drawPolyPolygon(
}
// use the path to prepare the graphics context
- SAL_INFO( "vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth );
- CGContextSaveGState( maContextHolder.get() );
+ maContextHolder.saveState();
SAL_INFO( "vcl.cg", "CGContextBeginPath(" << maContextHolder.get() << ")" );
CGContextBeginPath( maContextHolder.get() );
SAL_INFO( "vcl.cg", "CGContextAddPath(" << maContextHolder.get() << "," << xPath << ")" );
@@ -1034,8 +1024,7 @@ bool AquaSalGraphics::drawPolyPolygon(
CGContextSetAlpha( maContextHolder.get(), 1.0 - fTransparency );
SAL_INFO( "vcl.cg", "CGContextDrawPath(" << maContextHolder.get() << "," << eMode << ")" );
CGContextDrawPath( maContextHolder.get(), eMode );
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth-- );
- CGContextRestoreGState( maContextHolder.get() );
+ maContextHolder.restoreState();
// mark modified rectangle as updated
RefreshRect( aRefreshRect );
@@ -1555,9 +1544,7 @@ void AquaSalGraphics::invert( long nX, long nY, long nWidth, long nHeight, SalIn
if ( CheckContext() )
{
CGRect aCGRect = CGRectMake( nX, nY, nWidth, nHeight);
- SAL_INFO( "vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth);
- CGContextSaveGState(maContextHolder.get());
-
+ maContextHolder.saveState();
if ( nFlags & SalInvert::TrackFrame )
{
const CGFloat dashLengths[2] = { 4.0, 4.0 }; // for drawing dashed line
@@ -1584,8 +1571,7 @@ void AquaSalGraphics::invert( long nX, long nY, long nWidth, long nHeight, SalIn
SAL_INFO( "vcl.cg", "CGContextFillRect(" << maContextHolder.get() << "," << aCGRect << ")" );
CGContextFillRect ( maContextHolder.get(), aCGRect );
}
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth-- );
- CGContextRestoreGState( maContextHolder.get());
+ maContextHolder.restoreState();
RefreshRect( aCGRect );
}
}
@@ -1609,8 +1595,7 @@ void AquaSalGraphics::invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalIn
{
if ( CheckContext() )
{
- SAL_INFO( "vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth);
- CGContextSaveGState(maContextHolder.get());
+ maContextHolder.saveState();
CGPoint* CGpoints = makeCGptArray(nPoints,pPtAry);
CGContextAddLines ( maContextHolder.get(), CGpoints, nPoints );
if ( nSalFlags & SalInvert::TrackFrame )
@@ -1638,8 +1623,7 @@ void AquaSalGraphics::invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalIn
CGContextFillPath( maContextHolder.get() );
}
const CGRect aRefreshRect = CGContextGetClipBoundingBox(maContextHolder.get());
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth-- );
- CGContextRestoreGState( maContextHolder.get());
+ maContextHolder.restoreState();
delete [] CGpoints;
RefreshRect( aRefreshRect );
}
@@ -1680,10 +1664,8 @@ void AquaSalGraphics::ResetClipRegion()
void AquaSalGraphics::SetState()
{
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth--);
- CGContextRestoreGState( maContextHolder.get() );
- SAL_INFO( "vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth );
- CGContextSaveGState( maContextHolder.get() );
+ maContextHolder.restoreState();
+ maContextHolder.saveState();
// setup clipping
if( mxClipPath )
@@ -2093,8 +2075,7 @@ void AquaSalGraphics::SetVirDevGraphics( CGLayerRef xLayer, CGContextRef xContex
// We will return early a few lines lower.
// Undo the "stack initialization" done at the initial call of
// this method, see end.
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ") " << mnContextStackDepth--);
- CGContextRestoreGState( maContextHolder.get() );
+ maContextHolder.restoreState();
}
#endif
@@ -2146,8 +2127,7 @@ void AquaSalGraphics::SetVirDevGraphics( CGLayerRef xLayer, CGContextRef xContex
}
// initialize stack of CGContext states
- SAL_INFO( "vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth );
- CGContextSaveGState( maContextHolder.get() );
+ maContextHolder.saveState();
SetState();
}
diff --git a/vcl/quartz/salgdiutils.cxx b/vcl/quartz/salgdiutils.cxx
index 80abba2268de..98213b7c3344 100644
--- a/vcl/quartz/salgdiutils.cxx
+++ b/vcl/quartz/salgdiutils.cxx
@@ -76,8 +76,7 @@ void AquaSalGraphics::UnsetState()
{
if (maContextHolder.isSet())
{
- SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << maContextHolder.get() << ")" );
- CGContextRestoreGState( maContextHolder.get() );
+ maContextHolder.restoreState();
maContextHolder.set(nullptr);
}
if( mxClipPath )
@@ -164,8 +163,7 @@ bool AquaSalGraphics::CheckContext()
CGContextScaleCTM(maContextHolder.get(), 1.0, -1.0);
CGContextSetFillColorSpace(maContextHolder.get(), GetSalData()->mxRGBSpace);
CGContextSetStrokeColorSpace(maContextHolder.get(), GetSalData()->mxRGBSpace);
- SAL_INFO("vcl.cg", "CGContextSaveGState(" << maContextHolder.get() << ") " << ++mnContextStackDepth);
- CGContextSaveGState(maContextHolder.get());
+ maContextHolder.saveState();
SetState();
// re-enable XOR emulation for the new context