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 _DXCANVAS_SPRITECANVAS_HXX_
25 #define _DXCANVAS_SPRITECANVAS_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/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 "dx_bitmapprovider.hxx"
47 #include "dx_spritecanvashelper.hxx"
48 #include "dx_surfacebitmap.hxx"
49 #include "dx_impltools.hxx"
50 #include "dx_spritedevicehelper.hxx"
51 
52 
53 namespace dxcanvas
54 {
55     typedef ::cppu::WeakComponentImplHelper9< ::com::sun::star::rendering::XSpriteCanvas,
56                                               ::com::sun::star::rendering::XIntegerBitmap,
57                                               ::com::sun::star::rendering::XGraphicDevice,
58                                               ::com::sun::star::lang::XMultiServiceFactory,
59                                               ::com::sun::star::rendering::XBufferController,
60                                               ::com::sun::star::awt::XWindowListener,
61                                               ::com::sun::star::util::XUpdatable,
62                                               ::com::sun::star::beans::XPropertySet,
63                                               ::com::sun::star::lang::XServiceName >	WindowGraphicDeviceBase_Base;
64     typedef ::canvas::BufferedGraphicDeviceBase< ::canvas::BaseMutexHelper< WindowGraphicDeviceBase_Base >,
65                                                    SpriteDeviceHelper,
66                                                    ::osl::MutexGuard,
67                                                    ::cppu::OWeakObject > 	SpriteCanvasBase_Base;
68 	/** Mixin SpriteSurface
69 
70     	Have to mixin the SpriteSurface before deriving from
71     	::canvas::SpriteCanvasBase, as this template should already
72     	implement some of those interface methods.
73 
74         The reason why this appears kinda convoluted is the fact that
75         we cannot specify non-IDL types as WeakComponentImplHelperN
76         template args, and furthermore, don't want to derive
77         ::canvas::SpriteCanvasBase directly from
78         ::canvas::SpriteSurface (because derivees of
79         ::canvas::SpriteCanvasBase have to explicitely forward the
80         XInterface methods (e.g. via DECLARE_UNO3_AGG_DEFAULTS)
81         anyway). Basically, ::canvas::CanvasCustomSpriteBase should
82         remain a base class that provides implementation, not to
83         enforce any specific interface on its derivees.
84      */
85 	class SpriteCanvasBaseSpriteSurface_Base : public SpriteCanvasBase_Base,
86     										   public ::canvas::SpriteSurface
87     {
88     };
89 
90 	typedef ::canvas::SpriteCanvasBase< SpriteCanvasBaseSpriteSurface_Base,
91                                         SpriteCanvasHelper,
92                                         ::osl::MutexGuard,
93                                         ::cppu::OWeakObject >			SpriteCanvasBaseT;
94 
95     /** Product of this component's factory.
96 
97 		The SpriteCanvas object combines the actual Window canvas with
98 		the XGraphicDevice interface. This is because there's a
99 		one-to-one relation between them, anyway, since each window
100 		can have exactly one canvas and one associated
101 		XGraphicDevice. And to avoid messing around with circular
102 		references, this is implemented as one single object.
103      */
104     class SpriteCanvas : public SpriteCanvasBaseT, public BitmapProvider
105     {
106     public:
107         SpriteCanvas( const ::com::sun::star::uno::Sequence<
108                             ::com::sun::star::uno::Any >&               aArguments,
109                       const ::com::sun::star::uno::Reference<
110                             ::com::sun::star::uno::XComponentContext >& rxContext );
111 
112         void initialize();
113 
114         /// Dispose all internal references
115         virtual void SAL_CALL disposing();
116 
117 		// Forwarding the XComponent implementation to the
118         // cppu::ImplHelper templated base
119         //                                    Classname     Base doing refcounting        Base implementing the XComponent interface
120         //                                       |                 |                            |
121         //                                       V                 V                            V
122         DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS( SpriteCanvas, WindowGraphicDeviceBase_Base, ::cppu::WeakComponentImplHelperBase );
123 
124         // XBufferController (partial)
125         virtual ::sal_Bool SAL_CALL showBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
126         virtual ::sal_Bool SAL_CALL switchBuffer( ::sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
127 
128         // XSpriteCanvas (partial)
129         virtual sal_Bool SAL_CALL updateScreen( sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException);
130 
131         // XServiceName
132         virtual ::rtl::OUString SAL_CALL getServiceName(  ) throw (::com::sun::star::uno::RuntimeException);
133 
134         /// Retrieve rendermodule object for this Canvas
135         const IDXRenderModuleSharedPtr& getRenderModule() const;
136 
137         /// Get backbuffer for this canvas
138         const DXSurfaceBitmapSharedPtr& getBackBuffer() const;
139 
140         // BitmapProvider
141         virtual IBitmapSharedPtr getBitmap() const;
142 
143      private:
144         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > maArguments;
145         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxComponentContext;
146     };
147 
148     typedef ::rtl::Reference< SpriteCanvas > SpriteCanvasRef;
149 }
150 
151 #endif
152