OSDN Git Service

Use Gralloc 1.0 API directly.
authorKalyan Kondapally <kalyan.kondapally@intel.com>
Sun, 10 Dec 2017 09:26:25 +0000 (01:26 -0800)
committerKalyan Kondapally <kalyan.kondapally@intel.com>
Sun, 10 Dec 2017 09:26:25 +0000 (01:26 -0800)
Instead of using GrallocMapper API, let's use Gralloc
API directly. This is needed to set modifiers in future.

Jira: None.
Test: No new regressions on Android.

Signed-off-by: Kalyan Kondapally <kalyan.kondapally@intel.com>
os/android/gralloc1bufferhandler.cpp
os/android/gralloc1bufferhandler.h
os/android/platformdefines.h
os/android/utils_android.h

index 1ca7ae7..19051cd 100644 (file)
@@ -81,13 +81,80 @@ bool Gralloc1BufferHandler::Init() {
       reinterpret_cast<GRALLOC1_PFN_GET_DIMENSIONS>(gralloc1_dvc->getFunction(
           gralloc1_dvc, GRALLOC1_FUNCTION_GET_DIMENSIONS));
 
+  create_descriptor_ = reinterpret_cast<GRALLOC1_PFN_CREATE_DESCRIPTOR>(
+      gralloc1_dvc->getFunction(gralloc1_dvc,
+                                GRALLOC1_FUNCTION_CREATE_DESCRIPTOR));
+  destroy_descriptor_ = reinterpret_cast<GRALLOC1_PFN_DESTROY_DESCRIPTOR>(
+      gralloc1_dvc->getFunction(gralloc1_dvc,
+                                GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR));
+
+  set_consumer_usage_ = reinterpret_cast<GRALLOC1_PFN_SET_CONSUMER_USAGE>(
+      gralloc1_dvc->getFunction(gralloc1_dvc,
+                                GRALLOC1_FUNCTION_SET_CONSUMER_USAGE));
+  set_dimensions_ =
+      reinterpret_cast<GRALLOC1_PFN_SET_DIMENSIONS>(gralloc1_dvc->getFunction(
+          gralloc1_dvc, GRALLOC1_FUNCTION_SET_DIMENSIONS));
+  set_format_ = reinterpret_cast<GRALLOC1_PFN_SET_FORMAT>(
+      gralloc1_dvc->getFunction(gralloc1_dvc, GRALLOC1_FUNCTION_SET_FORMAT));
+  set_producer_usage_ = reinterpret_cast<GRALLOC1_PFN_SET_PRODUCER_USAGE>(
+      gralloc1_dvc->getFunction(gralloc1_dvc,
+                                GRALLOC1_FUNCTION_SET_PRODUCER_USAGE));
+  allocate_ = reinterpret_cast<GRALLOC1_PFN_ALLOCATE>(
+      gralloc1_dvc->getFunction(gralloc1_dvc, GRALLOC1_FUNCTION_ALLOCATE));
+
   return true;
 }
 
 bool Gralloc1BufferHandler::CreateBuffer(uint32_t w, uint32_t h, int format,
                                          HWCNativeHandle *handle,
                                          uint32_t layer_type) const {
-  return CreateGraphicsBuffer(w, h, format, handle, layer_type);
+  struct gralloc_handle *temp = new struct gralloc_handle();
+  gralloc1_device_t *gralloc1_dvc =
+      reinterpret_cast<gralloc1_device_t *>(device_);
+
+  create_descriptor_(gralloc1_dvc, &temp->gralloc1_buffer_descriptor_t_);
+  uint32_t usage = 0;
+  uint32_t pixel_format = 0;
+  if (format != 0) {
+    pixel_format = DrmFormatToHALFormat(format);
+  }
+
+  if (pixel_format == 0) {
+    pixel_format = HAL_PIXEL_FORMAT_RGBA_8888;
+  }
+
+  set_format_(gralloc1_dvc, temp->gralloc1_buffer_descriptor_t_, pixel_format);
+
+  if (layer_type == hwcomposer::kLayerNormal) {
+    usage |= GRALLOC1_CONSUMER_USAGE_HWCOMPOSER |
+             GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET |
+             GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE;
+  } else if (layer_type == hwcomposer::kLayerVideo) {
+    switch (pixel_format) {
+      case HAL_PIXEL_FORMAT_YCbCr_422_I:
+      case HAL_PIXEL_FORMAT_Y8:
+        usage |= GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE |
+                 GRALLOC1_PRODUCER_USAGE_VIDEO_DECODER;
+        break;
+      default:
+        usage |= GRALLOC1_PRODUCER_USAGE_CAMERA |
+                 GRALLOC1_CONSUMER_USAGE_CAMERA |
+                 GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE;
+    }
+  } else if (layer_type == hwcomposer::kLayerCursor) {
+    usage |= GRALLOC1_CONSUMER_USAGE_CURSOR;
+  }
+
+  set_consumer_usage_(gralloc1_dvc, temp->gralloc1_buffer_descriptor_t_, usage);
+  set_producer_usage_(gralloc1_dvc, temp->gralloc1_buffer_descriptor_t_, usage);
+  set_dimensions_(gralloc1_dvc, temp->gralloc1_buffer_descriptor_t_, w, h);
+  allocate_(gralloc1_dvc, 1, &temp->gralloc1_buffer_descriptor_t_,
+            &temp->handle_);
+
+  temp->hwc_buffer_ = true;
+  *handle = temp;
+
+  return true;
 }
 
 bool Gralloc1BufferHandler::ReleaseBuffer(HWCNativeHandle handle) const {
@@ -96,7 +163,15 @@ bool Gralloc1BufferHandler::ReleaseBuffer(HWCNativeHandle handle) const {
 
   gralloc1_device_t *gralloc1_dvc =
       reinterpret_cast<gralloc1_device_t *>(device_);
-  release_(gralloc1_dvc, handle->imported_handle_);
+
+  if (handle->hwc_buffer_) {
+    release_(gralloc1_dvc, handle->handle_);
+  } else if (handle->imported_handle_) {
+    release_(gralloc1_dvc, handle->imported_handle_);
+  }
+
+  if (handle->gralloc1_buffer_descriptor_t_ > 0)
+    destroy_descriptor_(gralloc1_dvc, handle->gralloc1_buffer_descriptor_t_);
 
   return true;
 }
@@ -151,9 +226,10 @@ void *Gralloc1BufferHandler::Map(HWCNativeHandle handle, uint32_t x, uint32_t y,
 
   gralloc1_device_t *gralloc1_dvc =
       reinterpret_cast<gralloc1_device_t *>(device_);
-  uint32_t status = lock_(
-      gralloc1_dvc, handle->handle_, GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN,
-      GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN, &rect, map_data, acquireFence);
+  uint32_t status = lock_(gralloc1_dvc, handle->imported_handle_,
+                          GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN,
+                          GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN, &rect,
+                          map_data, acquireFence);
   return (GRALLOC1_ERROR_NONE == status) ? *map_data : NULL;
 }
 
index e73d7a8..253d706 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <hardware/gralloc1.h>
 
+#include <i915_private_android_types.h>
+
 namespace hwcomposer {
 
 class GpuDevice;
@@ -55,6 +57,13 @@ class Gralloc1BufferHandler : public NativeBufferHandler {
   GRALLOC1_PFN_GET_DIMENSIONS dimensions_;
   GRALLOC1_PFN_LOCK lock_;
   GRALLOC1_PFN_UNLOCK unlock_;
+  GRALLOC1_PFN_CREATE_DESCRIPTOR create_descriptor_;
+  GRALLOC1_PFN_DESTROY_DESCRIPTOR destroy_descriptor_;
+  GRALLOC1_PFN_SET_CONSUMER_USAGE set_consumer_usage_;
+  GRALLOC1_PFN_SET_DIMENSIONS set_dimensions_;
+  GRALLOC1_PFN_SET_FORMAT set_format_;
+  GRALLOC1_PFN_SET_PRODUCER_USAGE set_producer_usage_;
+  GRALLOC1_PFN_ALLOCATE allocate_;
 };
 
 }  // namespace hwcomposer
index 6e59ce2..fbe61ed 100644 (file)
@@ -41,10 +41,10 @@ extern "C" {
 
 struct gralloc_handle {
   buffer_handle_t handle_ = NULL;
-  android::sp<android::GraphicBuffer> buffer_ = NULL;
   native_handle_t* imported_handle_ = NULL;
   uint32_t gem_handle_ = 0;
   HwcBuffer meta_data_;
+  uint64_t gralloc1_buffer_descriptor_t_ = 0;
   bool hwc_buffer_ = false;
 };
 
index bc67d0c..73dfb0e 100644 (file)
@@ -198,9 +198,9 @@ static void free_buffer_handle(native_handle_t *handle) {
 static void CopyBufferHandle(HWCNativeHandle source, HWCNativeHandle *target) {
   struct gralloc_handle *temp = new struct gralloc_handle();
   temp->handle_ = source->handle_;
-  temp->buffer_ = source->buffer_;
+  temp->gralloc1_buffer_descriptor_t_ = 0;
   temp->imported_handle_ = dup_buffer_handle(source->handle_);
-  temp->hwc_buffer_ = source->hwc_buffer_;
+  temp->hwc_buffer_ = false;
   *target = temp;
 }
 
@@ -212,52 +212,10 @@ static void DestroyBufferHandle(HWCNativeHandle handle) {
   handle = NULL;
 }
 
-static bool CreateGraphicsBuffer(uint32_t w, uint32_t h, int format,
-                                 HWCNativeHandle *handle, uint32_t layer_type) {
-  struct gralloc_handle *temp = new struct gralloc_handle();
-  uint32_t usage = 0;
-  uint32_t pixel_format = 0;
-  if (format != 0) {
-    pixel_format = DrmFormatToHALFormat(format);
-  }
-
-  if (pixel_format == 0) {
-    pixel_format = android::PIXEL_FORMAT_RGBA_8888;
-  }
-
-  if (layer_type == hwcomposer::kLayerNormal) {
-    usage |= GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_RENDER |
-             GRALLOC_USAGE_HW_COMPOSER;
-  } else if (layer_type == hwcomposer::kLayerVideo) {
-    switch (pixel_format) {
-      case HAL_PIXEL_FORMAT_YCbCr_422_I:
-      case HAL_PIXEL_FORMAT_Y8:
-        usage |= GRALLOC_USAGE_HW_TEXTURE;
-        break;
-      default:
-        usage |= GRALLOC_USAGE_HW_CAMERA_WRITE | GRALLOC_USAGE_HW_CAMERA_READ |
-                 GRALLOC_USAGE_HW_TEXTURE;
-    }
-  } else if (layer_type == hwcomposer::kLayerCursor) {
-    usage |= GRALLOC_USAGE_CURSOR;
-  }
-
-  temp->buffer_ = new android::GraphicBuffer(w, h, pixel_format, usage);
-  temp->handle_ = temp->buffer_->handle;
-  temp->hwc_buffer_ = true;
-  *handle = temp;
-
-  return true;
-}
-
 static bool ReleaseGraphicsBuffer(HWCNativeHandle handle, int fd) {
   if (!handle)
     return false;
 
-  if (handle->buffer_.get() && handle->hwc_buffer_) {
-    handle->buffer_.clear();
-  }
-
   if (handle->gem_handle_ > 0) {
     struct drm_gem_close gem_close;
     memset(&gem_close, 0, sizeof(gem_close));