bool MImXExtension::supported(int required_major, int required_minor) const
{
    if (!available)
        return false;

    int major = required_major, minor = required_minor;
    if (!queryVersion(&major, &minor))
        return false;

    if (required_major == 0 && required_minor == 0)
        return true;

    if (major < required_major || (major == required_major && minor < required_minor))
        return false;

    return true;
}
Exemplo n.º 2
0
bool FunctionsGLX::initialize(Display *xDisplay, int screen, std::string *errorString)
{
    terminate();
    mXDisplay = xDisplay;
    mXScreen = screen;

#if !defined(ANGLE_LINK_GLX)
    // Some OpenGL implementations can't handle having this library
    // handle closed while there's any X window still open against
    // which a GLXWindow was ever created.
    if (!sLibHandle)
    {
        sLibHandle = dlopen("libGL.so.1", RTLD_NOW);
        if (!sLibHandle)
        {
            *errorString = std::string("Could not dlopen libGL.so.1: ") + dlerror();
            return false;
        }
    }

    getProc = reinterpret_cast<PFNGETPROCPROC>(dlsym(sLibHandle, "glXGetProcAddress"));
    if (!getProc)
    {
        getProc = reinterpret_cast<PFNGETPROCPROC>(dlsym(sLibHandle, "glXGetProcAddressARB"));
    }
    if (!getProc)
    {
        *errorString = "Could not retrieve glXGetProcAddress";
        return false;
    }
#else
    getProc = reinterpret_cast<PFNGETPROCPROC>(glXGetProcAddress);
#endif

#define GET_PROC_OR_ERROR(MEMBER, NAME) \
    if (!GetProc(getProc, MEMBER, #NAME)) \
    { \
        *errorString = "Could not load GLX entry point " #NAME; \
        return false; \
    }
#if !defined(ANGLE_LINK_GLX)
#define GET_FNPTR_OR_ERROR(MEMBER, NAME) GET_PROC_OR_ERROR(MEMBER, NAME)
#else
#define GET_FNPTR_OR_ERROR(MEMBER, NAME) *MEMBER = NAME;
#endif

    // GLX 1.0
    GET_FNPTR_OR_ERROR(&mFnPtrs->createContextPtr, glXCreateContext);
    GET_FNPTR_OR_ERROR(&mFnPtrs->destroyContextPtr, glXDestroyContext);
    GET_FNPTR_OR_ERROR(&mFnPtrs->makeCurrentPtr, glXMakeCurrent);
    GET_FNPTR_OR_ERROR(&mFnPtrs->swapBuffersPtr, glXSwapBuffers);
    GET_FNPTR_OR_ERROR(&mFnPtrs->queryExtensionPtr, glXQueryExtension);
    GET_FNPTR_OR_ERROR(&mFnPtrs->queryVersionPtr, glXQueryVersion);
    GET_FNPTR_OR_ERROR(&mFnPtrs->getCurrentContextPtr, glXGetCurrentContext);
    GET_FNPTR_OR_ERROR(&mFnPtrs->getCurrentDrawablePtr, glXGetCurrentDrawable);
    GET_FNPTR_OR_ERROR(&mFnPtrs->waitXPtr, glXWaitX);
    GET_FNPTR_OR_ERROR(&mFnPtrs->waitGLPtr, glXWaitGL);

    // GLX 1.1
    GET_FNPTR_OR_ERROR(&mFnPtrs->getClientStringPtr, glXGetClientString);
    GET_FNPTR_OR_ERROR(&mFnPtrs->queryExtensionsStringPtr, glXQueryExtensionsString);

    // Check we have a working GLX
    {
        int errorBase;
        int eventBase;
        if (!queryExtension(&errorBase, &eventBase))
        {
            *errorString = "GLX is not present.";
            return false;
        }
    }

    // Check we have a supported version of GLX
    if (!queryVersion(&majorVersion, &minorVersion))
    {
        *errorString = "Could not query the GLX version.";
        return false;
    }
    if (majorVersion != 1 || minorVersion < 3)
    {
        *errorString = "Unsupported GLX version (requires at least 1.3).";
        return false;
    }

    const char *extensions = queryExtensionsString();
    if (!extensions)
    {
        *errorString = "glXQueryExtensionsString returned NULL";
        return false;
    }
    angle::SplitStringAlongWhitespace(extensions, &mExtensions);

    // GLX 1.3
    GET_FNPTR_OR_ERROR(&mFnPtrs->getFBConfigsPtr, glXGetFBConfigs);
    GET_FNPTR_OR_ERROR(&mFnPtrs->chooseFBConfigPtr, glXChooseFBConfig);
    GET_FNPTR_OR_ERROR(&mFnPtrs->getFBConfigAttribPtr, glXGetFBConfigAttrib);
    GET_FNPTR_OR_ERROR(&mFnPtrs->getVisualFromFBConfigPtr, glXGetVisualFromFBConfig);
    GET_FNPTR_OR_ERROR(&mFnPtrs->createWindowPtr, glXCreateWindow);
    GET_FNPTR_OR_ERROR(&mFnPtrs->destroyWindowPtr, glXDestroyWindow);
    GET_FNPTR_OR_ERROR(&mFnPtrs->createPbufferPtr, glXCreatePbuffer);
    GET_FNPTR_OR_ERROR(&mFnPtrs->destroyPbufferPtr, glXDestroyPbuffer);
    GET_FNPTR_OR_ERROR(&mFnPtrs->queryDrawablePtr, glXQueryDrawable);

    // Extensions
    if (hasExtension("GLX_ARB_create_context"))
    {
        GET_PROC_OR_ERROR(&mFnPtrs->createContextAttribsARBPtr, glXCreateContextAttribsARB);
    }
    if (hasExtension("GLX_EXT_swap_control"))
    {
        GET_PROC_OR_ERROR(&mFnPtrs->swapIntervalEXTPtr, glXSwapIntervalEXT);
    }
    if (hasExtension("GLX_MESA_swap_control"))
    {
        GET_PROC_OR_ERROR(&mFnPtrs->swapIntervalMESAPtr, glXSwapIntervalMESA);
    }
    if (hasExtension("GLX_SGI_swap_control"))
    {
        GET_PROC_OR_ERROR(&mFnPtrs->swapIntervalSGIPtr, glXSwapIntervalSGI);
    }

#undef GET_FNPTR_OR_ERROR
#undef GET_PROC_OR_ERROR

    *errorString = "";
    return true;
}
Exemplo n.º 3
0
Arquivo: main.cpp Projeto: vogel/kadu
int main(int argc, char *argv[]) try
{
    WSAHandler wsaHandler;

    QApplication application{argc, argv};
    application.setApplicationName("Kadu");
    application.setQuitOnLastWindowClosed(false);

    auto executionArgumentsParser = ExecutionArgumentsParser{};
    // do not parse program name
    auto executionArguments = executionArgumentsParser.parse(QCoreApplication::arguments().mid(1));

    if (executionArguments.queryVersion())
    {
        printVersion();
        return 0;
    }

    if (executionArguments.queryUsage())
    {
        printUsage();
        return 0;
    }

    if (!executionArguments.debugMask().isEmpty())
    {
        bool ok;
        executionArguments.debugMask().toInt(&ok);
        if (ok)
            qputenv("DEBUG_MASK", executionArguments.debugMask().toUtf8());
        else
            fprintf(stderr, "Ignoring invalid debug mask '%s'\n", executionArguments.debugMask().toUtf8().constData());
    }

    qRegisterMetaType<Message>();

    auto profileDirectory = executionArguments.profileDirectory().isEmpty()
                            ? QString::fromUtf8(qgetenv("CONFIG_DIR"))
                            : executionArguments.profileDirectory();

    auto modules = std::vector<std::unique_ptr<injeqt::module>> {};
    modules.emplace_back(std::make_unique<AccountModule>());
    modules.emplace_back(std::make_unique<ActionsModule>());
    modules.emplace_back(std::make_unique<AvatarModule>());
    modules.emplace_back(std::make_unique<BuddyModule>());
    modules.emplace_back(std::make_unique<ChatModule>());
    modules.emplace_back(std::make_unique<ChatStyleModule>());
    modules.emplace_back(std::make_unique<ChatWidgetModule>());
    modules.emplace_back(std::make_unique<ChatWindowModule>());
    modules.emplace_back(std::make_unique<CoreModule>(std::move(profileDirectory)));
    modules.emplace_back(std::make_unique<ConfigurationModule>());
    modules.emplace_back(std::make_unique<ContactModule>());
    modules.emplace_back(std::make_unique<DomModule>());
    modules.emplace_back(std::make_unique<FileTransferModule>());
    modules.emplace_back(std::make_unique<FormattedStringModule>());
    modules.emplace_back(std::make_unique<GuiModule>());
    modules.emplace_back(std::make_unique<IconsModule>());
    modules.emplace_back(std::make_unique<IdentityModule>());
    modules.emplace_back(std::make_unique<MessageModule>());
    modules.emplace_back(std::make_unique<MultilogonModule>());
    modules.emplace_back(std::make_unique<NetworkModule>());
    modules.emplace_back(std::make_unique<NotificationModule>());
    modules.emplace_back(std::make_unique<OsModule>());
    modules.emplace_back(std::make_unique<ParserModule>());
    modules.emplace_back(std::make_unique<PluginModule>());
    modules.emplace_back(std::make_unique<RosterModule>());
    modules.emplace_back(std::make_unique<SslModule>());
    modules.emplace_back(std::make_unique<StatusModule>());
    modules.emplace_back(std::make_unique<TalkableModule>());
    modules.emplace_back(std::make_unique<ThemesModule>());

    auto injector = injeqt::injector{std::move(modules)};

    try
    {
        injector.instantiate<Application>(); // force creation of Application object

#ifndef Q_OS_WIN
        // Qt version is better on win32
        qInstallMsgHandler(kaduQtMessageHandler);
#endif

#ifdef DEBUG_OUTPUT_ENABLED
        showTimesInDebug = (0 != qgetenv("SHOW_TIMES").toInt());
#endif

        Core core{std::move(injector)};
        return core.executeSingle(executionArguments);
    }
    catch (ConfigurationUnusableException &)
    {
        auto profilePath = injector.get<ConfigurationPathProvider>()->configurationDirectoryPath();
        auto errorMessage = QCoreApplication::translate("@default", "We're sorry, but Kadu cannot be loaded. "
                            "Profile is inaccessible. Please check permissions in the '%1' directory.")
                            .arg(profilePath.left(profilePath.length() - 1));
        QMessageBox::critical(0, QCoreApplication::translate("@default", "Profile Inaccessible"), errorMessage, QMessageBox::Abort);

        throw;
    }
}
#if defined(Q_OS_WIN)
catch (WSAException &)
{
    return 2;
}
#endif
catch (ConfigurationUnusableException &)
{
    // already handled
}
catch (...)
{
    throw;
}