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