OSDN Git Service

Add API to set Modifier.
authorKalyan Kondapally <kalyan.kondapally@intel.com>
Mon, 13 Nov 2017 01:20:41 +0000 (17:20 -0800)
committerKalyan Kondapally <kalyan.kondapally@intel.com>
Mon, 20 Nov 2017 07:07:12 +0000 (23:07 -0800)
This will be needed to pass prefered modifier from user space
and get rid of all custom enums we have. Also, would help enable
RBC support.

Jira: None.
Test: No regressions on Android.

Android.gralloc.mk
cros_gralloc/cros_gralloc_driver.cc
cros_gralloc/cros_gralloc_types.h
cros_gralloc/gralloc0/gralloc0.cc
cros_gralloc/gralloc1/cros_gralloc1_module.cc
cros_gralloc/gralloc1/cros_gralloc1_module.h
cros_gralloc/i915_private_android_types.h

index d8e6e63..318d6a5 100644 (file)
@@ -12,6 +12,7 @@ LOCAL_SRC_FILES += \
 
 ifeq ($(strip $(BOARD_USES_GRALLOC1)), true)
 LOCAL_SRC_FILES += cros_gralloc/gralloc1/cros_gralloc1_module.cc
+LOCAL_CPPFLAGS += -DUSE_GRALLOC1
 else
 LOCAL_SRC_FILES += cros_gralloc/gralloc0/gralloc0.cc
 endif
index 066a8aa..28857c2 100644 (file)
@@ -97,8 +97,13 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
        struct cros_gralloc_handle *hnd;
 
        resolved_format = drv_resolve_format(drv_, descriptor->drm_format, descriptor->use_flags);
-       bo = drv_bo_create(drv_, descriptor->width, descriptor->height, resolved_format,
-                          descriptor->use_flags);
+       if (descriptor->modifier == 0) {
+               bo = drv_bo_create(drv_, descriptor->width, descriptor->height, resolved_format,
+                                  descriptor->use_flags);
+       } else {
+               bo = drv_bo_create_with_modifiers(drv_, descriptor->width, descriptor->height,
+                                                 resolved_format, &descriptor->modifier, 1);
+       }
        if (!bo) {
                cros_gralloc_error("Failed to create bo.");
                return -ENOMEM;
index 1fa81de..d970ae9 100644 (file)
@@ -14,6 +14,7 @@ struct cros_gralloc_buffer_descriptor {
        uint32_t producer_usage;
        uint32_t droid_format;
        uint32_t drm_format;
+       uint64_t modifier;
        uint64_t use_flags;
 };
 
index 71e189a..7d5b004 100644 (file)
@@ -105,6 +105,7 @@ static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usa
        descriptor.height = h;
        descriptor.droid_format = format;
        descriptor.producer_usage = descriptor.consumer_usage = usage;
+       descriptor.modifier = 0;
        descriptor.drm_format = cros_gralloc_convert_format(format);
        descriptor.use_flags = gralloc0_convert_usage(usage);
 
index 5df43a2..660568d 100644 (file)
@@ -162,8 +162,8 @@ void CrosGralloc1::doGetCapabilities(uint32_t *outCount, int32_t *outCapabilitie
 gralloc1_function_pointer_t CrosGralloc1::doGetFunction(int32_t intDescriptor)
 {
        constexpr auto lastDescriptor = static_cast<int32_t>(GRALLOC1_LAST_FUNCTION);
-       if (intDescriptor < 0 || intDescriptor > lastDescriptor) {
-               ALOGE("Invalid function descriptor");
+       if (intDescriptor < 0 || ((intDescriptor > lastDescriptor) && ((intDescriptor < 100) || (intDescriptor > GRALLOC1_LAST_CUSTOM)))) {
+               ALOGE("Invalid function descriptor %d", intDescriptor);
                return nullptr;
        }
 
@@ -214,6 +214,8 @@ gralloc1_function_pointer_t CrosGralloc1::doGetFunction(int32_t intDescriptor)
                    lockHook<struct android_flex_layout, &CrosGralloc1::lockFlex>);
        case GRALLOC1_FUNCTION_UNLOCK:
                return asFP<GRALLOC1_PFN_UNLOCK>(unlockHook);
+       case GRALLOC1_FUNCTION_SET_MODIFIER:
+               return asFP<GRALLOC1_PFN_SET_MODIFIER>(setModifierHook);
        case GRALLOC1_FUNCTION_INVALID:
                ALOGE("Invalid function descriptor");
                return nullptr;
@@ -276,6 +278,13 @@ int32_t CrosGralloc1::setFormat(gralloc1_buffer_descriptor_t descriptorId, int32
        return CROS_GRALLOC_ERROR_NONE;
 }
 
+int32_t CrosGralloc1::setModifier(gralloc1_buffer_descriptor_t descriptorId, uint64_t modifier)
+{
+       auto hnd = (struct cros_gralloc_buffer_descriptor *)descriptorId;
+       hnd->modifier = modifier;
+       return CROS_GRALLOC_ERROR_NONE;
+}
+
 int32_t CrosGralloc1::allocate(struct cros_gralloc_buffer_descriptor *descriptor,
                               buffer_handle_t *outBufferHandle)
 {
index 9e670f9..791f43c 100644 (file)
@@ -285,6 +285,13 @@ class CrosGralloc1 : public gralloc1_device_t
                return error;
        }
 
+       int32_t setModifier(gralloc1_buffer_descriptor_t descriptor, uint64_t modifier);
+       static int32_t setModifierHook(gralloc1_device_t *device,
+                                      gralloc1_buffer_descriptor_t descriptor, uint64_t modifier)
+       {
+               return getAdapter(device)->setModifier(descriptor, modifier);
+       }
+
        // Adapter internals
        std::unique_ptr<cros_gralloc_driver> driver;
 };
index 13b43c5..a361628 100644 (file)
@@ -4,12 +4,18 @@
  * found in the LICENSE file.
  */
 
-#ifdef DRV_I915
-
 /*
  * Android graphics.h defines the formats and leaves 0x100 - 0x1FF
  * range available for HAL implementation specific formats.
  */
+
+#ifndef i915_PRIVATE_ANDROID_TYPES_H_
+#define i915_PRIVATE_ANDROID_TYPES_H_
+
+#ifdef USE_GRALLOC1
+#include <hardware/gralloc1.h>
+#endif
+
 enum { HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL = 0x100,
        HAL_PIXEL_FORMAT_NV12_LINEAR_INTEL = 0x101,
        HAL_PIXEL_FORMAT_YCrCb_422_H_INTEL = 0x102,
@@ -57,4 +63,12 @@ enum { HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL = 0x100,
        HAL_PIXEL_FORMAT_YUV420PackedSemiPlanar_Tiled_INTEL = 0x7FA00F00,
 };
 
+#ifdef USE_GRALLOC1
+enum { GRALLOC1_FUNCTION_SET_MODIFIER = 101,
+       GRALLOC1_LAST_CUSTOM = 500 };
+
+typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_MODIFIER)(
+    gralloc1_device_t *device, gralloc1_buffer_descriptor_t descriptor, uint64_t modifier);
+#endif
+
 #endif