summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Clark <robdclark@gmail.com>2016-10-19 10:48:14 -0400
committerRobert Foss <robert.foss@collabora.com>2017-03-10 21:34:46 -0500
commit09b0d672d0283220b4ec5aae75b9b2e370a03c0f (patch)
treec964e9aa8a86652adb82801c0e0a0c83283d4cc3
parent80b1a5d903a7f9e14d9cde2de7f996185271a739 (diff)
downloaddrm_hwcomposer-09b0d672d0283220b4ec5aae75b9b2e370a03c0f.tar.gz
drm_hwcomposer-09b0d672d0283220b4ec5aae75b9b2e370a03c0f.tar.xz
drm_hwcomposer: Move eglCreateImageKHR into Importer
Since NV has a "special" nonstandard way to get an EGLImage from a handle, move this into Importer where the other NV specialness is abstracted. For the platformdrmgeneric case, use the dmabuf EGL Extension. Change-Id: I5353f4c95f55174df55ba92931cdc9a9eab80dca Signed-off-by: Robert Foss <robert.foss@collabora.com>
-rw-r--r--drmdisplaycompositor.cpp6
-rw-r--r--glworker.cpp16
-rw-r--r--glworker.h3
-rw-r--r--platform.h4
-rw-r--r--platformdrmgeneric.cpp17
-rw-r--r--platformdrmgeneric.h1
-rw-r--r--platformnv.cpp11
-rw-r--r--platformnv.h1
8 files changed, 46 insertions, 13 deletions
diff --git a/drmdisplaycompositor.cpp b/drmdisplaycompositor.cpp
index 3675af4..bc0adbc 100644
--- a/drmdisplaycompositor.cpp
+++ b/drmdisplaycompositor.cpp
@@ -423,7 +423,8 @@ int DrmDisplayCompositor::ApplySquash(DrmDisplayComposition *display_comp) {
std::vector<DrmCompositionRegion> &regions = display_comp->squash_regions();
ret = pre_compositor_->Composite(display_comp->layers().data(),
- regions.data(), regions.size(), fb.buffer());
+ regions.data(), regions.size(), fb.buffer(),
+ display_comp->importer());
pre_compositor_->Finish();
if (ret) {
@@ -456,7 +457,8 @@ int DrmDisplayCompositor::ApplyPreComposite(
std::vector<DrmCompositionRegion> &regions = display_comp->pre_comp_regions();
ret = pre_compositor_->Composite(display_comp->layers().data(),
- regions.data(), regions.size(), fb.buffer());
+ regions.data(), regions.size(), fb.buffer(),
+ display_comp->importer());
pre_compositor_->Finish();
if (ret) {
diff --git a/glworker.cpp b/glworker.cpp
index 6ce2de3..e12995e 100644
--- a/glworker.cpp
+++ b/glworker.cpp
@@ -35,14 +35,10 @@
#include <utils/Trace.h>
#include "drmdisplaycomposition.h"
+#include "platform.h"
#include "glworker.h"
-// TODO(zachr): use hwc_drm_bo to turn buffer handles into textures
-#ifndef EGL_NATIVE_HANDLE_ANDROID_NVX
-#define EGL_NATIVE_HANDLE_ANDROID_NVX 0x322A
-#endif
-
#define MAX_OVERLAPPING_LAYERS 64
namespace android {
@@ -416,10 +412,9 @@ static int EGLFenceWait(EGLDisplay egl_display, int acquireFenceFd) {
static int CreateTextureFromHandle(EGLDisplay egl_display,
buffer_handle_t handle,
+ Importer *importer,
AutoEGLImageAndGLTexture *out) {
- EGLImageKHR image = eglCreateImageKHR(
- egl_display, EGL_NO_CONTEXT, EGL_NATIVE_HANDLE_ANDROID_NVX,
- (EGLClientBuffer)handle, NULL /* no attribs */);
+ EGLImageKHR image = importer->ImportImage(egl_display, handle);
if (image == EGL_NO_IMAGE_KHR) {
ALOGE("Failed to make image %s %p", GetEGLError(), handle);
@@ -552,7 +547,8 @@ GLWorkerCompositor::~GLWorkerCompositor() {
int GLWorkerCompositor::Composite(DrmHwcLayer *layers,
DrmCompositionRegion *regions,
size_t num_regions,
- const sp<GraphicBuffer> &framebuffer) {
+ const sp<GraphicBuffer> &framebuffer,
+ Importer *importer) {
ATRACE_CALL();
int ret = 0;
std::vector<AutoEGLImageAndGLTexture> layer_textures;
@@ -590,7 +586,7 @@ int GLWorkerCompositor::Composite(DrmHwcLayer *layers,
continue;
ret = CreateTextureFromHandle(egl_display_, layer->get_usable_handle(),
- &layer_textures.back());
+ importer, &layer_textures.back());
if (!ret) {
ret = EGLFenceWait(egl_display_, layer->acquire_fence.Release());
diff --git a/glworker.h b/glworker.h
index 222cf6f..158490c 100644
--- a/glworker.h
+++ b/glworker.h
@@ -43,7 +43,8 @@ class GLWorkerCompositor {
int Init();
int Composite(DrmHwcLayer *layers, DrmCompositionRegion *regions,
- size_t num_regions, const sp<GraphicBuffer> &framebuffer);
+ size_t num_regions, const sp<GraphicBuffer> &framebuffer,
+ Importer *importer);
void Finish();
private:
diff --git a/platform.h b/platform.h
index da6b7cb..9a42ad5 100644
--- a/platform.h
+++ b/platform.h
@@ -38,6 +38,10 @@ class Importer {
// Creates a platform-specific importer instance
static Importer *CreateInstance(DrmResources *drm);
+ // 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;
+
// Imports the buffer referred to by handle into bo.
//
// Note: This can be called from a different thread than ReleaseBuffer. The
diff --git a/platformdrmgeneric.cpp b/platformdrmgeneric.cpp
index 90ba0e2..aa3d0fa 100644
--- a/platformdrmgeneric.cpp
+++ b/platformdrmgeneric.cpp
@@ -27,6 +27,7 @@
#include <cutils/log.h>
#include <gralloc_drm_handle.h>
#include <hardware/gralloc.h>
+#include <EGL/eglext.h>
namespace android {
@@ -83,6 +84,22 @@ uint32_t DrmGenericImporter::ConvertHalFormatToDrm(uint32_t hal_format) {
}
}
+EGLImageKHR DrmGenericImporter::ImportImage(EGLDisplay egl_display, 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);
+}
+
int DrmGenericImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
gralloc_drm_handle_t *gr_handle = gralloc_drm_handle(handle);
if (!gr_handle)
diff --git a/platformdrmgeneric.h b/platformdrmgeneric.h
index 3400876..8376580 100644
--- a/platformdrmgeneric.h
+++ b/platformdrmgeneric.h
@@ -31,6 +31,7 @@ class DrmGenericImporter : public Importer {
int Init();
+ EGLImageKHR ImportImage(EGLDisplay egl_display, 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 db7ee36..02b607c 100644
--- a/platformnv.cpp
+++ b/platformnv.cpp
@@ -28,6 +28,10 @@
#include <cutils/log.h>
#include <hardware/gralloc.h>
+#ifndef EGL_NATIVE_HANDLE_ANDROID_NVX
+#define EGL_NATIVE_HANDLE_ANDROID_NVX 0x322A
+#endif
+
namespace android {
#ifdef USE_NVIDIA_IMPORTER
@@ -68,6 +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 */);
+}
+
int NvImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
memset(bo, 0, sizeof(hwc_drm_bo_t));
NvBuffer_t *buf = GrallocGetNvBuffer(handle);
diff --git a/platformnv.h b/platformnv.h
index a9e5d39..678ccfa 100644
--- a/platformnv.h
+++ b/platformnv.h
@@ -34,6 +34,7 @@ class NvImporter : public Importer {
int Init();
+ EGLImageKHR ImportImage(EGLDisplay egl_display, 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;