xref: /trunk/main/canvas/source/vcl/canvasbitmap.cxx (revision 25ea7f45)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_canvas.hxx"
26 
27 #include <canvas/debug.hxx>
28 #include <tools/diagnose_ex.h>
29 #include "canvasbitmap.hxx"
30 
31 #include <vcl/bmpacc.hxx>
32 
33 using namespace ::com::sun::star;
34 
35 
36 namespace vclcanvas
37 {
38     // Currently, the only way to generate an XBitmap is from
39     // XGraphicDevice.getCompatibleBitmap(). Therefore, we don't even
40     // take a bitmap here, but a VDev directly.
CanvasBitmap(const::Size & rSize,bool bAlphaBitmap,rendering::XGraphicDevice & rDevice,const OutDevProviderSharedPtr & rOutDevProvider)41     CanvasBitmap::CanvasBitmap( const ::Size&                  rSize,
42                                 bool                           bAlphaBitmap,
43                                 rendering::XGraphicDevice&     rDevice,
44                                 const OutDevProviderSharedPtr& rOutDevProvider )
45     {
46         // create bitmap for given reference device
47         // ========================================
48         const sal_uInt16 nBitCount( (sal_uInt16)24U );
49         const BitmapPalette*	pPalette = NULL;
50 
51         Bitmap aBitmap( rSize, nBitCount, pPalette );
52 
53         // only create alpha channel bitmap, if factory requested
54         // that. Providing alpha-channeled bitmaps by default has,
55         // especially under VCL, a huge performance penalty (have to
56         // use alpha VDev, then).
57         if( bAlphaBitmap )
58         {
59             AlphaMask 	aAlpha ( rSize );
60 
61             maCanvasHelper.init( BitmapEx( aBitmap, aAlpha ),
62                                  rDevice,
63                                  rOutDevProvider );
64         }
65         else
66         {
67             maCanvasHelper.init( BitmapEx( aBitmap ),
68                                  rDevice,
69                                  rOutDevProvider );
70         }
71     }
72 
CanvasBitmap(const BitmapEx & rBitmap,rendering::XGraphicDevice & rDevice,const OutDevProviderSharedPtr & rOutDevProvider)73     CanvasBitmap::CanvasBitmap( const BitmapEx&                rBitmap,
74                                 rendering::XGraphicDevice&     rDevice,
75                                 const OutDevProviderSharedPtr& rOutDevProvider )
76     {
77         maCanvasHelper.init( rBitmap, rDevice, rOutDevProvider );
78     }
79 
disposing()80     void SAL_CALL CanvasBitmap::disposing()
81     {
82         // forward to base
83         CanvasBitmap_Base::disposing();
84     }
85 
86 #define IMPLEMENTATION_NAME "VCLCanvas.CanvasBitmap"
87 #define SERVICE_NAME "com.sun.star.rendering.CanvasBitmap"
88 
getImplementationName()89     ::rtl::OUString SAL_CALL CanvasBitmap::getImplementationName(  ) throw (uno::RuntimeException)
90     {
91         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
92     }
93 
supportsService(const::rtl::OUString & ServiceName)94     sal_Bool SAL_CALL CanvasBitmap::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
95     {
96         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
97     }
98 
getSupportedServiceNames()99     uno::Sequence< ::rtl::OUString > SAL_CALL CanvasBitmap::getSupportedServiceNames(  ) throw (uno::RuntimeException)
100     {
101         uno::Sequence< ::rtl::OUString > aRet(1);
102         aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
103 
104         return aRet;
105     }
106 
getBitmap() const107     BitmapEx CanvasBitmap::getBitmap() const
108     {
109         tools::LocalGuard aGuard;
110 
111         // TODO(T3): Rework to use shared_ptr all over the place for
112         // BmpEx. This is highly un-threadsafe
113         return maCanvasHelper.getBitmap();
114     }
115 
repaint(const GraphicObjectSharedPtr & rGrf,const rendering::ViewState & viewState,const rendering::RenderState & renderState,const::Point & rPt,const::Size & rSz,const GraphicAttr & rAttr) const116     bool CanvasBitmap::repaint( const GraphicObjectSharedPtr& rGrf,
117                                 const rendering::ViewState&   viewState,
118                                 const rendering::RenderState& renderState,
119                                 const ::Point&                rPt,
120                                 const ::Size&                 rSz,
121                                 const GraphicAttr&            rAttr ) const
122     {
123         tools::LocalGuard aGuard;
124 
125         mbSurfaceDirty = true;
126 
127         return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
128     }
129 
getFastPropertyValue(sal_Int32 nHandle)130     uno::Any SAL_CALL CanvasBitmap::getFastPropertyValue( sal_Int32 nHandle ) throw (uno::RuntimeException)
131     {
132         if( nHandle == 0 ) {
133             BitmapEx* pBitmapEx = new BitmapEx( getBitmap() );
134 
135             return uno::Any( reinterpret_cast<sal_Int64>( pBitmapEx ) );
136         }
137 
138         return uno::Any( sal_Int64(0) );
139     }
140 }
141