fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / shapes / viewshape.hxx
blobfcddf74c9884b4f6b39314d3981b34654d8aa9b4
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 .
20 #ifndef INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_VIEWSHAPE_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_VIEWSHAPE_HXX
23 #include <cppcanvas/renderer.hxx>
24 #include <cppcanvas/bitmap.hxx>
26 #include <basegfx/range/b2drectangle.hxx>
27 #include <basegfx/polygon/b2dpolygon.hxx>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/utility.hpp>
32 #include "tools.hxx"
33 #include "shapeattributelayer.hxx"
34 #include "animatedsprite.hxx"
35 #include "viewlayer.hxx"
36 #include "doctreenode.hxx"
38 #include <vector>
41 namespace slideshow
43 namespace internal
45 /** This class is the viewable representation of a draw
46 document's XShape, associated to a specific View
48 The class is able to render the associated XShape on
49 View implementations.
51 class ViewShape : private boost::noncopyable
53 public:
54 /** Create a ViewShape for the given View
56 @param rView
57 The associated View object.
59 explicit ViewShape( const ViewLayerSharedPtr& rViewLayer );
61 /** Query the associated view layer of this shape
63 ViewLayerSharedPtr getViewLayer() const;
65 /** Query dimension of a safety border around the shape for AA
67 If the view performs antialiasing, this method
68 calculates a safety border around the shape, in the
69 shape coordinate system, which is guaranteed to
70 include every pixel touched when rendering the shape.
72 ::basegfx::B2DSize getAntialiasingBorder() const;
75 // animation methods
78 /** Notify the ViewShape that an animation starts now
80 This method enters animation mode on the associate
81 target view. The shape can be animated in parallel on
82 different views.
84 @return whether the mode change finished successfully.
86 bool enterAnimationMode();
88 /** Notify the ViewShape that it is no longer animated
90 This methods ends animation mode on the associate
91 target view
93 void leaveAnimationMode();
95 /** Query whether the ViewShape is currently animated
97 This method checks whether the ViewShape is currently in
98 animation mode.
100 bool isBackgroundDetached() const { return mbAnimationMode; }
103 // render methods
106 enum UpdateFlags
108 NONE= 0,
109 TRANSFORMATION= 1,
110 CLIP= 2,
111 ALPHA= 4,
112 POSITION= 8,
113 CONTENT= 16,
114 FORCE= 32
117 struct RenderArgs
119 /** Create render argument struct
121 @param rOrigBounds
122 The initial shape bounds
124 @param rUpdateBounds
125 The area covered by the shape
127 @param rBounds
128 The current shape bounds
130 @param rAttr
131 The current shape attribute set. Can be NULL, for
132 default attributes. Attention: stored as a reference,
133 thus, parameter object must stay valid!
135 @param rSubsets
136 Vector of subset rendering ranges. Attention:
137 stored as a reference, thus, parameter object must
138 stay valid!
140 @param nPrio
141 Shape priority
143 RenderArgs( const ::basegfx::B2DRectangle& rOrigBounds,
144 const ::basegfx::B2DRectangle& rUpdateBounds,
145 const ::basegfx::B2DRectangle& rBounds,
146 const ::basegfx::B2DRectangle& rUnitBounds,
147 const ShapeAttributeLayerSharedPtr& rAttr,
148 const VectorOfDocTreeNodes& rSubsets,
149 double nPrio ) :
150 maOrigBounds( rOrigBounds ),
151 maUpdateBounds( rUpdateBounds ),
152 maBounds( rBounds ),
153 maUnitBounds( rUnitBounds ),
154 mrAttr( rAttr ),
155 mrSubsets( rSubsets ),
156 mnShapePriority( nPrio )
160 const ::basegfx::B2DRectangle maOrigBounds;
161 const ::basegfx::B2DRectangle maUpdateBounds;
162 const ::basegfx::B2DRectangle maBounds;
163 const ::basegfx::B2DRectangle maUnitBounds;
164 const ShapeAttributeLayerSharedPtr& mrAttr;
165 const VectorOfDocTreeNodes& mrSubsets;
166 const double mnShapePriority;
169 /** Update the ViewShape
171 This method updates the ViewShape on the associated
172 view. If the shape is currently animated, the render
173 target is the sprite, otherwise the view's
174 canvas. This method does not render anything, if the
175 update flags are 0.
177 @param rMtf
178 The metafile representation of the shape
180 @param rArgs
181 Parameter structure, containing all necessary arguments
183 @param nUpdateFlags
184 Bitmask of things to update. Use FORCE to force a repaint.
186 @param bIsVisible
187 When false, the shape is fully invisible (and possibly
188 don't need to be painted)
190 @return whether the rendering finished successfully.
192 bool update( const GDIMetaFileSharedPtr& rMtf,
193 const RenderArgs& rArgs,
194 int nUpdateFlags,
195 bool bIsVisible ) const;
197 /** Retrieve renderer for given canvas and metafile.
199 If necessary, the renderer is created or updated for
200 the metafile and attribute layer.
202 @return a renderer that renders to the given
203 destination canvas
205 ::cppcanvas::RendererSharedPtr getRenderer( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
206 const GDIMetaFileSharedPtr& rMtf,
207 const ShapeAttributeLayerSharedPtr& rAttr ) const;
210 private:
211 struct RendererCacheEntry
213 RendererCacheEntry() :
214 mpDestinationCanvas(),
215 mpRenderer(),
216 mpMtf(),
217 mpLastBitmap(),
218 mpLastBitmapCanvas()
222 ::cppcanvas::CanvasSharedPtr getDestinationCanvas() const
224 return mpDestinationCanvas;
227 ::cppcanvas::CanvasSharedPtr mpDestinationCanvas;
228 ::cppcanvas::RendererSharedPtr mpRenderer;
229 GDIMetaFileSharedPtr mpMtf;
230 ::cppcanvas::BitmapSharedPtr mpLastBitmap;
231 ::cppcanvas::BitmapCanvasSharedPtr mpLastBitmapCanvas;
234 typedef ::std::vector< RendererCacheEntry > RendererCacheVector;
237 /** Prefetch Renderer for given canvas
239 static bool prefetch( RendererCacheEntry& io_rCacheEntry,
240 const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
241 const GDIMetaFileSharedPtr& rMtf,
242 const ShapeAttributeLayerSharedPtr& rAttr );
244 /** Draw with prefetched Renderer to stored canvas
246 This method draws prefetched Renderer to its
247 associated canvas (which happens to be mpLastCanvas).
249 bool draw( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
250 const GDIMetaFileSharedPtr& rMtf,
251 const ShapeAttributeLayerSharedPtr& rAttr,
252 const ::basegfx::B2DHomMatrix& rTransform,
253 const ::basegfx::B2DPolyPolygon* pClip,
254 const VectorOfDocTreeNodes& rSubsets ) const;
256 /** Render shape to an active sprite
258 bool renderSprite( const ViewLayerSharedPtr& rViewLayer,
259 const GDIMetaFileSharedPtr& rMtf,
260 const ::basegfx::B2DRectangle& rOrigBounds,
261 const ::basegfx::B2DRectangle& rBounds,
262 const ::basegfx::B2DRectangle& rUnitBounds,
263 int nUpdateFlags,
264 const ShapeAttributeLayerSharedPtr& pAttr,
265 const VectorOfDocTreeNodes& rSubsets,
266 double nPrio,
267 bool bIsVisible ) const;
269 /** Render shape to given canvas
271 bool render( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
272 const GDIMetaFileSharedPtr& rMtf,
273 const ::basegfx::B2DRectangle& rBounds,
274 const ::basegfx::B2DRectangle& rUpdateBounds,
275 int nUpdateFlags,
276 const ShapeAttributeLayerSharedPtr& pAttr,
277 const VectorOfDocTreeNodes& rSubsets,
278 bool bIsVisible ) const;
280 /** Calc sprite size in pixel
282 Converts user coordinate system to device pixel, and
283 adds antialiasing border.
285 @param rUserSize
286 Size of the sprite in user coordinate system (doc coordinates)
288 ::basegfx::B2DSize calcSpriteSizePixel( const ::basegfx::B2DSize& rUserSize ) const;
290 enum{ MAX_RENDER_CACHE_ENTRIES=2 };
292 /** Retrieve a valid iterator to renderer cache entry
294 This method ensures that an internal limit of
295 MAX_RENDER_CACHE_ENTRIES is not exceeded.
297 @param rDestinationCanvas
298 Destination canvas to retrieve cache entry for
300 @return a valid iterator to a renderer cache entry for
301 the given canvas. The entry might be
302 default-constructed (if newly added)
304 RendererCacheVector::iterator getCacheEntry( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas ) const;
306 void invalidateRenderer() const;
308 /** The view layer this object is part of.
310 Needed for sprite creation
312 ViewLayerSharedPtr mpViewLayer;
314 /// A set of cached mtf/canvas combinations
315 mutable RendererCacheVector maRenderers;
317 /// The sprite object
318 mutable AnimatedSpriteSharedPtr mpSprite;
320 /// If true, render() calls go to the sprite
321 mutable bool mbAnimationMode;
323 /// If true, shape needs full repaint (and the sprite a setup, if any)
324 mutable bool mbForceUpdate;
327 typedef ::boost::shared_ptr< ViewShape > ViewShapeSharedPtr;
332 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_VIEWSHAPE_HXX
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */