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