Line data Source code
1 :
2 : /* Copyright (c) 2011-2015, 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 0 : void _choosePixelViewport( Window& window )
46 : {
47 0 : int32_t width = window.getIAttribute( WindowSettings::IATTR_HINT_WIDTH );
48 0 : int32_t height = window.getIAttribute( WindowSettings::IATTR_HINT_HEIGHT );
49 0 : if( width == fabric::UNDEFINED && height == fabric::UNDEFINED )
50 : {
51 0 : window.setViewport( Viewport( .25f, .2f, .5f, .5f ));
52 :
53 : // Make the window aspect ratio 16:10, assuming square pixels
54 0 : PixelViewport pvp = window.getPixelViewport();
55 0 : pvp.w = pvp.h * 1.6f;
56 :
57 : // Position window in the middle of the first monitor, assuming 16:10 AR
58 0 : pvp.x = pvp.w / 2;
59 0 : window.setPixelViewport( pvp );
60 0 : return;
61 : }
62 :
63 0 : const PixelViewport& pvp = window.getPipe()->getPixelViewport();
64 : const int32_t drawable =
65 0 : window.getIAttribute( WindowSettings::IATTR_HINT_DRAWABLE );
66 :
67 0 : if( width > 0 )
68 : {
69 0 : if ( drawable == fabric::WINDOW && pvp.isValid( ))
70 0 : width = std::min( pvp.w, width );
71 : }
72 0 : else if( pvp.isValid( ))
73 0 : width = pvp.w * .5f;
74 : else
75 0 : width = 860; // An arbitrary value
76 :
77 0 : if( height > 0 )
78 : {
79 0 : if ( drawable == fabric::WINDOW && pvp.isValid( ))
80 0 : height = std::min( pvp.h, height );
81 : }
82 0 : else if( pvp.isValid( ))
83 0 : height = pvp.h * .5f;
84 : else
85 0 : height = 540; // An arbitrary value
86 :
87 0 : const uint32_t x = ( pvp.w - width ) * 0.5;
88 0 : const uint32_t y = ( pvp.h - height ) * 0.5;
89 :
90 0 : window.setPixelViewport( PixelViewport( x, y, width, height ));
91 : }
92 :
93 : }
94 :
95 0 : void Display::discoverLocal( Config* config, const ConfigParams& params )
96 : {
97 0 : Node* node = config->findAppNode();
98 0 : LBASSERT( node );
99 0 : if( !node )
100 0 : return;
101 :
102 0 : const Pipes& pipes = node->getPipes();
103 0 : LBASSERT( !pipes.empty( ));
104 0 : if( pipes.empty( ))
105 0 : return;
106 :
107 0 : Pipe* pipe = pipes.front();
108 0 : Window* window = new Window( pipe );
109 0 : _choosePixelViewport( *window );
110 0 : window->setName( params.getName( ));
111 0 : window->setIAttribute( WindowSettings::IATTR_PLANES_STENCIL, 1 );
112 :
113 0 : Channel* channel = new Channel( window );
114 0 : channel->setName( pipe->getName() + " channel" );
115 0 : Observer* observer = new Observer( config );
116 :
117 0 : const PixelViewport& pvp = pipe->getPixelViewport();
118 0 : const PixelViewport& windowPvp = window->getPixelViewport( );
119 0 : Wall wall;
120 :
121 0 : if( windowPvp.isValid( ))
122 0 : wall.resizeHorizontalToAR( float( windowPvp.w ) / float( windowPvp.h ));
123 0 : else if( pvp.isValid( ))
124 0 : wall.resizeHorizontalToAR( float( pvp.w ) / float( pvp.h ));
125 :
126 0 : Canvas* canvas = new Canvas( config );
127 0 : canvas->setWall( wall );
128 :
129 0 : Segment* segment = new Segment( canvas );
130 0 : segment->setChannel( channel );
131 :
132 0 : Strings names;
133 0 : const Nodes& nodes = config->getNodes();
134 0 : const bool scalability = nodes.size() > 1 || pipes.size() > 1;
135 :
136 0 : if( scalability )
137 0 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_2D_DYNAMIC );
138 :
139 0 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_SIMPLE );
140 :
141 0 : if( scalability )
142 : {
143 0 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_DS );
144 0 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_STATIC );
145 0 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_DYNAMIC );
146 0 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_2D_STATIC );
147 0 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_SUBPIXEL );
148 :
149 0 : if( params.getFlags() & fabric::ConfigParams::FLAG_MULTIPROCESS_DB &&
150 0 : nodes.size() > 1 )
151 : {
152 0 : for( NodesCIter i = nodes.begin(); i != nodes.end(); ++i )
153 : {
154 0 : if( (*i)->getPipes().size() > 1 )
155 : {
156 0 : names.push_back( EQ_SERVER_CONFIG_LAYOUT_DB_2D );
157 0 : break;
158 : }
159 : }
160 : }
161 : }
162 :
163 0 : for( StringsCIter i = names.begin(); i != names.end(); ++i )
164 : {
165 0 : Layout* layout = new Layout( config );
166 0 : layout->setName( *i );
167 :
168 0 : View* view = new View( layout );
169 0 : view->setObserver( observer );
170 0 : view->setWall( wall );
171 :
172 0 : canvas->addLayout( layout );
173 : }
174 :
175 0 : config->activateCanvas( canvas );
176 : }
177 :
178 : }
179 : }
180 84 : }
|