vcl/inc/quartz/salbmp.h | 2 vcl/quartz/salbmp.cxx | 105 ++++++++++++++++++++++---------------------- vcl/quartz/salgdicommon.cxx | 26 +++++----- 3 files changed, 66 insertions(+), 67 deletions(-)
New commits: commit e9ebb8c1f12812bcb0459092984e5aad1e955c8e Author: Tomaž Vajngerl <[email protected]> AuthorDate: Fri May 17 12:03:04 2019 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Sat May 18 09:00:15 2019 +0200 use CGContextHolder in AquaSalBitmap Change-Id: I87f5a1bc2c41c58cff747bbad82867d53ea92ce7 Reviewed-on: https://gerrit.libreoffice.org/72442 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/vcl/inc/quartz/salbmp.h b/vcl/inc/quartz/salbmp.h index cd9cfb43a549..cb4151f73d28 100644 --- a/vcl/inc/quartz/salbmp.h +++ b/vcl/inc/quartz/salbmp.h @@ -39,7 +39,7 @@ class BitmapPalette; class QuartzSalBitmap : public SalBitmap { public: - CGContextRef mxGraphicContext; + CGContextHolder maGraphicContext; mutable CGImageRef mxCachedImage; BitmapPalette maPalette; std::shared_ptr<sal_uInt8> m_pUserBuffer; diff --git a/vcl/quartz/salbmp.cxx b/vcl/quartz/salbmp.cxx index 745b57bd82a9..dce5b06ff1f8 100644 --- a/vcl/quartz/salbmp.cxx +++ b/vcl/quartz/salbmp.cxx @@ -55,8 +55,7 @@ static bool isValidBitCount( sal_uInt16 nBitCount ) } QuartzSalBitmap::QuartzSalBitmap() - : mxGraphicContext( nullptr ) - , mxCachedImage( nullptr ) + : mxCachedImage( nullptr ) , mnBits(0) , mnWidth(0) , mnHeight(0) @@ -105,18 +104,18 @@ bool QuartzSalBitmap::Create(CGLayerHolder const & rLayerHolder, int nBitmapBits // copy layer content into the bitmap buffer const CGPoint aSrcPoint = { static_cast<CGFloat>(-nX), static_cast<CGFloat>(-nY) }; - if(mxGraphicContext) // remove warning + if (maGraphicContext.isSet()) // remove warning { - SAL_INFO("vcl.cg", "CGContextDrawLayerAtPoint(" << mxGraphicContext << "," << aSrcPoint << "," << rLayerHolder.get() << ")" ); + SAL_INFO("vcl.cg", "CGContextDrawLayerAtPoint(" << maGraphicContext.get() << "," << aSrcPoint << "," << rLayerHolder.get() << ")"); if( bFlipped ) { - SAL_INFO( "vcl.cg", "CGContextTranslateCTM(" << mxGraphicContext << ",0," << mnHeight << ")" ); - CGContextTranslateCTM( mxGraphicContext, 0, +mnHeight ); - SAL_INFO( "vcl.cg", "CGContextScaleCTM(" << mxGraphicContext << ",+1,-1)" ); - CGContextScaleCTM( mxGraphicContext, +1, -1 ); + SAL_INFO( "vcl.cg", "CGContextTranslateCTM(" << maGraphicContext.get() << ",0," << mnHeight << ")" ); + CGContextTranslateCTM( maGraphicContext.get(), 0, +mnHeight ); + SAL_INFO( "vcl.cg", "CGContextScaleCTM(" << maGraphicContext.get() << ",+1,-1)" ); + CGContextScaleCTM( maGraphicContext.get(), +1, -1 ); } - CGContextDrawLayerAtPoint( mxGraphicContext, aSrcPoint, rLayerHolder.get() ); + CGContextDrawLayerAtPoint(maGraphicContext.get(), aSrcPoint, rLayerHolder.get()); } return true; } @@ -187,11 +186,11 @@ void QuartzSalBitmap::DestroyContext() mxCachedImage = nullptr; } - if( mxGraphicContext ) + if (maGraphicContext.isSet()) { - SAL_INFO("vcl.cg", "CGContextRelease(" << mxGraphicContext << ")" ); - CGContextRelease( mxGraphicContext ); - mxGraphicContext = nullptr; + SAL_INFO("vcl.cg", "CGContextRelease(" << maGraphicContext.get() << ")" ); + CGContextRelease(maGraphicContext.get()); + maGraphicContext.set(nullptr); m_pContextBuffer.reset(); } } @@ -244,22 +243,22 @@ bool QuartzSalBitmap::CreateContext() } catch( const std::bad_alloc& ) { - mxGraphicContext = nullptr; + maGraphicContext.set(nullptr); } } if (m_pContextBuffer.get()) { - mxGraphicContext = CGBitmapContextCreate( m_pContextBuffer.get(), mnWidth, mnHeight, - bitsPerComponent, nContextBytesPerRow, - aCGColorSpace, aCGBmpInfo ); - SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << mnWidth << "x" << mnHeight << "x" << bitsPerComponent << ") = " << mxGraphicContext ); + maGraphicContext.set(CGBitmapContextCreate(m_pContextBuffer.get(), mnWidth, mnHeight, + bitsPerComponent, nContextBytesPerRow, + aCGColorSpace, aCGBmpInfo)); + SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << mnWidth << "x" << mnHeight << "x" << bitsPerComponent << ") = " << maGraphicContext.get()); } - if( !mxGraphicContext ) + if (!maGraphicContext.isSet()) m_pContextBuffer.reset(); - return mxGraphicContext != nullptr; + return maGraphicContext.isSet(); } bool QuartzSalBitmap::AllocateUserData() @@ -783,7 +782,7 @@ void QuartzSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMo if( nMode == BitmapAccessMode::Write ) { maPalette = pBuffer->maPalette; - if( mxGraphicContext ) + if (maGraphicContext.isSet()) { DestroyContext(); } @@ -797,15 +796,15 @@ CGImageRef QuartzSalBitmap::CreateCroppedImage( int nX, int nY, int nNewWidth, i { if( !mxCachedImage ) { - if( !mxGraphicContext ) + if (!maGraphicContext.isSet()) { if( !const_cast<QuartzSalBitmap*>(this)->CreateContext() ) { return nullptr; } } - mxCachedImage = CGBitmapContextCreateImage( mxGraphicContext ); - SAL_INFO("vcl.cg", "CGBitmapContextCreateImage(" << mxGraphicContext << ") = " << mxCachedImage ); + mxCachedImage = CGBitmapContextCreateImage(maGraphicContext.get()); + SAL_INFO("vcl.cg", "CGBitmapContextCreateImage(" << maGraphicContext.get() << ") = " << mxCachedImage ); } CGImageRef xCroppedImage = nullptr; @@ -942,15 +941,15 @@ bool QuartzSalBitmap::GetSystemData( BitmapSystemData& rData ) { bool bRet = false; - if( !mxGraphicContext ) + if (!maGraphicContext.isSet()) CreateContext(); - if ( mxGraphicContext ) + if (maGraphicContext.isSet()) { bRet = true; - if ((CGBitmapContextGetBitsPerPixel(mxGraphicContext) == 32) && - (CGBitmapContextGetBitmapInfo(mxGraphicContext) & kCGBitmapByteOrderMask) != kCGBitmapByteOrder32Host) + if ((CGBitmapContextGetBitsPerPixel(maGraphicContext.get()) == 32) && + (CGBitmapContextGetBitmapInfo(maGraphicContext.get()) & kCGBitmapByteOrderMask) != kCGBitmapByteOrder32Host) { /** * We need to hack things because VCL does not use kCGBitmapByteOrder32Host, while Cairo requires it. @@ -962,40 +961,42 @@ bool QuartzSalBitmap::GetSystemData( BitmapSystemData& rData ) */ SAL_INFO("vcl.cg", "QuartzSalBitmap::" << __func__ << "(): kCGBitmapByteOrder32Host not found => inserting it."); - CGImageRef xImage = CGBitmapContextCreateImage (mxGraphicContext); - SAL_INFO("vcl.cg", "CGBitmapContextCreateImage(" << mxGraphicContext << ") = " << xImage ); + CGImageRef xImage = CGBitmapContextCreateImage(maGraphicContext.get()); + SAL_INFO("vcl.cg", "CGBitmapContextCreateImage(" << maGraphicContext.get() << ") = " << xImage ); // re-create the context with single change: include kCGBitmapByteOrder32Host flag. - CGContextRef mxGraphicContextNew = CGBitmapContextCreate( CGBitmapContextGetData(mxGraphicContext), - CGBitmapContextGetWidth(mxGraphicContext), - CGBitmapContextGetHeight(mxGraphicContext), - CGBitmapContextGetBitsPerComponent(mxGraphicContext), - CGBitmapContextGetBytesPerRow(mxGraphicContext), - CGBitmapContextGetColorSpace(mxGraphicContext), - CGBitmapContextGetBitmapInfo(mxGraphicContext) | kCGBitmapByteOrder32Host); - SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << CGBitmapContextGetWidth(mxGraphicContext) << "x" << CGBitmapContextGetHeight(mxGraphicContext) << "x" << CGBitmapContextGetBitsPerComponent(mxGraphicContext) << ") = " << mxGraphicContextNew ); - - SAL_INFO("vcl.cg", "CFRelease(" << mxGraphicContext << ")" ); - CFRelease(mxGraphicContext); + CGContextHolder maGraphicContextNew(CGBitmapContextCreate(CGBitmapContextGetData(maGraphicContext.get()), + CGBitmapContextGetWidth(maGraphicContext.get()), + CGBitmapContextGetHeight(maGraphicContext.get()), + CGBitmapContextGetBitsPerComponent(maGraphicContext.get()), + CGBitmapContextGetBytesPerRow(maGraphicContext.get()), + CGBitmapContextGetColorSpace(maGraphicContext.get()), + CGBitmapContextGetBitmapInfo(maGraphicContext.get()) | kCGBitmapByteOrder32Host)); + SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << CGBitmapContextGetWidth(maGraphicContext.get()) << "x" + << CGBitmapContextGetHeight(maGraphicContext.get()) << "x" + << CGBitmapContextGetBitsPerComponent(maGraphicContext.get()) << ") = " + << maGraphicContextNew.get()); + + SAL_INFO("vcl.cg", "CFRelease(" << maGraphicContext.get() << ")"); + CFRelease(maGraphicContext.get()); // Needs to be flipped - SAL_INFO("vcl.cg", "CGContextSaveGState(" << mxGraphicContextNew << ")" ); - CGContextSaveGState( mxGraphicContextNew ); - SAL_INFO("vcl.cg", "CGContextTranslateCTM(" << mxGraphicContextNew << ",0," << CGBitmapContextGetHeight(mxGraphicContextNew) << ")" ); - CGContextTranslateCTM (mxGraphicContextNew, 0, CGBitmapContextGetHeight(mxGraphicContextNew)); - SAL_INFO("vcl.cg", "CGContextScaleCTM(" << mxGraphicContextNew << ",1,-1)" ); - CGContextScaleCTM (mxGraphicContextNew, 1.0, -1.0); + maGraphicContextNew.saveState(); + SAL_INFO("vcl.cg", "CGContextTranslateCTM(" << maGraphicContextNew.get() << ",0," << CGBitmapContextGetHeight(maGraphicContextNew.get()) << ")" ); + CGContextTranslateCTM (maGraphicContextNew.get(), 0, CGBitmapContextGetHeight(maGraphicContextNew.get())); + SAL_INFO("vcl.cg", "CGContextScaleCTM(" << maGraphicContextNew.get() << ",1,-1)" ); + CGContextScaleCTM (maGraphicContextNew.get(), 1.0, -1.0); - SAL_INFO("vcl.cg", "CGContextDrawImage(" << mxGraphicContextNew << "," << CGRectMake(0, 0, CGImageGetWidth(xImage), CGImageGetHeight(xImage)) << "," << xImage << ")" ); - CGContextDrawImage(mxGraphicContextNew, CGRectMake( 0, 0, CGImageGetWidth(xImage), CGImageGetHeight(xImage)), xImage); + SAL_INFO("vcl.cg", "CGContextDrawImage(" << maGraphicContextNew.get() << "," << CGRectMake(0, 0, CGImageGetWidth(xImage), CGImageGetHeight(xImage)) << "," << xImage << ")" ); + CGContextDrawImage(maGraphicContextNew.get(), CGRectMake( 0, 0, CGImageGetWidth(xImage), CGImageGetHeight(xImage)), xImage); // Flip back - SAL_INFO("vcl.cg", "CGContextRestoreGState(" << mxGraphicContextNew << ")" ); - CGContextRestoreGState( mxGraphicContextNew ); + SAL_INFO("vcl.cg", "CGContextRestoreGState(" << maGraphicContextNew.get() << ")" ); + CGContextRestoreGState( maGraphicContextNew.get() ); SAL_INFO("vcl.cg", "CGImageRelease(" << xImage << ")" ); CGImageRelease( xImage ); - mxGraphicContext = mxGraphicContextNew; + maGraphicContext = maGraphicContextNew; } rData.mnWidth = mnWidth; commit 0353d0e5cdfd2847f1d30c629ce19aa202e43c40 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Thu May 16 21:18:58 2019 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Sat May 18 09:00:06 2019 +0200 use CGContextHolder in copyBits Change-Id: I98f1723da170712e2f2c2a846e02954381376c7e Reviewed-on: https://gerrit.libreoffice.org/72441 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/vcl/quartz/salgdicommon.cxx b/vcl/quartz/salgdicommon.cxx index 11fc42fc6cfc..dd35917cd949 100644 --- a/vcl/quartz/salgdicommon.cxx +++ b/vcl/quartz/salgdicommon.cxx @@ -358,37 +358,35 @@ void AquaSalGraphics::copyBits( const SalTwoRect& rPosAry, SalGraphics *pSrcGrap { // in XOR mode the drawing context is redirected to the XOR mask // if source and target are identical then copyBits() paints onto the target context though - CGContextRef xCopyContext = maContextHolder.get(); + CGContextHolder aCopyContext = maContextHolder; if( mpXorEmulation && mpXorEmulation->IsEnabled() ) { if( pSrcGraphics == this ) { - xCopyContext = mpXorEmulation->GetTargetContext(); + aCopyContext.set(mpXorEmulation->GetTargetContext()); } } - SAL_INFO( "vcl.cg", "CGContextSaveGState(" << xCopyContext << ")" ); - CGContextSaveGState( xCopyContext ); + aCopyContext.saveState(); const CGRect aDstRect = CGRectMake(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight); - SAL_INFO( "vcl.cg", "CGContextClipToRect(" << xCopyContext << "," << aDstRect << ")" ); - CGContextClipToRect( xCopyContext, aDstRect ); + SAL_INFO( "vcl.cg", "CGContextClipToRect(" << aCopyContext.get() << "," << aDstRect << ")" ); + CGContextClipToRect(aCopyContext.get(), aDstRect); // draw at new destination // NOTE: flipped drawing gets disabled for this, else the subimage would be drawn upside down if( pSrc->IsFlipped() ) { - SAL_INFO( "vcl.cg", "CGContextTranslateCTM(" << xCopyContext << ",0," << mnHeight << ")" ); - CGContextTranslateCTM( xCopyContext, 0, +mnHeight ); - SAL_INFO( "vcl.cg", "CGContextScaleCTM(" << xCopyContext << ",+1,-1)" ); - CGContextScaleCTM( xCopyContext, +1, -1 ); + SAL_INFO( "vcl.cg", "CGContextTranslateCTM(" << aCopyContext.get() << ",0," << mnHeight << ")" ); + CGContextTranslateCTM( aCopyContext.get(), 0, +mnHeight ); + SAL_INFO( "vcl.cg", "CGContextScaleCTM(" << aCopyContext.get() << ",+1,-1)" ); + CGContextScaleCTM( aCopyContext.get(), +1, -1 ); } // TODO: pSrc->size() != this->size() - SAL_INFO( "vcl.cg", "CGContextDrawLayerAtPoint(" << xCopyContext << "," << aDstPoint << "," << pSrc->maLayer.get() << ")"); - CGContextDrawLayerAtPoint(xCopyContext, aDstPoint, pSrc->maLayer.get()); + SAL_INFO("vcl.cg", "CGContextDrawLayerAtPoint(" << aCopyContext.get() << "," << aDstPoint << "," << pSrc->maLayer.get() << ")"); + CGContextDrawLayerAtPoint(aCopyContext.get(), aDstPoint, pSrc->maLayer.get()); - SAL_INFO( "vcl.cg", "CGContextRestoreGState(" << xCopyContext << ")" ); - CGContextRestoreGState( xCopyContext ); + aCopyContext.restoreState(); // mark the destination rectangle as updated RefreshRect( aDstRect ); } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
