Gnash  0.8.11dev
DisplayList.h
Go to the documentation of this file.
1 // dlist.h: Display list definitions, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 
20 #ifndef GNASH_DLIST_H
21 #define GNASH_DLIST_H
22 
23 #include <list>
24 #include <iosfwd>
25 #if GNASH_PARANOIA_LEVEL > 1 && !defined(NDEBUG)
26 #include "DisplayObject.h"
27 #include <set> // for testInvariant
28 #include <algorithm>
29 #include "log.h"
30 #endif
31 
32 #include "snappingrange.h"
33 #include "dsodefs.h" // for DSOTEXPORT
34 
35 
36 // GNASH_PARANOIA_LEVEL:
37 // 0 : (not unimplemented)
38 // 1 : quick assertions
39 // 2 : add testInvariant
40 //
41 #ifndef GNASH_PARANOIA_LEVEL
42 # define GNASH_PARANOIA_LEVEL 1
43 #endif
44 
45 namespace gnash {
46  class SWFCxForm;
47  class Renderer;
48  struct ObjectURI;
49  class Transform;
50  class string_table;
51  class DisplayObject;
52  class SWFMatrix;
53 }
54 
55 namespace gnash {
56 
58 //
65 {
66 
67 public:
68 
69  typedef std::list<DisplayObject*> container_type;
70  typedef container_type::iterator iterator;
71  typedef container_type::const_iterator const_iterator;
72  typedef container_type::reverse_iterator reverse_iterator;
73  typedef container_type::const_reverse_iterator const_reverse_iterator;
74 
77 
79  friend std::ostream& operator<< (std::ostream&, const DisplayList&);
80 
84  //
97  DSOTEXPORT void placeDisplayObject(DisplayObject* ch, int depth);
98 
102  //
118  void replaceDisplayObject(DisplayObject* ch, int depth, bool use_old_cxform,
119  bool use_old_matrix);
120 
124  //
144  void swapDepths(DisplayObject* ch, int depth);
145 
149  //
155  //
163  void moveDisplayObject(int depth, const SWFCxForm* color_xform,
164  const SWFMatrix* mat, std::uint16_t* ratio);
165 
167  //
169  void removeDisplayObject(int depth);
170 
172  //
179  void removeUnloaded();
180 
187  bool unload();
188 
190  void destroy();
191 
193  //
201  void add(DisplayObject* ch, bool replace);
202 
204  //
207  //
213  void insertDisplayObject(DisplayObject* obj, int index);
214 
216  //
218  void display(Renderer& renderer, const Transform& xform);
219 
220  void omit_display();
221 
224 
226  //
237  const ObjectURI& uri, bool caseless) const;
238 
242  //
251  template <class V> inline void visitBackward(V& visitor);
252  template <class V> inline void visitBackward(V& visitor) const;
253 
256  //
266  template <class V> inline void visitAll(V& visitor);
267  template <class V> inline void visitAll(V& visitor) const;
268 
271  void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
272 
274  size_t size() const {
275  return _charsByDepth.size();
276  }
277 
279  bool empty() const {
280  return _charsByDepth.empty();
281  }
282 
284  //
289  int getNextHighestDepth() const;
290 
292  //
295  void mergeDisplayList(DisplayList& newList, DisplayObject& o);
296 
297  bool operator==(const DisplayList& other) const {
298  return _charsByDepth == other._charsByDepth;
299  }
300 
301  bool operator!=(const DisplayList& other) const {
302  return _charsByDepth != other._charsByDepth;
303  }
304 
305 #if GNASH_PARANOIA_LEVEL > 1 && !defined(NDEBUG)
306  DisplayList::const_iterator nonRemoved() const;
307 
308  void testInvariant() const
309  {
310  DisplayList sorted = *this;
311 
312  // check no duplicated depths above non-removed zone.
313  std::set<int> depths;
314  for (const_iterator it = nonRemoved(),
315  itEnd = _charsByDepth.end(); it != itEnd; ++it) {
316 
317  DisplayObject* ch = *it;
318  int depth = ch->get_depth();
319  if (!depths.insert(depth).second) {
320  log_debug("Depth %d is duplicated in DisplayList %p",
321  depth, (const void*)this);
322  std::abort();
323  }
324  }
325  if (_charsByDepth.empty()) return;
326  // check we didn't screw up ordering
327  assert(std::adjacent_find(_charsByDepth.begin(), _charsByDepth.end(),
328  DepthGreaterThan()) == _charsByDepth.end());
329  }
330 #else
331  void testInvariant() const {}
332 #endif
333 
334 private:
335 
339  //
346  void reinsertRemovedCharacter(DisplayObject* ch);
347 
348  container_type _charsByDepth;
349 };
350 
351 template <class V>
352 void
354 {
355  for (reverse_iterator it = _charsByDepth.rbegin(),
356  itEnd = _charsByDepth.rend(); it != itEnd; ++it) {
357  if (!visitor(*it)) break;
358  }
359 }
360 
361 template <class V>
362 void
364 {
365  for (const_reverse_iterator it = _charsByDepth.rbegin(),
366  itEnd = _charsByDepth.rend(); it != itEnd; ++it) {
367  if (!visitor(*it)) break;
368  }
369 }
370 
371 template <class V>
372 void
374 {
375  for (DisplayObject* ch : _charsByDepth) {
376  visitor(ch);
377  }
378 }
379 
380 template <class V>
381 void
382 DisplayList::visitAll(V& visitor) const
383 {
384  for (DisplayObject* const ch : _charsByDepth) {
385  visitor(ch);
386  }
387 }
388 
389 DSOTEXPORT std::ostream& operator<< (std::ostream&, const DisplayList&);
390 
391 } // namespace gnash
392 
393 
394 #endif // GNASH_DLIST_H
395 
396 
397 
398 // Local Variables:
399 // mode: C++
400 // c-basic-offset: 8
401 // tab-width: 8
402 // indent-tabs-mode: t
403 // End:
void testInvariant() const
Definition: DisplayList.h:331
void add(DisplayObject *ch, bool replace)
Add a DisplayObject in the list, maintaining depth-order.
Definition: DisplayList.cpp:212
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
DSOTEXPORT void placeDisplayObject(DisplayObject *ch, int depth)
Place a new DisplayObject at the specified depth, replacing any existing DisplayObject at the same de...
Definition: DisplayList.cpp:172
container_type::const_reverse_iterator const_reverse_iterator
Definition: DisplayList.h:73
void visitAll(V &visitor)
Visit each and all DisplayObject in the list.
Definition: DisplayList.h:373
void removeDisplayObject(int depth)
Removes the object at the specified depth.
Definition: DisplayList.cpp:331
Definition: SWFMatrix.h:53
void destroy()
destroy all DisplayObjects in this DisplayList
Definition: DisplayList.cpp:516
uri
Definition: test.py:12
void add_invalidated_bounds(InvalidatedRanges &ranges, bool force)
Definition: DisplayList.cpp:619
container_type::reverse_iterator reverse_iterator
Definition: DisplayList.h:72
bool empty() const
Return true if the list contains no elements.
Definition: DisplayList.h:279
void swapDepths(DisplayObject *ch, int depth)
Change depth of the given DisplayObjects in the list, swapping with any existing DisplayObject at tar...
Definition: DisplayList.cpp:372
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
void visitBackward(V &visitor)
Visit each DisplayObject in the list in reverse depth order (higher depth first). ...
Definition: DisplayList.h:353
void removeUnloaded()
Remove all unloaded DisplayObject from the list.
Definition: DisplayList.cpp:917
void omit_display()
Definition: DisplayList.cpp:609
~DisplayList()
Definition: DisplayList.h:76
Definition: GnashKey.h:161
Color transformation record.
Definition: SWFCxForm.h:34
Base class for render handlers.
Definition: Renderer.h:188
DisplayList()
Definition: DisplayList.h:75
A general use string table.
Definition: string_table.h:41
std::list< DisplayObject * > container_type
Definition: DisplayList.h:69
A URI for describing as_objects.
Definition: ObjectURI.h:44
void display(Renderer &renderer, const Transform &xform)
Display the list&#39;s DisplayObjects.
Definition: DisplayList.cpp:541
void moveDisplayObject(int depth, const SWFCxForm *color_xform, const SWFMatrix *mat, std::uint16_t *ratio)
Updates the transform properties of the object at the specified depth, unless its get_accept_anim_mov...
Definition: DisplayList.cpp:294
void replaceDisplayObject(DisplayObject *ch, int depth, bool use_old_cxform, bool use_old_matrix)
Replace the old DisplayObject at the specified depth with the given new DisplayObject.
Definition: DisplayList.cpp:230
int getNextHighestDepth() const
Return the next highest available depth.
Definition: DisplayList.cpp:117
Definition: GnashKey.h:134
DSOTEXPORT DisplayObject * getDisplayObjectAtDepth(int depth) const
May return NULL.
Definition: DisplayList.cpp:133
bool unload()
Definition: DisplayList.cpp:477
container_type::const_iterator const_iterator
Definition: DisplayList.h:71
bool operator==(const DisplayList &other) const
Definition: DisplayList.h:297
size_t size() const
Return number of elements in the list.
Definition: DisplayList.h:274
bool operator!=(const DisplayList &other) const
Definition: DisplayList.h:301
bool caseless(const as_object &o)
Return whether property matching is caseless.
Definition: as_object.h:924
#define DSOTEXPORT
Definition: dsodefs.h:63
void log_debug(StringType msg, Args... args)
Definition: log.h:301
DSOTEXPORT DisplayObject * getDisplayObjectByName(string_table &st, const ObjectURI &uri, bool caseless) const
If there are multiples, returns the first match only!
Definition: DisplayList.cpp:155
A list of on-stage DisplayObjects, ordered by depth.
Definition: DisplayList.h:64
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:33
void insertDisplayObject(DisplayObject *obj, int index)
Inserts a DisplayObject at the specified index (depth)
Definition: DisplayList.cpp:447
friend std::ostream & operator<<(std::ostream &, const DisplayList &)
Output operator.
Definition: DisplayList.cpp:975
void mergeDisplayList(DisplayList &newList, DisplayObject &o)
Merge the given display list.
Definition: DisplayList.cpp:732
container_type::iterator iterator
Definition: DisplayList.h:70
int get_depth() const
Definition: DisplayObject.h:268