summaryrefslogtreecommitdiff
path: root/canvas/source/vcl/spritehelper.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'canvas/source/vcl/spritehelper.cxx')
-rw-r--r--canvas/source/vcl/spritehelper.cxx146
1 files changed, 18 insertions, 128 deletions
diff --git a/canvas/source/vcl/spritehelper.cxx b/canvas/source/vcl/spritehelper.cxx
index 53116fa9d53d..7b3384c934e7 100644
--- a/canvas/source/vcl/spritehelper.cxx
+++ b/canvas/source/vcl/spritehelper.cxx
@@ -26,18 +26,14 @@
#include <basegfx/range/b2drectangle.hxx>
#include <basegfx/utils/canvastools.hxx>
#include <rtl/math.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <vcl/alpha.hxx>
#include <vcl/bitmapex.hxx>
#include <vcl/canvastools.hxx>
#include <vcl/outdev.hxx>
-#include <vcl/BitmapMonochromeFilter.hxx>
-#include <vcl/skia/SkiaHelper.hxx>
#include <canvas/canvastools.hxx>
-#include <config_features.h>
-#include "impltools.hxx"
#include "spritehelper.hxx"
using namespace ::com::sun::star;
@@ -46,9 +42,6 @@ using namespace ::com::sun::star;
namespace vclcanvas
{
SpriteHelper::SpriteHelper() :
- mpBackBuffer(),
- mpBackBufferMask(),
- maContent(),
mbShowSpriteBounds(false)
{
}
@@ -81,10 +74,8 @@ namespace vclcanvas
void SpriteHelper::redraw( OutputDevice& rTargetSurface,
const ::basegfx::B2DPoint& rPos,
bool& io_bSurfacesDirty,
- bool bBufferedUpdate ) const
+ bool /*bBufferedUpdate*/ ) const
{
- (void)bBufferedUpdate; // not used on every platform
-
if( !mpBackBuffer ||
!mpBackBufferMask )
{
@@ -143,100 +134,20 @@ namespace vclcanvas
// sprite content might contain alpha, create
// BmpEx, then.
BitmapEx aMask( mpBackBufferMask->getOutDev().GetBitmapEx( aEmptyPoint,
- aOutputSize ) );
-
- // bitmasks are much faster than alphamasks on some platforms
- // so convert to bitmask if useful
- bool convertTo1Bpp = aMask.GetBitCount() != 1;
-#ifdef MACOSX
- convertTo1Bpp = false;
-#endif
- if( SkiaHelper::isVCLSkiaEnabled())
- convertTo1Bpp = false;
-
- if( convertTo1Bpp )
- {
- OSL_FAIL("CanvasCustomSprite::redraw(): Mask bitmap is not "
- "monochrome (performance!)");
- BitmapEx aMaskEx(aMask);
- BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(255));
- aMask = aMaskEx.GetBitmap();
- }
+ aOutputSize ) );
+ AlphaMask aAlpha( aMask.GetBitmap() );
+ aAlpha.Invert();
// Note: since we retrieved aBmp and aMask
// directly from an OutDev, it's already a
// 'display bitmap' on windows.
- if( aMask.GetBitCount() == 1 )
- maContent = BitmapEx( aBmp.GetBitmap(), aMask.GetBitmap() );
- else
- maContent = BitmapEx( aBmp.GetBitmap(), AlphaMask( aMask.GetBitmap()) );
+ maContent = BitmapEx( aBmp.GetBitmap(), aAlpha );
}
}
::basegfx::B2DHomMatrix aTransform( getTransformation() );
- // check whether matrix is "easy" to handle - pure
- // translations or scales are handled by OutputDevice
- // alone
- const bool bIdentityTransform( aTransform.isIdentity() );
-
- // make transformation absolute (put sprite to final
- // output position). Need to happen here, as we also have
- // to translate the clip polygon
- aTransform.translate( aOutPos.X(),
- aOutPos.Y() );
-
- if( !bIdentityTransform )
- {
- if (!::basegfx::fTools::equalZero( aTransform.get(0,1) ) ||
- !::basegfx::fTools::equalZero( aTransform.get(1,0) ))
- {
- // "complex" transformation, employ affine
- // transformator
-
- // modify output position, to account for the fact
- // that transformBitmap() always normalizes its output
- // bitmap into the smallest enclosing box.
- ::basegfx::B2DRectangle aDestRect;
- ::canvas::tools::calcTransformedRectBounds( aDestRect,
- ::basegfx::B2DRectangle(0,
- 0,
- rOrigOutputSize.getX(),
- rOrigOutputSize.getY()),
- aTransform );
-
- aOutPos.setX( ::basegfx::fround( aDestRect.getMinX() ) );
- aOutPos.setY( ::basegfx::fround( aDestRect.getMinY() ) );
-
- // TODO(P3): Use optimized bitmap transformation here.
-
- // actually re-create the bitmap ONLY if necessary
- if( bNeedBitmapUpdate )
- maContent = tools::transformBitmap( *maContent,
- aTransform );
-
- aOutputSize = maContent->GetSizePixel();
- }
- else
- {
- // relatively 'simplistic' transformation -
- // retrieve scale and translational offset
- aOutputSize.setWidth (
- ::basegfx::fround( rOrigOutputSize.getX() * aTransform.get(0,0) ) );
- aOutputSize.setHeight(
- ::basegfx::fround( rOrigOutputSize.getY() * aTransform.get(1,1) ) );
-
- aOutPos.setX( ::basegfx::fround( aTransform.get(0,2) ) );
- aOutPos.setY( ::basegfx::fround( aTransform.get(1,2) ) );
- }
- }
-
- // transformBitmap() might return empty bitmaps, for tiny
- // scales.
- if( !(*maContent) )
- return;
-
- rTargetSurface.Push( PushFlags::CLIPREGION );
+ rTargetSurface.Push( vcl::PushFlags::CLIPREGION );
// apply clip (if any)
if( getClip().is() )
@@ -247,15 +158,15 @@ namespace vclcanvas
if( aClipPoly.count() )
{
- // aTransform already contains the
- // translational component, moving the clip to
- // the final sprite output position.
- aClipPoly.transform( aTransform );
+ // Move the clip to the final sprite output position.
+ ::basegfx::B2DHomMatrix aClipTransform( aTransform );
+ aClipTransform.translate( aOutPos.X(), aOutPos.Y() );
+ aClipPoly.transform( aClipTransform );
if( mbShowSpriteBounds )
{
// Paint green sprite clip area
- rTargetSurface.SetLineColor( Color( 0,255,0 ) );
+ rTargetSurface.SetLineColor( COL_LIGHTGREEN );
rTargetSurface.SetFillColor();
rTargetSurface.DrawPolyPolygon(::tools::PolyPolygon(aClipPoly)); // #i76339#
@@ -266,33 +177,12 @@ namespace vclcanvas
}
}
- if( ::rtl::math::approxEqual(fAlpha, 1.0) )
- {
- // no alpha modulation -> just copy to output
- if( maContent->IsTransparent() )
- rTargetSurface.DrawBitmapEx( aOutPos, aOutputSize, *maContent );
- else
- rTargetSurface.DrawBitmap( aOutPos, aOutputSize, maContent->GetBitmap() );
- }
- else
- {
- // TODO(P3): Switch to OutputDevice::DrawTransparent()
- // here
-
- // draw semi-transparent
- sal_uInt8 nColor( static_cast<sal_uInt8>( ::basegfx::fround( 255.0*(1.0 - fAlpha) + .5) ) );
- AlphaMask aAlpha( maContent->GetSizePixel(),
- &nColor );
-
- // mask out fully transparent areas
- if( maContent->IsTransparent() )
- aAlpha.Replace( maContent->GetMask(), 255 );
-
- // alpha-blend to output
- rTargetSurface.DrawBitmapEx( aOutPos, aOutputSize,
- BitmapEx( maContent->GetBitmap(),
- aAlpha ) );
- }
+ ::basegfx::B2DHomMatrix aSizeTransform, aMoveTransform;
+ aSizeTransform.scale( aOutputSize.Width(), aOutputSize.Height() );
+ aMoveTransform.translate( aOutPos.X(), aOutPos.Y() );
+ aTransform = aMoveTransform * aTransform * aSizeTransform;
+
+ rTargetSurface.DrawTransformedBitmapEx( aTransform, *maContent, fAlpha );
rTargetSurface.Pop();