Branch data 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 : : #ifndef INCLUDED_SLIDESHOW_VIEWSHAPE_HXX
21 : : #define INCLUDED_SLIDESHOW_VIEWSHAPE_HXX
22 : :
23 : : #include <cppcanvas/renderer.hxx>
24 : : #include <cppcanvas/bitmap.hxx>
25 : :
26 : : #include <basegfx/range/b2drectangle.hxx>
27 : : #include <basegfx/polygon/b2dpolygon.hxx>
28 : :
29 : : #include <boost/shared_ptr.hpp>
30 : : #include <boost/utility.hpp>
31 : :
32 : : #include "tools.hxx"
33 : : #include "shapeattributelayer.hxx"
34 : : #include "animatedsprite.hxx"
35 : : #include "viewlayer.hxx"
36 : : #include "doctreenode.hxx"
37 : :
38 : : #include <vector>
39 : :
40 : :
41 : : namespace slideshow
42 : : {
43 : : namespace internal
44 : : {
45 : : /** This class is the viewable representation of a draw
46 : : document's XShape, associated to a specific View
47 : :
48 : : The class is able to render the associated XShape on
49 : : View implementations.
50 : : */
51 : 0 : class ViewShape : private boost::noncopyable
52 : : {
53 : : public:
54 : : /** Create a ViewShape for the given View
55 : :
56 : : @param rView
57 : : The associated View object.
58 : : */
59 : : explicit ViewShape( const ViewLayerSharedPtr& rViewLayer );
60 : :
61 : : /** Query the associated view layer of this shape
62 : : */
63 : : ViewLayerSharedPtr getViewLayer() const;
64 : :
65 : : /** Query dimension of a safety border around the shape for AA
66 : :
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.
71 : : */
72 : : ::basegfx::B2DSize getAntialiasingBorder() const;
73 : :
74 : :
75 : : // animation methods
76 : : //------------------------------------------------------------------
77 : :
78 : : /** Notify the ViewShape that an animation starts now
79 : :
80 : : This method enters animation mode on the associate
81 : : target view. The shape can be animated in parallel on
82 : : different views.
83 : :
84 : : @return whether the mode change finished successfully.
85 : : */
86 : : bool enterAnimationMode();
87 : :
88 : : /** Notify the ViewShape that it is no longer animated
89 : :
90 : : This methods ends animation mode on the associate
91 : : target view
92 : : */
93 : : void leaveAnimationMode();
94 : :
95 : : /** Query whether the ViewShape is currently animated
96 : :
97 : : This method checks whether the ViewShape is currently in
98 : : animation mode.
99 : : */
100 : 0 : bool isBackgroundDetached() const { return mbAnimationMode; }
101 : :
102 : :
103 : : // render methods
104 : : //------------------------------------------------------------------
105 : :
106 : : enum UpdateFlags
107 : : {
108 : : NONE= 0,
109 : : TRANSFORMATION= 1,
110 : : CLIP= 2,
111 : : ALPHA= 4,
112 : : POSITION= 8,
113 : : CONTENT= 16,
114 : : FORCE= 32
115 : : };
116 : :
117 : : struct RenderArgs
118 : : {
119 : : /** Create render argument struct
120 : :
121 : : @param rOrigBounds
122 : : The initial shape bounds
123 : :
124 : : @param rUpdateBounds
125 : : The area covered by the shape
126 : :
127 : : @param rBounds
128 : : The current shape bounds
129 : :
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!
134 : :
135 : : @param rSubsets
136 : : Vector of subset rendering ranges. Attention:
137 : : stored as a reference, thus, parameter object must
138 : : stay valid!
139 : :
140 : : @param nPrio
141 : : Shape priority
142 : : */
143 : 0 : 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 : 0 : mnShapePriority( nPrio )
157 : : {
158 : 0 : }
159 : :
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;
167 : : };
168 : :
169 : : /** Update the ViewShape
170 : :
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.
176 : :
177 : : @param rMtf
178 : : The metafile representation of the shape
179 : :
180 : : @param rArgs
181 : : Parameter structure, containing all necessary arguments
182 : :
183 : : @param nUpdateFlags
184 : : Bitmask of things to update. Use FORCE to force a repaint.
185 : :
186 : : @param bIsVisible
187 : : When false, the shape is fully invisible (and possibly
188 : : don't need to be painted)
189 : :
190 : : @return whether the rendering finished successfully.
191 : : */
192 : : bool update( const GDIMetaFileSharedPtr& rMtf,
193 : : const RenderArgs& rArgs,
194 : : int nUpdateFlags,
195 : : bool bIsVisible ) const;
196 : :
197 : : /** Retrieve renderer for given canvas and metafile.
198 : :
199 : : If necessary, the renderer is created or updated for
200 : : the metafile and attribute layer.
201 : :
202 : : @return a renderer that renders to the given
203 : : destination canvas
204 : : */
205 : : ::cppcanvas::RendererSharedPtr getRenderer( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
206 : : const GDIMetaFileSharedPtr& rMtf,
207 : : const ShapeAttributeLayerSharedPtr& rAttr ) const;
208 : :
209 : :
210 : : private:
211 : 0 : struct RendererCacheEntry
212 : : {
213 : 0 : RendererCacheEntry() :
214 : : mpDestinationCanvas(),
215 : : mpRenderer(),
216 : : mpMtf(),
217 : : mpLastBitmap(),
218 : 0 : mpLastBitmapCanvas()
219 : : {
220 : 0 : }
221 : :
222 : 0 : ::cppcanvas::CanvasSharedPtr getDestinationCanvas() const
223 : : {
224 : 0 : return mpDestinationCanvas;
225 : : }
226 : :
227 : : ::cppcanvas::CanvasSharedPtr mpDestinationCanvas;
228 : : ::cppcanvas::RendererSharedPtr mpRenderer;
229 : : GDIMetaFileSharedPtr mpMtf;
230 : : ::cppcanvas::BitmapSharedPtr mpLastBitmap;
231 : : ::cppcanvas::BitmapCanvasSharedPtr mpLastBitmapCanvas;
232 : : };
233 : :
234 : : typedef ::std::vector< RendererCacheEntry > RendererCacheVector;
235 : :
236 : :
237 : : /** Prefetch Renderer for given canvas
238 : : */
239 : : bool prefetch( RendererCacheEntry& io_rCacheEntry,
240 : : const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
241 : : const GDIMetaFileSharedPtr& rMtf,
242 : : const ShapeAttributeLayerSharedPtr& rAttr ) const;
243 : :
244 : : /** Draw with prefetched Renderer to stored canvas
245 : :
246 : : This method draws prefetched Renderer to its
247 : : associated canvas (which happens to be mpLastCanvas).
248 : : */
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;
255 : :
256 : : /** Render shape to an active sprite
257 : : */
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;
268 : :
269 : : /** Render shape to given canvas
270 : : */
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;
279 : :
280 : : /** Calc sprite size in pixel
281 : :
282 : : Converts user coordinate system to device pixel, and
283 : : adds antialiasing border.
284 : :
285 : : @param rUserSize
286 : : Size of the sprite in user coordinate system (doc coordinates)
287 : : */
288 : : ::basegfx::B2DSize calcSpriteSizePixel( const ::basegfx::B2DSize& rUserSize ) const;
289 : :
290 : : enum{ MAX_RENDER_CACHE_ENTRIES=2 };
291 : :
292 : : /** Retrieve a valid iterator to renderer cache entry
293 : :
294 : : This method ensures that an internal limit of
295 : : MAX_RENDER_CACHE_ENTRIES is not exceeded.
296 : :
297 : : @param rDestinationCanvas
298 : : Destination canvas to retrieve cache entry for
299 : :
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)
303 : : */
304 : : RendererCacheVector::iterator getCacheEntry( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas ) const;
305 : :
306 : : void invalidateRenderer() const;
307 : :
308 : : /** The view layer this object is part of.
309 : :
310 : : Needed for sprite creation
311 : : */
312 : : ViewLayerSharedPtr mpViewLayer;
313 : :
314 : : /// A set of cached mtf/canvas combinations
315 : : mutable RendererCacheVector maRenderers;
316 : :
317 : : /// The sprite object
318 : : mutable AnimatedSpriteSharedPtr mpSprite;
319 : :
320 : : /// If true, render() calls go to the sprite
321 : : mutable bool mbAnimationMode;
322 : :
323 : : /// If true, shape needs full repaint (and the sprite a setup, if any)
324 : : mutable bool mbForceUpdate;
325 : : };
326 : :
327 : : typedef ::boost::shared_ptr< ViewShape > ViewShapeSharedPtr;
328 : :
329 : : }
330 : : }
331 : :
332 : : #endif /* INCLUDED_SLIDESHOW_VIEWSHAPE_HXX */
333 : :
334 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|