Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qopenvgoffscreensurface.cpp
Go to the documentation of this file.
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
<
QDebug
>
5
#
include
"qopenvgoffscreensurface.h"
6
7
#
include
<
QtGui
/
QImage
>
8
9
10
QT_BEGIN_NAMESPACE
11
12
QOpenVGOffscreenSurface::QOpenVGOffscreenSurface(
const
QSize &size)
13
: m_size(size)
14
{
15
m_display = eglGetCurrentDisplay();
16
m_image = vgCreateImage(VG_sARGB_8888_PRE, m_size.width(), m_size.height(), VG_IMAGE_QUALITY_BETTER);
17
18
const
EGLint configAttribs[] = {
19
EGL_CONFORMANT, EGL_OPENVG_BIT,
20
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
21
EGL_RED_SIZE, 8,
22
EGL_GREEN_SIZE, 8,
23
EGL_BLUE_SIZE, 8,
24
EGL_ALPHA_SIZE, 8,
25
EGL_ALPHA_MASK_SIZE, 8,
26
EGL_NONE
27
};
28
29
EGLConfig pbufferConfig;
30
EGLint numConfig;
31
eglChooseConfig(m_display, configAttribs, &pbufferConfig, 1, &numConfig);
32
33
m_context = eglCreateContext(m_display, pbufferConfig, eglGetCurrentContext(), 0);
34
if
(m_context == EGL_NO_CONTEXT)
35
qWarning(
"QOpenVGOffscreenSurface: failed to create EGLContext"
);
36
37
m_renderTarget = eglCreatePbufferFromClientBuffer(m_display,
38
EGL_OPENVG_IMAGE,
39
reinterpret_cast
<EGLClientBuffer>(uintptr_t(m_image)),
40
pbufferConfig,
41
0);
42
if
(m_renderTarget == EGL_NO_SURFACE)
43
qWarning(
"QOpenVGOffscreenSurface: failed to create EGLSurface from VGImage"
);
44
}
45
46
QOpenVGOffscreenSurface
::~
QOpenVGOffscreenSurface
()
47
{
48
vgDestroyImage(m_image);
49
eglDestroySurface(m_display, m_renderTarget);
50
eglDestroyContext(m_display, m_context);
51
}
52
53
void
QOpenVGOffscreenSurface
::
makeCurrent
()
54
{
55
EGLContext currentContext = eglGetCurrentContext();
56
if
(m_context != currentContext) {
57
m_previousContext = eglGetCurrentContext();
58
m_previousReadSurface = eglGetCurrentSurface(EGL_READ);
59
m_previousDrawSurface = eglGetCurrentSurface(EGL_DRAW);
60
61
eglMakeCurrent(m_display, m_renderTarget, m_renderTarget, m_context);
62
}
63
}
64
65
void
QOpenVGOffscreenSurface
::
doneCurrent
()
66
{
67
EGLContext currentContext = eglGetCurrentContext();
68
if
(m_context == currentContext) {
69
eglMakeCurrent(m_display, m_previousDrawSurface, m_previousReadSurface, m_previousContext);
70
m_previousContext = EGL_NO_CONTEXT;
71
m_previousReadSurface = EGL_NO_SURFACE;
72
m_previousDrawSurface = EGL_NO_SURFACE;
73
}
74
}
75
76
void
QOpenVGOffscreenSurface
::
swapBuffers
()
77
{
78
eglSwapBuffers(m_display, m_renderTarget);
79
}
80
81
QImage
QOpenVGOffscreenSurface
::
readbackQImage
()
82
{
83
QImage readbackImage(m_size, QImage::Format_ARGB32_Premultiplied);
84
vgGetImageSubData(m_image, readbackImage.bits(), readbackImage.bytesPerLine(), VG_sARGB_8888_PRE, 0, 0, m_size.width(), m_size.height());
85
return
readbackImage;
86
}
87
88
QT_END_NAMESPACE
QOpenVGOffscreenSurface
Definition
qopenvgoffscreensurface.h:12
QOpenVGOffscreenSurface::swapBuffers
void swapBuffers()
Definition
qopenvgoffscreensurface.cpp:76
QOpenVGOffscreenSurface::makeCurrent
void makeCurrent()
Definition
qopenvgoffscreensurface.cpp:53
QOpenVGOffscreenSurface::~QOpenVGOffscreenSurface
~QOpenVGOffscreenSurface()
Definition
qopenvgoffscreensurface.cpp:46
QOpenVGOffscreenSurface::doneCurrent
void doneCurrent()
Definition
qopenvgoffscreensurface.cpp:65
QOpenVGOffscreenSurface::readbackQImage
QImage readbackQImage()
Definition
qopenvgoffscreensurface.cpp:81
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
plugins
scenegraph
openvg
qopenvgoffscreensurface.cpp
Generated on
for Qt by
1.18.0