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