Equalizer  1.10.1
Parallel Rendering Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fabric/canvas.h
1 
2 /* Copyright (c) 2010-2015, 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 // cppcheck-suppress noConstructor
35 class Canvas : public Object, public Frustum
36 {
37 public:
38  typedef std::vector< C* > Canvases;
39  typedef std::vector< S* > Segments;
40  typedef std::vector< L* > Layouts;
41 
43 
47  CFG* getConfig() { return _config; }
49  const CFG* getConfig() const { return _config; }
50 
52  CanvasPath getPath() const;
53 
55  uint32_t getActiveLayoutIndex() const { return _data.activeLayout; }
56 
58  EQFABRIC_INL const L* getActiveLayout() const;
59 
61  const Segments& getSegments() const { return _segments; }
62 
64  S* findSegment( const std::string& name );
65 
67  const S* findSegment( const std::string& name ) const;
68 
70  const Layouts& getLayouts() const { return _layouts; }
71 
73  EQFABRIC_INL void addLayout( L* layout );
74 
76  EQFABRIC_INL bool removeLayout( L* layout );
77 
86  EQFABRIC_INL void setSwapBarrier( SwapBarrierPtr barrier );
87 
89  SwapBarrierConstPtr getSwapBarrier() const { return _swapBarrier; }
90 
92  SwapBarrierPtr getSwapBarrier() { return _swapBarrier; }
93 
95  EQFABRIC_INL virtual void setWall( const Wall& wall );
96 
98  EQFABRIC_INL virtual void setProjection( const Projection& );
99 
101  EQFABRIC_INL virtual void unsetFrustum();
103 
111  EQFABRIC_INL virtual bool useLayout( const uint32_t index );
112 
120  EQFABRIC_INL VisitorResult accept( Visitor& visitor );
121 
123  EQFABRIC_INL VisitorResult accept( Visitor& visitor ) const;
124 
125  EQFABRIC_INL virtual void backup();
126  EQFABRIC_INL virtual void restore();
127 
128  void create( S** segment );
129  void release( S* segment );
130 
131 
132 protected:
134  EQFABRIC_INL explicit Canvas( CFG* config );
135 
137  EQFABRIC_INL virtual ~Canvas();
138 
140  EQFABRIC_INL virtual void attach( const uint128_t& id,
141  const uint32_t instanceID );
142 
144  EQFABRIC_INL void serialize( co::DataOStream& os,
145  const uint64_t dirtyBits );
147  EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
148  const uint64_t dirtyBits );
149 
150  EQFABRIC_INL virtual void notifyDetach();
151 
153  EQFABRIC_INL virtual void setDirty( const uint64_t bits );
154 
156  virtual void activateLayout( const uint32_t index )
157  { _data.activeLayout = index; }
158 
159 private:
161  CFG* const _config;
162 
163  struct BackupData
164  {
165  BackupData() : activeLayout( 0 ) {}
166 
168  uint32_t activeLayout;
169  }
170  _data, _backup;
171 
173  Layouts _layouts;
174 
176  Segments _segments;
177 
178  SwapBarrierPtr _swapBarrier;
179 
180  struct Private;
181  Private* _private; // placeholder for binary-compatible changes
182 
183  enum DirtyBits
184  {
185  DIRTY_LAYOUT = Object::DIRTY_CUSTOM << 0,
186  DIRTY_SEGMENTS = Object::DIRTY_CUSTOM << 1,
187  DIRTY_LAYOUTS = Object::DIRTY_CUSTOM << 2,
188  DIRTY_FRUSTUM = Object::DIRTY_CUSTOM << 3,
189  DIRTY_CANVAS_BITS = DIRTY_LAYOUT | DIRTY_SEGMENTS | DIRTY_LAYOUTS |
190  DIRTY_FRUSTUM | DIRTY_OBJECT_BITS
191  };
192 
194  virtual uint64_t getRedistributableBits() const
195  { return DIRTY_CANVAS_BITS; }
196 
197  template< class, class, class > friend class Segment;
198  friend class Object;
199  void _addChild( S* segment );
200  bool _removeChild( S* segment );
201 
203  EQFABRIC_INL virtual uint128_t commit( const uint32_t incarnation );
204  bool _mapViewObjects();
205 
206  typedef co::CommandFunc< Canvas< CFG, C, S, L > > CmdFunc;
207  bool _cmdNewSegment( co::ICommand& command );
208  bool _cmdNewSegmentReply( co::ICommand& command );
209 };
210 
211 template< class CFG, class C, class S, class L >
212 std::ostream& operator << ( std::ostream&, const Canvas< CFG, C, S, L >& );
213 }
214 }
215 #endif // EQFABRIC_CANVAS_H
std::vector< C * > Canvases
A vector of canvases.
Definition: fabric/canvas.h:38
virtual EQFABRIC_INL void setProjection(const Projection &)
ElementVisitor< C, LeafVisitor< S > > Visitor
A Canvas visitor.
Definition: fabric/canvas.h:42
EQFABRIC_INL void serialize(co::DataOStream &os, const uint64_t dirtyBits)
std::vector< L * > Layouts
A vector of layouts.
Definition: fabric/canvas.h:40
virtual EQFABRIC_INL void setDirty(const uint64_t bits)
const CFG * getConfig() const
Definition: fabric/canvas.h:49
EQFABRIC_INL VisitorResult accept(Visitor &visitor)
Traverse this canvas and all children using a canvas visitor.
uint32_t getActiveLayoutIndex() const
Definition: fabric/canvas.h:55
const Layouts & getLayouts() const
Definition: fabric/canvas.h:70
A visitor to traverse non-leaf elements and their children in a tree.
virtual EQFABRIC_INL void unsetFrustum()
virtual EQFABRIC_INL bool useLayout(const uint32_t index)
Activate the given layout on this canvas.
EQFABRIC_INL const L * getActiveLayout() const
std::vector< S * > Segments
A vector of segments.
Definition: fabric/canvas.h:39
EQFABRIC_INL Canvas(CFG *config)
Construct a new Canvas.
const Segments & getSegments() const
Definition: fabric/canvas.h:61
virtual EQFABRIC_INL void deserialize(co::DataIStream &is, const uint64_t dirtyBits)
virtual EQFABRIC_INL ~Canvas()
Destruct this canvas.
A canvas represents a logical 2D projection surface.
Definition: fabric/canvas.h:35
virtual EQFABRIC_INL void setWall(const Wall &wall)
Internal base class for all distributed, inheritable Equalizer objects.
Definition: object.h:41
EQFABRIC_API Object()
Construct a new Object.
A distributed object for frustum data.
Definition: frustum.h:30