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
drmeglserverbufferintegration.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
5#include <QtWaylandClient/private/qwaylanddisplay_p.h>
6#include <QDebug>
7#include <QtOpenGL/QOpenGLTexture>
8#include <QtGui/QOpenGLContext>
9
10#include <EGL/egl.h>
11
13
14namespace QtWaylandClient {
15
17 , int32_t name
18 , int32_t width
19 , int32_t height
20 , int32_t stride
21 , int32_t format)
22 : m_integration(integration)
23{
25 EGLint egl_format;
26 int32_t format_stride;
27 switch (format) {
28 case QtWayland::qt_drm_egl_server_buffer::format_RGBA32:
30 egl_format = EGL_DRM_BUFFER_FORMAT_ARGB32_MESA;
31 format_stride = stride / 4;
32 break;
33#ifdef EGL_DRM_BUFFER_FORMAT_A8_MESA
34 case QtWayland::qt_drm_egl_server_buffer::format_A8:
36 egl_format = EGL_DRM_BUFFER_FORMAT_A8_MESA;
37 format_stride = stride;
38 break;
39#endif
40 default:
41 qWarning("DrmServerBuffer: unknown format");
43 egl_format = EGL_DRM_BUFFER_FORMAT_ARGB32_MESA;
44 format_stride = stride / 4;
45 break;
46 }
47 EGLint attribs[] = {
48 EGL_WIDTH, width,
49 EGL_HEIGHT, height,
50 EGL_DRM_BUFFER_STRIDE_MESA, format_stride,
51 EGL_DRM_BUFFER_FORMAT_MESA, egl_format,
52 EGL_NONE
53 };
54
55 qintptr name_pointer = name;
56 m_image = integration->eglCreateImageKHR(EGL_NO_CONTEXT, EGL_DRM_BUFFER_MESA, (EGLClientBuffer) name_pointer, attribs);
57
58}
59
61{
62 m_integration->eglDestroyImageKHR(m_image);
63}
64
66{
68 qWarning("DrmServerBuffer: creating texture with no current context");
69
70 if (!m_texture) {
72 m_texture->create();
73 }
74
75 m_texture->bind();
76 m_integration->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_image);
77 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
78 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
79 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
81 m_texture->release();
82 m_texture->setSize(m_size.width(), m_size.height());
83 return m_texture;
84}
85
86void DrmEglServerBufferIntegration::initializeEgl()
87{
88 if (m_egl_initialized)
89 return;
90 m_egl_initialized = true;
91
92#if QT_CONFIG(egl_extension_platform_wayland)
93 m_egl_display = eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_EXT, m_display->wl_display(), nullptr);
94#else
95 m_egl_display = eglGetDisplay((EGLNativeDisplayType) m_display->wl_display());
96#endif
97 if (m_egl_display == EGL_NO_DISPLAY) {
98 qWarning("Failed to initialize drm egl server buffer integration. Could not get egl display from wl_display.");
99 return;
100 }
101
102 const char *extensionString = eglQueryString(m_egl_display, EGL_EXTENSIONS);
103 if (!extensionString || !strstr(extensionString, "EGL_KHR_image")) {
104 qWarning("Failed to initialize drm egl server buffer integration. There is no EGL_KHR_image extension.\n");
105 return;
106 }
107 m_egl_create_image = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress("eglCreateImageKHR"));
108 m_egl_destroy_image = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress("eglDestroyImageKHR"));
109 if (!m_egl_create_image || !m_egl_destroy_image) {
110 qWarning("Failed to initialize drm egl server buffer integration. Could not resolve eglCreateImageKHR or eglDestroyImageKHR");
111 return;
112 }
113
114 m_gl_egl_image_target_texture = reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC>(eglGetProcAddress("glEGLImageTargetTexture2DOES"));
115 if (!m_gl_egl_image_target_texture) {
116 qWarning("Failed to initialize drm egl server buffer integration. Could not resolve glEGLImageTargetTexture2DOES");
117 return;
118 }
119 m_egl_initialized = true;
120}
121
123{
124 m_display = display;
125 display->addRegistryListener(&wlDisplayHandleGlobal, this);
126}
127
129{
130 return static_cast<QWaylandServerBuffer *>(qt_server_buffer_get_user_data(buffer));
131}
132
133void DrmEglServerBufferIntegration::wlDisplayHandleGlobal(void *data, ::wl_registry *registry, uint32_t id, const QString &interface, uint32_t version)
134{
135 Q_UNUSED(version);
136 if (interface == QStringLiteral("qt_drm_egl_server_buffer")) {
137 auto *integration = static_cast<DrmEglServerBufferIntegration *>(data);
138 integration->QtWayland::qt_drm_egl_server_buffer::init(registry, id, 1);
139 }
140}
141
143 , int32_t name
144 , int32_t width
145 , int32_t height
146 , int32_t stride
147 , int32_t format)
148{
149 DrmServerBuffer *server_buffer = new DrmServerBuffer(this, name, width, height, stride, format);
150 qt_server_buffer_set_user_data(id, server_buffer);
151}
152
153}
154
static QOpenGLContext * currentContext()
Returns the last context which called makeCurrent in the current thread, or \nullptr,...
\inmodule QtGui
void release()
Unbinds this texture from the currently active texture unit.
bool create()
Creates the underlying OpenGL texture object.
void bind()
Binds this texture to the currently active texture unit ready for rendering.
void setSize(int width, int height=1, int depth=1)
Sets the dimensions of this texture object to width, height, and depth.
\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
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void drm_egl_server_buffer_server_buffer_created(struct ::qt_server_buffer *id, int32_t name, int32_t width, int32_t height, int32_t stride, int32_t format) override
QWaylandServerBuffer * serverBuffer(struct qt_server_buffer *buffer) override
void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
EGLImageKHR eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
DrmServerBuffer(DrmEglServerBufferIntegration *integration, int32_t name, int32_t width, int32_t height, int32_t stride, int32_t format)
struct wl_display * wl_display() const
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char * interface
#define qWarning
Definition qlogging.h:166
GLint GLsizei GLsizei height
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
const void GLsizei GLsizei stride
GLenum GLuint buffer
GLint GLsizei width
GLuint name
GLint GLsizei GLsizei GLenum format
#define GL_CLAMP_TO_EDGE
Definition qopenglext.h:100
const GLint * attribs
#define QStringLiteral(str)
#define Q_UNUSED(x)
ptrdiff_t qintptr
Definition qtypes.h:166