27#include <rtl/math.hxx>
35using namespace ::
cairo;
48 "SpriteHelper::init(): Invalid device, sprite canvas or surface" );
54 CanvasCustomSpriteHelper::init( rSpriteSize, rSpriteCanvas );
68 CanvasCustomSpriteHelper::disposing();
72 const ::basegfx::B2DPoint& rPos,
76#ifdef CAIRO_CANVAS_PERF_TRACE
77 struct timespec aTimer;
78 mxDevice->startPerfTrace( &aTimer );
84 if( !
isActive() || ::basegfx::fTools::equalZero( fAlpha ) )
87 SAL_INFO(
"canvas.cairo",
"CanvasCustomSprite::redraw called");
92 cairo_save( pCairo.get() );
99 if( !aTransform.isIdentity() )
101 cairo_matrix_t aMatrix, aInverseMatrix;
102 cairo_matrix_init( &aMatrix,
103 aTransform.get( 0, 0 ), aTransform.get( 1, 0 ), aTransform.get( 0, 1 ),
104 aTransform.get( 1, 1 ), aTransform.get( 0, 2 ), aTransform.get( 1, 2 ) );
109 cairo_matrix_init( &aInverseMatrix, aMatrix.xx, aMatrix.yx, aMatrix.xy, aMatrix.yy, aMatrix.x0, aMatrix.y0 );
110 cairo_matrix_invert( &aInverseMatrix );
111 cairo_matrix_transform_distance( &aInverseMatrix, &fX, &fY );
113 cairo_set_matrix( pCairo.get(), &aMatrix );
119 cairo_matrix_t aOrigMatrix;
120 cairo_get_matrix( pCairo.get(), &aOrigMatrix );
121 cairo_translate( pCairo.get(), fX, fY );
125 const uno::Reference<rendering::XPolyPolygon2D>& rClip(
getClip() );
128 ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(
133 rClip->getFillRule() );
136 SAL_INFO(
"canvas.cairo",
"aSize " << aSize.
getX() <<
" x " << aSize.
getY() <<
" position: " << fX <<
"," << fY );
137 cairo_rectangle( pCairo.get(), 0, 0, floor( aSize.
getX() ), floor( aSize.
getY() ) );
138 cairo_clip( pCairo.get() );
139 cairo_set_matrix( pCairo.get(), &aOrigMatrix );
141 cairo_matrix_t aInverseMatrix = aOrigMatrix;
142 bool matrixProblem =
false;
151#define PIXMAN_MAX_INT ((pixman_fixed_1 >> 1) - pixman_fixed_e)
152 if(cairo_matrix_invert(&aInverseMatrix) == CAIRO_STATUS_SUCCESS)
160 matrixProblem =
true;
164 matrixProblem =
true;
167 SAL_WARN(
"canvas.cairo",
"matrix would overflow PIXMAN_MAX_INT, avoiding drawing" );
168 cairo_restore( pCairo.get() );
173 cairo_set_operator( pCairo.get(), CAIRO_OPERATOR_SOURCE );
174 cairo_set_source_surface( pCairo.get(),
177 if( ::rtl::math::approxEqual( fAlpha, 1.0 ) )
178 cairo_paint( pCairo.get() );
180 cairo_paint_with_alpha( pCairo.get(), fAlpha );
182 cairo_restore( pCairo.get() );
184#ifdef CAIRO_CANVAS_PERF_TRACE
185 mxDevice->stopPerfTrace( &aTimer,
"sprite redraw" );
191 return ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(xPoly);
void init(const css::geometry::RealSize2D &rSpriteSize, const SpriteCanvasRef &rSpriteCanvas)
Late-init the sprite helper.
void setSurface(const ::cairo::SurfaceSharedPtr &pBufferSurface)
SpriteCanvasRef mpSpriteCanvas
virtual ::basegfx::B2DPolyPolygon polyPolygonFromXPolyPolygon2D(css::uno::Reference< css::rendering::XPolyPolygon2D > &xPoly) const override
Called to convert an API polygon to a basegfx polygon.
void redraw(const ::cairo::CairoSharedPtr &pCairo, const ::basegfx::B2DPoint &rPos, bool &bSurfacesDirty, bool bBufferedUpdate) const
Repaint sprite content to associated sprite canvas.
::cairo::SurfaceSharedPtr mpBufferSurface
SpriteHelper()
Create sprite helper.
bool isContentFullyOpaque() const
Returns true, if sprite content bitmap is fully opaque.
const css::uno::Reference< css::rendering::XPolyPolygon2D > & getClip() const
Retrieve current clip.
bool isActive() const
Retrieve current activation state.
const ::basegfx::B2DHomMatrix & getTransformation() const
double getAlpha() const
Retrieve current alpha value.
const ::basegfx::B2DVector & getSizePixel() const
#define ENSURE_OR_THROW(c, m)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
B2IRange fround(const B2DRange &rRange)
std::shared_ptr< Surface > SurfaceSharedPtr
std::shared_ptr< cairo_t > CairoSharedPtr
void doPolyPolygonImplementation(const ::basegfx::B2DPolyPolygon &aPolyPolygon, Operation aOperation, cairo_t *pCairo, const uno::Sequence< rendering::Texture > *pTextures, const SurfaceProviderRef &pDevice, rendering::FillRule eFillrule)
class SAL_LOPLUGIN_ANNOTATE("crosscast") SurfaceProvider typedef ::rtl::Reference< SurfaceProvider > SurfaceProviderRef
Target interface for XCachedPrimitive implementations.
SwNodeOffset abs(const SwNodeOffset &a)