Gnash 0.8.9

DisplayList.h

Go to the documentation of this file.
00001 // dlist.h:  Display list definitions, for Gnash.
00002 // 
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
00004 //   2011 Free Software Foundation, Inc
00005 // 
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // This program is distributed in the hope that it will be useful,
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 //
00019 
00020 #ifndef GNASH_DLIST_H
00021 #define GNASH_DLIST_H
00022 
00023 #include "snappingrange.h"
00024 #include "DisplayObject.h"
00025 
00026 #include <string>
00027 #include <list>
00028 #include <iosfwd>
00029 #if GNASH_PARANOIA_LEVEL > 1 && !defined(NDEBUG)
00030 #include <set>  // for testInvariant
00031 #include <algorithm>
00032 #include "log.h"
00033 #endif
00034 
00035 // GNASH_PARANOIA_LEVEL:
00036 // 0 : (not unimplemented)
00037 // 1 : quick assertions
00038 // 2 : add testInvariant
00039 //
00040 #ifndef GNASH_PARANOIA_LEVEL
00041 # define GNASH_PARANOIA_LEVEL 1
00042 #endif
00043 
00044 namespace gnash {
00045         class SWFCxForm;
00046         class Renderer;
00047         struct ObjectURI;
00048 }
00049 
00050 namespace gnash {
00051 
00053 //
00059 class DisplayList
00060 {
00061 
00062 public:
00063 
00064         typedef std::list<DisplayObject*> container_type;
00065         typedef container_type::iterator iterator;
00066         typedef container_type::const_iterator const_iterator;
00067         typedef container_type::reverse_iterator reverse_iterator;
00068         typedef container_type::const_reverse_iterator const_reverse_iterator;
00069 
00070     DisplayList() {}
00071     ~DisplayList() {}
00072 
00074         friend std::ostream& operator<< (std::ostream&, const DisplayList&);
00075 
00079         //
00092     void placeDisplayObject(DisplayObject* ch, int depth);
00093 
00097         //
00113         void replaceDisplayObject(DisplayObject* ch, int depth, bool use_old_cxform,
00114                 bool use_old_matrix);
00115 
00119         //
00139         void swapDepths(DisplayObject* ch, int depth);
00140 
00144         //
00150         //
00158         void moveDisplayObject(int depth, const SWFCxForm* color_xform,
00159             const SWFMatrix* mat, boost::uint16_t* ratio);
00160 
00162         //
00164         void removeDisplayObject(int depth);
00165 
00167         //
00174         void removeUnloaded();
00175 
00182         bool unload();
00183 
00185         void destroy();
00186 
00188         //
00196         void add(DisplayObject* ch, bool replace);
00197 
00199     //
00202     //
00208     void insertDisplayObject(DisplayObject* obj, int index);
00209 
00211     //
00213         void display(Renderer& renderer, const Transform& xform);
00214         
00215         void omit_display();
00216 
00218         DisplayObject* getDisplayObjectAtDepth(int depth) const;
00219 
00221         //
00231         DisplayObject* getDisplayObjectByName(string_table& st,
00232             const ObjectURI& uri, bool caseless) const;
00233 
00237         //
00246         template <class V> inline void visitBackward(V& visitor);
00247     template <class V> inline void visitBackward(V& visitor) const;
00248 
00251         //
00261         template <class V> inline void visitAll(V& visitor);
00262         template <class V> inline void visitAll(V& visitor) const;
00263 
00266         void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);     
00267         
00269         size_t size() const { 
00270                 return _charsByDepth.size();
00271         }
00272 
00274         bool empty() const {
00275                 return _charsByDepth.empty();
00276         }
00277 
00279         //
00284         int getNextHighestDepth() const;
00285         
00288         void mergeDisplayList(DisplayList& newList);
00289 
00290         bool operator==(const DisplayList& other) const {
00291         return _charsByDepth == other._charsByDepth;
00292     }
00293 
00294         bool operator!=(const DisplayList& other) const {
00295         return _charsByDepth != other._charsByDepth;
00296     }
00297         
00298 #if GNASH_PARANOIA_LEVEL > 1 && !defined(NDEBUG)
00299     DisplayList::const_iterator nonRemoved() const;
00300 
00301     void testInvariant() const
00302         {
00303                 DisplayList sorted = *this;
00304 
00305         // check no duplicated depths above non-removed zone.
00306                 std::set<int> depths;
00307                 for (const_iterator it = nonRemoved(),
00308                 itEnd = _charsByDepth.end(); it != itEnd; ++it) {
00309 
00310                         DisplayObject* ch = *it;
00311                         int depth = ch->get_depth();
00312                         if (!depths.insert(depth).second) {
00313                                 log_debug("Depth %d is duplicated in DisplayList %p",
00314                         depth, (const void*)this);
00315                 std::abort();
00316                         }
00317                 }
00318         if (_charsByDepth.empty()) return;
00319                 // check we didn't screw up ordering
00320         assert(std::adjacent_find(_charsByDepth.begin(), _charsByDepth.end(),
00321             DepthGreaterThan()) == _charsByDepth.end());
00322         }
00323 #else
00324     void testInvariant() const {}
00325 #endif 
00326 
00327 private:
00328 
00332         //
00339         void reinsertRemovedCharacter(DisplayObject* ch);
00340 
00341         container_type _charsByDepth;
00342 };
00343 
00344 template <class V>
00345 void
00346 DisplayList::visitBackward(V& visitor)
00347 {
00348         for (reverse_iterator it = _charsByDepth.rbegin(),
00349                         itEnd = _charsByDepth.rend(); it != itEnd; ++it) {
00350                 if (!visitor(*it)) break;
00351         }
00352 }
00353 
00354 template <class V>
00355 void
00356 DisplayList::visitBackward(V& visitor) const
00357 {
00358         for (const_reverse_iterator it = _charsByDepth.rbegin(),
00359                         itEnd = _charsByDepth.rend(); it != itEnd; ++it) {
00360                 if (!visitor(*it)) break;
00361         }
00362 }
00363 
00364 template <class V>
00365 void
00366 DisplayList::visitAll(V& visitor)
00367 {
00368         for (iterator it = _charsByDepth.begin(), itEnd = _charsByDepth.end();
00369                 it != itEnd; ++it) {
00370 
00371                 visitor(*it);
00372         }
00373 }
00374 
00375 template <class V>
00376 void
00377 DisplayList::visitAll(V& visitor) const
00378 {
00379         for (const_iterator it = _charsByDepth.begin(),
00380             itEnd = _charsByDepth.end(); it != itEnd; ++it) {
00381 
00382                 visitor(*it);
00383         }
00384 }
00385 
00386 std::ostream& operator<< (std::ostream&, const DisplayList&);
00387 
00388 } // namespace gnash
00389 
00390 
00391 #endif // GNASH_DLIST_H
00392 
00393 
00394 
00395 // Local Variables:
00396 // mode: C++
00397 // c-basic-offset: 8 
00398 // tab-width: 8
00399 // indent-tabs-mode: t
00400 // End: