OSDN Git Service

Use drm gem acess userdata IOCTL for set/get interlace
authorLin Johnson <johnson.lin@intel.com>
Tue, 4 Sep 2018 14:20:18 +0000 (22:20 +0800)
committerLin Johnson <johnson.lin@intel.com>
Wed, 5 Sep 2018 06:43:24 +0000 (14:43 +0800)
and it is potential beneficial for other IPC

Jira: None
Tests:Interlaced video playback
Signed-off-by: Lin Johnson <johnson.lin@intel.com>
cros_gralloc/cros_gralloc_driver.cc
cros_gralloc/cros_gralloc_driver.h
cros_gralloc/gralloc1/cros_gralloc1_module.cc
cros_gralloc/gralloc1/cros_gralloc1_module.h
cros_gralloc/i915_private_android_types.h

index f78c7e0..4574c5b 100644 (file)
@@ -9,11 +9,12 @@
 
 #include "i915_private_android.h"
 
-#include <errno.h>
 #include <cstdlib>
+#include <errno.h>
 #include <fcntl.h>
-#include <xf86drm.h>
+#include <i915_drm.h>
 #include <unistd.h>
+#include <xf86drm.h>
 
 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) {
index 375506f..bf84092 100644 (file)
@@ -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 &);
index d9136fa..f0b3f04 100644 (file)
@@ -221,10 +221,12 @@ gralloc1_function_pointer_t CrosGralloc1::doGetFunction(int32_t intDescriptor)
                return asFP<GRALLOC1_PFN_UNLOCK>(unlockHook);
        case GRALLOC1_FUNCTION_SET_MODIFIER:
                return asFP<GRALLOC1_PFN_SET_MODIFIER>(setModifierHook);
-        case GRALLOC1_FUNCTION_SET_INTERLACE:
-                return asFP<GRALLOC1_PFN_SET_INTERLACE>(setInterlaceHook);
-        case GRALLOC1_FUNCTION_SET_PROTECTIONINFO:
-                return asFP<GRALLOC1_PFN_SET_PROTECTIONINFO>(setProtectionInfoHook);
+       case GRALLOC1_FUNCTION_SET_INTERLACE:
+               return asFP<GRALLOC1_PFN_SET_INTERLACE>(setInterlaceHook);
+       case GRALLOC1_FUNCTION_GET_INTERLACE:
+               return asFP<GRALLOC1_PFN_GET_INTERLACE>(getInterlaceHook);
+       case GRALLOC1_FUNCTION_SET_PROTECTIONINFO:
+               return asFP<GRALLOC1_PFN_SET_PROTECTIONINFO>(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)
index 70e5176..cd222ec 100644 (file)
@@ -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);
         }
 
index b1e0410..4ed993c 100644 (file)
@@ -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;