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 "snappingrange.h"
24 
25 #include <string>
26 #include <list>
27 #include <iosfwd>
28 #if GNASH_PARANOIA_LEVEL > 1 && !defined(NDEBUG)
29 #include "DisplayObject.h"
30 #include <set> // for testInvariant
31 #include <algorithm>
32 #include "log.h"
33 #endif
34 
35 // GNASH_PARANOIA_LEVEL:
36 // 0 : (not unimplemented)
37 // 1 : quick assertions
38 // 2 : add testInvariant
39 //
40 #ifndef GNASH_PARANOIA_LEVEL
41 # define GNASH_PARANOIA_LEVEL 1
42 #endif
43 
44 namespace gnash {
45  class SWFCxForm;
46  class Renderer;
47  struct ObjectURI;
48  class Transform;
49  class string_table;
50  class DisplayObject;
51  class SWFMatrix;
52 }
53 
54 namespace gnash {
55 
57 //
64 {
65 
66 public:
67 
68  typedef std::list<DisplayObject*> container_type;
69  typedef container_type::iterator iterator;
70  typedef container_type::const_iterator const_iterator;
71  typedef container_type::reverse_iterator reverse_iterator;
72  typedef container_type::const_reverse_iterator const_reverse_iterator;
73 
76 
78  friend std::ostream& operator<< (std::ostream&, const DisplayList&);
79 
83  //
96  void placeDisplayObject(DisplayObject* ch, int depth);
97 
101  //
117  void replaceDisplayObject(DisplayObject* ch, int depth, bool use_old_cxform,
118  bool use_old_matrix);
119 
123  //
143  void swapDepths(DisplayObject* ch, int depth);
144 
148  //
154  //
162  void moveDisplayObject(int depth, const SWFCxForm* color_xform,
163  const SWFMatrix* mat, boost::uint16_t* ratio);
164 
166  //
168  void removeDisplayObject(int depth);
169 
171  //
178  void removeUnloaded();
179 
186  bool unload();
187 
189  void destroy();
190 
192  //
200  void add(DisplayObject* ch, bool replace);
201 
203  //
206  //
212  void insertDisplayObject(DisplayObject* obj, int index);
213 
215  //
217  void display(Renderer& renderer, const Transform& xform);
218 
219  void omit_display();
220 
222  DisplayObject* getDisplayObjectAtDepth(int depth) const;
223 
225  //
236  const ObjectURI& uri, bool caseless) const;
237 
241  //
250  template <class V> inline void visitBackward(V& visitor);
251  template <class V> inline void visitBackward(V& visitor) const;
252 
255  //
265  template <class V> inline void visitAll(V& visitor);
266  template <class V> inline void visitAll(V& visitor) const;
267 
270  void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
271 
273  size_t size() const {
274  return _charsByDepth.size();
275  }
276 
278  bool empty() const {
279  return _charsByDepth.empty();
280  }
281 
283  //
288  int getNextHighestDepth() const;
289 
291  //
294  void mergeDisplayList(DisplayList& newList, DisplayObject& o);
295 
296  bool operator==(const DisplayList& other) const {
297  return _charsByDepth == other._charsByDepth;
298  }
299 
300  bool operator!=(const DisplayList& other) const {
301  return _charsByDepth != other._charsByDepth;
302  }
303 
304 #if GNASH_PARANOIA_LEVEL > 1 && !defined(NDEBUG)
305  DisplayList::const_iterator nonRemoved() const;
306 
307  void testInvariant() const
308  {
309  DisplayList sorted = *this;
310 
311  // check no duplicated depths above non-removed zone.
312  std::set<int> depths;
313  for (const_iterator it = nonRemoved(),
314  itEnd = _charsByDepth.end(); it != itEnd; ++it) {
315 
316  DisplayObject* ch = *it;
317  int depth = ch->get_depth();
318  if (!depths.insert(depth).second) {
319  log_debug("Depth %d is duplicated in DisplayList %p",
320  depth, (const void*)this);
321  std::abort();
322  }
323  }
324  if (_charsByDepth.empty()) return;
325  // check we didn't screw up ordering
326  assert(std::adjacent_find(_charsByDepth.begin(), _charsByDepth.end(),
327  DepthGreaterThan()) == _charsByDepth.end());
328  }
329 #else
330  void testInvariant() const {}
331 #endif
332 
333 private:
334 
338  //
345  void reinsertRemovedCharacter(DisplayObject* ch);
346 
347  container_type _charsByDepth;
348 };
349 
350 template <class V>
351 void
353 {
354  for (reverse_iterator it = _charsByDepth.rbegin(),
355  itEnd = _charsByDepth.rend(); it != itEnd; ++it) {
356  if (!visitor(*it)) break;
357  }
358 }
359 
360 template <class V>
361 void
363 {
364  for (const_reverse_iterator it = _charsByDepth.rbegin(),
365  itEnd = _charsByDepth.rend(); it != itEnd; ++it) {
366  if (!visitor(*it)) break;
367  }
368 }
369 
370 template <class V>
371 void
373 {
374  for (iterator it = _charsByDepth.begin(), itEnd = _charsByDepth.end();
375  it != itEnd; ++it) {
376 
377  visitor(*it);
378  }
379 }
380 
381 template <class V>
382 void
383 DisplayList::visitAll(V& visitor) const
384 {
385  for (const_iterator it = _charsByDepth.begin(),
386  itEnd = _charsByDepth.end(); it != itEnd; ++it) {
387 
388  visitor(*it);
389  }
390 }
391 
392 std::ostream& operator<< (std::ostream&, const DisplayList&);
393 
394 } // namespace gnash
395 
396 
397 #endif // GNASH_DLIST_H
398 
399 
400 
401 // Local Variables:
402 // mode: C++
403 // c-basic-offset: 8
404 // tab-width: 8
405 // indent-tabs-mode: t
406 // End: