Equalizer  1.6.1
fabric/canvas.h
1 
2 /* Copyright (c) 2010-2013, Stefan Eilemann <eile@eyescale.ch>
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 #ifndef EQFABRIC_CANVAS_H
19 #define EQFABRIC_CANVAS_H
20 
21 #include <eq/fabric/types.h>
22 #include <eq/fabric/frustum.h> // base class
23 #include <eq/fabric/object.h> // base class
24 #include <eq/fabric/swapBarrier.h> // RefPtr member
25 
26 #include <string>
27 
28 namespace eq
29 {
30 namespace fabric
31 {
33  template< class CFG, class C, class S, class L >
34  class Canvas : public Object, public Frustum
35  {
36  public:
37  typedef std::vector< C* > Canvases;
38  typedef std::vector< S* > Segments;
39  typedef std::vector< L* > Layouts;
40 
42 
46  CFG* getConfig() { return _config; }
48  const CFG* getConfig() const { return _config; }
49 
51  CanvasPath getPath() const;
52 
54  uint32_t getActiveLayoutIndex() const { return _data.activeLayout; }
55 
57  EQFABRIC_INL const L* getActiveLayout() const;
58 
60  const Segments& getSegments() const { return _segments; }
61 
63  S* findSegment( const std::string& name );
64 
66  const S* findSegment( const std::string& name ) const;
67 
69  const Layouts& getLayouts() const { return _layouts; }
70 
72  EQFABRIC_INL void addLayout( L* layout );
73 
75  EQFABRIC_INL bool removeLayout( L* layout );
76 
85  EQFABRIC_INL void setSwapBarrier( SwapBarrierPtr barrier );
86 
88  SwapBarrierConstPtr getSwapBarrier() const { return _swapBarrier; }
89 
91  SwapBarrierPtr getSwapBarrier() { return _swapBarrier; }
92 
94  EQFABRIC_INL virtual void setWall( const Wall& wall );
95 
97  EQFABRIC_INL virtual void setProjection( const Projection& );
98 
100  EQFABRIC_INL virtual void unsetFrustum();
102 
110  EQFABRIC_INL virtual bool useLayout( const uint32_t index );
111 
119  EQFABRIC_INL VisitorResult accept( Visitor& visitor );
120 
122  EQFABRIC_INL VisitorResult accept( Visitor& visitor ) const;
123 
124  EQFABRIC_INL virtual void backup();
125  EQFABRIC_INL virtual void restore();
126 
127  void create( S** segment );
128  void release( S* segment );
129 
130 
131  protected:
133  EQFABRIC_INL Canvas( CFG* config );
134 
136  EQFABRIC_INL virtual ~Canvas();
137 
139  EQFABRIC_INL virtual void attach( const UUID& id,
140  const uint32_t instanceID );
141 
143  EQFABRIC_INL void serialize( co::DataOStream& os,
144  const uint64_t dirtyBits );
146  EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
147  const uint64_t dirtyBits );
148 
149  EQFABRIC_INL virtual void notifyDetach();
150 
152  EQFABRIC_INL virtual void setDirty( const uint64_t bits );
153 
155  virtual void activateLayout( const uint32_t index )
156  { _data.activeLayout = index; }
157 
158  private:
160  CFG* const _config;
161 
162  struct BackupData
163  {
164  BackupData() : activeLayout( 0 ) {}
165 
167  uint32_t activeLayout;
168  }
169  _data, _backup;
170 
172  Layouts _layouts;
173 
175  Segments _segments;
176 
177  SwapBarrierPtr _swapBarrier;
178 
179  struct Private;
180  Private* _private; // placeholder for binary-compatible changes
181 
182  enum DirtyBits
183  {
184  DIRTY_LAYOUT = Object::DIRTY_CUSTOM << 0,
185  DIRTY_SEGMENTS = Object::DIRTY_CUSTOM << 1,
186  DIRTY_LAYOUTS = Object::DIRTY_CUSTOM << 2,
187  DIRTY_FRUSTUM = Object::DIRTY_CUSTOM << 3,
188  DIRTY_CANVAS_BITS = DIRTY_LAYOUT | DIRTY_SEGMENTS | DIRTY_LAYOUTS |
189  DIRTY_FRUSTUM | DIRTY_OBJECT_BITS
190  };
191 
193  virtual uint64_t getRedistributableBits() const
194  { return DIRTY_CANVAS_BITS; }
195 
196  template< class, class, class > friend class Segment;
197  friend class Object;
198  void _addChild( S* segment );
199  bool _removeChild( S* segment );
200 
202  EQFABRIC_INL virtual uint128_t commit( const uint32_t incarnation );
203  bool _mapViewObjects();
204 
205  typedef co::CommandFunc< Canvas< CFG, C, S, L > > CmdFunc;
206  bool _cmdNewSegment( co::ICommand& command );
207  bool _cmdNewSegmentReply( co::ICommand& command );
208  };
209 
210  template< class CFG, class C, class S, class L >
211  std::ostream& operator << ( std::ostream&, const Canvas< CFG, C, S, L >& );
212 }
213 }
214 #endif // EQFABRIC_CANVAS_H
Internal base class for all distributed, inheritable Equalizer objects.
Definition: object.h:39
ElementVisitor< C, LeafVisitor< S > > Visitor
A Canvas visitor.
Definition: fabric/canvas.h:41
virtual EQFABRIC_INL void setWall(const Wall &wall)
EQFABRIC_INL void serialize(co::DataOStream &os, const uint64_t dirtyBits)
virtual EQFABRIC_INL ~Canvas()
Destruct this canvas.
A visitor to traverse non-leaf elements and their children in a tree.
const Layouts & getLayouts() const
Definition: fabric/canvas.h:69
EQFABRIC_INL VisitorResult accept(Visitor &visitor)
Traverse this canvas and all children using a canvas visitor.
const Segments & getSegments() const
Definition: fabric/canvas.h:60
A canvas represents a logical 2D projection surface.
Definition: fabric/canvas.h:34
virtual EQFABRIC_INL void setProjection(const Projection &)
virtual EQFABRIC_INL bool useLayout(const uint32_t index)
Activate the given layout on this canvas.
virtual EQFABRIC_INL void setDirty(const uint64_t bits)
virtual EQFABRIC_INL void deserialize(co::DataIStream &is, const uint64_t dirtyBits)
std::vector< S * > Segments
A vector of segments.
Definition: fabric/canvas.h:38
EQFABRIC_INL Canvas(CFG *config)
Construct a new Canvas.
std::vector< L * > Layouts
A vector of layouts.
Definition: fabric/canvas.h:39
uint32_t getActiveLayoutIndex() const
Definition: fabric/canvas.h:54
EQFABRIC_INL const L * getActiveLayout() const
A distributed object for frustum data.
Definition: frustum.h:36
std::vector< C * > Canvases
A vector of canvases.
Definition: fabric/canvas.h:37
virtual EQFABRIC_INL void unsetFrustum()
const CFG * getConfig() const
Definition: fabric/canvas.h:48
Object()
Construct a new Object.