cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / slideshow / source / engine / slide / layer.hxx
blobd10709ffe26e232e5c5f73ee23845f532c3ad320
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_LAYER_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYER_HXX
23 #include <basegfx/range/b2dpolyrange.hxx>
25 #include <shape.hxx>
26 #include <utility>
27 #include <view.hxx>
29 #include <vector>
30 #include <memory>
33 namespace slideshow::internal
35 class LayerEndUpdate;
36 class Layer;
37 typedef ::std::shared_ptr< Layer > LayerSharedPtr;
38 typedef ::std::weak_ptr< Layer > LayerWeakPtr;
41 /* Definition of Layer class */
43 /** This class represents one layer of output on a Slide.
45 Layers group shapes for a certain depth region of a slide.
47 Since slides have a notion of depth, i.e. shapes on it
48 have a certain order in which they lie upon each other,
49 this layering must be modelled. A prime example for this
50 necessity are animations of shapes lying behind other
51 shapes. Then, everything behind the animated shape will be
52 in a background layer, the shape itself will be in an
53 animation layer, and everything before it will be in a
54 foreground layer (these layers are most preferably
55 modelled as XSprite objects internally).
57 @attention All methods of this class are only supposed to
58 be called from the LayerManager. Normally, it shouldn't be
59 possible to get hold of an instance of this class at all.
61 class Layer : public std::enable_shared_from_this<Layer>
63 public:
64 typedef std::shared_ptr<LayerEndUpdate> EndUpdater;
66 /// Forbid copy construction
67 Layer(const Layer&) = delete;
68 /// Forbid copy assignment
69 Layer& operator=(const Layer&) = delete;
71 /** Create background layer
73 This method will create a layer without a ViewLayer,
74 i.e. one that displays directly on the background.
76 static LayerSharedPtr createBackgroundLayer();
78 /** Create non-background layer
80 This method will create a layer in front of the
81 background, to contain shapes that should appear in
82 front of animated objects.
84 static LayerSharedPtr createLayer();
87 /** Predicate, whether this layer is the special
88 background layer
90 This method is mostly useful for checking invariants.
92 bool isBackgroundLayer() const { return mbBackgroundLayer; }
94 /** Add a view to this layer.
96 If the view is already added, this method does not add
97 it a second time, just returning the existing ViewLayer.
99 @param rNewView
100 New view to add to this layer.
102 @return the newly generated ViewLayer for this View
104 ViewLayerSharedPtr addView( const ViewSharedPtr& rNewView );
106 /** Remove a view
108 This method removes the view from this Layer and all
109 shapes included herein.
111 @return the ViewLayer of the removed Layer, if
112 any. Otherwise, NULL is returned.
114 ViewLayerSharedPtr removeView( const ViewSharedPtr& rView );
116 /** Init shape with this layer's views
118 @param rShape
119 The shape, that will subsequently display on this
120 layer's views
122 void setShapeViews( ShapeSharedPtr const& rShape ) const;
125 /** Change layer priority range.
127 The layer priority affects the position of the layer
128 in the z direction (i.e. before/behind which other
129 layers this one appears). The higher the prio, the
130 further on top of the layer stack this one appears.
132 @param rPrioRange
133 The priority range of differing layers must not
134 intersect
136 void setPriority( const ::basegfx::B1DRange& rPrioRange );
138 /** Add an area that needs update
140 @param rUpdateRange
141 Area on this layer that needs update
143 void addUpdateRange( ::basegfx::B2DRange const& rUpdateRange );
145 /** Whether any update ranges have been added
147 @return true, if any non-empty addUpdateRange() calls
148 have been made since the last render()/update() call.
150 bool isUpdatePending() const { return maUpdateAreas.count()!=0; }
152 /** Update layer bound rect from shape bounds
154 void updateBounds( ShapeSharedPtr const& rShape );
156 /** Commit collected layer bounds to ViewLayer
158 Call this method when you're done adding new shapes to
159 the layer.
161 @return true, if layer needed a resize (which
162 invalidates its content - you have to repaint all
163 contained shapes!)
165 bool commitBounds();
167 /** Clear all registered update ranges
169 This method clears all update ranges that are
170 registered at this layer.
172 void clearUpdateRanges();
174 /** Clear whole layer content
176 This method clears the whole layer content. As a
177 byproduct, all update ranges are cleared as well. It
178 makes no sense to maintain them any further, since
179 they only serve for partial updates.
181 void clearContent();
183 /** Init layer update.
185 This method initializes a full layer update of the
186 update area. When the last copy of the returned
187 EndUpdater is destroyed, the Layer leaves update mode
188 again.
190 @return an update end RAII object.
192 EndUpdater beginUpdate();
194 /** Finish layer update
196 Resets clipping and transformation to normal values
198 void endUpdate();
200 /** Check whether given shape is inside current update area.
202 @return true, if the given shape is at least partially
203 inside the current update area.
205 bool isInsideUpdateArea( ShapeSharedPtr const& rShape ) const;
207 private:
208 enum Dummy{ BackgroundLayer };
210 /** Create background layer
212 This constructor will create a layer without a
213 ViewLayer, i.e. one that displays directly on the
214 background.
216 @param eFlag
217 Dummy parameter, to disambiguate from normal layer
218 constructor
220 explicit Layer( Dummy eFlag );
222 /** Create non-background layer
224 This constructor will create a layer in front of the
225 background, to contain shapes that should appear in
226 front of animated objects.
228 explicit Layer();
230 struct ViewEntry
232 ViewEntry( ViewSharedPtr xView,
233 ViewLayerSharedPtr xViewLayer ) :
234 mpView(std::move( xView )),
235 mpViewLayer(std::move( xViewLayer ))
238 ViewSharedPtr mpView;
239 ViewLayerSharedPtr mpViewLayer;
241 // for generic algo access (which needs actual functions)
242 const ViewSharedPtr& getView() const { return mpView; }
243 const ViewLayerSharedPtr& getViewLayer() const { return mpViewLayer; }
246 typedef ::std::vector< ViewEntry > ViewEntryVector;
248 ViewEntryVector maViewEntries;
249 basegfx::B2DPolyRange maUpdateAreas;
250 basegfx::B2DRange maBounds;
251 basegfx::B2DRange maNewBounds;
252 bool mbBoundsDirty; // true, if view layers need resize
253 bool mbBackgroundLayer; // true, if this
254 // layer is the
255 // special
256 // background layer
257 bool mbClipSet; // true, if beginUpdate set a clip
262 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYER_HXX
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */