xref: /AOO41X/main/canvas/source/cairo/cairo_canvascustomsprite.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_canvas.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <canvas/debug.hxx>
32*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
33*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <rtl/logfile.hxx>
36*cdf0e10cSrcweir #include <rtl/math.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <canvas/canvastools.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
41*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include "cairo_canvascustomsprite.hxx"
44*cdf0e10cSrcweir #include "cairo_spritecanvas.hxx"
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir using namespace ::cairo;
48*cdf0e10cSrcweir using namespace ::com::sun::star;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace cairocanvas
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir     CanvasCustomSprite::CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& 	rSpriteSize,
53*cdf0e10cSrcweir                                             const SpriteCanvasRef&                          rRefDevice ) :
54*cdf0e10cSrcweir         mpSpriteCanvas( rRefDevice ),
55*cdf0e10cSrcweir 		maSize( ::canvas::tools::roundUp( rSpriteSize.Width ),
56*cdf0e10cSrcweir 				::canvas::tools::roundUp( rSpriteSize.Height ) )
57*cdf0e10cSrcweir     {
58*cdf0e10cSrcweir         ENSURE_OR_THROW( rRefDevice.get(),
59*cdf0e10cSrcweir                           "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 		OSL_TRACE("sprite size: %d, %d",
62*cdf0e10cSrcweir 				  ::canvas::tools::roundUp( rSpriteSize.Width ),
63*cdf0e10cSrcweir 				  ::canvas::tools::roundUp( rSpriteSize.Height ));
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 		mpBufferSurface = mpSpriteCanvas->createSurface( maSize );
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir         maCanvasHelper.init( maSize,
68*cdf0e10cSrcweir                              *rRefDevice,
69*cdf0e10cSrcweir                              rRefDevice.get() );
70*cdf0e10cSrcweir 		maCanvasHelper.setSurface( mpBufferSurface, true );
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir         maSpriteHelper.init( rSpriteSize,
73*cdf0e10cSrcweir                              rRefDevice );
74*cdf0e10cSrcweir 		maSpriteHelper.setSurface( mpBufferSurface );
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir         // clear sprite to 100% transparent
77*cdf0e10cSrcweir         maCanvasHelper.clear();
78*cdf0e10cSrcweir     }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     void SAL_CALL CanvasCustomSprite::disposing()
81*cdf0e10cSrcweir     {
82*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir         mpSpriteCanvas.clear();
85*cdf0e10cSrcweir 		mpBufferSurface.reset();
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir         // forward to parent
88*cdf0e10cSrcweir         CanvasCustomSpriteBaseT::disposing();
89*cdf0e10cSrcweir     }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     void CanvasCustomSprite::redraw( const CairoSharedPtr& pCairo,
92*cdf0e10cSrcweir                                      bool                  bBufferedUpdate ) const
93*cdf0e10cSrcweir     {
94*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir         redraw( pCairo, maSpriteHelper.getPosPixel(), bBufferedUpdate );
97*cdf0e10cSrcweir     }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     void CanvasCustomSprite::redraw( const CairoSharedPtr&      pCairo,
100*cdf0e10cSrcweir                                      const ::basegfx::B2DPoint& rOrigOutputPos,
101*cdf0e10cSrcweir                                      bool                       bBufferedUpdate ) const
102*cdf0e10cSrcweir     {
103*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         maSpriteHelper.redraw( pCairo,
106*cdf0e10cSrcweir                                rOrigOutputPos,
107*cdf0e10cSrcweir                                mbSurfaceDirty,
108*cdf0e10cSrcweir                                bBufferedUpdate );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         mbSurfaceDirty = false;
111*cdf0e10cSrcweir     }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     bool CanvasCustomSprite::repaint( const SurfaceSharedPtr&       pSurface,
114*cdf0e10cSrcweir                                       const rendering::ViewState&	viewState,
115*cdf0e10cSrcweir                                       const rendering::RenderState&	renderState )
116*cdf0e10cSrcweir     {
117*cdf0e10cSrcweir         return maCanvasHelper.repaint( pSurface, viewState, renderState );
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     SurfaceSharedPtr CanvasCustomSprite::getSurface()
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         return mpBufferSurface;
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     SurfaceSharedPtr CanvasCustomSprite::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
126*cdf0e10cSrcweir     {
127*cdf0e10cSrcweir         return mpSpriteCanvas->createSurface(rSize,aContent);
128*cdf0e10cSrcweir     }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     SurfaceSharedPtr CanvasCustomSprite::createSurface( ::Bitmap& rBitmap )
131*cdf0e10cSrcweir     {
132*cdf0e10cSrcweir         return mpSpriteCanvas->createSurface(rBitmap);
133*cdf0e10cSrcweir     }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	SurfaceSharedPtr CanvasCustomSprite::changeSurface( bool bHasAlpha, bool bCopyContent )
136*cdf0e10cSrcweir 	{
137*cdf0e10cSrcweir 		if( !bHasAlpha && !bCopyContent )
138*cdf0e10cSrcweir 		{
139*cdf0e10cSrcweir 			OSL_TRACE("replacing sprite background surface");
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 			mpBufferSurface = mpSpriteCanvas->createSurface( maSize, CAIRO_CONTENT_COLOR );
142*cdf0e10cSrcweir 			maSpriteHelper.setSurface( mpBufferSurface );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 			return mpBufferSurface;
145*cdf0e10cSrcweir 		}
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 		return SurfaceSharedPtr();
148*cdf0e10cSrcweir 	}
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     OutputDevice* CanvasCustomSprite::getOutputDevice()
151*cdf0e10cSrcweir     {
152*cdf0e10cSrcweir         return mpSpriteCanvas->getOutputDevice();
153*cdf0e10cSrcweir     }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir #define IMPLEMENTATION_NAME "CairoCanvas.CanvasCustomSprite"
156*cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite"
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException )
159*cdf0e10cSrcweir     {
160*cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
164*cdf0e10cSrcweir     {
165*cdf0e10cSrcweir         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
166*cdf0e10cSrcweir     }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames()  throw( uno::RuntimeException )
169*cdf0e10cSrcweir     {
170*cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aRet(1);
171*cdf0e10cSrcweir         aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir         return aRet;
174*cdf0e10cSrcweir     }
175*cdf0e10cSrcweir }
176