1*25b11142SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25b11142SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25b11142SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25b11142SAndrew Rist  * distributed with this work for additional information
6*25b11142SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25b11142SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25b11142SAndrew Rist  * "License"); you may not use this file except in compliance
9*25b11142SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*25b11142SAndrew Rist  *
11*25b11142SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*25b11142SAndrew Rist  *
13*25b11142SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25b11142SAndrew Rist  * software distributed under the License is distributed on an
15*25b11142SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25b11142SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25b11142SAndrew Rist  * specific language governing permissions and limitations
18*25b11142SAndrew Rist  * under the License.
19*25b11142SAndrew Rist  *
20*25b11142SAndrew Rist  *************************************************************/
21*25b11142SAndrew Rist 
22*25b11142SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cppcanvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rtl/logfile.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/rendering/RepaintResult.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
32cdf0e10cSrcweir #include <canvas/canvastools.hxx>
33cdf0e10cSrcweir #include <cppcanvas/canvas.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "cachedprimitivebase.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace cppcanvas
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     namespace internal
42cdf0e10cSrcweir     {
CachedPrimitiveBase(const CanvasSharedPtr & rCanvas,bool bOnlyRedrawWithSameTransform)43cdf0e10cSrcweir         CachedPrimitiveBase::CachedPrimitiveBase( const CanvasSharedPtr& rCanvas,
44cdf0e10cSrcweir                                                   bool                   bOnlyRedrawWithSameTransform ) :
45cdf0e10cSrcweir             mpCanvas( rCanvas ),
46cdf0e10cSrcweir             mxCachedPrimitive(),
47cdf0e10cSrcweir             maLastTransformation(),
48cdf0e10cSrcweir             mbOnlyRedrawWithSameTransform( bOnlyRedrawWithSameTransform )
49cdf0e10cSrcweir         {
50cdf0e10cSrcweir             // TODO(F2): also store last view transform, and refuse to
51cdf0e10cSrcweir             // redraw if changed.
52cdf0e10cSrcweir         }
53cdf0e10cSrcweir 
render(const::basegfx::B2DHomMatrix & rTransformation) const54cdf0e10cSrcweir         bool CachedPrimitiveBase::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
55cdf0e10cSrcweir         {
56cdf0e10cSrcweir             RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::CachedPrimitiveBase::render()" );
57cdf0e10cSrcweir             RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::CachedPrimitiveBase: 0x%X", this );
58cdf0e10cSrcweir 
59cdf0e10cSrcweir             const rendering::ViewState& rViewState( mpCanvas->getViewState() );
60cdf0e10cSrcweir             ::basegfx::B2DHomMatrix     aTotalTransform;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir             ::canvas::tools::getViewStateTransform( aTotalTransform,
63cdf0e10cSrcweir                                                     rViewState );
64cdf0e10cSrcweir             aTotalTransform *= rTransformation;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir             // can we use the cached primitive? For that, it must be
67cdf0e10cSrcweir             // present in the first place, and, if
68cdf0e10cSrcweir             // mbOnlyRedrawWithSameTransform is true, the overall
69cdf0e10cSrcweir             // transformation must be the same.
70cdf0e10cSrcweir             if( mxCachedPrimitive.is() &&
71cdf0e10cSrcweir                 (!mbOnlyRedrawWithSameTransform ||
72cdf0e10cSrcweir                  maLastTransformation == aTotalTransform) )
73cdf0e10cSrcweir             {
74cdf0e10cSrcweir                 if( mxCachedPrimitive->redraw( rViewState ) ==
75cdf0e10cSrcweir                     rendering::RepaintResult::REDRAWN )
76cdf0e10cSrcweir                 {
77cdf0e10cSrcweir                     // cached repaint succeeded, done.
78cdf0e10cSrcweir                     return true;
79cdf0e10cSrcweir                 }
80cdf0e10cSrcweir             }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir             maLastTransformation = aTotalTransform;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir             // delegate rendering to derived classes
85cdf0e10cSrcweir             return render( mxCachedPrimitive,
86cdf0e10cSrcweir                            rTransformation );
87cdf0e10cSrcweir         }
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir }
90