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