Bump version to 5.0-14
[LibreOffice.git] / cppcanvas / source / mtfrenderer / cachedprimitivebase.cxx
blob02de8589db7325e093d1fa84236ef7c65af1a763
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 .
22 #include <com/sun/star/rendering/RepaintResult.hpp>
24 #include <basegfx/matrix/b2dhommatrix.hxx>
25 #include <canvas/canvastools.hxx>
26 #include <cppcanvas/canvas.hxx>
28 #include "cachedprimitivebase.hxx"
30 using namespace ::com::sun::star;
32 namespace cppcanvas
34 namespace internal
36 CachedPrimitiveBase::CachedPrimitiveBase( const CanvasSharedPtr& rCanvas,
37 bool bOnlyRedrawWithSameTransform ) :
38 mpCanvas( rCanvas ),
39 mxCachedPrimitive(),
40 maLastTransformation(),
41 mbOnlyRedrawWithSameTransform( bOnlyRedrawWithSameTransform )
43 // TODO(F2): also store last view transform, and refuse to
44 // redraw if changed.
47 bool CachedPrimitiveBase::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
49 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::CachedPrimitiveBase::render()" );
50 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::CachedPrimitiveBase: 0x" << std::hex << this );
52 const rendering::ViewState& rViewState( mpCanvas->getViewState() );
53 ::basegfx::B2DHomMatrix aTotalTransform;
55 ::canvas::tools::getViewStateTransform( aTotalTransform,
56 rViewState );
57 aTotalTransform *= rTransformation;
59 // can we use the cached primitive? For that, it must be
60 // present in the first place, and, if
61 // mbOnlyRedrawWithSameTransform is true, the overall
62 // transformation must be the same.
63 if( mxCachedPrimitive.is() &&
64 (!mbOnlyRedrawWithSameTransform ||
65 maLastTransformation == aTotalTransform) )
67 if( mxCachedPrimitive->redraw( rViewState ) ==
68 rendering::RepaintResult::REDRAWN )
70 // cached repaint succeeded, done.
71 return true;
75 maLastTransformation = aTotalTransform;
77 // delegate rendering to derived classes
78 return renderPrimitive( mxCachedPrimitive,
79 rTransformation );
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */