xref: /aoo42x/main/canvas/source/vcl/canvasbitmap.cxx (revision 25ea7f45)
1*25ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25ea7f45SAndrew Rist  * distributed with this work for additional information
6*25ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
9*25ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*25ea7f45SAndrew Rist  *
11*25ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*25ea7f45SAndrew Rist  *
13*25ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25ea7f45SAndrew Rist  * software distributed under the License is distributed on an
15*25ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25ea7f45SAndrew Rist  * specific language governing permissions and limitations
18*25ea7f45SAndrew Rist  * under the License.
19*25ea7f45SAndrew Rist  *
20*25ea7f45SAndrew Rist  *************************************************************/
21*25ea7f45SAndrew Rist 
22*25ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <canvas/debug.hxx>
28cdf0e10cSrcweir #include <tools/diagnose_ex.h>
29cdf0e10cSrcweir #include "canvasbitmap.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace vclcanvas
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     // Currently, the only way to generate an XBitmap is from
39cdf0e10cSrcweir     // XGraphicDevice.getCompatibleBitmap(). Therefore, we don't even
40cdf0e10cSrcweir     // take a bitmap here, but a VDev directly.
CanvasBitmap(const::Size & rSize,bool bAlphaBitmap,rendering::XGraphicDevice & rDevice,const OutDevProviderSharedPtr & rOutDevProvider)41cdf0e10cSrcweir     CanvasBitmap::CanvasBitmap( const ::Size&                  rSize,
42cdf0e10cSrcweir                                 bool                           bAlphaBitmap,
43cdf0e10cSrcweir                                 rendering::XGraphicDevice&     rDevice,
44cdf0e10cSrcweir                                 const OutDevProviderSharedPtr& rOutDevProvider )
45cdf0e10cSrcweir     {
46cdf0e10cSrcweir         // create bitmap for given reference device
47cdf0e10cSrcweir         // ========================================
48cdf0e10cSrcweir         const sal_uInt16 nBitCount( (sal_uInt16)24U );
49cdf0e10cSrcweir         const BitmapPalette*	pPalette = NULL;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir         Bitmap aBitmap( rSize, nBitCount, pPalette );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         // only create alpha channel bitmap, if factory requested
54cdf0e10cSrcweir         // that. Providing alpha-channeled bitmaps by default has,
55cdf0e10cSrcweir         // especially under VCL, a huge performance penalty (have to
56cdf0e10cSrcweir         // use alpha VDev, then).
57cdf0e10cSrcweir         if( bAlphaBitmap )
58cdf0e10cSrcweir         {
59cdf0e10cSrcweir             AlphaMask 	aAlpha ( rSize );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir             maCanvasHelper.init( BitmapEx( aBitmap, aAlpha ),
62cdf0e10cSrcweir                                  rDevice,
63cdf0e10cSrcweir                                  rOutDevProvider );
64cdf0e10cSrcweir         }
65cdf0e10cSrcweir         else
66cdf0e10cSrcweir         {
67cdf0e10cSrcweir             maCanvasHelper.init( BitmapEx( aBitmap ),
68cdf0e10cSrcweir                                  rDevice,
69cdf0e10cSrcweir                                  rOutDevProvider );
70cdf0e10cSrcweir         }
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
CanvasBitmap(const BitmapEx & rBitmap,rendering::XGraphicDevice & rDevice,const OutDevProviderSharedPtr & rOutDevProvider)73cdf0e10cSrcweir     CanvasBitmap::CanvasBitmap( const BitmapEx&                rBitmap,
74cdf0e10cSrcweir                                 rendering::XGraphicDevice&     rDevice,
75cdf0e10cSrcweir                                 const OutDevProviderSharedPtr& rOutDevProvider )
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir         maCanvasHelper.init( rBitmap, rDevice, rOutDevProvider );
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir 
disposing()80cdf0e10cSrcweir     void SAL_CALL CanvasBitmap::disposing()
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         // forward to base
83cdf0e10cSrcweir         CanvasBitmap_Base::disposing();
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir #define IMPLEMENTATION_NAME "VCLCanvas.CanvasBitmap"
87cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.CanvasBitmap"
88cdf0e10cSrcweir 
getImplementationName()89cdf0e10cSrcweir     ::rtl::OUString SAL_CALL CanvasBitmap::getImplementationName(  ) throw (uno::RuntimeException)
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir 
supportsService(const::rtl::OUString & ServiceName)94cdf0e10cSrcweir     sal_Bool SAL_CALL CanvasBitmap::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
95cdf0e10cSrcweir     {
96cdf0e10cSrcweir         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
getSupportedServiceNames()99cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > SAL_CALL CanvasBitmap::getSupportedServiceNames(  ) throw (uno::RuntimeException)
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aRet(1);
102cdf0e10cSrcweir         aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         return aRet;
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir 
getBitmap() const107cdf0e10cSrcweir     BitmapEx CanvasBitmap::getBitmap() const
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         tools::LocalGuard aGuard;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         // TODO(T3): Rework to use shared_ptr all over the place for
112cdf0e10cSrcweir         // BmpEx. This is highly un-threadsafe
113cdf0e10cSrcweir         return maCanvasHelper.getBitmap();
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
repaint(const GraphicObjectSharedPtr & rGrf,const rendering::ViewState & viewState,const rendering::RenderState & renderState,const::Point & rPt,const::Size & rSz,const GraphicAttr & rAttr) const116cdf0e10cSrcweir     bool CanvasBitmap::repaint( const GraphicObjectSharedPtr& rGrf,
117cdf0e10cSrcweir                                 const rendering::ViewState&   viewState,
118cdf0e10cSrcweir                                 const rendering::RenderState& renderState,
119cdf0e10cSrcweir                                 const ::Point&                rPt,
120cdf0e10cSrcweir                                 const ::Size&                 rSz,
121cdf0e10cSrcweir                                 const GraphicAttr&            rAttr ) const
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir         tools::LocalGuard aGuard;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         mbSurfaceDirty = true;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir 
getFastPropertyValue(sal_Int32 nHandle)130cdf0e10cSrcweir     uno::Any SAL_CALL CanvasBitmap::getFastPropertyValue( sal_Int32 nHandle ) throw (uno::RuntimeException)
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir         if( nHandle == 0 ) {
133cdf0e10cSrcweir             BitmapEx* pBitmapEx = new BitmapEx( getBitmap() );
134cdf0e10cSrcweir 
135cdf0e10cSrcweir             return uno::Any( reinterpret_cast<sal_Int64>( pBitmapEx ) );
136cdf0e10cSrcweir         }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         return uno::Any( sal_Int64(0) );
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir }
141