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:
gnash::geometry::SnappingRanges2d< std::int32_t >
gnash::DisplayObject::set_depth
void set_depth(int d)
Definition: DisplayObject.h:270
gnash::DisplayList::testInvariant
void testInvariant() const
Definition: DisplayList.h:331
gnash::log_swferror
void log_swferror(StringType msg, Args... args)
Definition: log.h:325
gnash::DisplayList::visitAll
void visitAll(V &visitor)
Visit each and all DisplayObject in the list.
Definition: DisplayList.h:373
ObjectURI.h
gnash::DisplayObject::transformedByScript
void transformedByScript()
Call this function when the sprite has been transformed due to ActionScript code.
Definition: DisplayObject.h:611
gnash::string_table
A general use string table.
Definition: string_table.h:42
gnash::DisplayObject::staticDepthOffset
static const int staticDepthOffset
Definition: DisplayObject.h:205
dsodefs.h
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::DisplayList::add_invalidated_bounds
void add_invalidated_bounds(InvalidatedRanges &ranges, bool force)
Definition: DisplayList.cpp:619
gnash::typeName
std::string typeName(const T &inst)
Definition: utility.h:93
_
#define _(String)
Definition: log.h:44
Renderer.h
gnash::DisplayList::add
void add(DisplayObject *ch, bool replace)
Add a DisplayObject in the list, maintaining depth-order.
Definition: DisplayList.cpp:212
gnash::DisplayList::container_type
std::list< DisplayObject * > container_type
Definition: DisplayList.h:69
gnash::DisplayObject::isDestroyed
bool isDestroyed() const
Return true if this DisplayObject was destroyed.
Definition: DisplayObject.h:807
gnash::getCxForm
const SWFCxForm & getCxForm(const DisplayObject &o)
Definition: DisplayObject.h:1125
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::DisplayList::swapDepths
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
gnash::DisplayObject::set_ratio
void set_ratio(std::uint16_t r)
Definition: DisplayObject.h:362
gnash::Renderer
Base class for render handlers.
Definition: Renderer.h:189
utility.h
gnash::DisplayObject::isDynamicMask
bool isDynamicMask() const
Definition: DisplayObject.h:404
gnash::DisplayObject::setMatrix
void setMatrix(const SWFMatrix &m, bool updateCache=false)
Set local transform SWFMatrix for this DisplayObject.
Definition: DisplayObject.cpp:395
gnash::SWFCxForm
Color transformation record.
Definition: SWFCxForm.h:35
gnash::DisplayObject::getTarget
std::string DSOEXPORT getTarget() const
Return full path to this object, in dot notation.
Definition: DisplayObject.cpp:621
gnash::DisplayList::placeDisplayObject
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
gnash::DisplayObject::isDynamic
bool isDynamic() const
Was this DisplayObject dynamically created ?
Definition: DisplayObject.h:592
gnash::Renderer::disable_mask
virtual void disable_mask()=0
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::geometry::SnappingRanges2d::inheritConfig
void inheritConfig(const SnappingRanges2d< T > &from)
Definition: snappingrange.h:155
gnash::DisplayList::removeUnloaded
void removeUnloaded()
Remove all unloaded DisplayObject from the list.
Definition: DisplayList.cpp:917
gnash::DisplayList::getNextHighestDepth
int getNextHighestDepth() const
Return the next highest available depth.
Definition: DisplayList.cpp:117
IF_VERBOSE_MALFORMED_SWF
#define IF_VERBOSE_MALFORMED_SWF(x)
Definition: log.h:404
gnash::DisplayList
A list of on-stage DisplayObjects, ordered by depth.
Definition: DisplayList.h:65
gnash::DisplayObject::omit_display
virtual void omit_display()
Definition: DisplayObject.h:750
gnash::DisplayList::getDisplayObjectAtDepth
DSOTEXPORT DisplayObject * getDisplayObjectAtDepth(int depth) const
May return NULL.
Definition: DisplayList.cpp:133
gnash::DisplayList::omit_display
void omit_display()
Definition: DisplayList.cpp:609
gnash::DisplayObject::get_accept_anim_moves
bool get_accept_anim_moves() const
Return true if PlaceObjects tag are allowed to move this DisplayObject.
Definition: DisplayObject.h:573
gnash::DisplayObject::get_depth
int get_depth() const
Definition: DisplayObject.h:268
gnash::DisplayList::reverse_iterator
container_type::reverse_iterator reverse_iterator
Definition: DisplayList.h:72
StringPredicates.h
IF_VERBOSE_ASCODING_ERRORS
#define IF_VERBOSE_ASCODING_ERRORS(x)
Definition: log.h:397
gnash::geometry::SnappingRanges2d::intersect
void intersect(const SnappingRanges2d< T > &o)
Definition: snappingrange.h:425
gnash::DisplayList::const_reverse_iterator
container_type::const_reverse_iterator const_reverse_iterator
Definition: DisplayList.h:73
gnash::DisplayObject::get_clip_depth
int get_clip_depth() const
Definition: DisplayObject.h:375
gnash::DisplayList::operator<<
friend std::ostream & operator<<(std::ostream &, const DisplayList &)
Output operator.
Definition: DisplayList.cpp:975
gnash::DisplayObject::setCxForm
void setCxForm(const SWFCxForm &cx)
Definition: DisplayObject.h:352
MovieClip.h
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::key::_1
@ _1
Definition: GnashKey.h:95
gnash::DisplayList::destroy
void destroy()
destroy all DisplayObjects in this DisplayList
Definition: DisplayList.cpp:516
gnash::DisplayList::replaceDisplayObject
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
gnash::DisplayObject::set_invalidated
void set_invalidated()
This function marks the DisplayObject as being modified in aspect and keeps track of current invalida...
Definition: DisplayObject.cpp:183
gnash::DisplayList::getDisplayObjectByName
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
gnash::SWFMatrix
Definition: SWFMatrix.h:54
gnash::DisplayList::mergeDisplayList
void mergeDisplayList(DisplayList &newList, DisplayObject &o)
Merge the given display list.
Definition: DisplayList.cpp:732
gnash::DisplayList::visitBackward
void visitBackward(V &visitor)
Visit each DisplayObject in the list in reverse depth order (higher depth first).
Definition: DisplayList.h:353
gnash::DisplayObject::unloaded
bool unloaded() const
Return true if this DisplayObject was unloaded from the stage.
Definition: DisplayObject.h:785
gnash::log_aserror
void log_aserror(StringType msg, Args... args)
Definition: log.h:331
DisplayObject.h
log.h
gnash::DisplayObject::parent
DisplayObject * parent() const
Return the parent of this DisplayObject, or NULL if the DisplayObject has no parent.
Definition: DisplayObject.h:252
gnash::geometry::SnappingRanges2d::add
void add(const RangeType &range)
Add a Range to the set, merging when possible and appropriate.
Definition: snappingrange.h:250
gnash::DisplayList::display
void display(Renderer &renderer, const Transform &xform)
Display the list's DisplayObjects.
Definition: DisplayList.cpp:541
gnash::DisplayObject::isMaskLayer
bool isMaskLayer() const
Definition: DisplayObject.h:390
gnash::key::V
@ V
Definition: GnashKey.h:134
gnash::Renderer::end_submit_mask
virtual void end_submit_mask()=0
gnash::DisplayList::operator!=
bool operator!=(const DisplayList &other) const
Definition: DisplayList.h:301
gnash::DisplayList::const_iterator
container_type::const_iterator const_iterator
Definition: DisplayList.h:71
DSOTEXPORT
#define DSOTEXPORT
Definition: dsodefs.h:63
gnash::DisplayObject::add_invalidated_bounds
virtual void add_invalidated_bounds(InvalidatedRanges &ranges, bool force)
Add the DisplayObject's invalidated bounds to the given ranges list.
Definition: DisplayObject.cpp:226
test.uri
uri
Definition: test.py:12
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::DisplayObject::boundsInClippingArea
bool boundsInClippingArea(Renderer &renderer) const
Definition: DisplayObject.cpp:784
gnash::Renderer::begin_submit_mask
virtual void begin_submit_mask()=0
gnash::DisplayList::insertDisplayObject
void insertDisplayObject(DisplayObject *obj, int index)
Inserts a DisplayObject at the specified index (depth)
Definition: DisplayList.cpp:447
gnash::DisplayObject::removedDepthOffset
static const int removedDepthOffset
Definition: DisplayObject.h:222
gnash::DisplayList::iterator
container_type::iterator iterator
Definition: DisplayList.h:70
gnash::DisplayList::~DisplayList
~DisplayList()
Definition: DisplayList.h:76
gnash::DisplayObject::display
virtual void display(Renderer &renderer, const Transform &xform)=0
Render the DisplayObject.
gnash::DisplayObject
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:169
gnash::DisplayObject::destroy
virtual void destroy()
Mark this DisplayObject as destroyed.
Definition: DisplayObject.cpp:677
gnash::DisplayList::DisplayList
DisplayList()
Definition: DisplayList.h:75
gnash::DisplayObject::unload
bool unload()
Unload this instance from the stage.
Definition: DisplayObject.cpp:448
gnash::DisplayList::moveDisplayObject
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
gnash::DisplayList::removeDisplayObject
void removeDisplayObject(int depth)
Removes the object at the specified depth.
Definition: DisplayList.cpp:331
gnash::DisplayObject::get_ratio
std::uint16_t get_ratio() const
Definition: DisplayObject.h:360
gnash::caseless
bool caseless(const as_object &o)
Return whether property matching is caseless.
Definition: as_object.h:924
gnash::Transform
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:34
gnash::key::o
@ o
Definition: GnashKey.h:161
gnash::getMatrix
const SWFMatrix & getMatrix(const DisplayObject &o)
Get local transform SWFMatrix for this DisplayObject.
Definition: DisplayObject.h:1119
DisplayList.h
gnash::DisplayObject::extend_invalidated_bounds
void extend_invalidated_bounds(const InvalidatedRanges &ranges)
Definition: DisplayObject.cpp:247
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::isReferenceable
bool isReferenceable(const DisplayObject &d)
Returns true if the DisplayObject is referenceable in ActionScript.
Definition: DisplayObject.h:1149
snappingrange.h
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::DisplayList::empty
bool empty() const
Return true if the list contains no elements.
Definition: DisplayList.h:279
gnash::DisplayList::operator==
bool operator==(const DisplayList &other) const
Definition: DisplayList.h:297
gnash::DisplayList::size
size_t size() const
Return number of elements in the list.
Definition: DisplayList.h:274
gnash::DisplayList::unload
bool unload()
Definition: DisplayList.cpp:477
gnash::DisplayObject::visible
bool visible() const
Definition: DisplayObject.h:623
gnash::operator<<
std::ostream & operator<<(std::ostream &o, const URL &u)
Definition: URL.cpp:447