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_SPRITECANVAS_HXX_
25 #define _CAIROCANVAS_SPRITECANVAS_HXX_
26 
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/lang/XInitialization.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/lang/XServiceName.hpp>
32 #include <com/sun/star/awt/XWindowListener.hpp>
33 #include <com/sun/star/util/XUpdatable.hpp>
34 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
35 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
36 #include <com/sun/star/rendering/XGraphicDevice.hpp>
37 #include <com/sun/star/rendering/XBufferController.hpp>
38 
39 #include <cppuhelper/compbase9.hxx>
40 #include <comphelper/uno3.hxx>
41 
42 #include <canvas/base/spritecanvasbase.hxx>
43 #include <canvas/base/basemutexhelper.hxx>
44 #include <canvas/base/bufferedgraphicdevicebase.hxx>
45 
46 #include <basegfx/vector/b2isize.hxx>
47 
48 #include "cairo_spritedevicehelper.hxx"
49 #include "cairo_repainttarget.hxx"
50 #include "cairo_surfaceprovider.hxx"
51 #include "cairo_spritecanvashelper.hxx"
52 
53 #define SPRITECANVAS_SERVICE_NAME        "com.sun.star.rendering.SpriteCanvas.Cairo"
54 #define SPRITECANVAS_IMPLEMENTATION_NAME "com.sun.star.comp.rendering.SpriteCanvas.Cairo"
55 
56 namespace cairocanvas
57 {
58     typedef ::cppu::WeakComponentImplHelper9< ::com::sun::star::rendering::XSpriteCanvas,
59                                                 ::com::sun::star::rendering::XIntegerBitmap,
60                                                 ::com::sun::star::rendering::XGraphicDevice,
61                                                 ::com::sun::star::lang::XMultiServiceFactory,
62                                                 ::com::sun::star::rendering::XBufferController,
63                                                 ::com::sun::star::awt::XWindowListener,
64                                                 ::com::sun::star::util::XUpdatable,
65                                                 ::com::sun::star::beans::XPropertySet,
66                                                 ::com::sun::star::lang::XServiceName >	WindowGraphicDeviceBase_Base;
67     typedef ::canvas::BufferedGraphicDeviceBase< ::canvas::BaseMutexHelper< WindowGraphicDeviceBase_Base >,
68                                                  SpriteDeviceHelper,
69                                                  ::osl::MutexGuard,
70                                                  ::cppu::OWeakObject > SpriteCanvasBase_Base;
71 	/** Mixin SpriteSurface
72 
73     	Have to mixin the SpriteSurface before deriving from
74     	::canvas::SpriteCanvasBase, as this template should already
75     	implement some of those interface methods.
76 
77         The reason why this appears kinda convoluted is the fact that
78         we cannot specify non-IDL types as WeakComponentImplHelperN
79         template args, and furthermore, don't want to derive
80         ::canvas::SpriteCanvasBase directly from
81         ::canvas::SpriteSurface (because derivees of
82         ::canvas::SpriteCanvasBase have to explicitly forward the
83         XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
84         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
85         remain a base class that provides implementation, not to
86         enforce any specific interface on its derivees.
87      */
88 	class SpriteCanvasBaseSpriteSurface_Base : public SpriteCanvasBase_Base,
89     										   public ::canvas::SpriteSurface,
90                                                public SurfaceProvider
91     {
92     };
93 
94 	typedef ::canvas::SpriteCanvasBase< SpriteCanvasBaseSpriteSurface_Base,
95                                         SpriteCanvasHelper,
96                                         ::osl::MutexGuard,
97                                         ::cppu::OWeakObject >			SpriteCanvasBaseT;
98 
99     /** Product of this component's factory.
100 
101 		The SpriteCanvas object combines the actual Window canvas with
102 		the XGraphicDevice interface. This is because there's a
103 		one-to-one relation between them, anyway, since each window
104 		can have exactly one canvas and one associated
105 		XGraphicDevice. And to avoid messing around with circular
106 		references, this is implemented as one single object.
107      */
108     class SpriteCanvas : public SpriteCanvasBaseT,
109 						 public RepaintTarget
110     {
111     public:
112         SpriteCanvas( const ::com::sun::star::uno::Sequence<
113                             ::com::sun::star::uno::Any >&               aArguments,
114                       const ::com::sun::star::uno::Reference<
115                             ::com::sun::star::uno::XComponentContext >& rxContext );
116 
117         void initialize();
118 
119 #if defined __SUNPRO_CC
120         using SpriteCanvasBaseT::disposing;
121 #endif
122 
123         /// Dispose all internal references
124         virtual void SAL_CALL disposing();
125 
126 		// Forwarding the XComponent implementation to the
127         // cppu::ImplHelper templated base
128         //                                    Classname     Base doing refcounting        Base implementing the XComponent interface
129         //                                       |                 |                            |
130         //                                       V                 V                            V
131         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( SpriteCanvas, WindowGraphicDeviceBase_Base, ::cppu::WeakComponentImplHelperBase );
132 
133         // XBufferController (partial)
134         virtual ::sal_Bool SAL_CALL showBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
135         virtual ::sal_Bool SAL_CALL switchBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
136 
137         // XSpriteCanvas (partial)
138         virtual sal_Bool SAL_CALL updateScreen( sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
139 
140         // XServiceName
141         virtual ::rtl::OUString SAL_CALL getServiceName(  ) throw (::com::sun::star::uno::RuntimeException);
142 
143         // SurfaceProvider
144 		virtual SurfaceSharedPtr getSurface();
145 		virtual SurfaceSharedPtr createSurface( const ::basegfx::B2ISize& rSize, Content aContent = CAIRO_CONTENT_COLOR_ALPHA );
146 		virtual SurfaceSharedPtr createSurface( ::Bitmap& rBitmap );
147 		virtual SurfaceSharedPtr changeSurface( bool bHasAlpha, bool bCopyContent );
148 		virtual OutputDevice* getOutputDevice();
149 
150         // RepaintTarget
151         virtual bool repaint( const ::cairo::SurfaceSharedPtr&                pSurface,
152                               const ::com::sun::star::rendering::ViewState&	  viewState,
153                               const ::com::sun::star::rendering::RenderState& renderState );
154 
155 		SurfaceSharedPtr getWindowSurface();
156         SurfaceSharedPtr getBufferSurface();
157 
158 		const ::basegfx::B2ISize& getSizePixel();
159 		void setSizePixel( const ::basegfx::B2ISize& rSize );
160 		void flush();
161 
162      private:
163         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > maArguments;
164         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxComponentContext;
165     };
166 
167     typedef ::rtl::Reference< SpriteCanvas > SpriteCanvasRef;
168 }
169 
170 #endif
171