HW-SD  1.0.0
gpuInfo.h
1 
2 /* Copyright (c) 2011-2012, Stefan Eilemann <eile@eyescale.ch>
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 #ifndef HWSD_GPUINFO_H
19 #define HWSD_GPUINFO_H
20 
21 #include <hwsd/nodeInfo.h> // base class
22 
23 #include <climits>
24 #include <cstring>
25 #include <iostream>
26 #include <string>
27 
28 
29 namespace hwsd
30 {
32  struct GPUInfo : public NodeInfo
33  {
35  static const unsigned defaultValue = UINT_MAX;
36 
38  static const unsigned FLAG_VIRTUALGL = 0x1;
39 
41  static const unsigned FLAG_VIRTUALGL_DISPLAY = 0x2;
42 
46  , flags( 0 )
47  { invalidatePVP(); }
48 
58  GPUInfo( const std::string& name )
60  , flags( 0 )
61  {
62  invalidatePVP();
63  strncpy( reinterpret_cast< char* >( &type ), name.c_str(), 4 );
64  }
65 
68  {
69  pvp[0] = 0;
70  pvp[1] = 0;
71  pvp[2] = -1;
72  pvp[3] = -1;
73  }
74 
76  bool operator == ( const GPUInfo& rhs ) const
77  {
78  return ( NodeInfo::operator==( rhs ) && type == rhs.type &&
79  port == rhs.port && device == rhs.device &&
80  pvp[0] == rhs.pvp[0] && pvp[1] == rhs.pvp[1] &&
81  pvp[2] == rhs.pvp[2] && pvp[3] == rhs.pvp[3] );
82  }
83 
85  bool operator != ( const GPUInfo& rhs ) const
86  {
87  return !(*this == rhs );
88  }
89 
91  std::string getName() const
92  { return std::string( reinterpret_cast<const char*>( &type ), 4 ); }
93 
95  unsigned type;
96 
98  unsigned port;
99 
104  unsigned device;
105 
107  int pvp[4];
108 
109  unsigned flags;
110  unsigned unused;
111  char dummy[32];
112  };
113 
114  inline std::ostream& operator << ( std::ostream& os, const GPUInfo& info )
115  {
116  os << "GPUInfo\n" << static_cast< const NodeInfo& >( info );
117  if( !info.getName().empty( ))
118  os << " Type " << info.getName() << std::endl;
119  if( info.port != GPUInfo::defaultValue )
120  os << " Port " << info.port << std::endl;
121  if( info.device != GPUInfo::defaultValue )
122  os << " Device " << info.device << std::endl;
123  if( info.pvp[2] >0 && info.pvp[3] > 0 )
124  os << " Viewport [" << info.pvp[0] << ' ' << info.pvp[1] << ' '
125  << info.pvp[2] << ' ' << info.pvp[3] << ']' << std::endl;
126  if( info.flags != 0 )
127  os << " Flags "
128  << (info.flags&GPUInfo::FLAG_VIRTUALGL ? "VirtualGL" : "")
129  << (info.flags&GPUInfo::FLAG_VIRTUALGL_DISPLAY ? "Display" : "")
130  << std::endl;
131  return os;
132  }
133 }
134 
135 #endif // HWSD_GPUINFO_H