aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/scenegraph/openvg/qopenvgcontext.cpp
blob: 353edc1e4d6064ac2fae5c4ecec92053dacfb71e (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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
176
177
178
179
180
181
182
// Copyright (C) 2016 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

#include <qpa/qplatformnativeinterface.h>
#include <QtGui/QGuiApplication>
#include <QtCore/QVector>
#include <QtCore/QDebug>

#include "qopenvgcontext_p.h"

QT_BEGIN_NAMESPACE

QOpenVGContext::QOpenVGContext(QWindow *window)
    : m_window(window)
{
    QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
    m_display = reinterpret_cast<EGLDisplay>(nativeInterface->nativeResourceForWindow("EglDisplay", window));
    m_surface = reinterpret_cast<EGLSurface>(nativeInterface->nativeResourceForWindow("EglSurface", window));

    if (m_display == 0)
        qFatal("QOpenVGContext: failed to get EGLDisplay");
    if (m_surface == 0)
        qFatal("QOpenVGContext: failed to get EGLSurface");

    EGLint configID = 0;
    if (eglQuerySurface(m_display, m_surface, EGL_CONFIG_ID, &configID)) {
        EGLint numConfigs;
        const EGLint configAttribs[] = {
            EGL_CONFIG_ID, configID,
            EGL_NONE
        };
        eglChooseConfig(m_display, configAttribs, &m_config, 1, &numConfigs);
    } else {
        qFatal("QOpenVGContext: failed to get surface config");
    }

    // Create an EGL Context
    eglBindAPI(EGL_OPENVG_API);
    m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, 0);
    if (!m_context)
        qFatal("QOpenVGContext: eglCreateContext failed");
}

QOpenVGContext::~QOpenVGContext()
{
    doneCurrent();
    eglDestroyContext(m_display, m_context);
}

void QOpenVGContext::makeCurrent()
{
    makeCurrent(m_surface);
}

void QOpenVGContext::makeCurrent(EGLSurface surface)
{
    eglMakeCurrent(m_display, surface, surface, m_context);
}

void QOpenVGContext::doneCurrent()
{
    eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}

void QOpenVGContext::swapBuffers()
{
    swapBuffers(m_surface);
}

void QOpenVGContext::swapBuffers(EGLSurface surface)
{
    eglSwapBuffers(m_display, surface);
}

QWindow *QOpenVGContext::window() const
{
    return m_window;
}

QImage QOpenVGContext::readFramebuffer(const QSize &size)
{
    QImage framebufferImage(size, QImage::Format_RGB32);
    vgReadPixels(framebufferImage.bits(), framebufferImage.bytesPerLine(), VG_sXRGB_8888, 0, 0, size.width(), size.height());
    return framebufferImage.mirrored(false, true);
}

void QOpenVGContext::getConfigs()
{
    EGLint configsAvailable = 0;
    eglGetConfigs(m_display, 0, 0, &configsAvailable);

    QVector<EGLConfig> configs(configsAvailable);
    eglGetConfigs(m_display, configs.data(), configs.size(), &configsAvailable);

    for (EGLConfig config : configs) {
        EGLint value;
        eglGetConfigAttrib(m_display, config, EGL_CONFIG_ID, &value);
        qDebug() << "#################\n" << "EGL_CONFIG_ID:" << value;
        eglGetConfigAttrib(m_display, config, EGL_BUFFER_SIZE, &value);
        qDebug() << "EGL_BUFFER_SIZE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_ALPHA_SIZE, &value);
        qDebug() << "EGL_ALPHA_SIZE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_RED_SIZE, &value);
        qDebug() << "EGL_RED_SIZE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_GREEN_SIZE, &value);
        qDebug() << "EGL_GREEN_SIZE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_BLUE_SIZE, &value);
        qDebug() << "EGL_BLUE_SIZE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_DEPTH_SIZE, &value);
        qDebug() << "EGL_DEPTH_SIZE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_STENCIL_SIZE, &value);
        qDebug() << "EGL_STENCIL_SIZE:" << value;

        eglGetConfigAttrib(m_display, config, EGL_ALPHA_MASK_SIZE, &value);
        qDebug() << "EGL_ALPHA_MASK_SIZE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_BIND_TO_TEXTURE_RGB, &value);
        qDebug() << "EGL_BIND_TO_TEXTURE_RGB:" << value;
        eglGetConfigAttrib(m_display, config, EGL_BIND_TO_TEXTURE_RGBA, &value);
        qDebug() << "EGL_BIND_TO_TEXTURE_RGBA:" << value;


        eglGetConfigAttrib(m_display, config, EGL_COLOR_BUFFER_TYPE, &value);
        qDebug() << "EGL_COLOR_BUFFER_TYPE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_CONFIG_CAVEAT, &value);
        qDebug() << "EGL_CONFIG_CAVEAT:" << value;
        eglGetConfigAttrib(m_display, config, EGL_CONFORMANT, &value);
        qDebug() << "EGL_CONFORMANT:" << value;


        eglGetConfigAttrib(m_display, config, EGL_LEVEL, &value);
        qDebug() << "EGL_LEVEL:" << value;
        eglGetConfigAttrib(m_display, config, EGL_LUMINANCE_SIZE, &value);
        qDebug() << "EGL_LUMINANCE_SIZE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_MAX_PBUFFER_WIDTH, &value);
        qDebug() << "EGL_MAX_PBUFFER_WIDTH:" << value;
        eglGetConfigAttrib(m_display, config, EGL_MAX_PBUFFER_HEIGHT, &value);
        qDebug() << "EGL_MAX_PBUFFER_HEIGHT:" << value;
        eglGetConfigAttrib(m_display, config, EGL_MAX_PBUFFER_PIXELS, &value);
        qDebug() << "EGL_MAX_PBUFFER_PIXELS:" << value;
        eglGetConfigAttrib(m_display, config, EGL_MAX_SWAP_INTERVAL, &value);
        qDebug() << "EGL_MAX_SWAP_INTERVAL:" << value;
        eglGetConfigAttrib(m_display, config, EGL_MIN_SWAP_INTERVAL, &value);
        qDebug() << "EGL_MIN_SWAP_INTERVAL:" << value;
        eglGetConfigAttrib(m_display, config, EGL_NATIVE_RENDERABLE, &value);
        qDebug() << "EGL_NATIVE_RENDERABLE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &value);
        qDebug() << "EGL_NATIVE_VISUAL_ID:" << value;
        eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_TYPE, &value);
        qDebug() << "EGL_NATIVE_VISUAL_TYPE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_RENDERABLE_TYPE, &value);
        qDebug() << "EGL_RENDERABLE_TYPE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_SAMPLE_BUFFERS, &value);
        qDebug() << "EGL_SAMPLE_BUFFERS:" << value;
        eglGetConfigAttrib(m_display, config, EGL_SAMPLES, &value);
        qDebug() << "EGL_SAMPLES:" << value;

        eglGetConfigAttrib(m_display, config, EGL_SURFACE_TYPE, &value);
        qDebug() << "EGL_SURFACE_TYPE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_TRANSPARENT_TYPE, &value);
        qDebug() << "EGL_TRANSPARENT_TYPE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_TRANSPARENT_RED_VALUE, &value);
        qDebug() << "EGL_TRANSPARENT_RED_VALUE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_TRANSPARENT_GREEN_VALUE, &value);
        qDebug() << "EGL_TRANSPARENT_GREEN_VALUE:" << value;
        eglGetConfigAttrib(m_display, config, EGL_TRANSPARENT_BLUE_VALUE, &value);
        qDebug() << "EGL_TRANSPARENT_BLUE_VALUE:" << value;
    }
}

void QOpenVGContext::checkErrors()
{
    VGErrorCode error;
    EGLint eglError;
    do {
        error = vgGetError();
        eglError = eglGetError();
        qDebug() << "error: " << QString::number(error, 16);
        qDebug() << "eglError: " << QString::number(eglError, 16);
    } while (error != VG_NO_ERROR && eglError != EGL_SUCCESS);
}

QT_END_NAMESPACE