• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

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 Free Software
00004 //   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 "log.h"
00032 #endif
00033 
00034 // GNASH_PARANOIA_LEVEL:
00035 // 0 : (not unimplemented)
00036 // 1 : quick assertions
00037 // 2 : add testInvariant
00038 //
00039 #ifndef GNASH_PARANOIA_LEVEL
00040 # define GNASH_PARANOIA_LEVEL 1
00041 #endif
00042 
00043 namespace gnash {
00044         class cxform;
00045         class Renderer;
00046 }
00047 
00048 namespace gnash {
00049 
00051 //
00057 class DisplayList
00058 {
00059 
00060 public:
00061 
00062         typedef std::list<DisplayObject*> container_type;
00063         typedef container_type::iterator iterator;
00064         typedef container_type::const_iterator const_iterator;
00065         typedef container_type::reverse_iterator reverse_iterator;
00066         typedef container_type::const_reverse_iterator const_reverse_iterator;
00067 
00068     DisplayList() {}
00069     ~DisplayList() {}
00070 
00072         friend std::ostream& operator<< (std::ostream&, const DisplayList&);
00073 
00077         //
00090     void placeDisplayObject(DisplayObject* ch, int depth);
00091 
00095         //
00111         void replaceDisplayObject(DisplayObject* ch, int depth, bool use_old_cxform,
00112                 bool use_old_matrix);
00113 
00117         //
00137         void swapDepths(DisplayObject* ch, int depth);
00138 
00142         //
00148         //
00160         void moveDisplayObject( int depth, const cxform* color_xform,
00161             const SWFMatrix* mat, int* ratio, int* clip_depth);
00162 
00164         //
00166         void removeDisplayObject(int depth);
00167 
00169         //
00176         void removeUnloaded();
00177 
00184         bool unload();
00185 
00187         void destroy();
00188 
00190         //
00198         void add(DisplayObject* ch, bool replace);
00199 
00201     //
00204     //
00206     void removeDisplayObject(DisplayObject* obj);
00207 
00209     //
00212     //
00215     DisplayObject* removeDisplayObjectAt(int index);
00216 
00218     //
00221     //
00227     void insertDisplayObject(DisplayObject* obj, int index);
00228 
00230     //
00232     //
00237     void addDisplayObject(DisplayObject* obj);
00238 
00242         void display(Renderer& renderer);
00243         
00244         void omit_display();
00245 
00247         DisplayObject* getDisplayObjectAtDepth(int depth) const;
00248 
00250         DisplayObject* getDisplayObjectByName(string_table& st,
00251             string_table::key name, bool caseless) const;
00252 
00256         //
00264         template <class V> inline void visitForward(V& visitor);
00265 
00269         //
00278         template <class V> inline void visitBackward(V& visitor);
00279     template <class V> inline void visitBackward(V& visitor) const;
00280 
00283         //
00293         template <class V> inline void visitAll(V& visitor);
00294         template <class V> inline void visitAll(V& visitor) const;
00295 
00297         void dump() const;
00298 
00301         void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);     
00302         
00304         size_t size() const { 
00305                 return _charsByDepth.size();
00306         }
00307 
00309         bool empty() const {
00310                 return _charsByDepth.empty();
00311         }
00312 
00314         //
00319         int getNextHighestDepth() const;
00320 
00322         //
00331         void sort();
00332         
00335         void mergeDisplayList(DisplayList& newList);
00336 
00337         bool operator==(const DisplayList& other) const {
00338         return _charsByDepth == other._charsByDepth;
00339     }
00340 
00341         bool operator!=(const DisplayList& other) const {
00342         return _charsByDepth != other._charsByDepth;
00343     }
00344         
00345 #if GNASH_PARANOIA_LEVEL > 1 && !defined(NDEBUG)
00346     DisplayList::const_iterator nonRemoved() const;
00347 
00348     void testInvariant() const
00349         {
00350                 DisplayList sorted = *this;
00351 
00352         // check no duplicated depths above non-removed zone.
00353                 std::set<int> depths;
00354                 for (const_iterator it = nonRemoved(),
00355                 itEnd = _charsByDepth.end(); it != itEnd; ++it) {
00356 
00357                         DisplayObject* ch = *it;
00358                         int depth = ch->get_depth();
00359                         if (!depths.insert(depth).second) {
00360                                 log_debug("Depth %d is duplicated in DisplayList %p",
00361                         depth, (const void*)this);
00362                 std::abort();
00363                         }
00364                 }
00365                 assert(isSorted()); // check we didn't screw up ordering
00366         }
00367 #else
00368     void testInvariant() const {}
00369 #endif 
00370 
00371 private:
00372 
00376         //
00383         void reinsertRemovedCharacter(DisplayObject* ch);
00384 
00385         container_type _charsByDepth;
00386 
00388         bool isSorted() const;
00389 };
00390 
00391 template <class V>
00392 void
00393 DisplayList::visitForward(V& visitor)
00394 {
00395         for (iterator it = _charsByDepth.begin(), itEnd = _charsByDepth.end();
00396                 it != itEnd; ++it) {
00397                 if (!visitor(*it)) break;
00398         }
00399 }
00400 
00401 template <class V>
00402 void
00403 DisplayList::visitBackward(V& visitor)
00404 {
00405         for (reverse_iterator it = _charsByDepth.rbegin(),
00406                         itEnd = _charsByDepth.rend(); it != itEnd; ++it) {
00407                 if (!visitor(*it)) break;
00408         }
00409 }
00410 
00411 template <class V>
00412 void
00413 DisplayList::visitBackward(V& visitor) const
00414 {
00415         for (const_reverse_iterator it = _charsByDepth.rbegin(),
00416                         itEnd = _charsByDepth.rend(); it != itEnd; ++it) {
00417                 if (!visitor(*it)) break;
00418         }
00419 }
00420 
00421 template <class V>
00422 void
00423 DisplayList::visitAll(V& visitor)
00424 {
00425         for (iterator it = _charsByDepth.begin(), itEnd = _charsByDepth.end();
00426                 it != itEnd; ++it) {
00427 
00428                 visitor(*it);
00429         }
00430 }
00431 
00432 template <class V>
00433 void
00434 DisplayList::visitAll(V& visitor) const
00435 {
00436         for (const_iterator it = _charsByDepth.begin(),
00437             itEnd = _charsByDepth.end(); it != itEnd; ++it) {
00438 
00439                 visitor(*it);
00440         }
00441 }
00442 
00443 std::ostream& operator<< (std::ostream&, const DisplayList&);
00444 
00445 } // namespace gnash
00446 
00447 
00448 #endif // GNASH_DLIST_H
00449 
00450 
00451 
00452 // Local Variables:
00453 // mode: C++
00454 // c-basic-offset: 8 
00455 // tab-width: 8
00456 // indent-tabs-mode: t
00457 // End:

Generated on Thu Sep 30 2010 14:34:57 for Gnash by  doxygen 1.7.1