summaryrefslogtreecommitdiffstats
path: root/src/core/ozone/glx_helper.h
blob: b5852fe04a49bd8c354533a2bc0bf94b4f4fe82d (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default

#ifndef GLX_HELPER_H
#define GLX_HELPER_H

#include <QtCore/qscopedpointer.h>

#include <GL/glx.h>
#include <xcb/xcb.h>

#undef glXBindTexImageEXT
#undef glXReleaseTexImageEXT

QT_BEGIN_NAMESPACE

class GLXHelper
{
public:
    struct GLXFunctions
    {
        GLXFunctions();

        PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT;
        PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT;
    };

    static GLXHelper *instance();

    Display *getXDisplay() const { return m_display; }
    GLXFunctions *functions() const { return m_functions.get(); }

    GLXFBConfig getFBConfig();
    GLXPixmap importBufferAsPixmap(int dmaBufFd, uint32_t size, uint16_t width, uint16_t height,
                                   uint16_t stride) const;
    void freePixmap(uint32_t pixmapId) const;
    bool isDmaBufSupported() const { return m_isDmaBufSupported; }

private:
    GLXHelper();

    QScopedPointer<GLXFunctions> m_functions;
    Display *m_display = nullptr;
    xcb_connection_t *m_connection = nullptr;
    GLXFBConfig *m_configs = nullptr;
    bool m_isDmaBufSupported = false;
};

QT_END_NAMESPACE

#endif // GLX_HELPER_H