Merge branch 'master' of https://github.com/abaph/SingularityViewer
This commit is contained in:
@@ -75,6 +75,9 @@ static bool ATIbug = false;
|
|||||||
|
|
||||||
#if LL_X11
|
#if LL_X11
|
||||||
# include <X11/Xutil.h>
|
# include <X11/Xutil.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
#endif //LL_X11
|
#endif //LL_X11
|
||||||
|
|
||||||
// TOFU HACK -- (*exactly* the same hack as LLWindowMacOSX for a similar
|
// TOFU HACK -- (*exactly* the same hack as LLWindowMacOSX for a similar
|
||||||
@@ -270,57 +273,41 @@ static SDL_Surface *Load_BMP_Resource(const char *basename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if LL_X11
|
#if LL_X11
|
||||||
// This is an XFree86/XOrg-specific hack for detecting the amount of Video RAM
|
// This function scrapes the Xorg log to determine the amount of VRAM available to the system.
|
||||||
// on this machine. It works by searching /var/log/var/log/Xorg.?.log or
|
// Believe it or not, this is the most reliable way at present to detect VRAM on Linux (until
|
||||||
// /var/log/XFree86.?.log for a ': (VideoRAM ?|Memory): (%d+) kB' regex, where
|
// some angelic being ports the whole viewer to SDL 2.0 or something).
|
||||||
// '?' is the X11 display number derived from $DISPLAY
|
//
|
||||||
static int x11_detect_VRAM_kb_fp(FILE *fp, const char *prefix_str)
|
// Returns -1 if it couldn't open the file,
|
||||||
{
|
// 0 if it could open the file but couldn't detect the amount of VRAM, or
|
||||||
const int line_buf_size = 1000;
|
// >0 if it open the file and detect the amount of VRAM present.
|
||||||
char line_buf[line_buf_size];
|
// In that case, the number will be the amount of available VRAM in kilobytes.
|
||||||
while (fgets(line_buf, line_buf_size, fp))
|
//
|
||||||
{
|
//
|
||||||
//lldebugs << "XLOG: " << line_buf << llendl;
|
static int x11_detect_VRAM_kb_br(std::string filename) {
|
||||||
|
boost::regex pattern(".*?(VRAM|Memory|Video\\s?RAM)\\D*(\\d+)\\s?([kK]B?)");
|
||||||
// Why the ad-hoc parser instead of using a regex? Our
|
std::string line;
|
||||||
// favourite regex implementation - libboost_regex - is
|
std::ifstream in(filename.c_str());
|
||||||
// quite a heavy and troublesome dependency for the client, so
|
int matched = -1;
|
||||||
// it seems a shame to introduce it for such a simple task.
|
if(in.is_open()) {
|
||||||
// *FIXME: libboost_regex is a dependency now anyway, so we may
|
matched = 0;
|
||||||
// as well use it instead of this hand-rolled nonsense.
|
while (getline(in, line))
|
||||||
const char *part1_template = prefix_str;
|
{
|
||||||
const char part2_template[] = " kB";
|
// lldebugs << "Processing line: " << line << llendl;
|
||||||
char *part1 = strstr(line_buf, part1_template);
|
boost::cmatch match;
|
||||||
if (part1) // found start of matching line
|
if(boost::regex_search(line.c_str(), match, pattern))
|
||||||
{
|
{
|
||||||
part1 = &part1[strlen(part1_template)]; // -> after
|
matched = atoi(std::string(match[2]).c_str());
|
||||||
char *part2 = strstr(part1, part2_template);
|
lldebugs << "VRAM found: " << matched << llendl;
|
||||||
if (part2) // found end of matching line
|
lldebugs << "Line matched: " << line << llendl;
|
||||||
{
|
}
|
||||||
// now everything between part1 and part2 is
|
}
|
||||||
// supposed to be numeric, describing the
|
in.close();
|
||||||
// number of kB of Video RAM supported
|
}
|
||||||
int rtn = 0;
|
else // We couldn't open the file, so bow out.
|
||||||
for (; part1 < part2; ++part1)
|
{
|
||||||
{
|
lldebugs << "Couldn't open logfile " << filename << llendl;
|
||||||
if (*part1 < '0' || *part1 > '9')
|
}
|
||||||
{
|
return matched;
|
||||||
// unexpected char, abort parse
|
|
||||||
rtn = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
rtn *= 10;
|
|
||||||
rtn += (*part1) - '0';
|
|
||||||
}
|
|
||||||
if (rtn > 0)
|
|
||||||
{
|
|
||||||
// got the kB number. return it now.
|
|
||||||
return rtn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0; // 'could not detect'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int x11_detect_VRAM_kb()
|
static int x11_detect_VRAM_kb()
|
||||||
@@ -335,9 +322,16 @@ static int x11_detect_VRAM_kb()
|
|||||||
std::string fname;
|
std::string fname;
|
||||||
int rtn = 0; // 'could not detect'
|
int rtn = 0; // 'could not detect'
|
||||||
int display_num = 0;
|
int display_num = 0;
|
||||||
FILE *fp;
|
char *display_env = getenv("VGL_DISPLAY"); // e.g. :0 or :0.0 or :1.0 etc
|
||||||
char *display_env = getenv("DISPLAY"); // e.g. :0 or :0.0 or :1.0 etc
|
// We parse $VGL_DISPLAY first so we can grab the right Xorg filename
|
||||||
// parse DISPLAY number so we can go grab the right log file
|
// if we're using VirtualGL (like Optimus systems do).
|
||||||
|
|
||||||
|
if (display_env == NULL) {
|
||||||
|
// if $VGL_DISPLAY doesn't exist, then we're in a single-card setup
|
||||||
|
display_env = getenv("DISPLAY");
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse display number so we can go grab the right log file
|
||||||
if (display_env[0] == ':' &&
|
if (display_env[0] == ':' &&
|
||||||
display_env[1] >= '0' && display_env[1] <= '9')
|
display_env[1] >= '0' && display_env[1] <= '9')
|
||||||
{
|
{
|
||||||
@@ -345,40 +339,16 @@ static int x11_detect_VRAM_kb()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// *TODO: we could be smarter and see which of Xorg/XFree86 has the
|
// *TODO: we could be smarter and see which of Xorg/XFree86 has the
|
||||||
// freshest time-stamp.
|
// freshest time-stamp. (...but would it work with VirtualGL?)
|
||||||
|
|
||||||
// Try Xorg log first
|
// Try Xorg log first
|
||||||
fname = x_log_location;
|
fname = x_log_location;
|
||||||
fname += "Xorg.";
|
fname += "Xorg.";
|
||||||
fname += ('0' + display_num);
|
fname += ('0' + display_num);
|
||||||
fname += ".log";
|
fname += ".log";
|
||||||
fp = fopen(fname.c_str(), "r");
|
llinfos << "Looking in " << fname << " for VRAM info..." << llendl;
|
||||||
if (fp)
|
rtn = x11_detect_VRAM_kb_br(fname);
|
||||||
{
|
if(rtn == -1) // we couldn't read the Xorg file
|
||||||
llinfos << "Looking in " << fname
|
|
||||||
<< " for VRAM info..." << llendl;
|
|
||||||
rtn = x11_detect_VRAM_kb_fp(fp, ": VideoRAM: ");
|
|
||||||
fclose(fp);
|
|
||||||
if (0 == rtn)
|
|
||||||
{
|
|
||||||
fp = fopen(fname.c_str(), "r");
|
|
||||||
if (fp)
|
|
||||||
{
|
|
||||||
rtn = x11_detect_VRAM_kb_fp(fp, ": Video RAM: ");
|
|
||||||
fclose(fp);
|
|
||||||
if (0 == rtn)
|
|
||||||
{
|
|
||||||
fp = fopen(fname.c_str(), "r");
|
|
||||||
if (fp)
|
|
||||||
{
|
|
||||||
rtn = x11_detect_VRAM_kb_fp(fp, ": Memory: ");
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
llinfos << "Could not open " << fname
|
llinfos << "Could not open " << fname
|
||||||
<< " - skipped." << llendl;
|
<< " - skipped." << llendl;
|
||||||
@@ -387,29 +357,17 @@ static int x11_detect_VRAM_kb()
|
|||||||
fname += "XFree86.";
|
fname += "XFree86.";
|
||||||
fname += ('0' + display_num);
|
fname += ('0' + display_num);
|
||||||
fname += ".log";
|
fname += ".log";
|
||||||
fp = fopen(fname.c_str(), "r");
|
llinfos << "Looking in " << fname << " for VRAM info..." << llendl;
|
||||||
if (fp)
|
rtn = x11_detect_VRAM_kb_br(fname);
|
||||||
{
|
if(rtn == -1) // couldn't read old X log file either
|
||||||
llinfos << "Looking in " << fname
|
|
||||||
<< " for VRAM info..." << llendl;
|
|
||||||
rtn = x11_detect_VRAM_kb_fp(fp, ": VideoRAM: ");
|
|
||||||
fclose(fp);
|
|
||||||
if (0 == rtn)
|
|
||||||
{
|
|
||||||
fp = fopen(fname.c_str(), "r");
|
|
||||||
if (fp)
|
|
||||||
{
|
|
||||||
rtn = x11_detect_VRAM_kb_fp(fp, ": Memory: ");
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
llinfos << "Could not open " << fname
|
llinfos << "Could not open " << fname
|
||||||
<< " - skipped." << llendl;
|
<< " - skipped." << llendl;
|
||||||
|
//stumped here, return 0
|
||||||
|
rtn = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
llinfos << "Amount of VRAM detected: "<< rtn << " KB" << llendl;
|
||||||
return rtn;
|
return rtn;
|
||||||
#endif // LL_SOLARIS
|
#endif // LL_SOLARIS
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user