LibreOffice Module slideshow (master) 1
layer.cxx
Go to the documentation of this file.
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
26#include <utility>
27#include <osl/diagnose.h>
28
29#include "layer.hxx"
30
31using namespace ::com::sun::star;
32
33namespace slideshow::internal
34{
36 maViewEntries(),
37 maBounds(),
38 maNewBounds(),
39 mbBoundsDirty(false),
40 mbBackgroundLayer(true),
41 mbClipSet(false)
42 {
43 }
44
46 maViewEntries(),
47 maBounds(),
48 maNewBounds(),
49 mbBoundsDirty(false),
50 mbBackgroundLayer(false),
51 mbClipSet(false)
52 {
53 }
54
56 {
57 OSL_ASSERT( rNewView );
58
59 ViewEntryVector::iterator aIter;
60 const ViewEntryVector::iterator aEnd( maViewEntries.end() );
61 if( (aIter=std::find_if( maViewEntries.begin(),
62 aEnd,
63 [&rNewView]( const ViewEntry& rViewEntry )
64 { return rViewEntry.getView() == rNewView; } ) ) != aEnd )
65 {
66 // already added - just return existing layer
67 return aIter->mpViewLayer;
68
69 }
70
71 // not yet added - create new view layer
72 ViewLayerSharedPtr pNewLayer;
74 pNewLayer = rNewView;
75 else
76 pNewLayer = rNewView->createViewLayer(maBounds);
77
78 // add to local list
79 maViewEntries.emplace_back( rNewView,
80 pNewLayer );
81
82 return maViewEntries.back().mpViewLayer;
83 }
84
86 {
87 OSL_ASSERT( rView );
88
89 ViewEntryVector::iterator aIter;
90 const ViewEntryVector::iterator aEnd( maViewEntries.end() );
91 if( (aIter=std::find_if( maViewEntries.begin(),
92 aEnd,
93 [&rView]( const ViewEntry& rViewEntry )
94 { return rViewEntry.getView() == rView; } ) ) == aEnd )
95 {
96 // View was not added/is already removed
97 return ViewLayerSharedPtr();
98 }
99
100 OSL_ENSURE( std::count_if( maViewEntries.begin(),
101 aEnd,
102 [&rView]( const ViewEntry& rViewEntry )
103 { return rViewEntry.getView() == rView; } ) == 1,
104 "Layer::removeView(): view added multiple times" );
105
106 ViewLayerSharedPtr pRet( aIter->mpViewLayer );
107 maViewEntries.erase(aIter);
108
109 return pRet;
110 }
111
112 void Layer::setShapeViews( ShapeSharedPtr const& rShape ) const
113 {
114 rShape->clearAllViewLayers();
115
116 for( const auto& rViewEntry : maViewEntries )
117 rShape->addViewLayer( rViewEntry.getViewLayer(), false );
118 }
119
120 void Layer::setPriority( const ::basegfx::B1DRange& rPrioRange )
121 {
122 if( !mbBackgroundLayer )
123 {
124 for( const auto& rViewEntry : maViewEntries )
125 rViewEntry.getViewLayer()->setPriority( rPrioRange );
126 }
127 }
128
129 void Layer::addUpdateRange( ::basegfx::B2DRange const& rUpdateRange )
130 {
131 // TODO(Q1): move this to B2DMultiRange
132 if( !rUpdateRange.isEmpty() )
133 maUpdateAreas.appendElement( rUpdateRange,
135 }
136
138 {
139 if( !mbBackgroundLayer )
140 {
141 if( !mbBoundsDirty )
143
144 maNewBounds.expand( rShape->getUpdateArea() );
145 }
146
147 mbBoundsDirty = true;
148 }
149
151 {
152 mbBoundsDirty = false;
153
155 return false;
156
157 if( maNewBounds == maBounds )
158 return false;
159
161 if( std::count_if( maViewEntries.begin(),
162 maViewEntries.end(),
163 [this]( const ViewEntry& rViewEntry )
164 { return rViewEntry.getViewLayer()->resize( this->maBounds ); }
165 ) == 0 )
166 {
167 return false;
168 }
169
170 // layer content invalid, update areas have wrong
171 // coordinates/not sensible anymore.
173
174 return true;
175 }
176
178 {
180 }
181
183 {
184 // clear content on all view layers
185 for( const auto& rViewEntry : maViewEntries )
186 rViewEntry.getViewLayer()->clearAll();
187
188 // layer content cleared, update areas are not sensible
189 // anymore.
191 }
192
194 {
195 public:
196 LayerEndUpdate( const LayerEndUpdate& ) = delete;
198 explicit LayerEndUpdate( LayerSharedPtr xLayer ) :
199 mpLayer(std::move( xLayer ))
200 {}
201
202 ~LayerEndUpdate() { if(mpLayer) mpLayer->endUpdate(); }
203
204 private:
206 };
207
209 {
210 if( maUpdateAreas.count() )
211 {
212 // perform proper layer update. That means, setup proper
213 // clipping, and render each shape that intersects with
214 // the calculated update area
216 aClip = ::basegfx::utils::stripNeutralPolygons(aClip);
217 aClip = ::basegfx::utils::stripDispensablePolygons(aClip);
218
219 // actually, if there happen to be shapes with zero
220 // update area in the maUpdateAreas vector, the
221 // resulting clip polygon will be empty.
222 if( aClip.count() )
223 {
224 for( const auto& rViewEntry : maViewEntries )
225 {
226 const ViewLayerSharedPtr& pViewLayer = rViewEntry.getViewLayer();
227
228 // set clip to all view layers and
229 pViewLayer->setClip( aClip );
230
231 // clear update area on all view layers
232 pViewLayer->clear();
233 }
234
235 mbClipSet = true;
236 }
237 }
238
239 return std::make_shared<LayerEndUpdate>(shared_from_this());
240 }
241
243 {
244 if( mbClipSet )
245 {
246 mbClipSet = false;
247
248 basegfx::B2DPolyPolygon aEmptyClip;
249 for( const auto& rViewEntry : maViewEntries )
250 rViewEntry.getViewLayer()->setClip( aEmptyClip );
251 }
252
254 }
255
256 bool Layer::isInsideUpdateArea( ShapeSharedPtr const& rShape ) const
257 {
258 return maUpdateAreas.overlaps( rShape->getUpdateArea() );
259 }
260
262 {
263 return LayerSharedPtr(new Layer( BackgroundLayer ));
264 }
265
267 {
268 return LayerSharedPtr( new Layer );
269 }
270
271}
272
273/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::basegfx::B2DRectangle maBounds
sal_uInt32 count() const
sal_uInt32 count() const
B2DPolyPolygon solveCrossovers() const
void appendElement(const B2DRange &rRange, B2VectorOrientation eOrient)
bool overlaps(const B2DRange &rRange) const
void expand(const Tuple2D< TYPE > &rTuple)
bool isEmpty() const
LayerEndUpdate(const LayerEndUpdate &)=delete
LayerEndUpdate(LayerSharedPtr xLayer)
Definition: layer.cxx:198
LayerEndUpdate & operator=(const LayerEndUpdate &)=delete
This class represents one layer of output on a Slide.
Definition: layer.hxx:62
void updateBounds(ShapeSharedPtr const &rShape)
Update layer bound rect from shape bounds.
Definition: layer.cxx:137
basegfx::B2DPolyRange maUpdateAreas
Definition: layer.hxx:249
Layer()
Create non-background layer.
Definition: layer.cxx:45
ViewLayerSharedPtr addView(const ViewSharedPtr &rNewView)
Add a view to this layer.
Definition: layer.cxx:55
ViewLayerSharedPtr removeView(const ViewSharedPtr &rView)
Remove a view.
Definition: layer.cxx:85
void endUpdate()
Finish layer update.
Definition: layer.cxx:242
bool isInsideUpdateArea(ShapeSharedPtr const &rShape) const
Check whether given shape is inside current update area.
Definition: layer.cxx:256
static LayerSharedPtr createBackgroundLayer()
Create background layer.
Definition: layer.cxx:261
bool commitBounds()
Commit collected layer bounds to ViewLayer.
Definition: layer.cxx:150
basegfx::B2DRange maNewBounds
Definition: layer.hxx:251
void clearUpdateRanges()
Clear all registered update ranges.
Definition: layer.cxx:177
void addUpdateRange(::basegfx::B2DRange const &rUpdateRange)
Add an area that needs update.
Definition: layer.cxx:129
std::shared_ptr< LayerEndUpdate > EndUpdater
Definition: layer.hxx:64
basegfx::B2DRange maBounds
Definition: layer.hxx:250
void setShapeViews(ShapeSharedPtr const &rShape) const
Init shape with this layer's views.
Definition: layer.cxx:112
void clearContent()
Clear whole layer content.
Definition: layer.cxx:182
void setPriority(const ::basegfx::B1DRange &rPrioRange)
Change layer priority range.
Definition: layer.cxx:120
ViewEntryVector maViewEntries
Definition: layer.hxx:248
static LayerSharedPtr createLayer()
Create non-background layer.
Definition: layer.cxx:266
EndUpdater beginUpdate()
Init layer update.
Definition: layer.cxx:208
std::shared_ptr< View > ViewSharedPtr
Definition: view.hxx:80
std::shared_ptr< ViewLayer > ViewLayerSharedPtr
Definition: viewlayer.hxx:168
::std::shared_ptr< Layer > LayerSharedPtr
Definition: layer.hxx:36
::std::shared_ptr< Shape > ShapeSharedPtr