GPUInfos Module::discover() const { GPUInfos result; GPUInfo defaultInfo( "GLX" ); const char* displayEnv = getenv( "DISPLAY" ); if( displayEnv && displayEnv[0] != '\0' ) { const std::string display( displayEnv ); if( queryDisplay_( display, defaultInfo )) { defaultInfo.flags = GPUInfo::FLAG_DEFAULT; result.push_back( defaultInfo ); #ifdef __APPLE__ // OS X only has one X server, but launchd magic makes duplicate // detection hard return result; #endif } } // try x servers :0 - :n for( unsigned i = 0; i < std::numeric_limits< unsigned >::max() ; ++i ) // x screens :n.0 - :n.m for( unsigned j = 0; j < std::numeric_limits< unsigned >::max(); ++j ) { std::stringstream stream; stream << ':' << i << '.' << j; GPUInfo info( "GLX" ); if( queryDisplay_( stream.str(), info )) { if( info != defaultInfo ) result.push_back( info ); } else if( j == 0 && i > TRY_PORTS ) // X Server does not exist, stop query return result; else // X Screen does not exist, try next server break; } return result; }
GPUInfos Module::discover() const { GPUInfos result; GPUInfo defaultInfo( "GLX" ); const char* displayEnv = getenv( "DISPLAY" ); if( displayEnv && displayEnv[0] != '\0' ) { const std::string display( displayEnv ); if( queryDisplay_( display, defaultInfo )) { if( display[0] != ':' && display[0] != '/' /* OS X launchd */ ) { defaultInfo.port = GPUInfo::defaultValue; defaultInfo.device = GPUInfo::defaultValue; } result.push_back( defaultInfo ); } } // try x servers :0 - :n for( unsigned i = 0; i < std::numeric_limits< unsigned >::max() ; ++i ) // x screens :n.0 - :n.m for( unsigned j = 0; j < std::numeric_limits< unsigned >::max(); ++j ) { std::stringstream stream; stream << ':' << i << '.' << j; GPUInfo info( "GLX" ); if( queryDisplay_( stream.str(), info )) { if( info != defaultInfo ) result.push_back( info ); } else if( j == 0 && i >= TRY_PORTS ) // X Server does not exist, stop query return result; else // X Screen does not exist, try next server break; } return result; }
GPUInfos Module::discoverGPUs( FilterPtr filter ) { GPUInfos result; for( Module* module = stack_; module; module = module->impl_->next_ ) { const GPUInfos infos = module->discoverGPUs_(); for( GPUInfosCIter i = infos.begin(); i != infos.end(); ++i ) { const GPUInfo& info = *i; if( !filter || (*filter)( result, info )) result.push_back( info ); } } return result; }