Line data Source code
1 :
2 : /* Copyright (c) 2010-2015, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 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 3059 : N* getNode() { return _node; }
41 : /** @return the parent node of this pipe. @version 1.0 */
42 92 : const N* getNode() const { return _node; }
43 :
44 : /** @return the vector of child windows. @version 1.0 */
45 29157 : 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 X11/GLX
51 : * window system, i.e., the :<strong><port></strong>.<screen> of
52 : * the DISPLAY name. It currently has no meaning on all other systems.
53 : *
54 : * @return the port number of this pipe, or LB_UNDEFINED_UINT32.
55 : * @version 1.0
56 : */
57 575 : uint32_t getPort() const { return _port; }
58 :
59 : EQFABRIC_INL void setPort( const uint32_t port ); //!< @internal
60 :
61 : /**
62 : * Returns the device number of this pipe.
63 : *
64 : * The device number identifies the X screen for systems using the X11/GLX
65 : * window system, or the number of the virtual screen for the AGL window
66 : * system. On Windows systems it identifies the graphics adapter. Normally
67 : * the device identifies a GPU.
68 : *
69 : * @return the device number of this pipe, or LB_UNDEFINED_UINT32.
70 : * @version 1.0
71 : */
72 651 : uint32_t getDevice() const { return _device; }
73 :
74 : EQFABRIC_INL void setDevice( const uint32_t device ); //!< @internal
75 :
76 : /** @return the pixel viewport. @version 1.0 */
77 3352 : const PixelViewport& getPixelViewport() const { return _data.pvp; }
78 :
79 : /**
80 : * Set the pipe's pixel viewport.
81 : *
82 : * If invalid, the OSPipe has to set it to the device viewport during
83 : * configInit().
84 : *
85 : * @param pvp the viewport in pixels.
86 : * @version 1.0
87 : */
88 : EQFABRIC_INL void setPixelViewport( const PixelViewport& pvp );
89 :
90 : /** @internal Notify this pipe that the viewport has changed. */
91 : void notifyPixelViewportChanged();
92 :
93 : /** @internal @return the index path to this pipe. */
94 : EQFABRIC_INL PipePath getPath() const;
95 :
96 : /**
97 : * Perform a depth-first traversal of this pipe.
98 : *
99 : * @param visitor the visitor.
100 : * @return the result of the visitor traversal.
101 : * @version 1.0
102 : */
103 : EQFABRIC_INL VisitorResult accept( V& visitor );
104 :
105 : /** Const-version of accept(). @version 1.0 */
106 : EQFABRIC_INL VisitorResult accept( V& visitor ) const;
107 : //@}
108 :
109 : /** @name Attributes */
110 : //@{
111 : /** Pipe attributes. @version 1.0 */
112 : enum IAttribute
113 : {
114 : // Note: also update string array initialization in pipe.cpp
115 : IATTR_HINT_THREAD, //!< Execute tasks in separate thread (default)
116 : IATTR_HINT_AFFINITY, //!< Bind render thread to subset of cores
117 : IATTR_HINT_CUDA_GL_INTEROP, //!< Configure CUDA context
118 : IATTR_LAST,
119 : IATTR_ALL = IATTR_LAST + 5
120 : };
121 :
122 : /** @internal Set a pipe attribute. */
123 : EQFABRIC_INL void setIAttribute( const IAttribute attr,
124 : const int32_t value );
125 :
126 : /** @return the value of a pipe integer attribute. @version 1.0 */
127 1727 : int32_t getIAttribute( const IAttribute attr ) const
128 1727 : { return _iAttributes[attr]; }
129 :
130 : /** @internal @return true if tasks are executed in a separate thread.*/
131 4 : bool isThreaded() const
132 4 : { return (getIAttribute( IATTR_HINT_THREAD ) == 1 ); }
133 :
134 : /** @internal @return the name of a pipe attribute. */
135 : EQFABRIC_INL static const std::string& getIAttributeString(
136 : const IAttribute attr );
137 : //@}
138 :
139 : /** @name internal */
140 : //@{
141 : EQFABRIC_INL virtual void backup(); //!< @internal
142 : EQFABRIC_INL virtual void restore(); //!< @internal
143 : void create( W** window ); //!< @internal
144 : void release( W* window ); //!< @internal
145 0 : virtual void output( std::ostream& ) const {} //!< @internal
146 : /** @internal */
147 : EQFABRIC_INL virtual uint128_t commit( const uint32_t incarnation =
148 : CO_COMMIT_NEXT );
149 : //@}
150 :
151 : protected:
152 : /** @internal Construct a new pipe. */
153 : explicit Pipe( N* parent );
154 : EQFABRIC_INL virtual ~Pipe( ); //!< @internal
155 :
156 : virtual void attach( const uint128_t& id,
157 : const uint32_t instanceID ); //!< @internal
158 : /** @internal */
159 : EQFABRIC_INL virtual void serialize( co::DataOStream& os,
160 : const uint64_t dirtyBits );
161 : /** @internal */
162 : EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
163 : const uint64_t dirtyBits );
164 :
165 : EQFABRIC_INL virtual void notifyDetach(); //!< @internal
166 :
167 : /** @internal @sa Serializable::setDirty() */
168 : EQFABRIC_INL virtual void setDirty( const uint64_t bits );
169 :
170 : /** @internal */
171 6 : virtual ChangeType getChangeType() const { return UNBUFFERED; }
172 :
173 : W* _findWindow( const uint128_t& id ); //!< @internal
174 :
175 : enum DirtyBits
176 : {
177 : DIRTY_ATTRIBUTES = Object::DIRTY_CUSTOM << 0,
178 : DIRTY_WINDOWS = Object::DIRTY_CUSTOM << 1,
179 : DIRTY_PIXELVIEWPORT = Object::DIRTY_CUSTOM << 2,
180 : DIRTY_MEMBER = Object::DIRTY_CUSTOM << 3,
181 : DIRTY_PIPE_BITS =
182 : DIRTY_ATTRIBUTES | DIRTY_WINDOWS | DIRTY_PIXELVIEWPORT |
183 : DIRTY_MEMBER | DIRTY_OBJECT_BITS
184 : };
185 :
186 : /** @internal @return the bits to be re-committed by the master. */
187 0 : virtual uint64_t getRedistributableBits() const
188 0 : { return DIRTY_PIPE_BITS; }
189 :
190 : private:
191 : /** The parent node. */
192 : N* const _node;
193 :
194 : /** The list of windows. */
195 : Windows _windows;
196 :
197 : /** Integer attributes. */
198 : int32_t _iAttributes[IATTR_ALL];
199 :
200 : /** The display (GLX) or ignored (Win32, AGL). */
201 : uint32_t _port;
202 :
203 : /** The screen (GLX), GPU (Win32) or virtual screen (AGL). */
204 : uint32_t _device;
205 :
206 2474 : struct BackupData
207 : {
208 : /** The size (and location) of the pipe. */
209 : PixelViewport pvp;
210 : }
211 : _data, _backup;
212 :
213 : struct Private;
214 : Private* _private; // placeholder for binary-compatible changes
215 :
216 : void _addWindow( W* window );
217 : EQFABRIC_INL bool _removeWindow( W* window );
218 : template< class, class, class, class > friend class Window;
219 :
220 : /** @internal */
221 6 : bool _mapNodeObjects() { return _node->_mapNodeObjects(); }
222 :
223 : typedef co::CommandFunc< Pipe< N, P, W, V > > CmdFunc;
224 : bool _cmdNewWindow( co::ICommand& command );
225 : bool _cmdNewWindowReply( co::ICommand& command );
226 : };
227 :
228 : template< class N, class P, class W, class V > EQFABRIC_INL
229 : std::ostream& operator << ( std::ostream&, const Pipe< N, P, W, V >& );
230 : }
231 : }
232 :
233 : #endif // EQFABRIC_PIPE_H
|