Line data Source code
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 : {
32 : /** A canvas represents a logical 2D projection surface. */
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; //!< A vector of canvases
38 : typedef std::vector< S* > Segments; //!< A vector of segments
39 : typedef std::vector< L* > Layouts; //!< A vector of layouts
40 : /** A Canvas visitor */
41 : typedef ElementVisitor< C, LeafVisitor< S > > Visitor;
42 :
43 : /** @name Data Access */
44 : //@{
45 : /** @return the parent config. @version 1.0 */
46 890 : CFG* getConfig() { return _config; }
47 : /** @return the parent config. @version 1.0 */
48 1019 : const CFG* getConfig() const { return _config; }
49 :
50 : /** @internal @return the index path to this canvas. */
51 : CanvasPath getPath() const;
52 :
53 : /** @return the index of the active layout. @version 1.0 */
54 16 : uint32_t getActiveLayoutIndex() const { return _data.activeLayout; }
55 :
56 : /** @return the active layout. @version 1.0 */
57 : EQFABRIC_INL const L* getActiveLayout() const;
58 :
59 : /** @return the vector of child segments. @version 1.0 */
60 3837 : const Segments& getSegments() const { return _segments; }
61 :
62 : /** @internal Find the first segment of a given name. */
63 : S* findSegment( const std::string& name );
64 :
65 : /** @internal Find the first segment of a given name. */
66 : const S* findSegment( const std::string& name ) const;
67 :
68 : /** @return the vector of possible layouts. @version 1.0 */
69 371 : const Layouts& getLayouts() const { return _layouts; }
70 :
71 : /** @internal Add a new allowed layout to this canvas, can be 0. */
72 : EQFABRIC_INL void addLayout( L* layout );
73 :
74 : /** @internal Remove a layout from this canvas, can be the 0 layout. */
75 : EQFABRIC_INL bool removeLayout( L* layout );
76 :
77 : /** @internal
78 : * Set a swap barrier.
79 : *
80 : * This barrier will be set as a barrier on all segments added
81 : * afterwards.
82 : *
83 : * @param barrier the swap barrier.
84 : */
85 : EQFABRIC_INL void setSwapBarrier( SwapBarrierPtr barrier );
86 :
87 : /** @internal @return the current swap barrier. */
88 127 : SwapBarrierConstPtr getSwapBarrier() const { return _swapBarrier; }
89 :
90 : /** @internal @return the current swap barrier. */
91 385 : SwapBarrierPtr getSwapBarrier() { return _swapBarrier; }
92 :
93 : /** @sa Frustum::setWall() */
94 : EQFABRIC_INL virtual void setWall( const Wall& wall );
95 :
96 : /** @sa Frustum::setProjection() */
97 : EQFABRIC_INL virtual void setProjection( const Projection& );
98 :
99 : /** @sa Frustum::unsetFrustum() */
100 : EQFABRIC_INL virtual void unsetFrustum();
101 : //@}
102 :
103 : /** @name Operations */
104 : //@{
105 : /**
106 : * Activate the given layout on this canvas.
107 : * @return true if the active layout changed.
108 : * @version 1.0
109 : */
110 : EQFABRIC_INL virtual bool useLayout( const uint32_t index );
111 :
112 : /**
113 : * Traverse this canvas and all children using a canvas visitor.
114 : *
115 : * @param visitor the visitor.
116 : * @return the result of the visitor traversal.
117 : * @version 1.0
118 : */
119 : EQFABRIC_INL VisitorResult accept( Visitor& visitor );
120 :
121 : /** Const-version of accept(). @version 1.0 */
122 : EQFABRIC_INL VisitorResult accept( Visitor& visitor ) const;
123 :
124 : EQFABRIC_INL virtual void backup(); //!< @internal
125 : EQFABRIC_INL virtual void restore(); //!< @internal
126 :
127 : void create( S** segment ); //!< @internal
128 : void release( S* segment ); //!< @internal
129 : //@}
130 :
131 : protected:
132 : /** Construct a new Canvas. @internal */
133 : EQFABRIC_INL Canvas( CFG* config );
134 :
135 : /** Destruct this canvas. @internal */
136 : EQFABRIC_INL virtual ~Canvas();
137 :
138 : /** @internal */
139 : EQFABRIC_INL virtual void attach( const uint128_t& id,
140 : const uint32_t instanceID );
141 :
142 : /** @sa Frustum::serialize. @internal */
143 : EQFABRIC_INL void serialize( co::DataOStream& os,
144 : const uint64_t dirtyBits );
145 : /** @sa Frustum::deserialize. @internal */
146 : EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
147 : const uint64_t dirtyBits );
148 :
149 : EQFABRIC_INL virtual void notifyDetach(); //!< @internal
150 :
151 : /** @sa Serializable::setDirty() @internal */
152 : EQFABRIC_INL virtual void setDirty( const uint64_t bits );
153 :
154 : /** @internal */
155 20 : virtual void activateLayout( const uint32_t index )
156 20 : { _data.activeLayout = index; }
157 :
158 : private:
159 : /** The parent config. */
160 : CFG* const _config;
161 :
162 : struct BackupData
163 : {
164 466 : BackupData() : activeLayout( 0 ) {}
165 :
166 : /** The currently active layout on this canvas. */
167 : uint32_t activeLayout;
168 : }
169 : _data, _backup;
170 :
171 : /** Allowed layouts on this canvas. */
172 : Layouts _layouts;
173 :
174 : /** Child segments on this canvas. */
175 : Segments _segments;
176 :
177 : SwapBarrierPtr _swapBarrier; //!< default segment swap barrier
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 :
192 : /** @internal @return the bits to be re-committed by the master. */
193 8 : virtual uint64_t getRedistributableBits() const
194 8 : { return DIRTY_CANVAS_BITS; }
195 :
196 : template< class, class, class > friend class Segment;
197 : friend class Object;
198 : void _addChild( S* segment ); //!< @internal
199 : bool _removeChild( S* segment ); //!< @internal
200 :
201 : /** @internal */
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
|