1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qxcbglxnativeinterfacehandler.h"
5
6#include "qglxintegration.h"
7#include <QtGui/QOpenGLContext>
8QT_BEGIN_NAMESPACE
9
10static int resourceType(const QByteArray &key)
11{
12 static const QByteArray names[] = { // match QXcbGlxNativeInterfaceHandler::ResourceType
13 QByteArrayLiteral("glxconfig"),
14 QByteArrayLiteral("glxcontext"),
15 };
16 for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
17 if (key == names[i])
18 return i;
19 }
20
21 return sizeof(names) / sizeof(names[0]);
22}
23
24QXcbGlxNativeInterfaceHandler::QXcbGlxNativeInterfaceHandler(QXcbNativeInterface *nativeInterface)
25 : QXcbNativeInterfaceHandler(nativeInterface)
26{
27}
28
29QPlatformNativeInterface::NativeResourceForContextFunction QXcbGlxNativeInterfaceHandler::nativeResourceFunctionForContext(const QByteArray &resource) const
30{
31 switch (resourceType(key: resource)) {
32 case GLXConfig:
33 return glxConfigForContext;
34 case GLXContext:
35 return glxContextForContext;
36 default:
37 break;
38 }
39 return nullptr;
40}
41
42void *QXcbGlxNativeInterfaceHandler::glxContextForContext(QOpenGLContext *context)
43{
44 Q_ASSERT(context);
45 QGLXContext *glxPlatformContext = static_cast<QGLXContext *>(context->handle());
46 return glxPlatformContext->glxContext();
47}
48
49void *QXcbGlxNativeInterfaceHandler::glxConfigForContext(QOpenGLContext *context)
50{
51 Q_ASSERT(context);
52 QGLXContext *glxPlatformContext = static_cast<QGLXContext *>(context->handle());
53 return glxPlatformContext->glxConfig();
54
55}
56
57QT_END_NAMESPACE
58

source code of qtbase/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxnativeinterfacehandler.cpp