OSDN Git Service

Ensure we close all the gem handles.
authorKalyan Kondapally <kalyan.kondapally@intel.com>
Mon, 12 Jun 2017 18:29:43 +0000 (11:29 -0700)
committerKalyan Kondapally <kalyan.kondapally@intel.com>
Mon, 12 Jun 2017 18:33:28 +0000 (11:33 -0700)
We create gem handles in our side which need to be closed
when releasing buffer. This was not an issue on Linux as
minigbm takes care of it.

Jira: None.
Test: shmem doesn't grow when switching between apps on Android.

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

index f5ec05a..7d7576a 100644 (file)
@@ -83,7 +83,7 @@ bool Gralloc1BufferHandler::CreateBuffer(uint32_t w, uint32_t h, int format,
 }
 
 bool Gralloc1BufferHandler::ReleaseBuffer(HWCNativeHandle handle) {
-  if (!ReleaseGraphicsBuffer(handle))
+  if (!ReleaseGraphicsBuffer(handle, fd_))
     return false;
 
   gralloc1_device_t *gralloc1_dvc =
index 9b5c048..1f9e051 100644 (file)
@@ -76,7 +76,7 @@ bool GrallocBufferHandler::CreateBuffer(uint32_t w, uint32_t h, int format,
 }
 
 bool GrallocBufferHandler::ReleaseBuffer(HWCNativeHandle handle) {
-  return ReleaseGraphicsBuffer(handle);
+  return ReleaseGraphicsBuffer(handle, fd_);
 }
 
 void GrallocBufferHandler::DestroyHandle(HWCNativeHandle handle) {
index 864296a..c13bb16 100644 (file)
@@ -43,6 +43,7 @@ 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;
   bool hwc_buffer_ = false;
 };
 
index 917faca..c5c8135 100644 (file)
@@ -121,7 +121,7 @@ static bool CreateGraphicsBuffer(uint32_t w, uint32_t h, int /*format*/,
   return true;
 }
 
-static bool ReleaseGraphicsBuffer(HWCNativeHandle handle) {
+static bool ReleaseGraphicsBuffer(HWCNativeHandle handle, int fd) {
   if (!handle)
     return false;
 
@@ -129,6 +129,17 @@ static bool ReleaseGraphicsBuffer(HWCNativeHandle handle) {
     handle->buffer_.clear();
   }
 
+  if (handle->gem_handle_ > 0) {
+    struct drm_gem_close gem_close;
+    memset(&gem_close, 0, sizeof(gem_close));
+    gem_close.handle = handle->gem_handle_;
+    int ret = drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
+    if (ret)
+      ETRACE("Failed to close gem handle %d", ret);
+  }
+
+  handle->gem_handle_ = 0;
+
   return true;
 }
 
@@ -141,7 +152,7 @@ static bool ImportGraphicsBuffer(HWCNativeHandle handle, HwcBuffer *bo,
   bo->height = gr_handle->height;
   bo->prime_fd = gr_handle->fds[0];
 
-  uint32_t id;
+  uint32_t id = 0;
   if (drmPrimeFDToHandle(fd, bo->prime_fd, &id)) {
     ETRACE("drmPrimeFDToHandle failed.");
     return false;
@@ -163,6 +174,8 @@ static bool ImportGraphicsBuffer(HWCNativeHandle handle, HwcBuffer *bo,
     bo->usage |= hwcomposer::kLayerNormal;
   }
 
+  handle->gem_handle_ = id;
+
   return true;
 }
 #endif