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