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 <ctype.h> // don't ask. msdev breaks otherwise...
28 #include <canvas/debug.hxx>
29 #include <canvas/verbosetrace.hxx>
30 #include <tools/diagnose_ex.h>
31 
32 #include <rtl/logfile.hxx>
33 #include <rtl/math.hxx>
34 
35 #include <canvas/canvastools.hxx>
36 
37 #include <basegfx/matrix/b2dhommatrix.hxx>
38 #include <basegfx/point/b2dpoint.hxx>
39 
40 #include "dx_canvascustomsprite.hxx"
41 #include "dx_spritecanvas.hxx"
42 #include "dx_impltools.hxx"
43 
44 using namespace ::com::sun::star;
45 
46 namespace dxcanvas
47 {
CanvasCustomSprite(const::com::sun::star::geometry::RealSize2D & rSpriteSize,const SpriteCanvasRef & rRefDevice,const IDXRenderModuleSharedPtr & rRenderModule,const::canvas::ISurfaceProxyManagerSharedPtr & rSurfaceProxy,bool bShowSpriteBounds)48     CanvasCustomSprite::CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& 	rSpriteSize,
49                                             const SpriteCanvasRef&                          rRefDevice,
50                                             const IDXRenderModuleSharedPtr&					rRenderModule,
51 											const ::canvas::ISurfaceProxyManagerSharedPtr&	rSurfaceProxy,
52                                             bool											bShowSpriteBounds ) :
53         mpSpriteCanvas( rRefDevice ),
54         mpSurface()
55     {
56         ENSURE_OR_THROW( rRefDevice.get(),
57                          "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
58 
59 		mpSurface.reset(
60 			new DXSurfaceBitmap(
61 				::basegfx::B2IVector(
62 					::canvas::tools::roundUp( rSpriteSize.Width ),
63 					::canvas::tools::roundUp( rSpriteSize.Height )),
64 				rSurfaceProxy,
65 				rRenderModule,
66 				true));
67 
68 		maCanvasHelper.setDevice( *rRefDevice.get() );
69         maCanvasHelper.setTarget( mpSurface );
70 
71         maSpriteHelper.init( rSpriteSize,
72                              rRefDevice,
73                              rRenderModule,
74                              mpSurface,
75                              bShowSpriteBounds );
76 
77         // clear sprite to 100% transparent
78         maCanvasHelper.clear();
79     }
80 
disposing()81     void SAL_CALL CanvasCustomSprite::disposing()
82     {
83         ::osl::MutexGuard aGuard( m_aMutex );
84 
85         mpSurface.reset();
86         mpSpriteCanvas.clear();
87 
88         // forward to parent
89         CanvasCustomSpriteBaseT::disposing();
90     }
91 
92 #define IMPLEMENTATION_NAME "DXCanvas.CanvasCustomSprite"
93 #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite"
94 
getImplementationName()95     ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException )
96     {
97         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
98     }
99 
supportsService(const::rtl::OUString & ServiceName)100     sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
101     {
102         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
103     }
104 
getSupportedServiceNames()105     uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames()  throw( uno::RuntimeException )
106     {
107         uno::Sequence< ::rtl::OUString > aRet(1);
108         aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
109 
110         return aRet;
111     }
112 
redraw() const113     void CanvasCustomSprite::redraw() const
114     {
115         ::osl::MutexGuard aGuard( m_aMutex );
116 
117         maSpriteHelper.redraw( mbSurfaceDirty );
118     }
119 }
120