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