Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <canvas/debug.hxx>
21 : #include <cppuhelper/supportsservice.hxx>
22 : #include <tools/diagnose_ex.h>
23 : #include "canvasbitmap.hxx"
24 :
25 : #include <vcl/bmpacc.hxx>
26 :
27 : using namespace ::com::sun::star;
28 :
29 :
30 : namespace vclcanvas
31 : {
32 : // Currently, the only way to generate an XBitmap is from
33 : // XGraphicDevice.getCompatibleBitmap(). Therefore, we don't even
34 : // take a bitmap here, but a VDev directly.
35 0 : CanvasBitmap::CanvasBitmap( const ::Size& rSize,
36 : bool bAlphaBitmap,
37 : rendering::XGraphicDevice& rDevice,
38 0 : const OutDevProviderSharedPtr& rOutDevProvider )
39 : {
40 : // create bitmap for given reference device
41 : // ========================================
42 0 : const sal_uInt16 nBitCount( (sal_uInt16)24U );
43 0 : const BitmapPalette* pPalette = NULL;
44 :
45 0 : Bitmap aBitmap( rSize, nBitCount, pPalette );
46 :
47 : // only create alpha channel bitmap, if factory requested
48 : // that. Providing alpha-channeled bitmaps by default has,
49 : // especially under VCL, a huge performance penalty (have to
50 : // use alpha VDev, then).
51 0 : if( bAlphaBitmap )
52 : {
53 0 : AlphaMask aAlpha ( rSize );
54 :
55 : maCanvasHelper.init( BitmapEx( aBitmap, aAlpha ),
56 : rDevice,
57 0 : rOutDevProvider );
58 : }
59 : else
60 : {
61 : maCanvasHelper.init( BitmapEx( aBitmap ),
62 : rDevice,
63 0 : rOutDevProvider );
64 0 : }
65 0 : }
66 :
67 0 : CanvasBitmap::CanvasBitmap( const BitmapEx& rBitmap,
68 : rendering::XGraphicDevice& rDevice,
69 0 : const OutDevProviderSharedPtr& rOutDevProvider )
70 : {
71 0 : maCanvasHelper.init( rBitmap, rDevice, rOutDevProvider );
72 0 : }
73 :
74 :
75 0 : OUString SAL_CALL CanvasBitmap::getImplementationName( ) throw (uno::RuntimeException, std::exception)
76 : {
77 0 : return OUString( "VCLCanvas.CanvasBitmap" );
78 : }
79 :
80 0 : sal_Bool SAL_CALL CanvasBitmap::supportsService( const OUString& ServiceName ) throw (uno::RuntimeException, std::exception)
81 : {
82 0 : return cppu::supportsService( this, ServiceName );
83 : }
84 :
85 0 : uno::Sequence< OUString > SAL_CALL CanvasBitmap::getSupportedServiceNames( ) throw (uno::RuntimeException, std::exception)
86 : {
87 0 : uno::Sequence< OUString > aRet(1);
88 0 : aRet[0] = "com.sun.star.rendering.CanvasBitmap";
89 :
90 0 : return aRet;
91 : }
92 :
93 0 : BitmapEx CanvasBitmap::getBitmap() const
94 : {
95 0 : SolarMutexGuard aGuard;
96 :
97 : // TODO(T3): Rework to use shared_ptr all over the place for
98 : // BmpEx. This is highly un-threadsafe
99 0 : return maCanvasHelper.getBitmap();
100 : }
101 :
102 0 : bool CanvasBitmap::repaint( const GraphicObjectSharedPtr& rGrf,
103 : const rendering::ViewState& viewState,
104 : const rendering::RenderState& renderState,
105 : const ::Point& rPt,
106 : const ::Size& rSz,
107 : const GraphicAttr& rAttr ) const
108 : {
109 0 : SolarMutexGuard aGuard;
110 :
111 0 : mbSurfaceDirty = true;
112 :
113 0 : return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
114 : }
115 :
116 0 : uno::Any SAL_CALL CanvasBitmap::getFastPropertyValue( sal_Int32 nHandle ) throw (uno::RuntimeException, std::exception)
117 : {
118 0 : if( nHandle == 0 ) {
119 0 : BitmapEx* pBitmapEx = new BitmapEx( getBitmap() );
120 :
121 0 : return uno::Any( reinterpret_cast<sal_Int64>( pBitmapEx ) );
122 : }
123 :
124 0 : return uno::Any( sal_Int64(0) );
125 : }
126 0 : }
127 :
128 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|