From 0091d3fea76e64ffbd537b2ae47b8912c89c09d7 Mon Sep 17 00:00:00 2001 From: "Ung, Teng En" Date: Fri, 8 Oct 2021 14:38:45 +0000 Subject: [PATCH 3/3] sample_misc: use wayland dmabuf to render nv12 Upstream-Status: Submitted innersource PR #269 --- .../sample_misc/wayland/src/class_wayland.cpp | 60 +++++++++++++++---- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/tools/legacy/sample_misc/wayland/src/class_wayland.cpp b/tools/legacy/sample_misc/wayland/src/class_wayland.cpp index dc2fc718..d2e7e4e2 100644 --- a/tools/legacy/sample_misc/wayland/src/class_wayland.cpp +++ b/tools/legacy/sample_misc/wayland/src/class_wayland.cpp @@ -26,6 +26,7 @@ or https://software.intel.com/en-us/media-client-solutions-support. #include extern "C" { #include +#include #include #include } @@ -305,20 +306,53 @@ struct wl_buffer* Wayland::CreatePrimeBuffer(uint32_t name, int32_t offsets[3], int32_t pitches[3]) { struct wl_buffer* buffer = NULL; - if (NULL == m_drm) - return NULL; - buffer = wl_drm_create_prime_buffer(m_drm, - name, - width, - height, - format, - offsets[0], - pitches[0], - offsets[1], - pitches[1], - offsets[2], - pitches[2]); +#if defined(WAYLAND_LINUX_DMABUF_SUPPORT) + if (format == WL_DRM_FORMAT_NV12) { + if(NULL == m_dmabuf) + return NULL; + + struct zwp_linux_buffer_params_v1 *dmabuf_params = NULL; + int i = 0; + uint64_t modifier = I915_FORMAT_MOD_Y_TILED; + + dmabuf_params = zwp_linux_dmabuf_v1_create_params(m_dmabuf); + for(i = 0; i < 2; i++) { + zwp_linux_buffer_params_v1_add(dmabuf_params, + name, + i, + offsets[i], + pitches[i], + modifier >> 32, + modifier & 0xffffffff); + } + + buffer = zwp_linux_buffer_params_v1_create_immed(dmabuf_params, + width, + height, + format, + 0); + + zwp_linux_buffer_params_v1_destroy(dmabuf_params); + } else +#endif + { + if(NULL == m_drm) + return NULL; + + buffer = wl_drm_create_prime_buffer(m_drm, + name, + width, + height, + format, + offsets[0], + pitches[0], + offsets[1], + pitches[1], + offsets[2], + pitches[2]); + } + return buffer; } -- 2.31.1