Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / cppcanvas / source / mtfrenderer / cachedprimitivebase.cxx
blob8ffa1c6ab862008ec705f5ea35073bda1812eb01
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/rendering/RepaintResult.hpp>
23 #include <basegfx/matrix/b2dhommatrix.hxx>
24 #include <canvas/canvastools.hxx>
25 #include <cppcanvas/canvas.hxx>
27 #include "cachedprimitivebase.hxx"
29 using namespace ::com::sun::star;
31 namespace cppcanvas
33 namespace internal
35 CachedPrimitiveBase::CachedPrimitiveBase( const CanvasSharedPtr& rCanvas,
36 bool bOnlyRedrawWithSameTransform ) :
37 mpCanvas( rCanvas ),
38 mxCachedPrimitive(),
39 maLastTransformation(),
40 mbOnlyRedrawWithSameTransform( bOnlyRedrawWithSameTransform )
42 // TODO(F2): also store last view transform, and refuse to
43 // redraw if changed.
46 bool CachedPrimitiveBase::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
48 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::CachedPrimitiveBase::render()" );
49 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::CachedPrimitiveBase: 0x" << std::hex << this );
51 const rendering::ViewState& rViewState( mpCanvas->getViewState() );
52 ::basegfx::B2DHomMatrix aTotalTransform;
54 ::canvas::tools::getViewStateTransform( aTotalTransform,
55 rViewState );
56 aTotalTransform *= rTransformation;
58 // can we use the cached primitive? For that, it must be
59 // present in the first place, and, if
60 // mbOnlyRedrawWithSameTransform is true, the overall
61 // transformation must be the same.
62 if( mxCachedPrimitive.is() &&
63 (!mbOnlyRedrawWithSameTransform ||
64 maLastTransformation == aTotalTransform) )
66 if( mxCachedPrimitive->redraw( rViewState ) ==
67 rendering::RepaintResult::REDRAWN )
69 // cached repaint succeeded, done.
70 return true;
74 maLastTransformation = aTotalTransform;
76 // delegate rendering to derived classes
77 return renderPrimitive( mxCachedPrimitive,
78 rTransformation );
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */