OSDN Git Service

Remove choose_drm_modifier
[android-x86/external-IA-Hardware-Composer.git] / os / android / gralloc1bufferhandler.cpp
index 1fbd7f2..61eac39 100644 (file)
 
 #include "gralloc1bufferhandler.h"
 
+#include <cutils/native_handle.h>
 #include <hardware/hardware.h>
 #include <hardware/hwcomposer.h>
 #include <ui/GraphicBuffer.h>
-#include <cutils/native_handle.h>
 
 #include <hwcdefs.h>
 #include <hwctrace.h>
@@ -44,7 +44,23 @@ NativeBufferHandler *NativeBufferHandler::CreateInstance(uint32_t fd) {
   return handler;
 }
 
-Gralloc1BufferHandler::Gralloc1BufferHandler(uint32_t fd) : fd_(fd) {
+Gralloc1BufferHandler::Gralloc1BufferHandler(uint32_t fd)
+    : fd_(fd),
+      gralloc_(nullptr),
+      device_(nullptr),
+      register_(nullptr),
+      release_(nullptr),
+      dimensions_(nullptr),
+      lock_(nullptr),
+      unlock_(nullptr),
+      create_descriptor_(nullptr),
+      destroy_descriptor_(nullptr),
+      set_consumer_usage_(nullptr),
+      set_dimensions_(nullptr),
+      set_format_(nullptr),
+      set_producer_usage_(nullptr),
+      allocate_(nullptr),
+      set_modifier_(nullptr) {
 }
 
 Gralloc1BufferHandler::~Gralloc1BufferHandler() {
@@ -102,13 +118,19 @@ bool Gralloc1BufferHandler::Init() {
                                 GRALLOC1_FUNCTION_SET_PRODUCER_USAGE));
   allocate_ = reinterpret_cast<GRALLOC1_PFN_ALLOCATE>(
       gralloc1_dvc->getFunction(gralloc1_dvc, GRALLOC1_FUNCTION_ALLOCATE));
-
+#ifdef USE_GRALLOC1
+  set_modifier_ = reinterpret_cast<GRALLOC1_PFN_SET_MODIFIER>(
+      gralloc1_dvc->getFunction(gralloc1_dvc, GRALLOC1_FUNCTION_SET_MODIFIER));
+#endif
   return true;
 }
 
 bool Gralloc1BufferHandler::CreateBuffer(uint32_t w, uint32_t h, int format,
                                          HWCNativeHandle *handle,
-                                         uint32_t layer_type) const {
+                                         uint32_t layer_type,
+                                         bool *modifier_used,
+                                         int64_t preferred_modifier,
+                                         bool /*raw_pixel_buffer*/) const {
   struct gralloc_handle *temp = new struct gralloc_handle();
   gralloc1_device_t *gralloc1_dvc =
       reinterpret_cast<gralloc1_device_t *>(device_);
@@ -126,6 +148,23 @@ bool Gralloc1BufferHandler::CreateBuffer(uint32_t w, uint32_t h, int format,
   }
 
   set_format_(gralloc1_dvc, temp->gralloc1_buffer_descriptor_t_, pixel_format);
+#ifdef ENABLE_RBC
+  uint64_t modifier = 0;
+  if (set_modifier_) {
+    if (preferred_modifier != -1) {
+      modifier = preferred_modifier;
+    }
+    set_modifier_(gralloc1_dvc, temp->gralloc1_buffer_descriptor_t_, modifier);
+  }
+
+  if (modifier_used && modifier != DRM_FORMAT_MOD_NONE) {
+    *modifier_used = true;
+  }
+#else
+  if (modifier_used) {
+    *modifier_used = false;
+  }
+#endif
 
   if ((layer_type == hwcomposer::kLayerVideo) &&
       !IsSupportedMediaFormat(format)) {
@@ -137,7 +176,9 @@ bool Gralloc1BufferHandler::CreateBuffer(uint32_t w, uint32_t h, int format,
     usage |= GRALLOC1_CONSUMER_USAGE_HWCOMPOSER |
              GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET |
              GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE;
-  } else if (layer_type == hwcomposer::kLayerVideo) {
+    layer_type = hwcomposer::kLayerNormal;
+  } else if (layer_type == hwcomposer::kLayerVideo ||
+             layer_type == hwcomposer::kLayerProtected) {
     switch (pixel_format) {
       case HAL_PIXEL_FORMAT_YCbCr_422_I:
       case HAL_PIXEL_FORMAT_Y8:
@@ -165,61 +206,19 @@ bool Gralloc1BufferHandler::CreateBuffer(uint32_t w, uint32_t h, int format,
   }
 
   temp->hwc_buffer_ = true;
+  temp->meta_data_.usage_ = (hwcomposer::HWCLayerType)layer_type;
   *handle = temp;
 
   return true;
 }
 
-bool Gralloc1BufferHandler::CanReleaseGemHandles(HWCNativeHandle handle) const {
-  if (!handle) {
-    return false;
-  }
-
-  if (handle->hwc_buffer_) {
-    return true;
-  }
-
-  if (handle->imported_handle_) {
-    return true;
-  }
-
-  return false;
-}
-
-bool Gralloc1BufferHandler::ReleaseBuffer(HWCNativeHandle handle,
-                                          bool release_gem_handles) const {
+bool Gralloc1BufferHandler::ReleaseBuffer(HWCNativeHandle handle) const {
   gralloc1_device_t *gralloc1_dvc =
       reinterpret_cast<gralloc1_device_t *>(device_);
 
   if (handle->hwc_buffer_) {
     release_(gralloc1_dvc, handle->handle_);
   } else if (handle->imported_handle_) {
-    if (release_gem_handles) {
-      uint32_t total_planes = handle->meta_data_.num_planes_;
-      struct drm_gem_close gem_close;
-      int last_gem_handle = -1;
-
-      for (uint32_t plane = 0; plane < total_planes; plane++) {
-        uint32_t current_gem_handle = handle->meta_data_.gem_handles_[plane];
-        if ((last_gem_handle != -1) &&
-            (current_gem_handle == static_cast<uint32_t>(last_gem_handle))) {
-          break;
-        }
-
-        memset(&gem_close, 0, sizeof(gem_close));
-        last_gem_handle = current_gem_handle;
-        gem_close.handle = current_gem_handle;
-
-        int ret = drmIoctl(fd_, DRM_IOCTL_GEM_CLOSE, &gem_close);
-        if (ret) {
-          ETRACE(
-              "Failed to close gem handle ErrorCode: %d "
-              "GemHandle: %d  \n",
-              ret, current_gem_handle);
-        }
-      }
-    }
-
     release_(gralloc1_dvc, handle->imported_handle_);
   }
 
@@ -242,17 +241,15 @@ bool Gralloc1BufferHandler::ImportBuffer(HWCNativeHandle handle) const {
   gralloc1_device_t *gralloc1_dvc =
       reinterpret_cast<gralloc1_device_t *>(device_);
   register_(gralloc1_dvc, handle->imported_handle_);
-  return ImportGraphicsBuffer(handle, fd_);
-}
-
-uint32_t Gralloc1BufferHandler::GetTotalPlanes(HWCNativeHandle handle) const {
-  auto gr_handle = (struct cros_gralloc_handle *)handle->imported_handle_;
-  if (!gr_handle) {
-    ETRACE("could not find gralloc drm handle");
+  if (!ImportGraphicsBuffer(handle, fd_)) {
     return false;
   }
 
-  return drm_bo_get_num_planes(gr_handle->format);
+  return true;
+}
+
+uint32_t Gralloc1BufferHandler::GetTotalPlanes(HWCNativeHandle handle) const {
+  return handle->meta_data_.num_planes_;
 }
 
 void Gralloc1BufferHandler::CopyHandle(HWCNativeHandle source,
@@ -300,4 +297,11 @@ int32_t Gralloc1BufferHandler::UnMap(HWCNativeHandle handle,
   return unlock_(gralloc1_dvc, handle->imported_handle_, &releaseFence);
 }
 
+bool Gralloc1BufferHandler::GetInterlace(HWCNativeHandle handle) const {
+  if (((const struct cros_gralloc_handle *)handle->handle_)->is_interlaced > 0)
+    return true;
+  else
+    return false;
+}
+
 }  // namespace hwcomposer