1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
30 
31 #include <ctype.h> // don't ask. msdev breaks otherwise...
32 #include <canvas/debug.hxx>
33 #include <canvas/verbosetrace.hxx>
34 #include <tools/diagnose_ex.h>
35 
36 #include <rtl/logfile.hxx>
37 #include <rtl/math.hxx>
38 
39 #include <canvas/canvastools.hxx>
40 
41 #include <basegfx/matrix/b2dhommatrix.hxx>
42 #include <basegfx/point/b2dpoint.hxx>
43 
44 #include "dx_canvascustomsprite.hxx"
45 #include "dx_spritecanvas.hxx"
46 #include "dx_impltools.hxx"
47 
48 using namespace ::com::sun::star;
49 
50 namespace dxcanvas
51 {
52     CanvasCustomSprite::CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& 	rSpriteSize,
53                                             const SpriteCanvasRef&                          rRefDevice,
54                                             const IDXRenderModuleSharedPtr&					rRenderModule,
55 											const ::canvas::ISurfaceProxyManagerSharedPtr&	rSurfaceProxy,
56                                             bool											bShowSpriteBounds ) :
57         mpSpriteCanvas( rRefDevice ),
58         mpSurface()
59     {
60         ENSURE_OR_THROW( rRefDevice.get(),
61                          "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
62 
63 		mpSurface.reset(
64 			new DXSurfaceBitmap(
65 				::basegfx::B2IVector(
66 					::canvas::tools::roundUp( rSpriteSize.Width ),
67 					::canvas::tools::roundUp( rSpriteSize.Height )),
68 				rSurfaceProxy,
69 				rRenderModule,
70 				true));
71 
72 		maCanvasHelper.setDevice( *rRefDevice.get() );
73         maCanvasHelper.setTarget( mpSurface );
74 
75         maSpriteHelper.init( rSpriteSize,
76                              rRefDevice,
77                              rRenderModule,
78                              mpSurface,
79                              bShowSpriteBounds );
80 
81         // clear sprite to 100% transparent
82         maCanvasHelper.clear();
83     }
84 
85     void SAL_CALL CanvasCustomSprite::disposing()
86     {
87         ::osl::MutexGuard aGuard( m_aMutex );
88 
89         mpSurface.reset();
90         mpSpriteCanvas.clear();
91 
92         // forward to parent
93         CanvasCustomSpriteBaseT::disposing();
94     }
95 
96 #define IMPLEMENTATION_NAME "DXCanvas.CanvasCustomSprite"
97 #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite"
98 
99     ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException )
100     {
101         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
102     }
103 
104     sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
105     {
106         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
107     }
108 
109     uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames()  throw( uno::RuntimeException )
110     {
111         uno::Sequence< ::rtl::OUString > aRet(1);
112         aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
113 
114         return aRet;
115     }
116 
117     void CanvasCustomSprite::redraw() const
118     {
119         ::osl::MutexGuard aGuard( m_aMutex );
120 
121         maSpriteHelper.redraw( mbSurfaceDirty );
122     }
123 }
124