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_cppcanvas.hxx"
26 
27 #include <rtl/logfile.hxx>
28 
29 #include <com/sun/star/rendering/RepaintResult.hpp>
30 
31 #include <basegfx/matrix/b2dhommatrix.hxx>
32 #include <canvas/canvastools.hxx>
33 #include <cppcanvas/canvas.hxx>
34 
35 #include "cachedprimitivebase.hxx"
36 
37 using namespace ::com::sun::star;
38 
39 namespace cppcanvas
40 {
41     namespace internal
42     {
CachedPrimitiveBase(const CanvasSharedPtr & rCanvas,bool bOnlyRedrawWithSameTransform)43         CachedPrimitiveBase::CachedPrimitiveBase( const CanvasSharedPtr& rCanvas,
44                                                   bool                   bOnlyRedrawWithSameTransform ) :
45             mpCanvas( rCanvas ),
46             mxCachedPrimitive(),
47             maLastTransformation(),
48             mbOnlyRedrawWithSameTransform( bOnlyRedrawWithSameTransform )
49         {
50             // TODO(F2): also store last view transform, and refuse to
51             // redraw if changed.
52         }
53 
render(const::basegfx::B2DHomMatrix & rTransformation) const54         bool CachedPrimitiveBase::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
55         {
56             RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::CachedPrimitiveBase::render()" );
57             RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::CachedPrimitiveBase: 0x%X", this );
58 
59             const rendering::ViewState& rViewState( mpCanvas->getViewState() );
60             ::basegfx::B2DHomMatrix     aTotalTransform;
61 
62             ::canvas::tools::getViewStateTransform( aTotalTransform,
63                                                     rViewState );
64             aTotalTransform *= rTransformation;
65 
66             // can we use the cached primitive? For that, it must be
67             // present in the first place, and, if
68             // mbOnlyRedrawWithSameTransform is true, the overall
69             // transformation must be the same.
70             if( mxCachedPrimitive.is() &&
71                 (!mbOnlyRedrawWithSameTransform ||
72                  maLastTransformation == aTotalTransform) )
73             {
74                 if( mxCachedPrimitive->redraw( rViewState ) ==
75                     rendering::RepaintResult::REDRAWN )
76                 {
77                     // cached repaint succeeded, done.
78                     return true;
79                 }
80             }
81 
82             maLastTransformation = aTotalTransform;
83 
84             // delegate rendering to derived classes
85             return render( mxCachedPrimitive,
86                            rTransformation );
87         }
88     }
89 }
90