kwinglplatform.cpp 23.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/********************************************************************
 KWin - the KDE window manager
 This file is part of the KDE project.

Copyright (C) 2010 Fredrik Höglund <fredrik@kde.org>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/

#include "kwinglplatform.h"
#include "kwinglutils.h"

#include <kwinglobals.h>

#include <QRegExp>
#include <QStringList>
#include <QDebug>

#include <sys/utsname.h>

32 33
#include <iostream>
#include <iomanip>
34
#include <ios>
35

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#ifdef KWIN_HAVE_OPENGL

namespace KWin
{

GLPlatform *GLPlatform::s_platform = 0;

static qint64 parseVersionString(const QByteArray &version)
{
    // Skip any leading non digit
    int start = 0;
    while (start < version.length() && !QChar(version[start]).isDigit())
        start++;

    // Strip any non digit, non '.' characters from the end
    int end = start;
    while (end < version.length() && (version[end] == '.' || QChar(version[end]).isDigit()))
        end++;

    const QByteArray result = version.mid(start, end);
    const QList<QByteArray> tokens = result.split('.');
    const qint64 major = tokens.at(0).toInt();
    const qint64 minor = tokens.count() > 1 ? tokens.at(1).toInt() : 0;
    const qint64 patch = tokens.count() > 2 ? tokens.at(2).toInt() : 0;

    return kVersionNumber(major, minor, patch);
}

static qint64 getXServerVersion()
{
    qint64 major, minor, patch;

    Display *dpy = display();
    if (strstr(ServerVendor(dpy), "X.Org")) {
        const int release  = VendorRelease(dpy);
        major = (release / 10000000);
        minor = (release /   100000) % 100;
        patch = (release /     1000) % 100;
    } else {
        major = 0;
        minor = 0;
        patch = 0;
    }

    return kVersionNumber(major, minor, patch);
}

static qint64 getKernelVersion()
{
    struct utsname name;
    uname(&name);

    if (QByteArray(name.sysname) == "Linux")
        return parseVersionString(name.release);

    return 0;
}

// Extracts the portion of a string that matches a regular expression
static QString extract(const QString &string, const QString &match, int offset = 0)
{
    QString result;
    QRegExp rx(match);
    int pos = rx.indexIn(string, offset);
    if (pos != -1)
       result = string.mid(pos, rx.matchedLength());
    return result;
}

static ChipClass detectRadeonClass(const QString &chipset)
{
    if (chipset.isEmpty())
        return UnknownRadeon;

    if (chipset.contains("R100")  ||
        chipset.contains("RV100") ||
        chipset.contains("RS100"))
        return R100;

    if (chipset.contains("RV200") ||
        chipset.contains("RS200") ||
        chipset.contains("R200")  ||
        chipset.contains("RV250") ||
        chipset.contains("RS300") ||
        chipset.contains("RV280"))
        return R200;

    if (chipset.contains("R300")  ||
        chipset.contains("R350")  ||
125
        chipset.contains("R360")  ||
126
        chipset.contains("RV350") ||
127
        chipset.contains("RV370") ||
128 129 130 131
        chipset.contains("RV380"))
        return R300;

    if (chipset.contains("R420")  ||
132 133 134 135
        chipset.contains("R423")  ||
        chipset.contains("R430")  ||
        chipset.contains("R480")  ||
        chipset.contains("R481")  ||
136 137
        chipset.contains("RV410") ||
        chipset.contains("RS400") ||
138 139 140
        chipset.contains("RC410") ||
        chipset.contains("RS480") ||
        chipset.contains("RS482") ||
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
        chipset.contains("RS600") ||
        chipset.contains("RS690") ||
        chipset.contains("RS740"))
        return R400;

    if (chipset.contains("RV515") ||
        chipset.contains("R520")  ||
        chipset.contains("RV530") ||
        chipset.contains("R580")  ||
        chipset.contains("RV560") ||
        chipset.contains("RV570"))
        return R500;

    if (chipset.contains("R600")  ||
        chipset.contains("RV610") ||
        chipset.contains("RV630") ||
        chipset.contains("RV670") ||
        chipset.contains("RV620") ||
        chipset.contains("RV635") ||
        chipset.contains("RS780") ||
        chipset.contains("RS880"))
        return R600;

    if (chipset.contains("R700")  ||
        chipset.contains("RV770") ||
        chipset.contains("RV730") ||
        chipset.contains("RV710") ||
        chipset.contains("RV740"))
        return R700;

    if (chipset.contains("EVERGREEN") || // Not an actual chipset, but returned by R600G in 7.9
        chipset.contains("CEDAR")     ||
        chipset.contains("REDWOOD")   ||
        chipset.contains("JUNIPER")   ||
        chipset.contains("CYPRESS")   ||
Fredrik Höglund's avatar
Fredrik Höglund committed
176
        chipset.contains("PALM")      ||
177 178 179
        chipset.contains("HEMLOCK"))
        return Evergreen;

180 181 182 183 184
    if (chipset.contains("BARTS") ||
        chipset.contains("TURKS") ||
        chipset.contains("CAICOS"))
        return NorthernIslands;

Fredrik Höglund's avatar
Fredrik Höglund committed
185 186 187 188
    QString name = extract(chipset, "HD [0-9]{4}"); // HD followed by a space and 4 digits
    if (!name.isEmpty()) {
        const int id = name.right(4).toInt();
        if (id == 6250 || id == 6310)  // Palm
189
            return Evergreen;
Fredrik Höglund's avatar
Fredrik Höglund committed
190 191 192 193 194 195 196 197 198 199 200

        if (id >= 6000 && id < 7000)
            return NorthernIslands;    // HD 6xxx

        if (id >= 5000 && id < 6000)
            return Evergreen;          // HD 5xxx

        if (id >= 4000 && id < 5000)
            return R700;               // HD 4xxx

        if (id >= 2000 && id < 4000)   // HD 2xxx/3xxx
201
            return R600;
Fredrik Höglund's avatar
Fredrik Höglund committed
202 203

        return UnknownRadeon;
204 205
    }

Fredrik Höglund's avatar
Fredrik Höglund committed
206
    name = extract(chipset, "X[0-9]{3,4}"); // X followed by 3-4 digits
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
    if (!name.isEmpty()) {
        const int id = name.mid(1, -1).toInt();

        // X1xxx
        if (id >= 1300)
            return R500;

        // X7xx, X8xx, X12xx, 2100
        if ((id >= 700 && id < 1000) || id >= 1200)
            return R400;

        // X200, X3xx, X5xx, X6xx, X10xx, X11xx
        if ((id >= 300 && id < 700) || (id >= 1000 && id < 1200))
            return R300;

        return UnknownRadeon;
    }

Fredrik Höglund's avatar
Fredrik Höglund committed
225
    name = extract(chipset, "\\b[0-9]{4}\\b"); // A group of 4 digits
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
    if (!name.isEmpty()) {
        const int id = name.toInt();

        // 7xxx
        if (id >= 7000 && id < 8000)
            return R100;

        // 8xxx, 9xxx
        if (id >= 8000 && id < 9500)
            return R200;

        // 9xxx
        if (id >= 9500)
            return R300;

        if (id == 2100)
            return R400;
    }

    return UnknownRadeon;
}

static ChipClass detectNVidiaClass(const QString &chipset)
{
250
    QString name = extract(chipset, "\\bNV[0-9,A-F]{2}\\b"); // NV followed by two hexadecimal digits
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
    if (!name.isEmpty())
    {
        const int id = chipset.mid(2, -1).toInt(0, 16); // Strip the 'NV' from the id

        switch (id & 0xf0)
        {
        case 0x00:
        case 0x10:
            return NV10;

        case 0x20:
            return NV20;

        case 0x30:
            return NV30;

        case 0x40:
        case 0x60:
            return NV40;

        case 0x50:
        case 0x80:
        case 0x90:
        case 0xA0:
            return G80;

        default:
            return UnknownNVidia;
       }
    }

282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
    if (chipset.contains("GeForce2") || chipset.contains("GeForce 256"))
        return NV10;

    if (chipset.contains("GeForce3"))
        return NV20;

    if (chipset.contains("GeForce4")) {
        if (chipset.contains("MX 420")  ||
            chipset.contains("MX 440")  || // including MX 440SE
            chipset.contains("MX 460")  ||
            chipset.contains("MX 4000") ||
            chipset.contains("PCX 4300"))
            return NV10;

        return NV20;
    }

    // GeForce 5,6,7,8,9
    name = extract(chipset, "GeForce (FX |PCX |Go )?\\d{4}(M|\\b)").trimmed();
    if (!name.isEmpty()) {
        if (!name[name.length() - 1].isDigit())
            name.chop(1);

        const int id = name.right(4).toInt();
        if (id < 6000)
            return NV30;

        if (id >= 6000 && id < 8000)
            return NV40;

        if (id >= 8000)
            return G80;

        return UnknownNVidia;
    }

    // GeForce 100/200/300/400/500
    name = extract(chipset, "GeForce (G |GT |GTX |GTS )?\\d{3}(M|\\b)").trimmed();
    if (!name.isEmpty()) {
        if (!name[name.length() - 1].isDigit())
            name.chop(1);

        const int id = name.right(3).toInt();
        if (id >= 100 && id < 600) {
            if (id >= 400)
                return GF100;

            return G80;
        }
        return UnknownNVidia;
    } 

334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
    return UnknownNVidia;
}

static ChipClass detectIntelClass(const QByteArray &chipset)
{
    // GL 1.3, DX8? SM ?
    if (chipset.contains("845G")        ||
        chipset.contains("830M")        ||
        chipset.contains("852GM/855GM") ||
        chipset.contains("865G"))
        return I8XX;

    // GL 1.4, DX 9.0, SM 2.0
    if (chipset.contains("915G")   ||
        chipset.contains("E7221G") ||
        chipset.contains("915GM")  ||
        chipset.contains("945G")   ||   // DX 9.0c
        chipset.contains("945GM")  ||
        chipset.contains("945GME") ||
        chipset.contains("Q33")    ||   // GL1.5 
        chipset.contains("Q35")    ||
        chipset.contains("G33")    ||
        chipset.contains("965Q")   ||   // GMA 3000, but apparently considered gen 4 by the driver
        chipset.contains("946GZ")  ||   // GMA 3000, but apparently considered gen 4 by the driver
        chipset.contains("IGD"))
        return I915;

    // GL 2.0, DX 9.0c, SM 3.0
    if (chipset.contains("965G")       ||
        chipset.contains("G45/G43")    || // SM 4.0
        chipset.contains("965GM")      || // GL 2.1
        chipset.contains("965GME/GLE") ||
        chipset.contains("GM45")       ||
        chipset.contains("Q45/Q43")    ||
        chipset.contains("G41")        ||
        chipset.contains("B43")        ||
        chipset.contains("Ironlake")   ||
        chipset.contains("Sandybridge"))  // GL 3.1, CL 1.1, DX 10.1
        return I965;

    return UnknownIntel;
}

377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
static QString versionToString(qint64 version)
{
    int major = (version >> 32);
    int minor = (version >> 16) & 0xffff;
    int patch = version & 0xffff;

    QString string = QString::number(major) + QChar('.') + QString::number(minor);
    if (patch != 0)
        string += QChar('.') + QString::number(patch);

    return string;
}

static QString driverToString(Driver driver)
{
    switch (driver) {
    case Driver_R100:
        return "Radeon";
    case Driver_R200:
        return "R200";
    case Driver_R300C:
        return "R300C";
    case Driver_R300G:
        return "R300G";
    case Driver_R600C:
        return "R600C";
    case Driver_R600G:
        return "R600G";
    case Driver_Nouveau:
        return "Nouveau";
    case Driver_Intel:
        return "Intel";
    case Driver_NVidia:
        return "NVIDIA";
    case Driver_Catalyst:
        return "Catalyst";
    case Driver_Swrast:
        return "Software rasterizer";
    case Driver_Softpipe:
        return "softpipe";
    case Driver_Llvmpipe:
        return "LLVMpipe";

    default:
        return "Unknown";
    }
}

static QString chipClassToString(ChipClass chipClass)
{
    switch (chipClass) {
    case R100:
        return "R100";
    case R200:
        return "R200";
    case R300:
        return "R300";
    case R400:
        return "R400";
    case R500:
        return "R500";
    case R600:
        return "R600";
    case R700:
        return "R700";
    case Evergreen:
        return "EVERGREEN";
    case NorthernIslands:
        return "NI";

    case NV10:
        return "NV10";
    case NV20:
        return "NV20";
    case NV30:
        return "NV30";
    case NV40:
        return "NV40/G70";
    case G80:
        return "G80/G90";
    case GF100:
        return "GF100";

    case I8XX:
        return "i830/i835";
    case I915:
        return "i915/i945";
    case I965:
        return "i965";
    case SandyBridge:
        return "SandyBridge";

    default:
        return "Unknown";
    }
}

474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518


// -------



GLPlatform::GLPlatform()
    : m_driver(Driver_Unknown),
      m_chipClass(UnknownChipClass),
      m_mesaVersion(0),
      m_galliumVersion(0),
      m_looseBinding(false),
      m_directRendering(false),
      m_supportsGLSL(false),
      m_limitedGLSL(false)
{
}

GLPlatform::~GLPlatform()
{
}

void GLPlatform::detect()
{
    m_vendor       = (const char*)glGetString(GL_VENDOR);
    m_renderer     = (const char*)glGetString(GL_RENDERER);
    m_version      = (const char*)glGetString(GL_VERSION);

    const QByteArray extensions = (const char*)glGetString(GL_EXTENSIONS);
    m_extensions = QSet<QByteArray>::fromList(extensions.split(' '));

    // Parse the OpenGL version
    const QList<QByteArray> versionTokens = m_version.split(' ');
    if (versionTokens.count() > 0) {
        const QByteArray version = versionTokens.at(0);
        m_glVersion = parseVersionString(version);
    }

    // Parse the Mesa version
    const int mesaIndex = versionTokens.indexOf("Mesa");
    if (mesaIndex != -1) {
        const QByteArray version = versionTokens.at(mesaIndex + 1);
        m_mesaVersion = parseVersionString(version);
    }

Martin Flöser's avatar
Martin Flöser committed
519 520 521 522 523
#ifdef KWIN_HAVE_OPENGLES
    m_directRendering = true;
    m_supportsGLSL = true;
    m_textureNPOT = true;
#else
524 525 526 527 528 529
    GLXContext ctx = glXGetCurrentContext();
    m_directRendering = glXIsDirect(display(), ctx);

    m_supportsGLSL = m_extensions.contains("GL_ARB_shading_language_100") &&
                     m_extensions.contains("GL_ARB_shader_objects") &&
                     m_extensions.contains("GL_ARB_fragment_shader") &&
530
                     m_extensions.contains("GL_ARB_vertex_shader");
531

532
    m_textureNPOT = m_extensions.contains("GL_ARB_texture_non_power_of_two");
Martin Flöser's avatar
Martin Flöser committed
533 534 535 536
#endif

    m_serverVersion = getXServerVersion();
    m_kernelVersion = getKernelVersion();
537

538 539 540 541 542 543 544 545 546 547 548 549 550
    m_glslVersion = 0;
    m_glsl_version = QByteArray();

    if (m_supportsGLSL) {
        // Parse the GLSL version
        m_glsl_version = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
        const QList<QByteArray> glslVersionTokens = m_glsl_version.split(' ');
        if (glslVersionTokens.count() > 0) {
            const QByteArray version = glslVersionTokens.at(0);
            m_glslVersion = parseVersionString(version);
        }
    }

551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
    m_chipset = "Unknown";


    // Mesa classic drivers
    // ====================================================

    // Radeon
    if (m_renderer.startsWith("Mesa DRI R")) {
        // Sample renderer string: Mesa DRI R600 (RV740 94B3) 20090101 x86/MMX/SSE2 TCL DRI2
        const QList<QByteArray> tokens = m_renderer.split(' ');
        const QByteArray chipClass = tokens.at(2);
        m_chipset = tokens.at(3).mid(1, -1); // Strip the leading '('

        if (chipClass == "R100")
            // Vendor: Tungsten Graphics, Inc.
            m_driver = Driver_R100;

        else if (chipClass == "R200")
            // Vendor: Tungsten Graphics, Inc.
            m_driver = Driver_R200;

        else if (chipClass == "R300")
            // Vendor: DRI R300 Project
            m_driver = Driver_R300C;

        else if (chipClass == "R600")
            // Vendor: Advanced Micro Devices, Inc.
            m_driver = Driver_R600C;

        m_chipClass = detectRadeonClass(m_chipset);
    }

    // Intel
    else if (m_renderer.contains("Intel")) {
        // Vendor: Tungsten Graphics, Inc.        
        // Sample renderer string: Mesa DRI Mobile Intel® GM45 Express Chipset GEM 20100328 2010Q1

        QByteArray chipset;
        if (m_renderer.startsWith("Intel(R) Integrated Graphics Device"))
            chipset = "IGD";
        else
            chipset = m_renderer;

        m_driver = Driver_Intel;
        m_chipClass = detectIntelClass(chipset);
    } 

    // Gallium drivers
    // ====================================================
    else if (m_renderer.contains("Gallium")) {
        // Sample renderer string: Gallium 0.4 on AMD RV740 
        const QList<QByteArray> tokens = m_renderer.split(' ');
        m_galliumVersion = parseVersionString(tokens.at(1));
604 605
        m_chipset = (tokens.at(3) == "AMD" || tokens.at(3) == "ATI") ?
                tokens.at(4) : tokens.at(3);
606 607 608 609 610 611 612 613 614

        // R300G
        if (m_vendor == "X.Org R300 Project") {
            m_chipClass = detectRadeonClass(m_chipset);
            m_driver = Driver_R300G;
        }

        // R600G
        else if (m_vendor == "X.Org" &&
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
                 (m_renderer.contains("R6")        ||
                  m_renderer.contains("R7")        ||
                  m_renderer.contains("RV6")       ||
                  m_renderer.contains("RV7")       ||
                  m_renderer.contains("RS780")     ||
                  m_renderer.contains("RS880")     ||
                  m_renderer.contains("CEDAR")     ||
                  m_renderer.contains("REDWOOD")   ||
                  m_renderer.contains("JUNIPER")   ||
                  m_renderer.contains("CYPRESS")   ||
                  m_renderer.contains("HEMLOCK")   ||
                  m_renderer.contains("PALM")      ||
                  m_renderer.contains("EVERGREEN") ||
                  m_renderer.contains("BARTS")     ||
                  m_renderer.contains("TURKS")     ||
                  m_renderer.contains("CAICOS")))
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
        {
            m_chipClass = detectRadeonClass(m_chipset);
            m_driver = Driver_R600G;
        }

        // Nouveau
        else if (m_vendor == "nouveau") {
            m_chipClass = detectNVidiaClass(m_chipset);
            m_driver = Driver_Nouveau;
        }

        else if (m_chipset == "softpipe" || m_chipset == "llvmpipe") {
            // Vendor: VMware, Inc.
            // TODO
        }
    } 


    // Properietary drivers
    // ====================================================
    else if (m_vendor == "ATI Technologies Inc.") {
        m_chipClass = detectRadeonClass(m_renderer);
        m_driver = Driver_Catalyst;

        if (versionTokens.count() > 1 && versionTokens.at(2)[0] == '(')
            m_driverVersion = parseVersionString(versionTokens.at(1));
        else if (versionTokens.count() > 0)
            m_driverVersion = parseVersionString(versionTokens.at(0));
        else
            m_driverVersion = 0;
    }

    else if (m_vendor == "NVIDIA Corporation") {
664
        m_chipClass = detectNVidiaClass(m_renderer);
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
        m_driver = Driver_NVidia;
    
        int index = versionTokens.indexOf("NVIDIA");
        if (versionTokens.count() > index)
            m_driverVersion = parseVersionString(versionTokens.at(index + 1));
        else
            m_driverVersion = 0;
    }


    // Driver/GPU specific features
    // ====================================================
    if (isRadeon()) {
        // R200 technically has a programmable pipeline, but since it's SM 1.4,
        // it's too limited to to be of any practical value to us.
        if (m_chipClass < R300)
            m_supportsGLSL = false;

683 684 685 686 687 688 689 690 691 692 693
        m_limitedGLSL = false;
        m_limitedNPOT = false;

        if (m_chipClass < R600) {
            if (driver() == Driver_Catalyst)
                m_textureNPOT = m_limitedNPOT = false; // Software fallback
            else if (driver() == Driver_R300G)
                m_limitedNPOT = m_textureNPOT;

            m_limitedGLSL = m_supportsGLSL;
        }
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708

        if (driver() == Driver_R600G ||
            (driver() == Driver_R600C && m_renderer.contains("DRI2")))
        {
            m_looseBinding = true;
        }
    }

    if (isNvidia()) {
        if (m_driver == Driver_NVidia && m_chipClass < NV40)
            m_supportsGLSL = false; // High likelihood of software emulation

        if (m_driver == Driver_NVidia)
            m_looseBinding = true;

709
        m_limitedNPOT = m_textureNPOT && m_chipClass < NV40;
710 711 712 713 714 715 716 717 718 719 720
        m_limitedGLSL = m_supportsGLSL && m_chipClass < G80;
    } 

    if (isIntel()) {
        if (m_chipClass < I915)
            m_supportsGLSL = false;

        m_limitedGLSL = m_supportsGLSL && m_chipClass < I965;
    }
}

721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
static void print(const QString &label, const QString &setting)
{
    std::cout << std::setw(40) << std::left
        << qPrintable(label) << qPrintable(setting) << std::endl;
}

void GLPlatform::printResults() const
{
    print("OpenGL vendor string:",   m_vendor);
    print("OpenGL renderer string:", m_renderer);
    print("OpenGL version string:",  m_version);

    if (m_supportsGLSL)
        print("OpenGL shading language version string:", m_glsl_version);

    print("Driver:", driverToString(m_driver));
    if (!isMesaDriver())
        print("Driver version:", versionToString(m_driverVersion));

    print("GPU class:", chipClassToString(m_chipClass));
    
    print("OpenGL version:", versionToString(m_glVersion));
743 744 745

    if (m_supportsGLSL)
        print("GLSL version:", versionToString(m_glslVersion));
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767

    if (isMesaDriver())
        print("Mesa version:", versionToString(mesaVersion()));
    //if (galliumVersion() > 0)
    //    print("Gallium version:", versionToString(m_galliumVersion));
    if (serverVersion() > 0)
        print("X server version:", versionToString(m_serverVersion));
    if (kernelVersion() > 0)
        print("Linux kernel version:", versionToString(m_kernelVersion));

    print("Direct rendering:", m_directRendering ? "yes" : "no");
    print("Requires strict binding:", !m_looseBinding ? "yes" : "no");
    print("GLSL shaders:", m_supportsGLSL ? "yes" : "no");

    if (m_supportsGLSL)
        print("Limited GLSL support:", m_limitedGLSL ? "yes" : "no");

    print("Texture NPOT support:", m_textureNPOT ? "yes" : "no");
    if (m_textureNPOT)
        print("Limited NPOT support:", m_limitedNPOT ? "yes" : "no");
}

768 769 770 771 772 773 774 775 776 777 778 779
bool GLPlatform::supports(GLFeature feature) const
{
    switch (feature) {
    case LooseBinding:
        return m_looseBinding;

    case GLSL:
        return m_supportsGLSL;

    case LimitedGLSL:
        return m_limitedGLSL;

780 781 782 783 784 785
    case TextureNPOT:
        return m_textureNPOT;

    case LimitedNPOT:
        return m_limitedNPOT;

786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
    default:
        return false;
    }
}

qint64 GLPlatform::glVersion() const
{
    return m_glVersion;
}

qint64 GLPlatform::glslVersion() const
{
    return m_glVersion;
}

qint64 GLPlatform::mesaVersion() const
{
    return m_mesaVersion;
}

qint64 GLPlatform::galliumVersion() const
{
    return m_galliumVersion;
}

qint64 GLPlatform::serverVersion() const
{
    return m_serverVersion;
}

qint64 GLPlatform::kernelVersion() const
{
    return m_kernelVersion;
}

qint64 GLPlatform::driverVersion() const
{
    if (isMesaDriver())
        return mesaVersion();

    return m_driverVersion;
}

Driver GLPlatform::driver() const
{
    return m_driver;
}

ChipClass GLPlatform::chipClass() const
{
    return m_chipClass;
}

bool GLPlatform::isMesaDriver() const
{
    return mesaVersion() > 0;
}

bool GLPlatform::isRadeon() const
{
    return m_chipClass >= R100 && m_chipClass <= UnknownRadeon;
}

bool GLPlatform::isNvidia() const
{
    return m_chipClass >= NV10 && m_chipClass <= UnknownNVidia;
}

bool GLPlatform::isIntel() const
{
    return m_chipClass >= I8XX && m_chipClass <= UnknownIntel;
}

} // namespace KWin

#endif // KWIN_HAVE_OPENGL