14DmaBufServerBuffer::DmaBufServerBuffer(DmaBufServerBufferIntegration *integration,
const QImage &qimage, QtWayland::ServerBuffer::Format format)
15 : QtWayland::ServerBuffer(qimage.size(),format)
16 , m_integration(integration)
20 EGLContext eglContext = eglGetCurrentContext();
22 m_texture =
new QOpenGLTexture(qimage);
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;
36 if (!m_integration->eglExportDMABUFImageQueryMESA(m_image, &m_fourcc_format, &num_planes,
nullptr)) {
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;
41 if (num_planes != 1) {
42 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer: multi-plane formats not supported";
45 m_integration->eglDestroyImageKHR(m_image);
46 m_image = EGL_NO_IMAGE_KHR;
51 if (!m_integration->eglExportDMABUFImageMESA(m_image, &m_fd, &m_stride, &m_offset)) {
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;
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;
116 Q_ASSERT(QGuiApplication::platformNativeInterface());
118 m_egl_display =
static_cast<EGLDisplay>(QGuiApplication::platformNativeInterface()->nativeResourceForIntegration(
"egldisplay"));
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);