1*25ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25ea7f45SAndrew Rist  * distributed with this work for additional information
6*25ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
9*25ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*25ea7f45SAndrew Rist  *
11*25ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*25ea7f45SAndrew Rist  *
13*25ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25ea7f45SAndrew Rist  * software distributed under the License is distributed on an
15*25ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25ea7f45SAndrew Rist  * specific language governing permissions and limitations
18*25ea7f45SAndrew Rist  * under the License.
19*25ea7f45SAndrew Rist  *
20*25ea7f45SAndrew Rist  *************************************************************/
21*25ea7f45SAndrew Rist 
22*25ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <canvas/debug.hxx>
28cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
29cdf0e10cSrcweir #include <tools/diagnose_ex.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <rtl/logfile.hxx>
32cdf0e10cSrcweir #include <rtl/math.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <canvas/canvastools.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
37cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "cairo_canvascustomsprite.hxx"
40cdf0e10cSrcweir #include "cairo_spritecanvas.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace ::cairo;
44cdf0e10cSrcweir using namespace ::com::sun::star;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace cairocanvas
47cdf0e10cSrcweir {
CanvasCustomSprite(const::com::sun::star::geometry::RealSize2D & rSpriteSize,const SpriteCanvasRef & rRefDevice)48cdf0e10cSrcweir     CanvasCustomSprite::CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& 	rSpriteSize,
49cdf0e10cSrcweir                                             const SpriteCanvasRef&                          rRefDevice ) :
50cdf0e10cSrcweir         mpSpriteCanvas( rRefDevice ),
51cdf0e10cSrcweir 		maSize( ::canvas::tools::roundUp( rSpriteSize.Width ),
52cdf0e10cSrcweir 				::canvas::tools::roundUp( rSpriteSize.Height ) )
53cdf0e10cSrcweir     {
54cdf0e10cSrcweir         ENSURE_OR_THROW( rRefDevice.get(),
55cdf0e10cSrcweir                           "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 		OSL_TRACE("sprite size: %d, %d",
58cdf0e10cSrcweir 				  ::canvas::tools::roundUp( rSpriteSize.Width ),
59cdf0e10cSrcweir 				  ::canvas::tools::roundUp( rSpriteSize.Height ));
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 		mpBufferSurface = mpSpriteCanvas->createSurface( maSize );
62cdf0e10cSrcweir 
63cdf0e10cSrcweir         maCanvasHelper.init( maSize,
64cdf0e10cSrcweir                              *rRefDevice,
65cdf0e10cSrcweir                              rRefDevice.get() );
66cdf0e10cSrcweir 		maCanvasHelper.setSurface( mpBufferSurface, true );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         maSpriteHelper.init( rSpriteSize,
69cdf0e10cSrcweir                              rRefDevice );
70cdf0e10cSrcweir 		maSpriteHelper.setSurface( mpBufferSurface );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         // clear sprite to 100% transparent
73cdf0e10cSrcweir         maCanvasHelper.clear();
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir 
disposing()76cdf0e10cSrcweir     void SAL_CALL CanvasCustomSprite::disposing()
77cdf0e10cSrcweir     {
78cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         mpSpriteCanvas.clear();
81cdf0e10cSrcweir 		mpBufferSurface.reset();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         // forward to parent
84cdf0e10cSrcweir         CanvasCustomSpriteBaseT::disposing();
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir 
redraw(const CairoSharedPtr & pCairo,bool bBufferedUpdate) const87cdf0e10cSrcweir     void CanvasCustomSprite::redraw( const CairoSharedPtr& pCairo,
88cdf0e10cSrcweir                                      bool                  bBufferedUpdate ) const
89cdf0e10cSrcweir     {
90cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         redraw( pCairo, maSpriteHelper.getPosPixel(), bBufferedUpdate );
93cdf0e10cSrcweir     }
94cdf0e10cSrcweir 
redraw(const CairoSharedPtr & pCairo,const::basegfx::B2DPoint & rOrigOutputPos,bool bBufferedUpdate) const95cdf0e10cSrcweir     void CanvasCustomSprite::redraw( const CairoSharedPtr&      pCairo,
96cdf0e10cSrcweir                                      const ::basegfx::B2DPoint& rOrigOutputPos,
97cdf0e10cSrcweir                                      bool                       bBufferedUpdate ) const
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         maSpriteHelper.redraw( pCairo,
102cdf0e10cSrcweir                                rOrigOutputPos,
103cdf0e10cSrcweir                                mbSurfaceDirty,
104cdf0e10cSrcweir                                bBufferedUpdate );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         mbSurfaceDirty = false;
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
repaint(const SurfaceSharedPtr & pSurface,const rendering::ViewState & viewState,const rendering::RenderState & renderState)109cdf0e10cSrcweir     bool CanvasCustomSprite::repaint( const SurfaceSharedPtr&       pSurface,
110cdf0e10cSrcweir                                       const rendering::ViewState&	viewState,
111cdf0e10cSrcweir                                       const rendering::RenderState&	renderState )
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir         return maCanvasHelper.repaint( pSurface, viewState, renderState );
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
getSurface()116cdf0e10cSrcweir     SurfaceSharedPtr CanvasCustomSprite::getSurface()
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         return mpBufferSurface;
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
createSurface(const::basegfx::B2ISize & rSize,Content aContent)121cdf0e10cSrcweir     SurfaceSharedPtr CanvasCustomSprite::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir         return mpSpriteCanvas->createSurface(rSize,aContent);
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
createSurface(::Bitmap & rBitmap)126cdf0e10cSrcweir     SurfaceSharedPtr CanvasCustomSprite::createSurface( ::Bitmap& rBitmap )
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         return mpSpriteCanvas->createSurface(rBitmap);
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
changeSurface(bool bHasAlpha,bool bCopyContent)131cdf0e10cSrcweir 	SurfaceSharedPtr CanvasCustomSprite::changeSurface( bool bHasAlpha, bool bCopyContent )
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		if( !bHasAlpha && !bCopyContent )
134cdf0e10cSrcweir 		{
135cdf0e10cSrcweir 			OSL_TRACE("replacing sprite background surface");
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 			mpBufferSurface = mpSpriteCanvas->createSurface( maSize, CAIRO_CONTENT_COLOR );
138cdf0e10cSrcweir 			maSpriteHelper.setSurface( mpBufferSurface );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 			return mpBufferSurface;
141cdf0e10cSrcweir 		}
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		return SurfaceSharedPtr();
144cdf0e10cSrcweir 	}
145cdf0e10cSrcweir 
getOutputDevice()146cdf0e10cSrcweir     OutputDevice* CanvasCustomSprite::getOutputDevice()
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         return mpSpriteCanvas->getOutputDevice();
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir #define IMPLEMENTATION_NAME "CairoCanvas.CanvasCustomSprite"
152cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite"
153cdf0e10cSrcweir 
getImplementationName()154cdf0e10cSrcweir     ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException )
155cdf0e10cSrcweir     {
156cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir 
supportsService(const::rtl::OUString & ServiceName)159cdf0e10cSrcweir     sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
160cdf0e10cSrcweir     {
161cdf0e10cSrcweir         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir 
getSupportedServiceNames()164cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames()  throw( uno::RuntimeException )
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aRet(1);
167cdf0e10cSrcweir         aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         return aRet;
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir }
172