Line data Source code
1 :
2 : /* Copyright (c) 2005-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 EQSERVER_CHANNEL_H
20 : #define EQSERVER_CHANNEL_H
21 :
22 : #include <eq/server/api.h>
23 : #include "state.h" // enum
24 : #include "types.h"
25 :
26 : #include <eq/fabric/channel.h> // base class
27 : #include <eq/fabric/pixelViewport.h> // member
28 : #include <eq/fabric/viewport.h> // member
29 : #include <lunchbox/monitor.h> // member
30 :
31 : #include <iostream>
32 : #include <vector>
33 :
34 : namespace eq
35 : {
36 : namespace server
37 : {
38 : class Channel : public fabric::Channel< Window, Channel >
39 : {
40 : public:
41 : /** Construct a new channel. */
42 : EQSERVER_API explicit Channel( Window* parent );
43 :
44 : /** Construct a copy of a channel. */
45 : Channel( const Channel& from );
46 :
47 : /** Destruct this channel. */
48 : virtual ~Channel();
49 :
50 : /** @return the state of this channel. */
51 20 : State getState() const { return _state.get(); }
52 :
53 : /** @internal */
54 2 : void setState( const State state ) { _state = state; }
55 :
56 : /**
57 : * @name Data Access
58 : */
59 : //@{
60 : Config* getConfig();
61 : const Config* getConfig() const;
62 :
63 : EQSERVER_API Node* getNode();
64 : EQSERVER_API const Node* getNode() const;
65 :
66 : Pipe* getPipe();
67 : const Pipe* getPipe() const;
68 :
69 : /** @return the parent server. @version 1.0 */
70 : ServerPtr getServer();
71 :
72 : const Compounds& getCompounds() const;
73 :
74 : co::CommandQueue* getMainThreadQueue();
75 : co::CommandQueue* getCommandThreadQueue();
76 :
77 : /** Increase channel activition count. */
78 : void activate();
79 :
80 : /** Decrease channel activition count. */
81 : void deactivate();
82 :
83 : /** @return if this channel is actively used for rendering. */
84 14 : bool isActive() const { return (_active != 0); }
85 :
86 : /** @return if this window is running. */
87 10 : bool isRunning() const { return _state == STATE_RUNNING; }
88 :
89 : /** Schedule deletion of this channel. */
90 : void postDelete();
91 :
92 : /**
93 : * Add additional tasks this channel, and all its parents, might
94 : * potentially execute.
95 : */
96 : void addTasks( const uint32_t tasks );
97 :
98 : /** Set the output view and segment for this channel. */
99 : void setOutput( View* view, Segment* segment );
100 :
101 : /** Unset the output view and segment for this channel. */
102 : void unsetOutput();
103 :
104 : /** @return the channel's view. */
105 600 : const View* getView() const { return _view; }
106 :
107 : /** @return the channel's canvas. */
108 : const Canvas* getCanvas() const;
109 :
110 : /** @return the channel's view. */
111 21376 : View* getView() { return _view; }
112 :
113 : /**
114 : * @return true if this channel supports the capabilities needed for
115 : * the view.
116 : */
117 : bool supportsView( const View* view ) const;
118 :
119 : /** @return the channel's layout. */
120 : EQSERVER_API const Layout* getLayout() const;
121 :
122 : /** @return the channel's segment. */
123 594 : const Segment* getSegment() const { return _segment; }
124 :
125 : /** @return the channel's segment. */
126 4152 : Segment* getSegment() { return _segment; }
127 :
128 : /** The last drawing compound for this entity. */
129 0 : void setLastDrawCompound( const Compound* compound )
130 0 : { _lastDrawCompound = compound; }
131 0 : const Compound* getLastDrawCompound() const { return _lastDrawCompound;}
132 :
133 11550 : void setIAttribute( const IAttribute attr, const int32_t value )
134 11550 : { fabric::Channel< Window, Channel >::setIAttribute( attr, value );}
135 9902 : void setSAttribute( const SAttribute attr, const std::string& value )
136 9902 : { fabric::Channel< Window, Channel >::setSAttribute( attr, value );}
137 : //@}
138 :
139 : /**
140 : * @name Operations
141 : */
142 : //@{
143 : /** Start initializing this entity. */
144 : void configInit( const uint128_t& initID, const uint32_t frameNumber );
145 :
146 : /** Sync initialization of this entity. */
147 : bool syncConfigInit();
148 :
149 : /** Start exiting this entity. */
150 : void configExit();
151 :
152 : /** Sync exit of this entity. */
153 : bool syncConfigExit();
154 :
155 : /**
156 : * Update one frame.
157 : *
158 : * @param frameID a per-frame identifier passed to all rendering
159 : * methods.
160 : * @param frameNumber the number of the frame.
161 : * @return true if at least one rendering task was sent.
162 : */
163 : bool update( const uint128_t& frameID, const uint32_t frameNumber );
164 :
165 : co::ObjectOCommand send( const uint32_t cmd );
166 : //@}
167 :
168 : /** @name Channel listener interface. */
169 : //@{
170 : /** Register a channel listener. */
171 : void addListener( ChannelListener* listener );
172 : /** Deregister a channel listener. */
173 : void removeListener( ChannelListener* listener );
174 : /** @return true if the channel has listeners */
175 0 : bool hasListeners() const { return !_listeners.empty(); }
176 : //@}
177 :
178 : bool omitOutput() const; //!< @internal
179 : void output( std::ostream& ) const; //!< @internal
180 :
181 : protected:
182 : /** @sa net::Object::attach. */
183 : virtual void attach( const uint128_t& id, const uint32_t instanceID );
184 :
185 : private:
186 : //-------------------- Members --------------------
187 : /** Number of activations for this channel. */
188 : uint32_t _active;
189 :
190 : /** The view used by this channel. */
191 : View* _view;
192 :
193 : /** The segment used by this channel. */
194 : Segment* _segment;
195 :
196 : Vector4i _overdraw;
197 :
198 : /** The current state for state change synchronization. */
199 : lunchbox::Monitor< State > _state;
200 :
201 : /** The last draw compound for this entity */
202 : const Compound* _lastDrawCompound;
203 :
204 : typedef std::vector< ChannelListener* > ChannelListeners;
205 : ChannelListeners _listeners;
206 :
207 5644 : LB_TS_VAR( _serverThread );
208 :
209 : struct Private;
210 : Private* _private; // placeholder for binary-compatible changes
211 :
212 : //-------------------- Methods --------------------
213 : Vector3ub _getUniqueColor() const;
214 :
215 : void _setupRenderContext( const uint128_t& frameID,
216 : RenderContext& context );
217 :
218 : void _fireLoadData( const uint32_t frameNumber,
219 : const Statistics& statistics,
220 : const Viewport& region );
221 :
222 : /* command handler functions. */
223 : bool _cmdConfigInitReply( co::ICommand& command );
224 : bool _cmdConfigExitReply( co::ICommand& command );
225 : bool _cmdFrameFinishReply( co::ICommand& command );
226 0 : bool _cmdNop( co::ICommand& /*command*/ )
227 0 : { return true; }
228 :
229 : virtual void updateCapabilities();
230 : };
231 : }
232 : }
233 : #endif // EQSERVER_CHANNEL_H
|