From b3f47fbc17eb33a85ce6f0796dfa3a6d0df13cfe Mon Sep 17 00:00:00 2001 From: Lin Johnson Date: Tue, 4 Sep 2018 22:20:18 +0800 Subject: [PATCH] Use drm gem acess userdata IOCTL for set/get interlace and it is potential beneficial for other IPC Jira: None Tests:Interlaced video playback Signed-off-by: Lin Johnson --- cros_gralloc/cros_gralloc_driver.cc | 66 +++++++++++++++++++++++++-- cros_gralloc/cros_gralloc_driver.h | 4 ++ cros_gralloc/gralloc1/cros_gralloc1_module.cc | 28 ++++++++---- cros_gralloc/gralloc1/cros_gralloc1_module.h | 27 +++++++---- cros_gralloc/i915_private_android_types.h | 15 ++++-- 5 files changed, 114 insertions(+), 26 deletions(-) diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc index f78c7e0..4574c5b 100644 --- a/cros_gralloc/cros_gralloc_driver.cc +++ b/cros_gralloc/cros_gralloc_driver.cc @@ -9,11 +9,12 @@ #include "i915_private_android.h" -#include #include +#include #include -#include +#include #include +#include cros_gralloc_driver::cros_gralloc_driver() : drv_(nullptr) { @@ -170,10 +171,69 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto return 0; } +int32_t cros_gralloc_driver::setinterlace(buffer_handle_t handle, uint32_t interlace) +{ + uint32_t id; + SCOPED_SPIN_LOCK(mutex_); + + auto hnd = cros_gralloc_convert_handle(handle); + if (!hnd) { + cros_gralloc_error("Invalid handle."); + return -EINVAL; + } + + if (drmPrimeFDToHandle(drv_get_fd(drv_), hnd->fds[0], &id)) { + cros_gralloc_error("drmPrimeFDToHandle failed."); + return -errno; + } + + drm_i915_gem_access_userdata access_userdata; + access_userdata.handle = id; + access_userdata.write = 1; + access_userdata.userdata = interlace; + + if (drmIoctl(drv_get_fd(drv_), DRM_IOCTL_I915_GEM_ACCESS_USERDATA, &access_userdata)) { + cros_gralloc_error("access userdata failed"); + return -errno; + } + + return 0; +} + +int32_t cros_gralloc_driver::getinterlace(buffer_handle_t handle, uint32_t *interlace) +{ + uint32_t id; + SCOPED_SPIN_LOCK(mutex_); + + auto hnd = cros_gralloc_convert_handle(handle); + if (!hnd) { + cros_gralloc_error("Invalid handle."); + return -EINVAL; + } + + if (drmPrimeFDToHandle(drv_get_fd(drv_), hnd->fds[0], &id)) { + cros_gralloc_error("drmPrimeFDToHandle failed."); + return -errno; + } + + drm_i915_gem_access_userdata access_userdata; + access_userdata.handle = id; + access_userdata.write = 0; + access_userdata.userdata = 0; + + if (drmIoctl(drv_get_fd(drv_), DRM_IOCTL_I915_GEM_ACCESS_USERDATA, &access_userdata)) { + cros_gralloc_error("access userdata failed"); + return -errno; + } + *interlace = access_userdata.userdata; + + return 0; +} + int32_t cros_gralloc_driver::retain(buffer_handle_t handle) { uint32_t id; - SCOPED_SPIN_LOCK(mutex_); + SCOPED_SPIN_LOCK(mutex_); auto hnd = cros_gralloc_convert_handle(handle); if (!hnd) { diff --git a/cros_gralloc/cros_gralloc_driver.h b/cros_gralloc/cros_gralloc_driver.h index 375506f..bf84092 100644 --- a/cros_gralloc/cros_gralloc_driver.h +++ b/cros_gralloc/cros_gralloc_driver.h @@ -33,6 +33,10 @@ class cros_gralloc_driver int32_t get_backing_store(buffer_handle_t handle, uint64_t *out_store); + int32_t setinterlace(buffer_handle_t handle, uint32_t interlace); + + int32_t getinterlace(buffer_handle_t handle, uint32_t *interlace); + private: cros_gralloc_driver(cros_gralloc_driver const &); cros_gralloc_driver operator=(cros_gralloc_driver const &); diff --git a/cros_gralloc/gralloc1/cros_gralloc1_module.cc b/cros_gralloc/gralloc1/cros_gralloc1_module.cc index d9136fa..f0b3f04 100644 --- a/cros_gralloc/gralloc1/cros_gralloc1_module.cc +++ b/cros_gralloc/gralloc1/cros_gralloc1_module.cc @@ -221,10 +221,12 @@ gralloc1_function_pointer_t CrosGralloc1::doGetFunction(int32_t intDescriptor) return asFP(unlockHook); case GRALLOC1_FUNCTION_SET_MODIFIER: return asFP(setModifierHook); - case GRALLOC1_FUNCTION_SET_INTERLACE: - return asFP(setInterlaceHook); - case GRALLOC1_FUNCTION_SET_PROTECTIONINFO: - return asFP(setProtectionInfoHook); + case GRALLOC1_FUNCTION_SET_INTERLACE: + return asFP(setInterlaceHook); + case GRALLOC1_FUNCTION_GET_INTERLACE: + return asFP(getInterlaceHook); + case GRALLOC1_FUNCTION_SET_PROTECTIONINFO: + return asFP(setProtectionInfoHook); case GRALLOC1_FUNCTION_INVALID: ALOGE("Invalid function descriptor"); return nullptr; @@ -290,11 +292,19 @@ int32_t CrosGralloc1::setFormat(gralloc1_buffer_descriptor_t descriptorId, int32 int32_t CrosGralloc1::setInterlace(buffer_handle_t buffer, uint32_t interlace) { auto hnd = (cros_gralloc_handle*) cros_gralloc_convert_handle(buffer); - if (!hnd) { - return CROS_GRALLOC_ERROR_BAD_HANDLE; - } - hnd->is_interlaced = interlace; - return CROS_GRALLOC_ERROR_NONE; + if (!hnd) { + return CROS_GRALLOC_ERROR_BAD_HANDLE; + } + return driver->setinterlace(buffer, interlace); +} + +int32_t CrosGralloc1::getInterlace(buffer_handle_t buffer, uint32_t *interlace) +{ + auto hnd = (cros_gralloc_handle *)cros_gralloc_convert_handle(buffer); + if (!hnd) { + return CROS_GRALLOC_ERROR_BAD_HANDLE; + } + return driver->getinterlace(buffer, interlace); } int32_t CrosGralloc1::setProtectionInfo(buffer_handle_t buffer, uint32_t protection_info) diff --git a/cros_gralloc/gralloc1/cros_gralloc1_module.h b/cros_gralloc/gralloc1/cros_gralloc1_module.h index 70e5176..cd222ec 100644 --- a/cros_gralloc/gralloc1/cros_gralloc1_module.h +++ b/cros_gralloc/gralloc1/cros_gralloc1_module.h @@ -98,8 +98,9 @@ class CrosGralloc1 : public gralloc1_device_t uint32_t height); int32_t setFormat(gralloc1_buffer_descriptor_t descriptorId, int32_t format); - int32_t setInterlace(buffer_handle_t buffer, uint32_t interlace); - int32_t setProtectionInfo(buffer_handle_t buffer, uint32_t protection_info); + int32_t setInterlace(buffer_handle_t buffer, uint32_t interlace); + int32_t getInterlace(buffer_handle_t buffer, uint32_t *interlace); + int32_t setProtectionInfo(buffer_handle_t buffer, uint32_t protection_info); int32_t createDescriptor(gralloc1_buffer_descriptor_t *outDescriptor); static int32_t createDescriptorHook(gralloc1_device_t *device, @@ -135,15 +136,21 @@ class CrosGralloc1 : public gralloc1_device_t return getAdapter(device)->setFormat(descriptorId, format); } - static int32_t setInterlaceHook(gralloc1_device_t *device, - buffer_handle_t buffer, uint32_t interlace) - { - return getAdapter(device)->setInterlace(buffer, interlace); - } + static int32_t setInterlaceHook(gralloc1_device_t *device, buffer_handle_t buffer, + uint32_t interlace) + { + return getAdapter(device)->setInterlace(buffer, interlace); + } - static int32_t setProtectionInfoHook(gralloc1_device_t *device, - buffer_handle_t buffer, uint32_t protection_info) - { + static int32_t getInterlaceHook(gralloc1_device_t *device, buffer_handle_t buffer, + uint32_t *interlace) + { + return getAdapter(device)->getInterlace(buffer, interlace); + } + + static int32_t setProtectionInfoHook(gralloc1_device_t *device, buffer_handle_t buffer, + uint32_t protection_info) + { return getAdapter(device)->setProtectionInfo(buffer, protection_info); } diff --git a/cros_gralloc/i915_private_android_types.h b/cros_gralloc/i915_private_android_types.h index b1e0410..4ed993c 100644 --- a/cros_gralloc/i915_private_android_types.h +++ b/cros_gralloc/i915_private_android_types.h @@ -69,6 +69,7 @@ enum { GRALLOC1_FUNCTION_SET_MODIFIER = 101, GRALLOC1_FUNCTION_GET_PRIME = 103, GRALLOC1_FUNCTION_SET_INTERLACE = 104, GRALLOC1_FUNCTION_SET_PROTECTIONINFO = 105, + GRALLOC1_FUNCTION_GET_INTERLACE = 106, GRALLOC1_LAST_CUSTOM = 500 }; typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_MODIFIER)( @@ -80,11 +81,17 @@ typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_BYTE_STRIDE)( typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_PRIME)( gralloc1_device_t *device, buffer_handle_t buffer, uint32_t *prime); -typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_INTERLACE)( - gralloc1_device_t *device, buffer_handle_t buffer, uint32_t interlace); +typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_INTERLACE)(gralloc1_device_t *device, + buffer_handle_t buffer, + uint32_t interlace); -typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_PROTECTIONINFO)( - gralloc1_device_t *device, buffer_handle_t buffer, uint32_t protection_info); +typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_INTERLACE)(gralloc1_device_t *device, + buffer_handle_t buffer, + uint32_t *interlace); + +typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_PROTECTIONINFO)(gralloc1_device_t *device, + buffer_handle_t buffer, + uint32_t protection_info); typedef union intel_protection_info_type_t { uint32_t value; -- 2.11.0