Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / slide / layermanager.hxx
blob44e391fe5c7dfa7c31a5e1e2af63e903a87e054c
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_SLIDE_LAYERMANAGER_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYERMANAGER_HXX
23 #include <cppcanvas/spritecanvas.hxx>
25 #include <unoview.hxx>
26 #include <unoviewcontainer.hxx>
27 #include <attributableshape.hxx>
28 #include "layer.hxx"
29 #include <tools.hxx>
31 #include <algorithm>
32 #include <functional>
33 #include <memory>
34 #include <map>
35 #include <unordered_map>
36 #include <vector>
38 namespace basegfx {
39 class B2DRange;
42 namespace slideshow
44 namespace internal
46 /* Definition of Layermanager class */
48 /** This class manages all of a slide's layers (and shapes)
50 Since layer content changes when animations start or end,
51 the layer manager keeps track of this and also handles
52 starting/stopping of Shape animations. Note that none of
53 the methods actually perform a screen update, this is
54 always delayed until the ActivitiesQueue explicitly
55 performs it.
57 @see Layer
58 @see Shape
60 class LayerManager
62 public:
63 /** Create a new layer manager for the given page bounds
65 @param rViews
66 Views currently registered
68 @param bDisableAnimationZOrder
69 When true, all sprite animations run in the
70 foreground. That is, no extra layers are created, and
71 the slideshow runs potentially faster.
73 LayerManager( const UnoViewContainer& rViews,
74 bool bDisableAnimationZOrder );
76 /// Forbid copy construction
77 LayerManager(const LayerManager&) = delete;
79 /// Forbid copy assignment
80 LayerManager& operator=(const LayerManager&) = delete;
82 /** Activate the LayerManager
84 This method activates the LayerManager. Prior to
85 activation, this instance will be passive, i.e. won't
86 render anything to any view.
88 void activate();
90 /** Deactivate the LayerManager
92 This method deactivates the LayerManager. After
93 deactivation, this instance will be passive,
94 i.e. don't render anything to any view. Furthermore,
95 if there's currently more than one Layer active, this
96 method also removes all but one.
98 void deactivate();
100 // From ViewEventHandler, forwarded by SlideImpl
101 /// Notify new view added to UnoViewContainer
102 void viewAdded( const UnoViewSharedPtr& rView );
103 /// Notify view removed from UnoViewContainer
104 void viewRemoved( const UnoViewSharedPtr& rView );
105 void viewChanged( const UnoViewSharedPtr& rView );
106 void viewsChanged();
108 /** Add the shape to this object
110 This method adds a shape to the page.
112 void addShape( const ShapeSharedPtr& rShape );
114 /** Lookup a Shape from an XShape model object
116 This method looks up the internal shape map for one
117 representing the given XShape.
119 @param xShape
120 The XShape object, for which the representing Shape
121 should be looked up.
123 ShapeSharedPtr lookupShape( const css::uno::Reference< css::drawing::XShape >& xShape ) const;
125 /** Query a subset of the given original shape
127 This method queries a new (but not necessarily unique)
128 shape, which displays only the given subset of the
129 original one.
131 AttributableShapeSharedPtr getSubsetShape( const AttributableShapeSharedPtr& rOrigShape,
132 const DocTreeNode& rTreeNode );
134 /** Revoke a previously queried subset shape.
136 With this method, a previously requested subset shape
137 is revoked again. If the last client revokes a given
138 subset, it will cease to be displayed, and the
139 original shape will again show the subset data.
141 @param rOrigShape
142 The shape the subset was created from
144 @param rSubsetShape
145 The subset created from rOrigShape
147 void revokeSubset( const AttributableShapeSharedPtr& rOrigShape,
148 const AttributableShapeSharedPtr& rSubsetShape );
150 /** Notify the LayerManager that the given Shape starts an
151 animation now.
153 This method enters animation mode for the Shape on all
154 registered views.
156 void enterAnimationMode( const AnimatableShapeSharedPtr& rShape );
158 /** Notify the LayerManager that the given Shape is no
159 longer animated.
161 This methods ends animation mode for the given Shape
162 on all registered views.
164 void leaveAnimationMode( const AnimatableShapeSharedPtr& rShape );
166 /** Notify that a shape needs an update
168 This method notifies the layer manager that a shape
169 update is necessary. This is useful if, during
170 animation playback, changes occur to shapes which make
171 an update necessary on an update() call. Otherwise,
172 update() will not render anything, which is not
173 triggered by calling one of the other LayerManager
174 methods.
176 @param rShape
177 Shape which needs an update
179 void notifyShapeUpdate( const ShapeSharedPtr& rShape);
181 /** Check whether any update operations are pending.
183 @return true, if this LayerManager has any updates
184 pending, i.e. needs to repaint something for the next
185 frame.
187 bool isUpdatePending() const;
189 /** Update the content
191 This method updates the content on all layers on all
192 registered views. It does not issues a
193 View::updateScreen() call on registered views. Please
194 note that this method only takes into account changes
195 to shapes induced directly by calling methods of the
196 LayerManager. If a shape needs an update, because of
197 some external event unknown to the LayerManager (most
198 notably running animations), you have to notify the
199 LayerManager via notifyShapeUpdate().
201 @see LayerManager::updateScreen()
203 @return whether the update finished successfully.
205 bool update();
207 /** Render the content to given canvas
209 This is a one-shot operation, which simply draws all
210 shapes onto the given canvas, without any caching or
211 other fuzz. Don't use that for repeated output onto
212 the same canvas, the View concept is more optimal
213 then.
215 @param rTargetCanvas
216 Target canvas to output onto.
218 bool renderTo( const ::cppcanvas::CanvasSharedPtr& rTargetCanvas ) const;
220 private:
221 /** A hash map which maps the XShape to the corresponding Shape object.
223 Provides quicker lookup than ShapeSet for simple mappings
225 typedef std::unordered_map<
226 css::uno::Reference< css::drawing::XShape >,
227 ShapeSharedPtr,
228 hash< css::uno::Reference< css::drawing::XShape > >
229 > XShapeHash;
231 class ShapeComparator
233 public:
234 bool operator() (const ShapeSharedPtr& rpS1, const ShapeSharedPtr& rpS2 ) const
236 return Shape::lessThanShape::compare(rpS1.get(), rpS2.get());
239 /** Set of all shapes
241 private:
242 typedef ::std::map< ShapeSharedPtr, LayerWeakPtr, ShapeComparator > LayerShapeMap;
243 typedef ::std::set< ShapeSharedPtr > ShapeUpdateSet;
246 /// Adds shape area to containing layer's damage area
247 void addUpdateArea( ShapeSharedPtr const& rShape );
249 LayerSharedPtr createForegroundLayer() const;
251 /** Push changes from updateShapeLayerAssociations() to current layer
253 Factored-out method that resizes layer, if necessary,
254 assigns correct layer priority, and repaints contained shapes.
256 @param nCurrLayerIndex
257 Index of current layer in maLayers
259 @param aFirstLayerShape
260 Valid iterator out of maAllShapes, denoting the first
261 shape from nCurrLayerIndex
263 @param aEndLayerShapes
264 Valid iterator or end iterator out of maAllShapes,
265 denoting one-behind-the-last shape of nCurrLayerIndex
267 void commitLayerChanges( std::size_t nCurrLayerIndex,
268 LayerShapeMap::const_iterator aFirstLayerShape,
269 const LayerShapeMap::const_iterator& aEndLayerShapes );
271 /** Init Shape layers with background layer.
273 void putShape2BackgroundLayer( LayerShapeMap::value_type& rShapeEntry );
275 /** Commits any pending layer reorg, due to shapes either
276 entering or leaving animation mode
278 @param bBackgroundLayerPainted
279 When true, LayerManager does not render anything on
280 the background layer. Use this, if background has been
281 updated by other means (e.g. slide transition)
283 void updateShapeLayers( bool bBackgroundLayerPainted );
285 /** Common stuff when adding a shape
287 void implAddShape( const ShapeSharedPtr& rShape );
289 /** Common stuff when removing a shape
291 void implRemoveShape( const ShapeSharedPtr& rShape );
293 /** Add or remove views
295 Sharing duplicate code from viewAdded and viewRemoved
296 method. The only point of variation at those places
297 are removal vs. adding.
299 template<typename LayerFunc,
300 typename ShapeFunc> void manageViews( LayerFunc layerFunc,
301 ShapeFunc shapeFunc );
303 bool updateSprites();
305 /// Registered views
306 const UnoViewContainer& mrViews;
308 /// All layers of this object. Vector owns the layers
309 LayerVector maLayers;
311 /** Contains all shapes with their XShape reference as the key
313 XShapeHash maXShapeHash;
315 /** Set of shapes this LayerManager own
317 Contains the same set of shapes as XShapeHash, but is
318 sorted in z order, for painting and layer
319 association. Set entries are enriched with two flags
320 for buffering animation enable/disable changes, and
321 shape update requests.
323 LayerShapeMap maAllShapes;
325 /** Set of shapes that have requested an update
327 When a shape is member of this set, its maShapes entry
328 has bNeedsUpdate set to true. We maintain this
329 redundant information for faster update processing.
331 ShapeUpdateSet maUpdateShapes;
333 /// Number of shape sprites currently active on this LayerManager
334 sal_Int32 mnActiveSprites;
336 /// sal_True, if shapes might need to move to different layer
337 bool mbLayerAssociationDirty;
339 /// sal_False when deactivated
340 bool mbActive;
342 /** When true, all sprite animations run in the foreground. That
343 is, no extra layers are created, and the slideshow runs
344 potentially faster.
346 bool mbDisableAnimationZOrder;
349 typedef ::std::shared_ptr< LayerManager > LayerManagerSharedPtr;
353 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYERMANAGER_HXX
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */