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