15DmaBufServerBuffer::DmaBufServerBuffer(DmaBufServerBufferIntegration *integration,
const QImage &qimage, QtWayland::ServerBuffer::Format format)
16 : QtWayland::ServerBuffer(qimage.size(),format)
17 , m_integration(integration)
21 EGLContext eglContext = eglGetCurrentContext();
23 m_texture =
new QOpenGLTexture(qimage);
25 m_image = m_integration->eglCreateImageKHR(eglContext, EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer)(
unsigned long)m_texture->textureId(),
nullptr);
27 qCDebug(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer created egl image" << m_image;
29 int err = eglGetError();
30 if (err != EGL_SUCCESS || m_image == EGL_NO_IMAGE_KHR)
31 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer error creating EGL image" << Qt::hex << err;
37 if (!m_integration->eglExportDMABUFImageQueryMESA(m_image, &m_fourcc_format, &num_planes,
nullptr)) {
38 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer: Failed to query egl image";
39 qCDebug(qLcWaylandCompositorHardwareIntegration) <<
"error" << Qt::hex << eglGetError();
41 qCDebug(qLcWaylandCompositorHardwareIntegration) <<
"num_planes" << num_planes <<
"fourcc_format" << m_fourcc_format;
42 if (num_planes != 1) {
43 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer: multi-plane formats not supported";
46 m_integration->eglDestroyImageKHR(m_image);
47 m_image = EGL_NO_IMAGE_KHR;
52 if (!m_integration->eglExportDMABUFImageMESA(m_image, &m_fd, &m_stride, &m_offset)) {
53 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer: Failed to export egl image. Error code" << Qt::hex << eglGetError();
55 qCDebug(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer exported egl image: fd" << m_fd <<
"stride" << m_stride <<
"offset" << m_offset;
77 auto *bufferResource = resourceMap().value(client);
78 if (!bufferResource) {
79 auto integrationResource = m_integration->resourceMap().value(client);
80 if (!integrationResource) {
81 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"DmaBufServerBuffer::resourceForClient: Trying to get resource for ServerBuffer. But client is not bound to the qt_dmabuf_server_buffer interface";
84 struct ::wl_resource *dmabuf_integration_resource = integrationResource->handle;
86 Resource *resource = add(client, 1);
87 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);
88 return resource->handle;
90 return bufferResource->handle;
117 Q_ASSERT(QGuiApplication::platformNativeInterface());
119 m_egl_display =
static_cast<EGLDisplay>(QGuiApplication::platformNativeInterface()->nativeResourceForIntegration(
"egldisplay"));
120 if (!m_egl_display) {
121 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Cannot initialize dmabuf server buffer integration. Missing egl display from platform plugin";
125 const char *extensionString = eglQueryString(m_egl_display, EGL_EXTENSIONS);
126 if (!extensionString || !strstr(extensionString,
"EGL_KHR_image")) {
127 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Failed to initialize dmabuf server buffer integration. There is no EGL_KHR_image extension.";
131 m_egl_create_image =
reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress(
"eglCreateImageKHR"));
132 m_egl_destroy_image =
reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress(
"eglDestroyImageKHR"));
133 if (!m_egl_create_image || !m_egl_destroy_image) {
134 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Failed to initialize dmabuf server buffer integration. Could not resolve eglCreateImageKHR or eglDestroyImageKHR";
138 m_gl_egl_image_target_texture_2d =
reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC>(eglGetProcAddress(
"glEGLImageTargetTexture2DOES"));
139 if (!m_gl_egl_image_target_texture_2d) {
140 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Failed to initialize dmabuf server buffer integration. Could not find glEGLImageTargetTexture2DOES.";
144 m_egl_export_dmabuf_image_query =
reinterpret_cast<PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC>(eglGetProcAddress(
"eglExportDMABUFImageQueryMESA"));
145 if (!m_egl_export_dmabuf_image_query) {
146 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Failed to initialize dmabuf server buffer integration. Could not find eglExportDMABUFImageQueryMESA.";
150 m_egl_export_dmabuf_image =
reinterpret_cast<PFNEGLEXPORTDMABUFIMAGEMESAPROC>(eglGetProcAddress(
"eglExportDMABUFImageMESA"));
151 if (!m_egl_export_dmabuf_image) {
152 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"Failed to initialize dmabuf server buffer integration. Could not find eglExportDMABUFImageMESA.";
156 QtWaylandServer::qt_dmabuf_server_buffer::init(compositor->display(), 1);