Changeset View
Changeset View
Standalone View
Standalone View
Modules/opengl/opengl.cpp
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
58 | #include <GL/glu.h> | 58 | #include <GL/glu.h> | ||
59 | 59 | | |||
60 | // OpenGL includes | 60 | // OpenGL includes | ||
61 | #include <GL/gl.h> | 61 | #include <GL/gl.h> | ||
62 | #include <GL/glext.h> | 62 | #include <GL/glext.h> | ||
63 | #include <GL/glx.h> | 63 | #include <GL/glx.h> | ||
64 | #endif | 64 | #endif | ||
65 | 65 | | |||
66 | #if defined(Q_OS_LINUX) | ||||
67 | #include <QFileInfo> | ||||
68 | #include <sys/stat.h> | ||||
69 | #include <sys/sysmacros.h> | ||||
70 | #endif | ||||
71 | | ||||
66 | K_PLUGIN_FACTORY(KCMOpenGLFactory, | 72 | K_PLUGIN_FACTORY(KCMOpenGLFactory, | ||
67 | registerPlugin<KCMOpenGL>(); | 73 | registerPlugin<KCMOpenGL>(); | ||
68 | ) | 74 | ) | ||
69 | 75 | | |||
70 | // FIXME: Temporary! | 76 | // FIXME: Temporary! | ||
71 | bool GetInfo_OpenGL(QTreeWidget *treeWidget); | 77 | bool GetInfo_OpenGL(QTreeWidget *treeWidget); | ||
72 | 78 | | |||
73 | KCMOpenGL::KCMOpenGL(QWidget *parent, const QVariantList &) | 79 | KCMOpenGL::KCMOpenGL(QWidget *parent, const QVariantList &) | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 175 | return 0; | |||
173 | 179 | | |||
174 | while (!t.atEnd()) list.append(t.readLine()); | 180 | while (!t.atEnd()) list.append(t.readLine()); | ||
175 | 181 | | |||
176 | return list.count(); | 182 | return list.count(); | ||
177 | } | 183 | } | ||
178 | 184 | | |||
179 | #if defined(Q_OS_LINUX) | 185 | #if defined(Q_OS_LINUX) | ||
180 | 186 | | |||
187 | static QString get_sysfs_link_name(const QString& path) | ||||
188 | { | ||||
189 | const QString target = QFileInfo(path).symLinkTarget(); | ||||
190 | | ||||
191 | const int index = target.lastIndexOf(QChar('/')); | ||||
192 | if (index == -1) | ||||
193 | return QString(); | ||||
194 | | ||||
195 | return target.mid(index + 1); | ||||
196 | } | ||||
197 | | ||||
198 | static bool get_drm_device_sysfs() | ||||
199 | { | ||||
200 | struct stat fileInfo; | ||||
201 | if (::stat("/dev/dri/card0", &fileInfo) != 0) | ||||
202 | return false; | ||||
203 | if ((fileInfo.st_mode & S_IFCHR) != S_IFCHR) | ||||
204 | return false; | ||||
205 | | ||||
206 | const uint16_t devMajor = major(fileInfo.st_rdev); | ||||
207 | const uint16_t devMinor = minor(fileInfo.st_rdev); | ||||
208 | QString sysPath = QStringLiteral("/sys/dev/char/%1:%2/device").arg(devMajor).arg(devMinor); | ||||
209 | | ||||
210 | dri_info.pci = get_sysfs_link_name(sysPath); | ||||
211 | dri_info.module = get_sysfs_link_name(sysPath + QStringLiteral("/driver/module")); | ||||
wbauer: Using just "/driver" (instead of "/driver/module") makes it display "radeon" instead of "drm"… | |||||
Have changed to use /driver instead of /driver/module. Am preferring to err on the side of not adding more numbered line reads from lspci output. roberts: Have changed to use `/driver` instead of `/driver/module`.
Am preferring to err on the side of… | |||||
212 | | ||||
213 | return (dri_info.pci.size() && dri_info.module.size()); | ||||
214 | } | ||||
215 | | ||||
181 | #define INFO_DRI QStringLiteral("/proc/dri/0/name") | 216 | #define INFO_DRI QStringLiteral("/proc/dri/0/name") | ||
182 | 217 | | |||
183 | static bool get_dri_device() | 218 | static bool get_dri_device_proc() | ||
184 | { | 219 | { | ||
185 | QFile file; | 220 | QFile file; | ||
186 | file.setFileName(INFO_DRI); | 221 | file.setFileName(INFO_DRI); | ||
187 | if (!file.exists() || !file.open(QIODevice::ReadOnly)) | 222 | if (!file.exists() || !file.open(QIODevice::ReadOnly)) | ||
188 | return false; | 223 | return false; | ||
189 | 224 | | |||
190 | QTextStream stream(&file); | 225 | QTextStream stream(&file); | ||
191 | QString line = stream.readLine(); | 226 | QString line = stream.readLine(); | ||
192 | if (!line.isEmpty()) { | 227 | if (line.isEmpty()) | ||
228 | return false; | ||||
193 | dri_info.module = line.mid(0, line.indexOf(0x20)); | 229 | dri_info.module = line.mid(0, line.indexOf(0x20)); | ||
194 | 230 | | |||
195 | // possible formats, for regression testing | 231 | // possible formats, for regression testing | ||
196 | // line = " PCI:01:00:0"; | 232 | // line = " PCI:01:00:0"; | ||
197 | // line = " pci:0000:01:00.0" | 233 | // line = " pci:0000:01:00.0" | ||
198 | QRegExp rx = QRegExp("\\b[Pp][Cc][Ii][:]([0-9a-fA-F]+[:])?([0-9a-fA-F]+[:][0-9a-fA-F]+[:.][0-9a-fA-F]+)\\b"); | 234 | QRegExp rx = QRegExp("\\b[Pp][Cc][Ii][:]([0-9a-fA-F]+[:])?([0-9a-fA-F]+[:][0-9a-fA-F]+[:.][0-9a-fA-F]+)\\b"); | ||
199 | if (rx.indexIn(line)>0) { | 235 | if (rx.indexIn(line)>0) { | ||
200 | dri_info.pci = rx.cap(2); | 236 | dri_info.pci = rx.cap(2); | ||
201 | int end = dri_info.pci.lastIndexOf(':'); | 237 | int end = dri_info.pci.lastIndexOf(':'); | ||
202 | int end2 = dri_info.pci.lastIndexOf('.'); | 238 | int end2 = dri_info.pci.lastIndexOf('.'); | ||
203 | if (end2>end) end=end2; | 239 | if (end2>end) end=end2; | ||
204 | dri_info.pci[end]='.'; | 240 | dri_info.pci[end]='.'; | ||
241 | return true; | ||||
242 | } | ||||
243 | return false; | ||||
244 | } | ||||
245 | | ||||
246 | static bool get_dri_device() | ||||
247 | { | ||||
248 | if (!get_drm_device_sysfs() && !get_dri_device_proc()) | ||||
249 | return false; | ||||
205 | 250 | | |||
206 | QString cmd = QStringLiteral("lspci -m -v -s ") + dri_info.pci; | 251 | QString cmd = QStringLiteral("lspci -m -v -s ") + dri_info.pci; | ||
207 | QStringList pci_info; | 252 | QStringList pci_info; | ||
208 | int num; | 253 | int num; | ||
209 | if (((num = ReadPipe(cmd, pci_info)) || | 254 | if (((num = ReadPipe(cmd, pci_info)) || | ||
210 | (num = ReadPipe("/sbin/"+cmd, pci_info)) || | 255 | (num = ReadPipe("/sbin/"+cmd, pci_info)) || | ||
211 | (num = ReadPipe("/usr/sbin/"+cmd, pci_info)) || | 256 | (num = ReadPipe("/usr/sbin/"+cmd, pci_info)) || | ||
212 | (num = ReadPipe("/usr/local/sbin/"+cmd, pci_info))) && num>=7) { | 257 | (num = ReadPipe("/usr/local/sbin/"+cmd, pci_info))) && num>=7) { | ||
258 | QString line; | ||||
213 | for (int i=2; i<=6; i++) { | 259 | for (int i=2; i<=6; i++) { | ||
214 | line = pci_info[i]; | 260 | line = pci_info[i]; | ||
215 | line.remove(QRegExp("[^:]*:[ ]*")); | 261 | line.remove(QRegExp("[^:]*:[ ]*")); | ||
216 | switch (i){ | 262 | switch (i){ | ||
217 | case 2: dri_info.vendor = line; break; | 263 | case 2: dri_info.vendor = line; break; | ||
218 | case 3: dri_info.device = line; break; | 264 | case 3: dri_info.device = line; break; | ||
219 | case 4: dri_info.subvendor = line; break; | 265 | case 4: dri_info.subvendor = line; break; | ||
220 | case 6: dri_info.rev = line; break; | 266 | case 6: dri_info.rev = line; break; | ||
221 | } | 267 | } | ||
222 | } | 268 | } | ||
223 | return true; | 269 | return true; | ||
224 | } | 270 | } | ||
225 | } | | |||
226 | } | | |||
227 | 271 | | |||
228 | return false; | 272 | return false; | ||
229 | } | 273 | } | ||
230 | 274 | | |||
231 | #elif defined(Q_OS_FREEBSD) | 275 | #elif defined(Q_OS_FREEBSD) | ||
232 | 276 | | |||
233 | static bool get_dri_device() { | 277 | static bool get_dri_device() { | ||
234 | 278 | | |||
▲ Show 20 Lines • Show All 757 Lines • Show Last 20 Lines |
Using just "/driver" (instead of "/driver/module") makes it display "radeon" instead of "drm" here as I would expect.
OTOH, as it already runs lspci to get the other information, wouldn't it be better to get the kernel module from lspci as well?
Additionally specifying the '-k' parameter to lspci adds these two lines to lspci's output here:
Driver: radeon
Module: radeon
(the first one is the driver in use, the second one lists all available modules for that device, see also "man lspci")
That should be independent of the kernel version and also work the same in the get_dri_device_proc() case.
Just a thought though.