LibreOffice Module cppcanvas (master) 1
cachedprimitivebase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <com/sun/star/rendering/RepaintResult.hpp>
22
25#include <cppcanvas/canvas.hxx>
26
28#include <sal/log.hxx>
29#include <utility>
30
31using namespace ::com::sun::star;
32
33namespace cppcanvas::internal
34{
36 bool bOnlyRedrawWithSameTransform ) :
37 mpCanvas(std::move( xCanvas )),
38 mbOnlyRedrawWithSameTransform( bOnlyRedrawWithSameTransform )
39 {
40 // TODO(F2): also store last view transform, and refuse to
41 // redraw if changed.
42 }
43
44 bool CachedPrimitiveBase::render( const ::basegfx::B2DHomMatrix& rTransformation ) const
45 {
46 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::CachedPrimitiveBase::render()" );
47 SAL_INFO( "cppcanvas.emf", "::cppcanvas::internal::CachedPrimitiveBase: 0x" << std::hex << this );
48
49 const rendering::ViewState& rViewState( mpCanvas->getViewState() );
50 ::basegfx::B2DHomMatrix aTotalTransform;
51
52 ::canvas::tools::getViewStateTransform( aTotalTransform,
53 rViewState );
54 aTotalTransform *= rTransformation;
55
56 // can we use the cached primitive? For that, it must be
57 // present in the first place, and, if
58 // mbOnlyRedrawWithSameTransform is true, the overall
59 // transformation must be the same.
60 if( mxCachedPrimitive.is() &&
62 maLastTransformation == aTotalTransform) )
63 {
64 if( mxCachedPrimitive->redraw( rViewState ) ==
65 rendering::RepaintResult::REDRAWN )
66 {
67 // cached repaint succeeded, done.
68 return true;
69 }
70 }
71
72 maLastTransformation = aTotalTransform;
73
74 // delegate rendering to derived classes
76 rTransformation );
77 }
78}
79
80/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CanvasSharedPtr mpCanvas
mutable::basegfx::B2DHomMatrix maLastTransformation
css::uno::Reference< css::rendering::XCachedPrimitive > mxCachedPrimitive
virtual bool render(const ::basegfx::B2DHomMatrix &rTransformation) const override
Render this action to the associated canvas.
virtual bool renderPrimitive(css::uno::Reference< css::rendering::XCachedPrimitive > &rCachedPrimitive, const ::basegfx::B2DHomMatrix &rTransformation) const =0
CachedPrimitiveBase(CanvasSharedPtr xCanvas, bool bOnlyRedrawWithSameTransform)
Constructor.
#define SAL_INFO(area, stream)
std::shared_ptr< Canvas > CanvasSharedPtr