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