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