From e474c95cdec503bc2abb90619a7a3677d2942a63 Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Mon, 28 Apr 2014 00:10:47 +1000 Subject: VCL: Renamed two functions Renamed functions: + supportsOperation -> SupportsOperation For consistency + DrawAlphaBitmap -> DrawDeviceAlphaBitmap I want to make it more clear that these are the functions that call on mpGraphics to actually draw on the graphics device Change-Id: Ic4951bfcc0ac0c09fe5b6908dfdf1f699a634265 --- vcl/source/outdev/bitmap.cxx | 362 +++++++++++++++++++++---------------------- vcl/source/outdev/outdev.cxx | 2 +- 2 files changed, 181 insertions(+), 183 deletions(-) (limited to 'vcl') diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx index 2809f0c6a079..46d58da33356 100644 --- a/vcl/source/outdev/bitmap.cxx +++ b/vcl/source/outdev/bitmap.cxx @@ -486,8 +486,6 @@ BitmapEx OutputDevice::GetBitmapEx( const Point& rSrcPt, const Size& rSize ) con return GetBitmap( rSrcPt, rSize ); } - - void OutputDevice::DrawDeviceBitmap( const Point& rDestPt, const Size& rDestSize, const Point& rSrcPtPixel, const Size& rSrcSizePixel, BitmapEx& rBmpEx ) @@ -512,7 +510,7 @@ void OutputDevice::DrawDeviceBitmap( const Point& rDestPt, const Size& rDestSize aSrcPtPixel.X() = rSrcPtPixel.X() * fScaleX; aSrcPtPixel.Y() = rSrcPtPixel.Y() * fScaleY; } - DrawAlphaBitmap(aScaledBitmapEx.GetBitmap(), aScaledBitmapEx.GetAlpha(), rDestPt, rDestSize, aSrcPtPixel, aSrcSizePixel); + DrawDeviceAlphaBitmap(aScaledBitmapEx.GetBitmap(), aScaledBitmapEx.GetAlpha(), rDestPt, rDestSize, aSrcPtPixel, aSrcSizePixel); return; } @@ -653,6 +651,184 @@ void OutputDevice::DrawDeviceBitmap( const Point& rDestPt, const Size& rDestSize } } +void OutputDevice::DrawDeviceAlphaBitmap( const Bitmap& rBmp, const AlphaMask& rAlpha, + const Point& rDestPt, const Size& rDestSize, + const Point& rSrcPtPixel, const Size& rSrcSizePixel ) +{ + Point aOutPt( LogicToPixel( rDestPt ) ); + Size aOutSz( LogicToPixel( rDestSize ) ); + Rectangle aDstRect( Point(), GetOutputSizePixel() ); + const bool bHMirr = aOutSz.Width() < 0; + const bool bVMirr = aOutSz.Height() < 0; + + ClipToPaintRegion(aDstRect); + + if( bHMirr ) + { + aOutSz.Width() = -aOutSz.Width(); + aOutPt.X() -= ( aOutSz.Width() - 1L ); + } + + if( bVMirr ) + { + aOutSz.Height() = -aOutSz.Height(); + aOutPt.Y() -= ( aOutSz.Height() - 1L ); + } + + if( !aDstRect.Intersection( Rectangle( aOutPt, aOutSz ) ).IsEmpty() ) + { + bool bNativeAlpha = false; + static const char* pDisableNative = getenv( "SAL_DISABLE_NATIVE_ALPHA"); + // #i83087# Naturally, system alpha blending cannot work with + // separate alpha VDev + bool bTryDirectPaint(!mpAlphaVDev && !pDisableNative && !bHMirr && !bVMirr); + +#ifdef WNT + if(bTryDirectPaint) + { + // only paint direct when no scaling and no MapMode, else the + // more expensive conversions may be done for short-time Bitmap/BitmapEx + // used for buffering only + if(!IsMapMode() && rSrcSizePixel.Width() == aOutSz.Width() && rSrcSizePixel.Height() == aOutSz.Height()) + { + bTryDirectPaint = false; + } + } +#endif + + if(bTryDirectPaint) + { + Point aRelPt = aOutPt + Point( mnOutOffX, mnOutOffY ); + SalTwoRect aTR = { + rSrcPtPixel.X(), rSrcPtPixel.Y(), + rSrcSizePixel.Width(), rSrcSizePixel.Height(), + aRelPt.X(), aRelPt.Y(), + aOutSz.Width(), aOutSz.Height() + }; + SalBitmap* pSalSrcBmp = rBmp.ImplGetImpBitmap()->ImplGetSalBitmap(); + SalBitmap* pSalAlphaBmp = rAlpha.ImplGetImpBitmap()->ImplGetSalBitmap(); + bNativeAlpha = mpGraphics->DrawAlphaBitmap( aTR, *pSalSrcBmp, *pSalAlphaBmp, this ); + } + + VirtualDevice* pOldVDev = mpAlphaVDev; + + Rectangle aBmpRect( Point(), rBmp.GetSizePixel() ); + if( !bNativeAlpha + && !aBmpRect.Intersection( Rectangle( rSrcPtPixel, rSrcSizePixel ) ).IsEmpty() ) + { + // The scaling in this code path produces really ugly results - it + // does the most trivial scaling with no smoothing. + + GDIMetaFile* pOldMetaFile = mpMetaFile; + const bool bOldMap = mbMap; + mpMetaFile = NULL; // fdo#55044 reset before GetBitmap! + mbMap = false; + Bitmap aBmp( GetBitmap( aDstRect.TopLeft(), aDstRect.GetSize() ) ); + + // #109044# The generated bitmap need not necessarily be + // of aDstRect dimensions, it's internally clipped to + // window bounds. Thus, we correct the dest size here, + // since we later use it (in nDstWidth/Height) for pixel + // access) + // #i38887# reading from screen may sometimes fail + if( aBmp.ImplGetImpBitmap() ) + aDstRect.SetSize( aBmp.GetSizePixel() ); + + BitmapColor aDstCol; + const long nSrcWidth = aBmpRect.GetWidth(), nSrcHeight = aBmpRect.GetHeight(); + const long nDstWidth = aDstRect.GetWidth(), nDstHeight = aDstRect.GetHeight(); + const long nOutWidth = aOutSz.Width(), nOutHeight = aOutSz.Height(); + // calculate offset in original bitmap + // in RTL case this is a little more complicated since the contents of the + // bitmap is not mirrored (it never is), however the paint region and bmp region + // are in mirrored coordinates, so the intersection of (aOutPt,aOutSz) with these + // is content wise somewhere else and needs to take mirroring into account + const long nOffX = IsRTLEnabled() + ? aOutSz.Width() - aDstRect.GetWidth() - (aDstRect.Left() - aOutPt.X()) + : aDstRect.Left() - aOutPt.X(), + nOffY = aDstRect.Top() - aOutPt.Y(); + long nX, nOutX, nY, nOutY; + long nMirrOffX = 0; + long nMirrOffY = 0; + boost::scoped_array pMapX(new long[ nDstWidth ]); + boost::scoped_array pMapY(new long[ nDstHeight ]); + + // create horizontal mapping table + if( bHMirr ) + nMirrOffX = ( aBmpRect.Left() << 1 ) + nSrcWidth - 1; + + for( nX = 0L, nOutX = nOffX; nX < nDstWidth; nX++, nOutX++ ) + { + pMapX[ nX ] = aBmpRect.Left() + nOutX * nSrcWidth / nOutWidth; + if( bHMirr ) + pMapX[ nX ] = nMirrOffX - pMapX[ nX ]; + } + + // create vertical mapping table + if( bVMirr ) + nMirrOffY = ( aBmpRect.Top() << 1 ) + nSrcHeight - 1; + + for( nY = 0L, nOutY = nOffY; nY < nDstHeight; nY++, nOutY++ ) + { + pMapY[ nY ] = aBmpRect.Top() + nOutY * nSrcHeight / nOutHeight; + + if( bVMirr ) + pMapY[ nY ] = nMirrOffY - pMapY[ nY ]; + } + + BitmapReadAccess* pP = ( (Bitmap&) rBmp ).AcquireReadAccess(); + BitmapReadAccess* pA = ( (AlphaMask&) rAlpha ).AcquireReadAccess(); + + DBG_ASSERT( pA->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL || + pA->GetScanlineFormat() == BMP_FORMAT_8BIT_TC_MASK, + "OutputDevice::ImplDrawAlpha(): non-8bit alpha no longer supported!" ); + + // #i38887# reading from screen may sometimes fail + if( aBmp.ImplGetImpBitmap() ) + { + Bitmap aTmp; + + if( mpAlphaVDev ) + { + aTmp = BlendBitmapWithAlpha( + aBmp,pP,pA, + aDstRect, + nOffY,nDstHeight, + nOffX,nDstWidth, + pMapX.get(),pMapY.get() ); + } + else + { + aTmp = BlendBitmap( + aBmp,pP,pA, + nOffY,nDstHeight, + nOffX,nDstWidth, + aBmpRect,aOutSz, + bHMirr,bVMirr, + pMapX.get(),pMapY.get() ); + } + + // #110958# Disable alpha VDev, we're doing the necessary + // stuff explicitly furher below + if( mpAlphaVDev ) + mpAlphaVDev = NULL; + + DrawBitmap( aDstRect.TopLeft(), + aTmp ); + + // #110958# Enable alpha VDev again + mpAlphaVDev = pOldVDev; + } + + ( (Bitmap&) rBmp ).ReleaseAccess( pP ); + ( (AlphaMask&) rAlpha ).ReleaseAccess( pA ); + + mbMap = bOldMap; + mpMetaFile = pOldMetaFile; + } + } +} + void OutputDevice::ScaleBitmap (Bitmap &rBmp, SalTwoRect &rPosAry) { const double nScaleX = rPosAry.mnDestWidth / static_cast( rPosAry.mnSrcWidth ); @@ -775,7 +951,7 @@ bool OutputDevice::TransformAndReduceBitmapExToTargetRange( aVisibleRange.transform(aMakeVisibleRangeRelative); } - // for pixel devices, do *not* limit size, else OutputDevice::DrawAlphaBitmap + // for pixel devices, do *not* limit size, else OutputDevice::DrawDeviceAlphaBitmap // will create another, badly scaled bitmap to do the job. Nonetheless, do a // maximum clipping of something big (1600x1280x2). Add 1.0 to avoid rounding // errors in rough estimations @@ -1014,184 +1190,6 @@ void OutputDevice::DrawImage( const Point& rPos, const Size& rSize, } } -void OutputDevice::DrawAlphaBitmap( const Bitmap& rBmp, const AlphaMask& rAlpha, - const Point& rDestPt, const Size& rDestSize, - const Point& rSrcPtPixel, const Size& rSrcSizePixel ) -{ - Point aOutPt( LogicToPixel( rDestPt ) ); - Size aOutSz( LogicToPixel( rDestSize ) ); - Rectangle aDstRect( Point(), GetOutputSizePixel() ); - const bool bHMirr = aOutSz.Width() < 0; - const bool bVMirr = aOutSz.Height() < 0; - - ClipToPaintRegion(aDstRect); - - if( bHMirr ) - { - aOutSz.Width() = -aOutSz.Width(); - aOutPt.X() -= ( aOutSz.Width() - 1L ); - } - - if( bVMirr ) - { - aOutSz.Height() = -aOutSz.Height(); - aOutPt.Y() -= ( aOutSz.Height() - 1L ); - } - - if( !aDstRect.Intersection( Rectangle( aOutPt, aOutSz ) ).IsEmpty() ) - { - bool bNativeAlpha = false; - static const char* pDisableNative = getenv( "SAL_DISABLE_NATIVE_ALPHA"); - // #i83087# Naturally, system alpha blending cannot work with - // separate alpha VDev - bool bTryDirectPaint(!mpAlphaVDev && !pDisableNative && !bHMirr && !bVMirr); - -#ifdef WNT - if(bTryDirectPaint) - { - // only paint direct when no scaling and no MapMode, else the - // more expensive conversions may be done for short-time Bitmap/BitmapEx - // used for buffering only - if(!IsMapMode() && rSrcSizePixel.Width() == aOutSz.Width() && rSrcSizePixel.Height() == aOutSz.Height()) - { - bTryDirectPaint = false; - } - } -#endif - - if(bTryDirectPaint) - { - Point aRelPt = aOutPt + Point( mnOutOffX, mnOutOffY ); - SalTwoRect aTR = { - rSrcPtPixel.X(), rSrcPtPixel.Y(), - rSrcSizePixel.Width(), rSrcSizePixel.Height(), - aRelPt.X(), aRelPt.Y(), - aOutSz.Width(), aOutSz.Height() - }; - SalBitmap* pSalSrcBmp = rBmp.ImplGetImpBitmap()->ImplGetSalBitmap(); - SalBitmap* pSalAlphaBmp = rAlpha.ImplGetImpBitmap()->ImplGetSalBitmap(); - bNativeAlpha = mpGraphics->DrawAlphaBitmap( aTR, *pSalSrcBmp, *pSalAlphaBmp, this ); - } - - VirtualDevice* pOldVDev = mpAlphaVDev; - - Rectangle aBmpRect( Point(), rBmp.GetSizePixel() ); - if( !bNativeAlpha - && !aBmpRect.Intersection( Rectangle( rSrcPtPixel, rSrcSizePixel ) ).IsEmpty() ) - { - // The scaling in this code path produces really ugly results - it - // does the most trivial scaling with no smoothing. - - GDIMetaFile* pOldMetaFile = mpMetaFile; - const bool bOldMap = mbMap; - mpMetaFile = NULL; // fdo#55044 reset before GetBitmap! - mbMap = false; - Bitmap aBmp( GetBitmap( aDstRect.TopLeft(), aDstRect.GetSize() ) ); - - // #109044# The generated bitmap need not necessarily be - // of aDstRect dimensions, it's internally clipped to - // window bounds. Thus, we correct the dest size here, - // since we later use it (in nDstWidth/Height) for pixel - // access) - // #i38887# reading from screen may sometimes fail - if( aBmp.ImplGetImpBitmap() ) - aDstRect.SetSize( aBmp.GetSizePixel() ); - - BitmapColor aDstCol; - const long nSrcWidth = aBmpRect.GetWidth(), nSrcHeight = aBmpRect.GetHeight(); - const long nDstWidth = aDstRect.GetWidth(), nDstHeight = aDstRect.GetHeight(); - const long nOutWidth = aOutSz.Width(), nOutHeight = aOutSz.Height(); - // calculate offset in original bitmap - // in RTL case this is a little more complicated since the contents of the - // bitmap is not mirrored (it never is), however the paint region and bmp region - // are in mirrored coordinates, so the intersection of (aOutPt,aOutSz) with these - // is content wise somewhere else and needs to take mirroring into account - const long nOffX = IsRTLEnabled() - ? aOutSz.Width() - aDstRect.GetWidth() - (aDstRect.Left() - aOutPt.X()) - : aDstRect.Left() - aOutPt.X(), - nOffY = aDstRect.Top() - aOutPt.Y(); - long nX, nOutX, nY, nOutY; - long nMirrOffX = 0; - long nMirrOffY = 0; - boost::scoped_array pMapX(new long[ nDstWidth ]); - boost::scoped_array pMapY(new long[ nDstHeight ]); - - // create horizontal mapping table - if( bHMirr ) - nMirrOffX = ( aBmpRect.Left() << 1 ) + nSrcWidth - 1; - - for( nX = 0L, nOutX = nOffX; nX < nDstWidth; nX++, nOutX++ ) - { - pMapX[ nX ] = aBmpRect.Left() + nOutX * nSrcWidth / nOutWidth; - if( bHMirr ) - pMapX[ nX ] = nMirrOffX - pMapX[ nX ]; - } - - // create vertical mapping table - if( bVMirr ) - nMirrOffY = ( aBmpRect.Top() << 1 ) + nSrcHeight - 1; - - for( nY = 0L, nOutY = nOffY; nY < nDstHeight; nY++, nOutY++ ) - { - pMapY[ nY ] = aBmpRect.Top() + nOutY * nSrcHeight / nOutHeight; - - if( bVMirr ) - pMapY[ nY ] = nMirrOffY - pMapY[ nY ]; - } - - BitmapReadAccess* pP = ( (Bitmap&) rBmp ).AcquireReadAccess(); - BitmapReadAccess* pA = ( (AlphaMask&) rAlpha ).AcquireReadAccess(); - - DBG_ASSERT( pA->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL || - pA->GetScanlineFormat() == BMP_FORMAT_8BIT_TC_MASK, - "OutputDevice::ImplDrawAlpha(): non-8bit alpha no longer supported!" ); - - // #i38887# reading from screen may sometimes fail - if( aBmp.ImplGetImpBitmap() ) - { - Bitmap aTmp; - - if( mpAlphaVDev ) - { - aTmp = BlendBitmapWithAlpha( - aBmp,pP,pA, - aDstRect, - nOffY,nDstHeight, - nOffX,nDstWidth, - pMapX.get(),pMapY.get() ); - } - else - { - aTmp = BlendBitmap( - aBmp,pP,pA, - nOffY,nDstHeight, - nOffX,nDstWidth, - aBmpRect,aOutSz, - bHMirr,bVMirr, - pMapX.get(),pMapY.get() ); - } - - // #110958# Disable alpha VDev, we're doing the necessary - // stuff explicitly furher below - if( mpAlphaVDev ) - mpAlphaVDev = NULL; - - DrawBitmap( aDstRect.TopLeft(), - aTmp ); - - // #110958# Enable alpha VDev again - mpAlphaVDev = pOldVDev; - } - - ( (Bitmap&) rBmp ).ReleaseAccess( pP ); - ( (AlphaMask&) rAlpha ).ReleaseAccess( pA ); - - mbMap = bOldMap; - mpMetaFile = pOldMetaFile; - } - } -} - namespace { // Co = Cs + Cd*(1-As) premultiplied alpha -or- diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx index b72779621f42..ecf8cd4a5a5c 100644 --- a/vcl/source/outdev/outdev.cxx +++ b/vcl/source/outdev/outdev.cxx @@ -428,7 +428,7 @@ void OutputDevice::Pop() mpMetaFile = pOldMetaFile; } -bool OutputDevice::supportsOperation( OutDevSupportType eType ) const +bool OutputDevice::SupportsOperation( OutDevSupportType eType ) const { if( !mpGraphics ) if( !AcquireGraphics() ) -- cgit