1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <canvas/debug.hxx>
22 #include <tools/diagnose_ex.h>
23 #include <canvas/verbosetrace.hxx>
24 #include <cppuhelper/supportsservice.hxx>
26 #include <rtl/math.hxx>
28 #include <vcl/outdev.hxx>
29 #include <vcl/bitmap.hxx>
30 #include <vcl/alpha.hxx>
31 #include <vcl/bitmapex.hxx>
32 #include <vcl/canvastools.hxx>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <basegfx/point/b2dpoint.hxx>
36 #include <basegfx/tools/canvastools.hxx>
37 #include <basegfx/polygon/b2dpolygon.hxx>
38 #include <basegfx/polygon/b2dpolygontools.hxx>
39 #include <basegfx/polygon/b2dpolypolygontools.hxx>
40 #include <basegfx/numeric/ftools.hxx>
42 #include <canvas/canvastools.hxx>
44 #include "canvascustomsprite.hxx"
46 using namespace ::com::sun::star
;
52 CanvasCustomSprite::CanvasCustomSprite( const geometry::RealSize2D
& rSpriteSize
,
53 rendering::XGraphicDevice
& rDevice
,
54 const ::canvas::SpriteSurface::Reference
& rOwningSpriteCanvas
,
55 const OutDevProviderSharedPtr
& rOutDevProvider
,
56 bool bShowSpriteBounds
)
58 ENSURE_OR_THROW( rOwningSpriteCanvas
.get() &&
60 "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
66 static_cast<sal_Int32
>( ::std::max( 1.0,
67 ceil( rSpriteSize
.Width
))), // round up to nearest int,
68 // enforce sprite to have at
69 // least (1,1) pixel size
70 static_cast<sal_Int32
>( ::std::max( 1.0,
71 ceil( rSpriteSize
.Height
))) );
73 // create content backbuffer in screen depth
74 BackBufferSharedPtr
pBackBuffer( new BackBuffer( rOutDevProvider
->getOutDev() ) );
75 pBackBuffer
->setSize( aSize
);
77 // create mask backbuffer, with one bit color depth
78 BackBufferSharedPtr
pBackBufferMask( new BackBuffer( rOutDevProvider
->getOutDev(),
80 pBackBufferMask
->setSize( aSize
);
82 // TODO(F1): Implement alpha vdev (could prolly enable
83 // antialiasing again, then)
85 // disable font antialiasing (causes ugly shadows otherwise)
86 pBackBuffer
->getOutDev().SetAntialiasing( AntialiasingFlags::DisableText
);
87 pBackBufferMask
->getOutDev().SetAntialiasing( AntialiasingFlags::DisableText
);
89 // set mask vdev drawmode, such that everything is painted
90 // black. That leaves us with a binary image, white for
91 // background, black for painted content
92 pBackBufferMask
->getOutDev().SetDrawMode( DrawModeFlags::BlackLine
| DrawModeFlags::BlackFill
| DrawModeFlags::BlackText
|
93 DrawModeFlags::BlackGradient
| DrawModeFlags::BlackBitmap
);
96 // setup canvas helper
99 // always render into back buffer, don't preserve state (it's
100 // our private VDev, after all), have notion of alpha
101 maCanvasHelper
.init( rDevice
,
105 maCanvasHelper
.setBackgroundOutDev( pBackBufferMask
);
108 // setup sprite helper
111 maSpriteHelper
.init( rSpriteSize
,
117 // clear sprite to 100% transparent
118 maCanvasHelper
.clear();
121 OUString SAL_CALL
CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException
, std::exception
)
123 return OUString( "VCLCanvas.CanvasCustomSprite" );
126 sal_Bool SAL_CALL
CanvasCustomSprite::supportsService( const OUString
& ServiceName
) throw( uno::RuntimeException
, std::exception
)
128 return cppu::supportsService( this, ServiceName
);
131 uno::Sequence
< OUString
> SAL_CALL
CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException
, std::exception
)
133 uno::Sequence
< OUString
> aRet(1);
134 aRet
[0] = "com.sun.star.rendering.CanvasCustomSprite";
140 void CanvasCustomSprite::redraw( OutputDevice
& rOutDev
,
141 bool bBufferedUpdate
) const
143 SolarMutexGuard aGuard
;
145 redraw( rOutDev
, maSpriteHelper
.getPosPixel(), bBufferedUpdate
);
148 void CanvasCustomSprite::redraw( OutputDevice
& rOutDev
,
149 const ::basegfx::B2DPoint
& rOrigOutputPos
,
150 bool bBufferedUpdate
) const
152 SolarMutexGuard aGuard
;
154 maSpriteHelper
.redraw( rOutDev
,
159 mbSurfaceDirty
= false;
162 bool CanvasCustomSprite::repaint( const GraphicObjectSharedPtr
& rGrf
,
163 const rendering::ViewState
& viewState
,
164 const rendering::RenderState
& renderState
,
167 const GraphicAttr
& rAttr
) const
169 SolarMutexGuard aGuard
;
171 mbSurfaceDirty
= true;
173 return maCanvasHelper
.repaint( rGrf
, viewState
, renderState
, rPt
, rSz
, rAttr
);
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */