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

use CGContextHolder in AquaSalBitmap

Change-Id: I87f5a1bc2c41c58cff747bbad82867d53ea92ce7
Reviewed-on: https://gerrit.libreoffice.org/72442
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 0353d0e5
...@@ -39,7 +39,7 @@ class BitmapPalette; ...@@ -39,7 +39,7 @@ class BitmapPalette;
class QuartzSalBitmap : public SalBitmap class QuartzSalBitmap : public SalBitmap
{ {
public: public:
CGContextRef mxGraphicContext; CGContextHolder maGraphicContext;
mutable CGImageRef mxCachedImage; mutable CGImageRef mxCachedImage;
BitmapPalette maPalette; BitmapPalette maPalette;
std::shared_ptr<sal_uInt8> m_pUserBuffer; std::shared_ptr<sal_uInt8> m_pUserBuffer;
......
...@@ -55,8 +55,7 @@ static bool isValidBitCount( sal_uInt16 nBitCount ) ...@@ -55,8 +55,7 @@ static bool isValidBitCount( sal_uInt16 nBitCount )
} }
QuartzSalBitmap::QuartzSalBitmap() QuartzSalBitmap::QuartzSalBitmap()
: mxGraphicContext( nullptr ) : mxCachedImage( nullptr )
, mxCachedImage( nullptr )
, mnBits(0) , mnBits(0)
, mnWidth(0) , mnWidth(0)
, mnHeight(0) , mnHeight(0)
...@@ -105,18 +104,18 @@ bool QuartzSalBitmap::Create(CGLayerHolder const & rLayerHolder, int nBitmapBits ...@@ -105,18 +104,18 @@ bool QuartzSalBitmap::Create(CGLayerHolder const & rLayerHolder, int nBitmapBits
// copy layer content into the bitmap buffer // copy layer content into the bitmap buffer
const CGPoint aSrcPoint = { static_cast<CGFloat>(-nX), static_cast<CGFloat>(-nY) }; 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 ) if( bFlipped )
{ {
SAL_INFO( "vcl.cg", "CGContextTranslateCTM(" << mxGraphicContext << ",0," << mnHeight << ")" ); SAL_INFO( "vcl.cg", "CGContextTranslateCTM(" << maGraphicContext.get() << ",0," << mnHeight << ")" );
CGContextTranslateCTM( mxGraphicContext, 0, +mnHeight ); CGContextTranslateCTM( maGraphicContext.get(), 0, +mnHeight );
SAL_INFO( "vcl.cg", "CGContextScaleCTM(" << mxGraphicContext << ",+1,-1)" ); SAL_INFO( "vcl.cg", "CGContextScaleCTM(" << maGraphicContext.get() << ",+1,-1)" );
CGContextScaleCTM( mxGraphicContext, +1, -1 ); CGContextScaleCTM( maGraphicContext.get(), +1, -1 );
} }
CGContextDrawLayerAtPoint( mxGraphicContext, aSrcPoint, rLayerHolder.get() ); CGContextDrawLayerAtPoint(maGraphicContext.get(), aSrcPoint, rLayerHolder.get());
} }
return true; return true;
} }
...@@ -187,11 +186,11 @@ void QuartzSalBitmap::DestroyContext() ...@@ -187,11 +186,11 @@ void QuartzSalBitmap::DestroyContext()
mxCachedImage = nullptr; mxCachedImage = nullptr;
} }
if( mxGraphicContext ) if (maGraphicContext.isSet())
{ {
SAL_INFO("vcl.cg", "CGContextRelease(" << mxGraphicContext << ")" ); SAL_INFO("vcl.cg", "CGContextRelease(" << maGraphicContext.get() << ")" );
CGContextRelease( mxGraphicContext ); CGContextRelease(maGraphicContext.get());
mxGraphicContext = nullptr; maGraphicContext.set(nullptr);
m_pContextBuffer.reset(); m_pContextBuffer.reset();
} }
} }
...@@ -244,22 +243,22 @@ bool QuartzSalBitmap::CreateContext() ...@@ -244,22 +243,22 @@ bool QuartzSalBitmap::CreateContext()
} }
catch( const std::bad_alloc& ) catch( const std::bad_alloc& )
{ {
mxGraphicContext = nullptr; maGraphicContext.set(nullptr);
} }
} }
if (m_pContextBuffer.get()) if (m_pContextBuffer.get())
{ {
mxGraphicContext = CGBitmapContextCreate( m_pContextBuffer.get(), mnWidth, mnHeight, maGraphicContext.set(CGBitmapContextCreate(m_pContextBuffer.get(), mnWidth, mnHeight,
bitsPerComponent, nContextBytesPerRow, bitsPerComponent, nContextBytesPerRow,
aCGColorSpace, aCGBmpInfo ); aCGColorSpace, aCGBmpInfo));
SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << mnWidth << "x" << mnHeight << "x" << bitsPerComponent << ") = " << mxGraphicContext ); SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << mnWidth << "x" << mnHeight << "x" << bitsPerComponent << ") = " << maGraphicContext.get());
} }
if( !mxGraphicContext ) if (!maGraphicContext.isSet())
m_pContextBuffer.reset(); m_pContextBuffer.reset();
return mxGraphicContext != nullptr; return maGraphicContext.isSet();
} }
bool QuartzSalBitmap::AllocateUserData() bool QuartzSalBitmap::AllocateUserData()
...@@ -783,7 +782,7 @@ void QuartzSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMo ...@@ -783,7 +782,7 @@ void QuartzSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMo
if( nMode == BitmapAccessMode::Write ) if( nMode == BitmapAccessMode::Write )
{ {
maPalette = pBuffer->maPalette; maPalette = pBuffer->maPalette;
if( mxGraphicContext ) if (maGraphicContext.isSet())
{ {
DestroyContext(); DestroyContext();
} }
...@@ -797,15 +796,15 @@ CGImageRef QuartzSalBitmap::CreateCroppedImage( int nX, int nY, int nNewWidth, i ...@@ -797,15 +796,15 @@ CGImageRef QuartzSalBitmap::CreateCroppedImage( int nX, int nY, int nNewWidth, i
{ {
if( !mxCachedImage ) if( !mxCachedImage )
{ {
if( !mxGraphicContext ) if (!maGraphicContext.isSet())
{ {
if( !const_cast<QuartzSalBitmap*>(this)->CreateContext() ) if( !const_cast<QuartzSalBitmap*>(this)->CreateContext() )
{ {
return nullptr; return nullptr;
} }
} }
mxCachedImage = CGBitmapContextCreateImage( mxGraphicContext ); mxCachedImage = CGBitmapContextCreateImage(maGraphicContext.get());
SAL_INFO("vcl.cg", "CGBitmapContextCreateImage(" << mxGraphicContext << ") = " << mxCachedImage ); SAL_INFO("vcl.cg", "CGBitmapContextCreateImage(" << maGraphicContext.get() << ") = " << mxCachedImage );
} }
CGImageRef xCroppedImage = nullptr; CGImageRef xCroppedImage = nullptr;
...@@ -942,15 +941,15 @@ bool QuartzSalBitmap::GetSystemData( BitmapSystemData& rData ) ...@@ -942,15 +941,15 @@ bool QuartzSalBitmap::GetSystemData( BitmapSystemData& rData )
{ {
bool bRet = false; bool bRet = false;
if( !mxGraphicContext ) if (!maGraphicContext.isSet())
CreateContext(); CreateContext();
if ( mxGraphicContext ) if (maGraphicContext.isSet())
{ {
bRet = true; bRet = true;
if ((CGBitmapContextGetBitsPerPixel(mxGraphicContext) == 32) && if ((CGBitmapContextGetBitsPerPixel(maGraphicContext.get()) == 32) &&
(CGBitmapContextGetBitmapInfo(mxGraphicContext) & kCGBitmapByteOrderMask) != kCGBitmapByteOrder32Host) (CGBitmapContextGetBitmapInfo(maGraphicContext.get()) & kCGBitmapByteOrderMask) != kCGBitmapByteOrder32Host)
{ {
/** /**
* We need to hack things because VCL does not use kCGBitmapByteOrder32Host, while Cairo requires it. * We need to hack things because VCL does not use kCGBitmapByteOrder32Host, while Cairo requires it.
...@@ -962,40 +961,42 @@ bool QuartzSalBitmap::GetSystemData( BitmapSystemData& rData ) ...@@ -962,40 +961,42 @@ bool QuartzSalBitmap::GetSystemData( BitmapSystemData& rData )
*/ */
SAL_INFO("vcl.cg", "QuartzSalBitmap::" << __func__ << "(): kCGBitmapByteOrder32Host not found => inserting it."); SAL_INFO("vcl.cg", "QuartzSalBitmap::" << __func__ << "(): kCGBitmapByteOrder32Host not found => inserting it.");
CGImageRef xImage = CGBitmapContextCreateImage (mxGraphicContext); CGImageRef xImage = CGBitmapContextCreateImage(maGraphicContext.get());
SAL_INFO("vcl.cg", "CGBitmapContextCreateImage(" << mxGraphicContext << ") = " << xImage ); SAL_INFO("vcl.cg", "CGBitmapContextCreateImage(" << maGraphicContext.get() << ") = " << xImage );
// re-create the context with single change: include kCGBitmapByteOrder32Host flag. // re-create the context with single change: include kCGBitmapByteOrder32Host flag.
CGContextRef mxGraphicContextNew = CGBitmapContextCreate( CGBitmapContextGetData(mxGraphicContext), CGContextHolder maGraphicContextNew(CGBitmapContextCreate(CGBitmapContextGetData(maGraphicContext.get()),
CGBitmapContextGetWidth(mxGraphicContext), CGBitmapContextGetWidth(maGraphicContext.get()),
CGBitmapContextGetHeight(mxGraphicContext), CGBitmapContextGetHeight(maGraphicContext.get()),
CGBitmapContextGetBitsPerComponent(mxGraphicContext), CGBitmapContextGetBitsPerComponent(maGraphicContext.get()),
CGBitmapContextGetBytesPerRow(mxGraphicContext), CGBitmapContextGetBytesPerRow(maGraphicContext.get()),
CGBitmapContextGetColorSpace(mxGraphicContext), CGBitmapContextGetColorSpace(maGraphicContext.get()),
CGBitmapContextGetBitmapInfo(mxGraphicContext) | kCGBitmapByteOrder32Host); CGBitmapContextGetBitmapInfo(maGraphicContext.get()) | kCGBitmapByteOrder32Host));
SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << CGBitmapContextGetWidth(mxGraphicContext) << "x" << CGBitmapContextGetHeight(mxGraphicContext) << "x" << CGBitmapContextGetBitsPerComponent(mxGraphicContext) << ") = " << mxGraphicContextNew ); SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << CGBitmapContextGetWidth(maGraphicContext.get()) << "x"
<< CGBitmapContextGetHeight(maGraphicContext.get()) << "x"
SAL_INFO("vcl.cg", "CFRelease(" << mxGraphicContext << ")" ); << CGBitmapContextGetBitsPerComponent(maGraphicContext.get()) << ") = "
CFRelease(mxGraphicContext); << maGraphicContextNew.get());
SAL_INFO("vcl.cg", "CFRelease(" << maGraphicContext.get() << ")");
CFRelease(maGraphicContext.get());
// Needs to be flipped // Needs to be flipped
SAL_INFO("vcl.cg", "CGContextSaveGState(" << mxGraphicContextNew << ")" ); maGraphicContextNew.saveState();
CGContextSaveGState( mxGraphicContextNew ); SAL_INFO("vcl.cg", "CGContextTranslateCTM(" << maGraphicContextNew.get() << ",0," << CGBitmapContextGetHeight(maGraphicContextNew.get()) << ")" );
SAL_INFO("vcl.cg", "CGContextTranslateCTM(" << mxGraphicContextNew << ",0," << CGBitmapContextGetHeight(mxGraphicContextNew) << ")" ); CGContextTranslateCTM (maGraphicContextNew.get(), 0, CGBitmapContextGetHeight(maGraphicContextNew.get()));
CGContextTranslateCTM (mxGraphicContextNew, 0, CGBitmapContextGetHeight(mxGraphicContextNew)); SAL_INFO("vcl.cg", "CGContextScaleCTM(" << maGraphicContextNew.get() << ",1,-1)" );
SAL_INFO("vcl.cg", "CGContextScaleCTM(" << mxGraphicContextNew << ",1,-1)" ); CGContextScaleCTM (maGraphicContextNew.get(), 1.0, -1.0);
CGContextScaleCTM (mxGraphicContextNew, 1.0, -1.0);
SAL_INFO("vcl.cg", "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(mxGraphicContextNew, CGRectMake( 0, 0, CGImageGetWidth(xImage), CGImageGetHeight(xImage)), xImage); CGContextDrawImage(maGraphicContextNew.get(), CGRectMake( 0, 0, CGImageGetWidth(xImage), CGImageGetHeight(xImage)), xImage);
// Flip back // Flip back
SAL_INFO("vcl.cg", "CGContextRestoreGState(" << mxGraphicContextNew << ")" ); SAL_INFO("vcl.cg", "CGContextRestoreGState(" << maGraphicContextNew.get() << ")" );
CGContextRestoreGState( mxGraphicContextNew ); CGContextRestoreGState( maGraphicContextNew.get() );
SAL_INFO("vcl.cg", "CGImageRelease(" << xImage << ")" ); SAL_INFO("vcl.cg", "CGImageRelease(" << xImage << ")" );
CGImageRelease( xImage ); CGImageRelease( xImage );
mxGraphicContext = mxGraphicContextNew; maGraphicContext = maGraphicContextNew;
} }
rData.mnWidth = mnWidth; rData.mnWidth = mnWidth;
......
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