xref: /trunk/main/canvas/inc/canvas/base/bitmapcanvasbase.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 #ifndef INCLUDED_CANVAS_BITMAPCANVASBASE_HXX
23 #define INCLUDED_CANVAS_BITMAPCANVASBASE_HXX
24 
25 #include <canvas/base/canvasbase.hxx>
26 #include <com/sun/star/rendering/XBitmapCanvas.hpp>
27 
28 namespace canvas
29 {
30     /** Helper template to handle XBitmapCanvas method forwarding to
31         BitmapCanvasHelper
32 
33         Use this helper to handle the XBitmapCanvas part of your
34         implementation.
35 
36         @tpl Base
37         Base class to use, most probably one of the
38         WeakComponentImplHelperN templates with the appropriate
39         interfaces. At least XBitmapCanvas should be among them (why
40         else would you use this template, then?). Base class must have
41         an Base( const Mutex& ) constructor (like the
42         WeakComponentImplHelperN templates have).
43 
44         @tpl CanvasHelper
45         Canvas helper implementation for the backend in question
46 
47         @tpl Mutex
48         Lock strategy to use. Defaults to using the
49         OBaseMutex-provided lock.  Every time one of the methods is
50         entered, an object of type Mutex is created with m_aMutex as
51         the sole parameter, and destroyed again when the method scope
52         is left.
53 
54         @tpl UnambiguousBase
55         Optional unambiguous base class for XInterface of Base. It's
56         sometimes necessary to specify this parameter, e.g. if Base
57         derives from multiple UNO interface (were each provides its
58         own version of XInterface, making the conversion ambiguous)
59 
60         @see CanvasBase for further contractual requirements towards
61         the CanvasHelper type, and some examples.
62      */
63     template< class Base,
64               class CanvasHelper,
65               class Mutex=::osl::MutexGuard,
66               class UnambiguousBase=::com::sun::star::uno::XInterface > class BitmapCanvasBase :
67         public CanvasBase< Base, CanvasHelper, Mutex, UnambiguousBase >
68     {
69     public:
70         typedef CanvasBase< Base, CanvasHelper, Mutex, UnambiguousBase >    BaseType;
71 
72         // XBitmapCanvas
copyRect(const::com::sun::star::uno::Reference<::com::sun::star::rendering::XBitmapCanvas> & sourceCanvas,const::com::sun::star::geometry::RealRectangle2D & sourceRect,const::com::sun::star::rendering::ViewState & sourceViewState,const::com::sun::star::rendering::RenderState & sourceRenderState,const::com::sun::star::geometry::RealRectangle2D & destRect,const::com::sun::star::rendering::ViewState & destViewState,const::com::sun::star::rendering::RenderState & destRenderState)73         virtual void SAL_CALL copyRect( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas >&   sourceCanvas,
74                                         const ::com::sun::star::geometry::RealRectangle2D&                                      sourceRect,
75                                         const ::com::sun::star::rendering::ViewState&                                           sourceViewState,
76                                         const ::com::sun::star::rendering::RenderState&                                         sourceRenderState,
77                                         const ::com::sun::star::geometry::RealRectangle2D&                                      destRect,
78                                         const ::com::sun::star::rendering::ViewState&                                           destViewState,
79                                         const ::com::sun::star::rendering::RenderState&                                         destRenderState )
80         {
81             tools::verifyArgs(sourceCanvas, sourceRect, sourceViewState, sourceRenderState,
82                               destRect, destViewState, destRenderState,
83                               BOOST_CURRENT_FUNCTION,
84                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
85 
86             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
87 
88             BaseType::mbSurfaceDirty = true;
89             BaseType::maCanvasHelper.modifying();
90 
91             BaseType::maCanvasHelper.copyRect( this,
92                                                sourceCanvas,
93                                                sourceRect,
94                                                sourceViewState,
95                                                sourceRenderState,
96                                                destRect,
97                                                destViewState,
98                                                destRenderState );
99         }
100 
101         // XBitmap
getSize()102         virtual ::com::sun::star::geometry::IntegerSize2D SAL_CALL getSize(  )
103         {
104             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
105 
106             return BaseType::maCanvasHelper.getSize();
107         }
108 
hasAlpha()109         virtual ::sal_Bool SAL_CALL hasAlpha(  )
110         {
111             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
112 
113             return BaseType::maCanvasHelper.hasAlpha();
114         }
115 
getScaledBitmap(const::com::sun::star::geometry::RealSize2D & newSize,sal_Bool beFast)116         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > SAL_CALL getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& newSize,
117                                                                                                                    sal_Bool                                      beFast )
118         {
119             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
120 
121             return BaseType::maCanvasHelper.getScaledBitmap( newSize, beFast );
122         }
123 
124     };
125 }
126 
127 #endif /* INCLUDED_CANVAS_BITMAPCANVASBASE_HXX */
128 
129 /* vim: set noet sw=4 ts=4: */
130