Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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>
6
7#include <QtGui/QImage>
8
9
11
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
47{
48 vgDestroyImage(m_image);
49 eglDestroySurface(m_display, m_renderTarget);
50 eglDestroyContext(m_display, m_context);
51}
52
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
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
77{
78 eglSwapBuffers(m_display, m_renderTarget);
79}
80
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
\inmodule QtGui
Definition qimage.h:37
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
QOpenVGOffscreenSurface(const QSize &size)
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:166
GLenum GLuint GLintptr GLsizeiptr size
[1]