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 _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX
25 #define _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX
26 
27 #include <cppuhelper/compbase4.hxx>
28 #include <comphelper/uno3.hxx>
29 
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/rendering/XCustomSprite.hpp>
33 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
34 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
35 
36 #include <basegfx/point/b2dpoint.hxx>
37 #include <basegfx/vector/b2isize.hxx>
38 #include <basegfx/matrix/b2dhommatrix.hxx>
39 
40 #include <canvas/base/basemutexhelper.hxx>
41 #include <canvas/base/canvascustomspritebase.hxx>
42 
43 #include "cairo_sprite.hxx"
44 #include "cairo_cairo.hxx"
45 #include "cairo_canvashelper.hxx"
46 #include "cairo_repainttarget.hxx"
47 #include "cairo_spritehelper.hxx"
48 #include "cairo_spritecanvas.hxx"
49 
50 
51 namespace cairocanvas
52 {
53     typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::rendering::XCustomSprite,
54 									 		  ::com::sun::star::rendering::XBitmapCanvas,
55 											  ::com::sun::star::rendering::XIntegerBitmap,
56                          			 		  ::com::sun::star::lang::XServiceInfo >	CanvasCustomSpriteBase_Base;
57 	/** Mixin Sprite
58 
59     	Have to mixin the Sprite interface before deriving from
60     	::canvas::CanvasCustomSpriteBase, as this template should
61     	already implement some of those interface methods.
62 
63         The reason why this appears kinda convoluted is the fact that
64         we cannot specify non-IDL types as WeakComponentImplHelperN
65         template args, and furthermore, don't want to derive
66         ::canvas::CanvasCustomSpriteBase directly from
67         ::canvas::Sprite (because derivees of
68         ::canvas::CanvasCustomSpriteBase have to explicitely forward
69         the XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
70         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
71         remain a base class that provides implementation, not to
72         enforce any specific interface on its derivees.
73      */
74 	class CanvasCustomSpriteSpriteBase_Base : public ::canvas::BaseMutexHelper< CanvasCustomSpriteBase_Base >,
75     									   	  public Sprite,
76                                               public SurfaceProvider
77     {
78     };
79 
80 	typedef ::canvas::CanvasCustomSpriteBase< CanvasCustomSpriteSpriteBase_Base,
81                                               SpriteHelper,
82                                               CanvasHelper,
83                                               ::osl::MutexGuard,
84                                               ::cppu::OWeakObject > 					CanvasCustomSpriteBaseT;
85 
86 	/* Definition of CanvasCustomSprite class */
87 
88     class CanvasCustomSprite : public CanvasCustomSpriteBaseT,
89 							   public RepaintTarget
90     {
91     public:
92         /** Create a custom sprite
93 
94 			@param rSpriteSize
95             Size of the sprite in pixel
96 
97             @param rRefDevice
98             Associated output device
99 
100             @param rSpriteCanvas
101             Target canvas
102 
103             @param rDevice
104             Target DX device
105          */
106         CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& 	rSpriteSize,
107                             const SpriteCanvasRef&                          rRefDevice );
108 
109         virtual void SAL_CALL disposing();
110 
111 		// Forwarding the XComponent implementation to the
112         // cppu::ImplHelper templated base
113         //                                    Classname           Base doing refcount          Base implementing the XComponent interface
114         //                                          |                    |                         |
115         //                                          V                    V                         V
116         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( CanvasCustomSprite, CanvasCustomSpriteBase_Base, ::cppu::WeakComponentImplHelperBase );
117 
118         // XServiceInfo
119         virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
120         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException );
121         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()  throw( ::com::sun::star::uno::RuntimeException );
122 
123         // Sprite
124         virtual void redraw( const ::cairo::CairoSharedPtr& pCairo,
125                              bool                           bBufferedUpdate ) const;
126         virtual void redraw( const ::cairo::CairoSharedPtr& pCairo,
127                              const ::basegfx::B2DPoint&     rOrigOutputPos,
128                              bool                           bBufferedUpdate ) const;
129 
130         // RepaintTarget
131         virtual bool repaint( const ::cairo::SurfaceSharedPtr&                pSurface,
132                               const ::com::sun::star::rendering::ViewState&	  viewState,
133                               const ::com::sun::star::rendering::RenderState& renderState );
134 
135 		// SurfaceProvider
136 		virtual SurfaceSharedPtr getSurface();
137 		virtual SurfaceSharedPtr createSurface( const ::basegfx::B2ISize& rSize, Content aContent = CAIRO_CONTENT_COLOR_ALPHA );
138 		virtual SurfaceSharedPtr createSurface( ::Bitmap& rBitmap );
139 		virtual SurfaceSharedPtr changeSurface( bool bHasAlpha, bool bCopyContent );
140 		virtual OutputDevice* getOutputDevice();
141 
142     private:
143         /** MUST hold here, too, since CanvasHelper only contains a
144             raw pointer (without refcounting)
145         */
146         SpriteCanvasRef           mpSpriteCanvas;
147 		::cairo::SurfaceSharedPtr mpBufferSurface;
148 		::basegfx::B2ISize        maSize;
149     };
150 }
151 
152 #endif /* _CAIROCANVAS_CANVASCUSTOMSPRITE_HXX */
153