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

use CGContextHolder in AquaVirtualDevice

Change-Id: If5e27ea4049a76e560dd9823f335b86e2599d4cc
Reviewed-on: https://gerrit.libreoffice.org/72440
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst ca2aa307
......@@ -39,7 +39,7 @@ class AquaSalVirtualDevice : public SalVirtualDevice
private:
bool mbGraphicsUsed; // is Graphics used
bool mbForeignContext; // is mxContext from outside VCL
CGContextRef mxBitmapContext;
CGContextHolder maBitmapContext;
int mnBitmapDepth;
CGLayerHolder maLayer; // Quartz layer
AquaSalGraphics* mpGraphics; // current VirDev graphics
......
......@@ -65,7 +65,6 @@ std::unique_ptr<SalVirtualDevice> AquaSalInstance::CreateVirtualDevice( SalGraph
AquaSalVirtualDevice::AquaSalVirtualDevice( AquaSalGraphics* pGraphic, long &nDX, long &nDY,
DeviceFormat eFormat, const SystemGraphicsData *pData )
: mbGraphicsUsed( false )
, mxBitmapContext( nullptr )
, mnBitmapDepth( 0 )
, mnWidth(0)
, mnHeight(0)
......@@ -180,13 +179,13 @@ void AquaSalVirtualDevice::Destroy()
maLayer.set(nullptr);
}
if( mxBitmapContext )
if (maBitmapContext.isSet())
{
void* pRawData = CGBitmapContextGetData( mxBitmapContext );
std::free( pRawData );
SAL_INFO( "vcl.cg", "CGContextRelease(" << mxBitmapContext << ")" );
CGContextRelease( mxBitmapContext );
mxBitmapContext = nullptr;
void* pRawData = CGBitmapContextGetData(maBitmapContext.get());
std::free(pRawData);
SAL_INFO( "vcl.cg", "CGContextRelease(" << maBitmapContext.get() << ")" );
CGContextRelease(maBitmapContext.get());
maBitmapContext.set(nullptr);
}
}
......@@ -233,18 +232,18 @@ bool AquaSalVirtualDevice::SetSize( long nDX, long nDY )
mnHeight = nDY;
// create a Quartz layer matching to the intended virdev usage
CGContextRef xCGContext = nullptr;
CGContextHolder xCGContextHolder;
if( mnBitmapDepth && (mnBitmapDepth < 16) )
{
mnBitmapDepth = 8; // TODO: are 1bit vdevs worth it?
const int nBytesPerRow = (mnBitmapDepth * nDX + 7) / 8;
void* pRawData = std::malloc( nBytesPerRow * nDY );
mxBitmapContext = CGBitmapContextCreate( pRawData, nDX, nDY,
maBitmapContext.set(CGBitmapContextCreate( pRawData, nDX, nDY,
mnBitmapDepth, nBytesPerRow,
GetSalData()->mxGraySpace, kCGImageAlphaNone );
SAL_INFO( "vcl.cg", "CGBitmapContextCreate(" << nDX << "x" << nDY << "x" << mnBitmapDepth << ") = " << mxBitmapContext );
xCGContext = mxBitmapContext;
GetSalData()->mxGraySpace, kCGImageAlphaNone));
SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << nDX << "x" << nDY << "x" << mnBitmapDepth << ") = " << maBitmapContext.get());
xCGContextHolder = maBitmapContext;
}
else
{
......@@ -267,13 +266,13 @@ bool AquaSalVirtualDevice::SetSize( long nDX, long nDY )
NSGraphicsContext* pNSContext = [NSGraphicsContext graphicsContextWithWindow: pNSWindow];
if( pNSContext )
{
xCGContext = [pNSContext CGContext];
xCGContextHolder.set([pNSContext CGContext]);
}
}
}
#endif
if (!xCGContext)
if (!xCGContextHolder.isSet())
{
// assert(Application::IsBitmapRendering());
mnBitmapDepth = 32;
......@@ -285,18 +284,18 @@ bool AquaSalVirtualDevice::SetSize( long nDX, long nDY )
#else
const int nFlags = kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little;
#endif
mxBitmapContext = CGBitmapContextCreate(pRawData, nDX, nDY, 8, nBytesPerRow,
GetSalData()->mxRGBSpace, nFlags);
SAL_INFO( "vcl.cg", "CGBitmapContextCreate(" << nDX << "x" << nDY << "x32) = " << mxBitmapContext );
xCGContext = mxBitmapContext;
maBitmapContext.set(CGBitmapContextCreate(pRawData, nDX, nDY, 8, nBytesPerRow,
GetSalData()->mxRGBSpace, nFlags));
SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << nDX << "x" << nDY << "x32) = " << maBitmapContext.get());
xCGContextHolder = maBitmapContext;
}
}
SAL_WARN_IF( !xCGContext, "vcl.quartz", "No context" );
SAL_WARN_IF(!xCGContextHolder.isSet(), "vcl.quartz", "No context");
const CGSize aNewSize = { static_cast<CGFloat>(nDX), static_cast<CGFloat>(nDY) };
maLayer.set(CGLayerCreateWithContext(xCGContext, aNewSize, nullptr));
SAL_INFO("vcl.cg", "CGLayerCreateWithContext(" << xCGContext << "," << aNewSize << ",NULL) = " << maLayer.get());
maLayer.set(CGLayerCreateWithContext(xCGContextHolder.get(), aNewSize, nullptr));
SAL_INFO("vcl.cg", "CGLayerCreateWithContext(" << xCGContextHolder.get() << "," << aNewSize << ",NULL) = " << maLayer.get());
if (maLayer.isSet() && mpGraphics)
{
......
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