Line data Source code
1 :
2 : /* Copyright (c) 2010-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2010, Cedric Stalder <cedric.stalder@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #ifndef EQFABRIC_PIPE_H
20 : #define EQFABRIC_PIPE_H
21 :
22 : #include <eq/fabric/object.h> // base class
23 : #include <eq/fabric/pixelViewport.h> // property
24 : #include <eq/fabric/types.h>
25 :
26 : namespace eq
27 : {
28 : namespace fabric
29 : {
30 : /** Base data transport class for pipes. @sa eq::Pipe */
31 : template< class N, class P, class W, class V > class Pipe : public Object
32 : {
33 : public:
34 : /** A vector of pointers to windows. @version 1.0 */
35 : typedef std::vector< W* > Windows;
36 :
37 : /** @name Data Access */
38 : //@{
39 : /** @return the parent node of this pipe. @version 1.0 */
40 3150 : N* getNode() { return _node; }
41 : /** @return the parent node of this pipe. @version 1.0 */
42 127 : const N* getNode() const { return _node; }
43 :
44 : /** @return the vector of child windows. @version 1.0 */
45 17856 : const Windows& getWindows() const { return _windows; }
46 :
47 : /**
48 : * Returns the port number of this pipe.
49 : *
50 : * The port number identifies the X server for systems using the
51 : * X11/GLX window system, i.e., the
52 : * :<strong><port></strong>.<screen> of the DISPLAY
53 : * name. It currently has no meaning on all other systems.
54 : *
55 : * @return the port number of this pipe, or LB_UNDEFINED_UINT32.
56 : * @version 1.0
57 : */
58 382 : uint32_t getPort() const { return _port; }
59 :
60 : EQFABRIC_INL void setPort( const uint32_t port ); //!< @internal
61 :
62 : /**
63 : * Returns the device number of this pipe.
64 : *
65 : * The device number identifies the X screen for systems using the
66 : * X11/GLX window system, or the number of the virtual screen for the
67 : * AGL window system. On Windows systems it identifies the graphics
68 : * adapter. Normally the device identifies a GPU.
69 : *
70 : * @return the device number of this pipe, or LB_UNDEFINED_UINT32.
71 : * @version 1.0
72 : */
73 418 : uint32_t getDevice() const { return _device; }
74 :
75 : EQFABRIC_INL void setDevice( const uint32_t device ); //!< @internal
76 :
77 : /** @return the pixel viewport. @version 1.0 */
78 1810 : const PixelViewport& getPixelViewport() const { return _data.pvp; }
79 :
80 : /**
81 : * Set the pipe's pixel viewport.
82 : *
83 : * If invalid, the OSPipe has to set it to the device viewport during
84 : * configInit().
85 : *
86 : * @param pvp the viewport in pixels.
87 : * @version 1.0
88 : */
89 : EQFABRIC_INL void setPixelViewport( const PixelViewport& pvp );
90 :
91 : /** @internal Notify this pipe that the viewport has changed. */
92 : void notifyPixelViewportChanged();
93 :
94 : /** @internal @return the index path to this pipe. */
95 : EQFABRIC_INL PipePath getPath() const;
96 :
97 : /**
98 : * Perform a depth-first traversal of this pipe.
99 : *
100 : * @param visitor the visitor.
101 : * @return the result of the visitor traversal.
102 : * @version 1.0
103 : */
104 : EQFABRIC_INL VisitorResult accept( V& visitor );
105 :
106 : /** Const-version of accept(). @version 1.0 */
107 : EQFABRIC_INL VisitorResult accept( V& visitor ) const;
108 : //@}
109 :
110 : /** @name Attributes */
111 : //@{
112 : /** Pipe attributes. @version 1.0 */
113 : enum IAttribute
114 : {
115 : // Note: also update string array initialization in pipe.cpp
116 : IATTR_HINT_THREAD, //!< Execute tasks in separate thread (default)
117 : IATTR_HINT_AFFINITY, //!< Bind render thread to subset of cores
118 : IATTR_HINT_CUDA_GL_INTEROP, //!< Configure CUDA context
119 : IATTR_LAST,
120 : IATTR_ALL = IATTR_LAST + 5
121 : };
122 :
123 : /** @internal Set a pipe attribute. */
124 : EQFABRIC_INL void setIAttribute( const IAttribute attr,
125 : const int32_t value );
126 :
127 : /** @return the value of a pipe integer attribute. @version 1.0 */
128 1065 : int32_t getIAttribute( const IAttribute attr ) const
129 1065 : { return _iAttributes[attr]; }
130 :
131 : /** @internal @return true if tasks are executed in a separate thread.*/
132 67 : bool isThreaded() const
133 67 : { return (getIAttribute( IATTR_HINT_THREAD ) == 1 ); }
134 :
135 : /** @internal @return the name of a pipe attribute. */
136 : EQFABRIC_INL static const std::string& getIAttributeString(
137 : const IAttribute attr );
138 : //@}
139 :
140 : /** @name internal */
141 : //@{
142 : EQFABRIC_INL virtual void backup(); //!< @internal
143 : EQFABRIC_INL virtual void restore(); //!< @internal
144 : void create( W** window ); //!< @internal
145 : void release( W* window ); //!< @internal
146 0 : virtual void output( std::ostream& ) const {} //!< @internal
147 : /** @internal */
148 : EQFABRIC_INL virtual uint128_t commit( const uint32_t incarnation =
149 : CO_COMMIT_NEXT );
150 : //@}
151 :
152 : protected:
153 : //-------------------- Members --------------------
154 :
155 : /** @internal Construct a new pipe. */
156 : Pipe( N* parent );
157 : EQFABRIC_INL virtual ~Pipe( ); //!< @internal
158 :
159 : virtual void attach( const uint128_t& id,
160 : const uint32_t instanceID ); //!< @internal
161 : /** @internal */
162 : EQFABRIC_INL virtual void serialize( co::DataOStream& os,
163 : const uint64_t dirtyBits );
164 : /** @internal */
165 : EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
166 : const uint64_t dirtyBits );
167 :
168 : EQFABRIC_INL virtual void notifyDetach(); //!< @internal
169 :
170 : /** @internal @sa Serializable::setDirty() */
171 : EQFABRIC_INL virtual void setDirty( const uint64_t bits );
172 :
173 : /** @internal */
174 38 : virtual ChangeType getChangeType() const { return UNBUFFERED; }
175 :
176 : W* _findWindow( const uint128_t& id ); //!< @internal
177 :
178 : enum DirtyBits
179 : {
180 : DIRTY_ATTRIBUTES = Object::DIRTY_CUSTOM << 0,
181 : DIRTY_WINDOWS = Object::DIRTY_CUSTOM << 1,
182 : DIRTY_PIXELVIEWPORT = Object::DIRTY_CUSTOM << 2,
183 : DIRTY_MEMBER = Object::DIRTY_CUSTOM << 3,
184 : DIRTY_PIPE_BITS =
185 : DIRTY_ATTRIBUTES | DIRTY_WINDOWS | DIRTY_PIXELVIEWPORT |
186 : DIRTY_MEMBER | DIRTY_OBJECT_BITS
187 : };
188 :
189 : /** @internal @return the bits to be re-committed by the master. */
190 20 : virtual uint64_t getRedistributableBits() const
191 20 : { return DIRTY_PIPE_BITS; }
192 :
193 : private:
194 : /** The parent node. */
195 : N* const _node;
196 :
197 : /** The list of windows. */
198 : Windows _windows;
199 :
200 : /** Integer attributes. */
201 : int32_t _iAttributes[IATTR_ALL];
202 :
203 : /** The display (GLX) or ignored (Win32, AGL). */
204 : uint32_t _port;
205 :
206 : /** The screen (GLX), GPU (Win32) or virtual screen (AGL). */
207 : uint32_t _device;
208 :
209 1386 : struct BackupData
210 : {
211 : /** The size (and location) of the pipe. */
212 : PixelViewport pvp;
213 : }
214 : _data, _backup;
215 :
216 : struct Private;
217 : Private* _private; // placeholder for binary-compatible changes
218 :
219 : void _addWindow( W* window );
220 : EQFABRIC_INL bool _removeWindow( W* window );
221 : template< class, class, class, class > friend class Window;
222 :
223 : /** @internal */
224 134 : bool _mapNodeObjects() { return _node->_mapNodeObjects(); }
225 :
226 : typedef co::CommandFunc< Pipe< N, P, W, V > > CmdFunc;
227 : bool _cmdNewWindow( co::ICommand& command );
228 : bool _cmdNewWindowReply( co::ICommand& command );
229 : };
230 :
231 : template< class N, class P, class W, class V > EQFABRIC_INL
232 : std::ostream& operator << ( std::ostream&, const Pipe< N, P, W, V >& );
233 : }
234 : }
235 :
236 : #endif // EQFABRIC_PIPE_H
|