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 .
20 #include <canvas/debug.hxx>
21 #include <canvas/verbosetrace.hxx>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <tools/diagnose_ex.h>
25 #include <rtl/math.hxx>
27 #include <canvas/canvastools.hxx>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <basegfx/point/b2dpoint.hxx>
32 #include "cairo_canvascustomsprite.hxx"
33 #include "cairo_spritecanvas.hxx"
36 using namespace ::cairo
;
37 using namespace ::com::sun::star
;
41 CanvasCustomSprite::CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D
& rSpriteSize
,
42 const SpriteCanvasRef
& rRefDevice
) :
43 mpSpriteCanvas( rRefDevice
),
44 maSize( ::canvas::tools::roundUp( rSpriteSize
.Width
),
45 ::canvas::tools::roundUp( rSpriteSize
.Height
) )
47 ENSURE_OR_THROW( rRefDevice
.get(),
48 "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
50 SAL_INFO( "canvas.cairo", "sprite size: " << ::canvas::tools::roundUp( rSpriteSize
.Width
) << ", " << ::canvas::tools::roundUp( rSpriteSize
.Height
));
52 mpBufferSurface
= mpSpriteCanvas
->createSurface( maSize
);
54 maCanvasHelper
.init( maSize
,
57 maCanvasHelper
.setSurface( mpBufferSurface
, true );
59 maSpriteHelper
.init( rSpriteSize
,
61 maSpriteHelper
.setSurface( mpBufferSurface
);
63 // clear sprite to 100% transparent
64 maCanvasHelper
.clear();
67 void CanvasCustomSprite::disposeThis()
69 ::osl::MutexGuard
aGuard( m_aMutex
);
71 mpSpriteCanvas
.clear();
72 mpBufferSurface
.reset();
75 CanvasCustomSpriteBaseT::disposeThis();
78 void CanvasCustomSprite::redraw( const CairoSharedPtr
& pCairo
,
79 bool bBufferedUpdate
) const
81 ::osl::MutexGuard
aGuard( m_aMutex
);
83 redraw( pCairo
, maSpriteHelper
.getPosPixel(), bBufferedUpdate
);
86 void CanvasCustomSprite::redraw( const CairoSharedPtr
& pCairo
,
87 const ::basegfx::B2DPoint
& rOrigOutputPos
,
88 bool bBufferedUpdate
) const
90 ::osl::MutexGuard
aGuard( m_aMutex
);
92 maSpriteHelper
.redraw( pCairo
,
97 mbSurfaceDirty
= false;
100 bool CanvasCustomSprite::repaint( const SurfaceSharedPtr
& pSurface
,
101 const rendering::ViewState
& viewState
,
102 const rendering::RenderState
& renderState
)
104 return maCanvasHelper
.repaint( pSurface
, viewState
, renderState
);
107 SurfaceSharedPtr
CanvasCustomSprite::getSurface()
109 return mpBufferSurface
;
112 SurfaceSharedPtr
CanvasCustomSprite::createSurface( const ::basegfx::B2ISize
& rSize
, int aContent
)
114 return mpSpriteCanvas
->createSurface(rSize
,aContent
);
117 SurfaceSharedPtr
CanvasCustomSprite::createSurface( ::Bitmap
& rBitmap
)
119 return mpSpriteCanvas
->createSurface(rBitmap
);
122 SurfaceSharedPtr
CanvasCustomSprite::changeSurface( bool bHasAlpha
, bool bCopyContent
)
124 if( !bHasAlpha
&& !bCopyContent
)
126 SAL_INFO( "canvas.cairo", "replacing sprite background surface");
128 mpBufferSurface
= mpSpriteCanvas
->createSurface( maSize
, CAIRO_CONTENT_COLOR
);
129 maSpriteHelper
.setSurface( mpBufferSurface
);
131 return mpBufferSurface
;
134 return SurfaceSharedPtr();
137 OutputDevice
* CanvasCustomSprite::getOutputDevice()
139 return mpSpriteCanvas
->getOutputDevice();
142 OUString SAL_CALL
CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException
, std::exception
)
144 return OUString( "CairoCanvas.CanvasCustomSprite" );
147 sal_Bool SAL_CALL
CanvasCustomSprite::supportsService( const OUString
& ServiceName
) throw( uno::RuntimeException
, std::exception
)
149 return cppu::supportsService( this, ServiceName
);
152 uno::Sequence
< OUString
> SAL_CALL
CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException
, std::exception
)
154 uno::Sequence
< OUString
> aRet(1);
155 aRet
[0] = "com.sun.star.rendering.CanvasCustomSprite";
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */