1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_CANVAS_SPRITECANVASBASE_HXX
25 #define INCLUDED_CANVAS_SPRITECANVASBASE_HXX
26 
27 #include <rtl/ref.hxx>
28 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
29 #include <com/sun/star/rendering/InterpolationMode.hpp>
30 #include <canvas/base/integerbitmapbase.hxx>
31 #include <canvas/spriteredrawmanager.hxx>
32 
33 
34 namespace canvas
35 {
36     /** Helper template to handle XIntegerBitmap method forwarding to
37         BitmapCanvasHelper
38 
39     	Use this helper to handle the XIntegerBitmap part of your
40     	implementation.
41 
42         @tpl Base
43         Base class to use, most probably one of the
44         WeakComponentImplHelperN templates with the appropriate
45         interfaces. At least XSpriteCanvas and SpriteSurface should be
46         among them (why else would you use this template, then?). Base
47         class must have an Base( const Mutex& ) constructor (like the
48         WeakComponentImplHelperN templates have).
49 
50         @tpl CanvasHelper
51         Canvas helper implementation for the backend in question
52 
53         @tpl Mutex
54         Lock strategy to use. Defaults to using the
55         OBaseMutex-provided lock.  Every time one of the methods is
56         entered, an object of type Mutex is created with m_aMutex as
57         the sole parameter, and destroyed again when the method scope
58         is left.
59 
60         @tpl UnambiguousBase
61         Optional unambiguous base class for XInterface of Base. It's
62         sometimes necessary to specify this parameter, e.g. if Base
63         derives from multiple UNO interface (were each provides its
64         own version of XInterface, making the conversion ambiguous)
65 
66         @see CanvasBase for further contractual requirements towards
67         the CanvasHelper type, and some examples.
68      */
69     template< class Base,
70               class CanvasHelper,
71               class Mutex=::osl::MutexGuard,
72               class UnambiguousBase=::com::sun::star::uno::XInterface > class SpriteCanvasBase :
73         public IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase >
74     {
75     public:
76         typedef IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase >	BaseType;
77         typedef ::rtl::Reference< SpriteCanvasBase > 							Reference;
78 
SpriteCanvasBase()79         SpriteCanvasBase() :
80             maRedrawManager()
81         {
82         }
83 
84 #if defined __SUNPRO_CC
85         using Base::disposing;
86 #endif
disposing()87         virtual void SAL_CALL disposing()
88         {
89             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
90 
91             maRedrawManager.disposing();
92 
93             // pass on to base class
94             BaseType::disposing();
95         }
96 
97         // XSpriteCanvas
createSpriteFromAnimation(const::com::sun::star::uno::Reference<::com::sun::star::rendering::XAnimation> & animation)98         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromAnimation( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimation >& animation ) throw (::com::sun::star::lang::IllegalArgumentException,
99                                                                                                                                                                                                                                            ::com::sun::star::uno::RuntimeException)
100         {
101             tools::verifyArgs(animation,
102                               BOOST_CURRENT_FUNCTION,
103                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
104 
105             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
106 
107             return BaseType::maCanvasHelper.createSpriteFromAnimation(animation);
108         }
109 
createSpriteFromBitmaps(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Reference<::com::sun::star::rendering::XBitmap>> & animationBitmaps,sal_Int8 interpolationMode)110         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromBitmaps( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > >& animationBitmaps,
111                                                                                                                                    sal_Int8                                                                                                           interpolationMode ) throw (::com::sun::star::lang::IllegalArgumentException,
112                                                                                                                                                                                                                                                                                  ::com::sun::star::rendering::VolatileContentDestroyedException,
113                                                                                                                                                                                                                                                                                  ::com::sun::star::uno::RuntimeException)
114         {
115             tools::verifyArgs(animationBitmaps,
116                               BOOST_CURRENT_FUNCTION,
117                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
118             tools::verifyRange( interpolationMode,
119                                 ::com::sun::star::rendering::InterpolationMode::NEAREST_NEIGHBOR,
120                                 ::com::sun::star::rendering::InterpolationMode::BEZIERSPLINE4 );
121 
122             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
123 
124             return BaseType::maCanvasHelper.createSpriteFromBitmaps(animationBitmaps, interpolationMode);
125         }
126 
createCustomSprite(const::com::sun::star::geometry::RealSize2D & spriteSize)127         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCustomSprite > SAL_CALL createCustomSprite( const ::com::sun::star::geometry::RealSize2D& spriteSize ) throw (::com::sun::star::lang::IllegalArgumentException,
128                                                                                                                                                                                               ::com::sun::star::uno::RuntimeException)
129         {
130             tools::verifySpriteSize(spriteSize,
131                                     BOOST_CURRENT_FUNCTION,
132                                     static_cast< typename BaseType::UnambiguousBaseType* >(this));
133 
134             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
135 
136             return BaseType::maCanvasHelper.createCustomSprite(spriteSize);
137         }
138 
createClonedSprite(const::com::sun::star::uno::Reference<::com::sun::star::rendering::XSprite> & original)139         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSprite > SAL_CALL createClonedSprite( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSprite >& original ) throw (::com::sun::star::lang::IllegalArgumentException,
140                                                                                                                                                                                                                         ::com::sun::star::uno::RuntimeException)
141         {
142             tools::verifyArgs(original,
143                               BOOST_CURRENT_FUNCTION,
144                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
145 
146             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
147 
148             return BaseType::maCanvasHelper.createClonedSprite(original);
149         }
150 
151         // SpriteSurface
showSprite(const Sprite::Reference & rSprite)152         virtual void showSprite( const Sprite::Reference& rSprite )
153         {
154             OSL_ASSERT( rSprite.is() );
155 
156             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
157 
158             maRedrawManager.showSprite( rSprite );
159         }
160 
hideSprite(const Sprite::Reference & rSprite)161         virtual void hideSprite( const Sprite::Reference& rSprite )
162         {
163             OSL_ASSERT( rSprite.is() );
164 
165             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
166 
167             maRedrawManager.hideSprite( rSprite );
168         }
169 
moveSprite(const Sprite::Reference & rSprite,const::basegfx::B2DPoint & rOldPos,const::basegfx::B2DPoint & rNewPos,const::basegfx::B2DVector & rSpriteSize)170         virtual void moveSprite( const Sprite::Reference&		rSprite,
171                                  const ::basegfx::B2DPoint& 	rOldPos,
172                                  const ::basegfx::B2DPoint&		rNewPos,
173                                  const ::basegfx::B2DVector& 	rSpriteSize )
174         {
175             OSL_ASSERT( rSprite.is() );
176 
177             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
178 
179             maRedrawManager.moveSprite( rSprite, rOldPos, rNewPos, rSpriteSize );
180         }
181 
updateSprite(const Sprite::Reference & rSprite,const::basegfx::B2DPoint & rPos,const::basegfx::B2DRange & rUpdateArea)182         virtual void updateSprite( const Sprite::Reference& 	rSprite,
183                                    const ::basegfx::B2DPoint& 	rPos,
184                                    const ::basegfx::B2DRange&	rUpdateArea )
185         {
186             OSL_ASSERT( rSprite.is() );
187 
188             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
189 
190             maRedrawManager.updateSprite( rSprite, rPos, rUpdateArea );
191         }
192 
193     protected:
194         SpriteRedrawManager maRedrawManager;
195     };
196 }
197 
198 #endif /* INCLUDED_CANVAS_SPRITECANVASBASE_HXX */
199