6#include <QtOpenGL/QOpenGLTexture>
7#include <QtGui/QOpenGLContext>
16 , m_integration(integration)
20 EGLContext eglContext = eglGetCurrentContext();
24 m_image = m_integration->
eglCreateImageKHR(eglContext, EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer)(
unsigned long)m_texture->
textureId(),
nullptr);
26 qCDebug(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer created egl image" << m_image;
28 int err = eglGetError();
29 if (err != EGL_SUCCESS || m_image == EGL_NO_IMAGE_KHR)
30 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer error creating EGL image" <<
Qt::hex << err;
37 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer: Failed to query egl image";
38 qCDebug(qLcWaylandCompositorHardwareIntegration) <<
"error" <<
Qt::hex << eglGetError();
40 qCDebug(qLcWaylandCompositorHardwareIntegration) <<
"num_planes" <<
num_planes <<
"fourcc_format" << m_fourcc_format;
42 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer: multi-plane formats not supported";
46 m_image = EGL_NO_IMAGE_KHR;
52 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer: Failed to export egl image. Error code" <<
Qt::hex << eglGetError();
54 qCDebug(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer exported egl image: fd" << m_fd <<
"stride" << m_stride <<
"offset" << m_offset;
65 if ((err = eglGetError()) != EGL_SUCCESS)
66 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"~DmaBufServerBuffer: eglDestroyImageKHR error" <<
Qt::hex << err;
70 perror(
"~DmaBufServerBuffer:: error closing fd");
76 auto *bufferResource = resourceMap().value(client);
77 if (!bufferResource) {
78 auto integrationResource = m_integration->resourceMap().value(client);
79 if (!integrationResource) {
80 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer::resourceForClient: Trying to get resource for ServerBuffer. But client is not bound to the qt_dmabuf_server_buffer interface";
83 struct ::wl_resource *dmabuf_integration_resource = integrationResource->handle;
85 Resource *resource =
add(client, 1);
86 m_integration->send_server_buffer_created(dmabuf_integration_resource, resource->handle, m_fd,
m_size.
width(),
m_size.
height(), m_stride, m_offset, m_fourcc_format);
87 return resource->handle;
89 return bufferResource->handle;
96 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer::toOpenGlTexture: no texture defined";
103 return resourceMap().size() > 0;
119 if (!m_egl_display) {
120 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Cannot initialize dmabuf server buffer integration. Missing egl display from platform plugin";
124 const char *extensionString = eglQueryString(m_egl_display, EGL_EXTENSIONS);
125 if (!extensionString || !strstr(extensionString,
"EGL_KHR_image")) {
126 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Failed to initialize dmabuf server buffer integration. There is no EGL_KHR_image extension.";
130 m_egl_create_image =
reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC
>(eglGetProcAddress(
"eglCreateImageKHR"));
131 m_egl_destroy_image =
reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC
>(eglGetProcAddress(
"eglDestroyImageKHR"));
132 if (!m_egl_create_image || !m_egl_destroy_image) {
133 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Failed to initialize dmabuf server buffer integration. Could not resolve eglCreateImageKHR or eglDestroyImageKHR";
137 m_gl_egl_image_target_texture_2d =
reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC
>(eglGetProcAddress(
"glEGLImageTargetTexture2DOES"));
138 if (!m_gl_egl_image_target_texture_2d) {
139 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Failed to initialize dmabuf server buffer integration. Could not find glEGLImageTargetTexture2DOES.";
143 m_egl_export_dmabuf_image_query =
reinterpret_cast<PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC
>(eglGetProcAddress(
"eglExportDMABUFImageQueryMESA"));
144 if (!m_egl_export_dmabuf_image_query) {
145 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Failed to initialize dmabuf server buffer integration. Could not find eglExportDMABUFImageQueryMESA.";
149 m_egl_export_dmabuf_image =
reinterpret_cast<PFNEGLEXPORTDMABUFIMAGEMESAPROC
>(eglGetProcAddress(
"eglExportDMABUFImageMESA"));
150 if (!m_egl_export_dmabuf_image) {
151 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Failed to initialize dmabuf server buffer integration. Could not find eglExportDMABUFImageMESA.";
155 QtWaylandServer::qt_dmabuf_server_buffer::init(
compositor->display(), 1);
179 qCDebug(qLcWaylandCompositorHardwareIntegration) <<
"server_buffer RELEASE resource" << resource->handle << wl_resource_get_id(resource->handle) <<
"for client" << resource->client();
180 wl_resource_destroy(resource->handle);
EGLBoolean eglExportDMABUFImageQueryMESA(EGLImageKHR image, int *fourcc, int *num_planes, EGLuint64KHR *modifiers)
~DmaBufServerBufferIntegration() override
bool initializeHardware(QWaylandCompositor *) override
bool supportsFormat(QtWayland::ServerBuffer::Format format) const override
EGLImageKHR eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
EGLBoolean eglExportDMABUFImageMESA(EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets)
EGLBoolean eglDestroyImageKHR(EGLImageKHR image)
QtWayland::ServerBuffer * createServerBufferFromImage(const QImage &qimage, QtWayland::ServerBuffer::Format format) override
DmaBufServerBufferIntegration()
QOpenGLTexture * toOpenGlTexture() override
struct::wl_resource * resourceForClient(struct ::wl_client *) override
DmaBufServerBuffer(DmaBufServerBufferIntegration *integration, const QImage &qimage, QtWayland::ServerBuffer::Format format)
bool bufferInUse() override
~DmaBufServerBuffer() override
void server_buffer_release(Resource *resource) override
static QPlatformNativeInterface * platformNativeInterface()
void release()
Unbinds this texture from the currently active texture unit.
GLuint textureId() const
Returns the name of the underlying OpenGL texture object or 0 if it has not yet been created.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
EGLImageKHR int int * num_planes
Combined button and popup list for selecting options.
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
#define qCWarning(category,...)
#define qCDebug(category,...)
static QOpenGLCompositor * compositor
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum format
static void add(QPainterPath &path, const QWingedEdge &list, int edge, QPathEdge::Traversal traversal)