Line data Source code
1 :
2 : /* Copyright (c) 2011-2013, Stefan Eilemann <eile@eyescale.h>
3 : * 2012-2014, Daniel Nachbaur <danielnachbaur@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 : #include "display.h"
20 :
21 : #include "resources.h"
22 : #include "../canvas.h"
23 : #include "../channel.h"
24 : #include "../config.h"
25 : #include "../layout.h"
26 : #include "../node.h"
27 : #include "../pipe.h"
28 : #include "../observer.h"
29 : #include "../segment.h"
30 : #include "../view.h"
31 : #include "../window.h"
32 :
33 : #include <eq/fabric/configParams.h>
34 :
35 : namespace eq
36 : {
37 : namespace server
38 : {
39 : namespace config
40 : {
41 :
42 : namespace
43 : {
44 :
45 8 : void _choosePixelViewport( Window& window )
46 : {
47 8 : int32_t width = window.getIAttribute( WindowSettings::IATTR_HINT_WIDTH );
48 8 : int32_t height = window.getIAttribute( WindowSettings::IATTR_HINT_HEIGHT );
49 8 : if( width == fabric::UNDEFINED && height == fabric::UNDEFINED )
50 : {
51 8 : window.setViewport( Viewport( .25f, .2f, .5f, .5f ));
52 16 : return;
53 : }
54 :
55 0 : const PixelViewport& pvp = window.getPipe()->getPixelViewport();
56 : const int32_t drawable =
57 0 : window.getIAttribute( WindowSettings::IATTR_HINT_DRAWABLE );
58 :
59 0 : if( width > 0 )
60 : {
61 0 : if ( drawable == fabric::WINDOW && pvp.isValid( ))
62 0 : width = std::min( pvp.w, width );
63 : }
64 0 : else if( pvp.isValid( ))
65 0 : width = pvp.w * .5f;
66 : else
67 0 : width = 860; // An arbitrary value
68 :
69 0 : if( height > 0 )
70 : {
71 0 : if ( drawable == fabric::WINDOW && pvp.isValid( ))
72 0 : height = std::min( pvp.h, height );
73 : }
74 0 : else if( pvp.isValid( ))
75 0 : height = pvp.h * .5f;
76 : else
77 0 : height = 540; // An arbitrary value
78 :
79 0 : const uint32_t x = ( pvp.w - width ) * 0.5;
80 0 : const uint32_t y = ( pvp.h - height ) * 0.5;
81 :
82 0 : window.setPixelViewport( PixelViewport( x, y, width, height ));
83 : }
84 :
85 : }
86 :
87 :
88 8 : void Display::discoverLocal( Config* config, const uint32_t flags )
89 : {
90 8 : Node* node = config->findAppNode();
91 8 : LBASSERT( node );
92 8 : if( !node )
93 0 : return;
94 :
95 8 : const Pipes& pipes = node->getPipes();
96 8 : LBASSERT( !pipes.empty( ));
97 8 : if( pipes.empty( ))
98 0 : return;
99 :
100 8 : Pipe* pipe = pipes.front();
101 8 : Window* window = new Window( pipe );
102 8 : _choosePixelViewport( *window );
103 8 : window->setName( pipe->getName() + " window" );
104 8 : window->setIAttribute( WindowSettings::IATTR_PLANES_STENCIL, 1 );
105 :
106 8 : Channel* channel = new Channel( window );
107 8 : channel->setName( pipe->getName() + " channel" );
108 8 : Observer* observer = new Observer( config );
109 :
110 8 : const PixelViewport& pvp = pipe->getPixelViewport();
111 8 : const PixelViewport& windowPvp = window->getPixelViewport( );
112 8 : Wall wall;
113 :
114 8 : if( windowPvp.isValid( ))
115 8 : wall.resizeHorizontalToAR( float( windowPvp.w ) / float( windowPvp.h ));
116 0 : else if( pvp.isValid( ))
117 0 : wall.resizeHorizontalToAR( float( pvp.w ) / float( pvp.h ));
118 :
119 8 : Canvas* canvas = new Canvas( config );
120 8 : canvas->setWall( wall );
121 :
122 8 : Segment* segment = new Segment( canvas );
123 8 : segment->setChannel( channel );
124 :
125 8 : Strings names;
126 8 : const Nodes& nodes = config->getNodes();
127 8 : const bool scalability = nodes.size() > 1 || pipes.size() > 1;
128 :
129 8 : if( scalability )
130 8 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_2D_DYNAMIC );
131 :
132 8 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_SIMPLE );
133 :
134 8 : if( scalability )
135 : {
136 8 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_DS );
137 8 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_STATIC );
138 8 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_DYNAMIC );
139 8 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_2D_STATIC );
140 8 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_SUBPIXEL );
141 :
142 13 : if( flags & fabric::ConfigParams::FLAG_MULTIPROCESS_DB &&
143 5 : nodes.size() > 1 )
144 : {
145 5 : for( NodesCIter i = nodes.begin(); i != nodes.end(); ++i )
146 : {
147 5 : if( (*i)->getPipes().size() > 1 )
148 : {
149 5 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_2D );
150 5 : break;
151 : }
152 : }
153 : }
154 : }
155 :
156 69 : for( StringsCIter i = names.begin(); i != names.end(); ++i )
157 : {
158 61 : Layout* layout = new Layout( config );
159 61 : layout->setName( *i );
160 :
161 61 : View* view = new View( layout );
162 61 : view->setObserver( observer );
163 61 : view->setWall( wall );
164 :
165 61 : canvas->addLayout( layout );
166 : }
167 :
168 8 : config->activateCanvas( canvas );
169 : }
170 :
171 : }
172 : }
173 27 : }
|