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, boost::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 (iterator it = _charsByDepth.begin(), itEnd = _charsByDepth.end();
376  it != itEnd; ++it) {
377 
378  visitor(*it);
379  }
380 }
381 
382 template <class V>
383 void
384 DisplayList::visitAll(V& visitor) const
385 {
386  for (const_iterator it = _charsByDepth.begin(),
387  itEnd = _charsByDepth.end(); it != itEnd; ++it) {
388 
389  visitor(*it);
390  }
391 }
392 
393 DSOTEXPORT std::ostream& operator<< (std::ostream&, const DisplayList&);
394 
395 } // namespace gnash
396 
397 
398 #endif // GNASH_DLIST_H
399 
400 
401 
402 // Local Variables:
403 // mode: C++
404 // c-basic-offset: 8
405 // tab-width: 8
406 // indent-tabs-mode: t
407 // End:
void add(DisplayObject *ch, bool replace)
Add a DisplayObject in the list, maintaining depth-order.
Definition: DisplayList.cpp:215
size_t size() const
Return number of elements in the list.
Definition: DisplayList.h:274
void testInvariant() const
Definition: DisplayList.h:331
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:176
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:333
bool operator!=(const DisplayList &other) const
Definition: DisplayList.h:301
Definition: SWFMatrix.h:53
void destroy()
destroy all DisplayObjects in this DisplayList
Definition: DisplayList.cpp:516
void add_invalidated_bounds(InvalidatedRanges &ranges, bool force)
Definition: DisplayList.cpp:619
container_type::reverse_iterator reverse_iterator
Definition: DisplayList.h:72
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:374
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:915
void omit_display()
Definition: DisplayList.cpp:609
~DisplayList()
Definition: DisplayList.h:76
Definition: GnashKey.h:161
Color transformation record.
Definition: SWFCxForm.h:35
Base class for render handlers.
Definition: Renderer.h:190
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
std::ostream & operator<<(std::ostream &o, const URL &u)
Definition: URL.cpp:448
void display(Renderer &renderer, const Transform &xform)
Display the list&#39;s DisplayObjects.
Definition: DisplayList.cpp:541
DSOTEXPORT DisplayObject * getDisplayObjectByName(string_table &st, const ObjectURI &uri, bool caseless) const
If there are multiples, returns the first match only!
Definition: DisplayList.cpp:159
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:232
void moveDisplayObject(int depth, const SWFCxForm *color_xform, const SWFMatrix *mat, boost::uint16_t *ratio)
Updates the transform properties of the object at the specified depth, unless its get_accept_anim_mov...
Definition: DisplayList.cpp:296
Definition: GnashKey.h:134
bool unload()
Definition: DisplayList.cpp:477
container_type::const_iterator const_iterator
Definition: DisplayList.h:71
int getNextHighestDepth() const
Return the next highest available depth.
Definition: DisplayList.cpp:115
bool caseless(const as_object &o)
Return whether property matching is caseless.
Definition: as_object.h:924
DSOTEXPORT DisplayObject * getDisplayObjectAtDepth(int depth) const
May return NULL.
Definition: DisplayList.cpp:134
#define DSOTEXPORT
Definition: dsodefs.h:63
int get_depth() const
Definition: DisplayObject.h:268
bool operator==(const DisplayList &other) const
Definition: DisplayList.h:297
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:32
bool empty() const
Return true if the list contains no elements.
Definition: DisplayList.h:279
void insertDisplayObject(DisplayObject *obj, int index)
Inserts a DisplayObject at the specified index (depth)
Definition: DisplayList.cpp:448
friend std::ostream & operator<<(std::ostream &, const DisplayList &)
Output operator.
Definition: DisplayList.cpp:969
void mergeDisplayList(DisplayList &newList, DisplayObject &o)
Merge the given display list.
Definition: DisplayList.cpp:732
container_type::iterator iterator
Definition: DisplayList.h:70