summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalyan Kondapally <kalyan.kondapally@intel.com>2017-03-02 12:47:24 -0800
committerRobert Foss <robert.foss@collabora.com>2017-03-22 14:38:43 -0400
commit6f365e1e57bb1209d8c2a3be6d0c264c297e6295 (patch)
treeba1bb311693d17fd2a94f99230446b18a074f83a
parent12eca20cc77db2819e2ca53e97c82023a03ab6b3 (diff)
downloaddrm_hwcomposer-6f365e1e57bb1209d8c2a3be6d0c264c297e6295.tar.gz
drm_hwcomposer-6f365e1e57bb1209d8c2a3be6d0c264c297e6295.tar.xz
drm_hwcomposer: Add support for YUV to EGLImages import
BUG=None TEST=Test Video works fine on Skylake. Change-Id: I43bedb095a19044d7c3c883c7fdde616461b8e50 Signed-off-by: Kalyan Kondapally <kalyan.kondapally@intel.com>
-rw-r--r--glworker.cpp9
-rw-r--r--platform.h3
-rw-r--r--platformdrmgeneric.cpp78
-rw-r--r--platformdrmgeneric.h3
-rw-r--r--platformnv.cpp12
-rw-r--r--platformnv.h3
6 files changed, 83 insertions, 25 deletions
diff --git a/glworker.cpp b/glworker.cpp
index e90576a..c0966f3 100644
--- a/glworker.cpp
+++ b/glworker.cpp
@@ -443,10 +443,10 @@ static int EGLFenceWait(EGLDisplay egl_display, int acquireFenceFd) {
}
static int CreateTextureFromHandle(EGLDisplay egl_display,
- buffer_handle_t handle,
- Importer *importer,
+ buffer_handle_t handle, Importer *importer,
+ DrmHwcBuffer *buffer,
AutoEGLImageAndGLTexture *out) {
- EGLImageKHR image = importer->ImportImage(egl_display, handle);
+ EGLImageKHR image = importer->ImportImage(egl_display, buffer, handle);
if (image == EGL_NO_IMAGE_KHR) {
ALOGE("Failed to make image %s %p", GetEGLError(), handle);
@@ -625,7 +625,8 @@ int GLWorkerCompositor::Composite(DrmHwcLayer *layers,
continue;
ret = CreateTextureFromHandle(egl_display_, layer->get_usable_handle(),
- importer, &layer_textures.back());
+ importer, &layer->buffer,
+ &layer_textures.back());
if (!ret) {
ret = EGLFenceWait(egl_display_, layer->acquire_fence.Release());
diff --git a/platform.h b/platform.h
index 9a42ad5..ad3d905 100644
--- a/platform.h
+++ b/platform.h
@@ -40,7 +40,8 @@ class Importer {
// Imports EGLImage for glcompositor, since NV handles this in non-standard
// way, and fishing out the details is specific to the gralloc used.
- virtual EGLImageKHR ImportImage(EGLDisplay egl_display, buffer_handle_t handle) = 0;
+ virtual EGLImageKHR ImportImage(EGLDisplay egl_display, DrmHwcBuffer *buffer,
+ buffer_handle_t handle) = 0;
// Imports the buffer referred to by handle into bo.
//
diff --git a/platformdrmgeneric.cpp b/platformdrmgeneric.cpp
index aa3d0fa..29bfa4c 100644
--- a/platformdrmgeneric.cpp
+++ b/platformdrmgeneric.cpp
@@ -84,20 +84,72 @@ uint32_t DrmGenericImporter::ConvertHalFormatToDrm(uint32_t hal_format) {
}
}
-EGLImageKHR DrmGenericImporter::ImportImage(EGLDisplay egl_display, buffer_handle_t handle) {
+EGLImageKHR DrmGenericImporter::ImportImage(EGLDisplay egl_display,
+ DrmHwcBuffer *buffer,
+ buffer_handle_t handle) {
gralloc_drm_handle_t *gr_handle = gralloc_drm_handle(handle);
- if (!gr_handle)
- return NULL;
- EGLint attr[] = {
- EGL_WIDTH, gr_handle->width,
- EGL_HEIGHT, gr_handle->height,
- EGL_LINUX_DRM_FOURCC_EXT, (EGLint)ConvertHalFormatToDrm(gr_handle->format),
- EGL_DMA_BUF_PLANE0_FD_EXT, gr_handle->prime_fd,
- EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
- EGL_DMA_BUF_PLANE0_PITCH_EXT, gr_handle->stride,
- EGL_NONE,
- };
- return eglCreateImageKHR(egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attr);
+ EGLImageKHR image = EGL_NO_IMAGE_KHR;
+
+ if (!gr_handle) {
+ ALOGE("Cannot get gralloc_drm_handle");
+ return image;
+ }
+
+ // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT
+ // target, the EGL will take a reference to the dma_buf.
+ if (buffer->operator->()->format == DRM_FORMAT_YUV420) {
+ const EGLint attr_list_yv12[] = {
+ EGL_WIDTH,
+ static_cast<EGLint>(buffer->operator->()->width),
+ EGL_HEIGHT,
+ static_cast<EGLint>(buffer->operator->()->height),
+ EGL_LINUX_DRM_FOURCC_EXT,
+ DRM_FORMAT_YUV420,
+ EGL_DMA_BUF_PLANE0_FD_EXT,
+ gr_handle->prime_fd,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT,
+ static_cast<EGLint>(buffer->operator->()->pitches[0]),
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT,
+ static_cast<EGLint>(buffer->operator->()->offsets[0]),
+ EGL_DMA_BUF_PLANE1_FD_EXT,
+ gr_handle->prime_fd,
+ EGL_DMA_BUF_PLANE1_PITCH_EXT,
+ static_cast<EGLint>(buffer->operator->()->pitches[1]),
+ EGL_DMA_BUF_PLANE1_OFFSET_EXT,
+ static_cast<EGLint>(buffer->operator->()->offsets[1]),
+ EGL_DMA_BUF_PLANE2_FD_EXT,
+ gr_handle->prime_fd,
+ EGL_DMA_BUF_PLANE2_PITCH_EXT,
+ static_cast<EGLint>(buffer->operator->()->pitches[2]),
+ EGL_DMA_BUF_PLANE2_OFFSET_EXT,
+ static_cast<EGLint>(buffer->operator->()->offsets[2]),
+ EGL_NONE,
+ 0};
+ image = eglCreateImageKHR(
+ egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT,
+ static_cast<EGLClientBuffer>(nullptr), attr_list_yv12);
+ } else {
+ const EGLint attr_list[] = {
+ EGL_WIDTH,
+ static_cast<EGLint>(buffer->operator->()->width),
+ EGL_HEIGHT,
+ static_cast<EGLint>(buffer->operator->()->height),
+ EGL_LINUX_DRM_FOURCC_EXT,
+ static_cast<EGLint>(buffer->operator->()->format),
+ EGL_DMA_BUF_PLANE0_FD_EXT,
+ gr_handle->prime_fd,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT,
+ static_cast<EGLint>(buffer->operator->()->pitches[0]),
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT,
+ 0,
+ EGL_NONE,
+ 0};
+ image =
+ eglCreateImageKHR(egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT,
+ static_cast<EGLClientBuffer>(nullptr), attr_list);
+ }
+
+ return image;
}
int DrmGenericImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
diff --git a/platformdrmgeneric.h b/platformdrmgeneric.h
index 8376580..14137cf 100644
--- a/platformdrmgeneric.h
+++ b/platformdrmgeneric.h
@@ -31,7 +31,8 @@ class DrmGenericImporter : public Importer {
int Init();
- EGLImageKHR ImportImage(EGLDisplay egl_display, buffer_handle_t handle) override;
+ EGLImageKHR ImportImage(EGLDisplay egl_display, DrmHwcBuffer *buffer,
+ buffer_handle_t handle) override;
int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
int ReleaseBuffer(hwc_drm_bo_t *bo) override;
diff --git a/platformnv.cpp b/platformnv.cpp
index 02b607c..a704191 100644
--- a/platformnv.cpp
+++ b/platformnv.cpp
@@ -72,11 +72,13 @@ int NvImporter::Init() {
return 0;
}
-
-EGLImageKHR NvImporter::ImportImage(EGLDisplay egl_display, buffer_handle_t handle) {
- return eglCreateImageKHR(
- egl_display, EGL_NO_CONTEXT, EGL_NATIVE_HANDLE_ANDROID_NVX,
- (EGLClientBuffer)handle, NULL /* no attribs */);
+EGLImageKHR NvImporter::ImportImage(EGLDisplay egl_display,
+ DrmHwcBuffer *buffer,
+ buffer_handle_t handle) {
+ (void)buffer;
+ return eglCreateImageKHR(egl_display, EGL_NO_CONTEXT,
+ EGL_NATIVE_HANDLE_ANDROID_NVX,
+ (EGLClientBuffer)handle, NULL /* no attribs */);
}
int NvImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
diff --git a/platformnv.h b/platformnv.h
index 678ccfa..8524f21 100644
--- a/platformnv.h
+++ b/platformnv.h
@@ -34,7 +34,8 @@ class NvImporter : public Importer {
int Init();
- EGLImageKHR ImportImage(EGLDisplay egl_display, buffer_handle_t handle) override;
+ EGLImageKHR ImportImage(EGLDisplay egl_display, DrmHwcBuffer *buffer,
+ buffer_handle_t handle) override;
int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
int ReleaseBuffer(hwc_drm_bo_t *bo) override;