Kaydet (Commit) 9e35b5a7 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

handle CG state save/restore in ContextHolder class

Change-Id: I44ee257a8a196e8f2372dd01776c0c7c5193ad0a
Reviewed-on: https://gerrit.libreoffice.org/72436
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 06b46104
......@@ -130,10 +130,16 @@ private:
class CGContextHolder
{
CGContextRef mpContext;
#if OSL_DEBUG_LEVEL > 0
int mnContextStackDepth;
#endif
public:
CGContextHolder()
: mpContext(nullptr)
#if OSL_DEBUG_LEVEL > 0
, mnContextStackDepth( 0 )
#endif
{}
CGContextRef get() const
......@@ -150,6 +156,18 @@ public:
{
mpContext = pContext;
}
void saveState()
{
SAL_INFO("vcl.cg", "CGContextSaveGState(" << mpContext << ") " << ++mnContextStackDepth );
CGContextSaveGState(mpContext);
}
void restoreState()
{
SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << mpContext << ") " << mnContextStackDepth-- );
CGContextRestoreGState(mpContext);
}
};
class AquaSalGraphics : public SalGraphics
......@@ -159,7 +177,6 @@ class AquaSalGraphics : public SalGraphics
#ifdef MACOSX
AquaSalFrame* mpFrame;
#endif
int mnContextStackDepth;
XorEmulation* mpXorEmulation;
int mnXorMode; // 0: off 1: on 2: invert only
int mnWidth;
......
......@@ -303,7 +303,7 @@ bool AquaSalGraphics::drawNativeControl(ControlType nType,
if( ! CheckContext() )
return false;
CGContextSaveGState( maContextHolder.get() );
maContextHolder.saveState();
tools::Rectangle buttonRect = rControlRegion;
HIRect rc = ImplGetHIRectFromRectangle(buttonRect);
......@@ -986,7 +986,7 @@ bool AquaSalGraphics::drawNativeControl(ControlType nType,
default: break;
}
CGContextRestoreGState( maContextHolder.get() );
maContextHolder.restoreState();
/* #i90291# in most cases invalidating the whole control region instead
of just the unclipped part of it is sufficient (and probably faster).
......
......@@ -184,9 +184,6 @@ AquaSalGraphics::AquaSalGraphics()
: mxLayer( nullptr )
#ifdef MACOSX
, mpFrame( nullptr )
#endif
#if OSL_DEBUG_LEVEL > 0
, mnContextStackDepth( 0 )
#endif
, mpXorEmulation( nullptr )
, mnXorMode( 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)
......
......@@ -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();
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment