Line data Source code
1 :
2 : /* Copyright (c) 2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #include "segment.h"
19 :
20 : #include "canvas.h"
21 : #include "channel.h"
22 : #include "compound.h"
23 : #include "config.h"
24 : #include "configDestCompoundVisitor.h"
25 : #include "pipe.h"
26 : #include "view.h"
27 : #include "window.h"
28 :
29 : #include <co/dataOStream.h>
30 : #include <eq/fabric/paths.h>
31 :
32 : #include <boost/foreach.hpp>
33 :
34 : namespace eq
35 : {
36 : namespace server
37 : {
38 : typedef fabric::Segment<Canvas, Segment, Channel> Super;
39 :
40 792 : Segment::Segment(Canvas* parent)
41 : : Super(parent)
42 792 : , _private(0)
43 : {
44 792 : }
45 :
46 2370 : Segment::~Segment()
47 : {
48 : ConfigDestCompoundVisitor visitor(_destinationChannels,
49 1580 : false /*activeOnly*/);
50 790 : getConfig()->accept(visitor);
51 790 : const Compounds& compounds = visitor.getResult();
52 :
53 790 : for (Compounds::const_iterator i = compounds.begin(); i != compounds.end();
54 : ++i)
55 : {
56 0 : Compound* compound = *i;
57 0 : while (compound)
58 : {
59 0 : Compound* parent = compound->getParent();
60 0 : delete compound;
61 0 : if (parent && parent->isLeaf()) // empty parent now
62 0 : compound = parent;
63 : else
64 0 : compound = 0;
65 : }
66 : }
67 :
68 : // Use copy - Channel::unsetOutput modifies vector
69 1580 : Channels destinationChannels = _destinationChannels;
70 6036 : for (Channels::const_iterator i = destinationChannels.begin();
71 4024 : i != destinationChannels.end(); ++i)
72 : {
73 1222 : Channel* channel = *i;
74 1222 : LBASSERT(channel);
75 1222 : channel->unsetOutput();
76 : }
77 :
78 790 : LBASSERT(_destinationChannels.empty());
79 790 : _destinationChannels.clear();
80 1580 : }
81 :
82 0 : void Segment::updateFrustum()
83 : {
84 0 : BOOST_FOREACH (Channel* channel, _destinationChannels)
85 : {
86 0 : View* view = channel->getView();
87 0 : view->updateFrusta();
88 : }
89 0 : }
90 :
91 792 : Config* Segment::getConfig()
92 : {
93 792 : Canvas* canvas = getCanvas();
94 792 : LBASSERT(canvas);
95 792 : return canvas ? canvas->getConfig() : 0;
96 : }
97 :
98 398 : const Config* Segment::getConfig() const
99 : {
100 398 : const Canvas* canvas = getCanvas();
101 398 : LBASSERT(canvas);
102 398 : return canvas ? canvas->getConfig() : 0;
103 : }
104 :
105 2 : ServerPtr Segment::getServer()
106 : {
107 2 : Canvas* canvas = getCanvas();
108 2 : LBASSERT(canvas);
109 2 : return (canvas ? canvas->getServer() : 0);
110 : }
111 :
112 1224 : void Segment::addDestinationChannel(Channel* channel)
113 : {
114 1224 : LBASSERT(channel);
115 1224 : LBASSERT(std::find(_destinationChannels.begin(), _destinationChannels.end(),
116 : channel) == _destinationChannels.end());
117 :
118 1224 : _destinationChannels.push_back(channel);
119 1224 : }
120 :
121 1222 : bool Segment::removeDestinationChannel(Channel* channel)
122 : {
123 1222 : Channels::iterator i = lunchbox::find(_destinationChannels, channel);
124 :
125 1222 : LBASSERT(i != _destinationChannels.end());
126 1222 : if (i == _destinationChannels.end())
127 0 : return false;
128 :
129 1222 : _destinationChannels.erase(i);
130 :
131 1222 : LBASSERT(lunchbox::find(_destinationChannels, channel) ==
132 : _destinationChannels.end());
133 1222 : return true;
134 : }
135 :
136 0 : void Segment::findDestinationChannels(const Layout* layout,
137 : Channels& result) const
138 : {
139 0 : for (Channels::const_iterator i = _destinationChannels.begin();
140 0 : i != _destinationChannels.end(); ++i)
141 : {
142 0 : Channel* channel = *i;
143 0 : if (channel->getLayout() == layout)
144 0 : result.push_back(channel);
145 : }
146 0 : }
147 :
148 638 : SegmentPath Segment::getPath() const
149 : {
150 638 : const Canvas* canvas = getCanvas();
151 638 : LBASSERT(canvas);
152 638 : SegmentPath path(canvas->getPath());
153 :
154 638 : const Segments& segments = canvas->getSegments();
155 : Segments::const_iterator i =
156 638 : std::find(segments.begin(), segments.end(), this);
157 638 : LBASSERT(i != segments.end());
158 638 : path.segmentIndex = std::distance(segments.begin(), i);
159 638 : return path;
160 : }
161 : }
162 : }
163 :
164 : #include "../fabric/segment.ipp"
165 : template class eq::fabric::Segment<eq::server::Canvas, eq::server::Segment,
166 : eq::server::Channel>;
167 : /** @cond IGNORE */
168 : template std::ostream& eq::fabric::operator<<(std::ostream&,
169 60 : const eq::server::Super&);
170 : /** @endcond */
|