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 <canvas/debug.hxx>
32 #include <canvas/base/cachedprimitivebase.hxx>
33 
34 #include <com/sun/star/rendering/RepaintResult.hpp>
35 
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <basegfx/tools/canvastools.hxx>
38 
39 
40 using namespace ::com::sun::star;
41 
42 #define IMPLEMENTATION_NAME "canvas::CachedPrimitiveBase"
43 #define SERVICE_NAME "com.sun.star.rendering.CachedBitmap"
44 
45 namespace canvas
46 {
47     CachedPrimitiveBase::CachedPrimitiveBase( const rendering::ViewState&					rUsedViewState,
48                                               const uno::Reference< rendering::XCanvas >&	rTarget,
49                                               bool											bFailForChangedViewTransform ) :
50         CachedPrimitiveBase_Base( m_aMutex ),
51         maUsedViewState( rUsedViewState ),
52         mxTarget( rTarget ),
53         mbFailForChangedViewTransform( bFailForChangedViewTransform )
54     {
55     }
56 
57     CachedPrimitiveBase::~CachedPrimitiveBase()
58     {
59     }
60 
61     void SAL_CALL CachedPrimitiveBase::disposing()
62     {
63         ::osl::MutexGuard aGuard( m_aMutex );
64 
65         maUsedViewState.Clip.clear();
66         mxTarget.clear();
67     }
68 
69     sal_Int8 SAL_CALL CachedPrimitiveBase::redraw( const rendering::ViewState& aState ) throw (lang::IllegalArgumentException, uno::RuntimeException)
70     {
71         ::basegfx::B2DHomMatrix aUsedTransformation;
72         ::basegfx::B2DHomMatrix aNewTransformation;
73 
74         ::basegfx::unotools::homMatrixFromAffineMatrix( aUsedTransformation,
75                                                         maUsedViewState.AffineTransform );
76         ::basegfx::unotools::homMatrixFromAffineMatrix( aNewTransformation,
77                                                         aState.AffineTransform );
78 
79         const bool bSameViewTransforms( aUsedTransformation == aNewTransformation );
80 
81         if( mbFailForChangedViewTransform &&
82             !bSameViewTransforms )
83         {
84             // differing transformations, don't try to draft the
85             // output, just plain fail here.
86             return rendering::RepaintResult::FAILED;
87         }
88 
89         return doRedraw( aState,
90                          maUsedViewState,
91                          mxTarget,
92                          bSameViewTransforms );
93     }
94 
95     ::rtl::OUString SAL_CALL CachedPrimitiveBase::getImplementationName(  ) throw (uno::RuntimeException)
96     {
97         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
98     }
99 
100     sal_Bool SAL_CALL CachedPrimitiveBase::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
101     {
102         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
103     }
104 
105     uno::Sequence< ::rtl::OUString > SAL_CALL CachedPrimitiveBase::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 }
113