OSDN Git Service

close bo on unregister()
authorChia-I Wu <olvaffe@gmail.com>
Fri, 29 Jul 2011 10:57:04 +0000 (19:57 +0900)
committerChia-I Wu <olvaffe@gmail.com>
Fri, 29 Jul 2011 11:45:50 +0000 (20:45 +0900)
Not sure if a remote process ever destroys a bo.  But let register()
opens a bo and unregister() closes it.

gralloc.c
gralloc_drm.c
gralloc_drm.h

index 850a39e..fd4f848 100644 (file)
--- a/gralloc.c
+++ b/gralloc.c
@@ -114,13 +114,24 @@ static int drm_mod_perform(const struct gralloc_module_t *mod, int op, ...)
 static int drm_mod_register_buffer(const gralloc_module_t *mod,
                buffer_handle_t handle)
 {
-       return (gralloc_drm_handle(handle)) ? 0 : -EINVAL;
+       struct drm_module_t *dmod = (struct drm_module_t *) mod;
+
+       return (gralloc_drm_bo_register(dmod->drm, handle, 1)) ? 0 : -EINVAL;
 }
 
 static int drm_mod_unregister_buffer(const gralloc_module_t *mod,
                buffer_handle_t handle)
 {
-       return (gralloc_drm_handle(handle)) ? 0 : -EINVAL;
+       struct drm_module_t *dmod = (struct drm_module_t *) mod;
+       struct gralloc_drm_bo_t *bo;
+
+       bo = gralloc_drm_bo_validate(dmod->drm, handle);
+       if (!bo)
+               return -EINVAL;
+
+       gralloc_drm_bo_unregister(bo);
+
+       return 0;
 }
 
 static int drm_mod_lock(const gralloc_module_t *mod, buffer_handle_t handle,
index af33986..e220ebe 100644 (file)
@@ -234,10 +234,28 @@ struct gralloc_drm_bo_t *gralloc_drm_bo_create(struct gralloc_drm_t *drm,
 }
 
 /*
- * Validate a buffer handle and return the associated bo.
+ * Destroy a bo.
+ */
+void gralloc_drm_bo_destroy(struct gralloc_drm_bo_t *bo)
+{
+       struct gralloc_drm_handle_t *handle = bo->handle;
+       int imported = bo->imported;
+
+       bo->drm->drv->free(bo->drm->drv, bo);
+       if (imported) {
+               handle->data_owner = 0;
+               handle->data = 0;
+       }
+       else {
+               free(handle);
+       }
+}
+
+/*
+ * Register a buffer handle and return the associated bo.
  */
-struct gralloc_drm_bo_t *gralloc_drm_bo_validate(struct gralloc_drm_t *drm,
-               buffer_handle_t _handle)
+struct gralloc_drm_bo_t *gralloc_drm_bo_register(struct gralloc_drm_t *drm,
+               buffer_handle_t _handle, int create)
 {
        struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle);
 
@@ -245,6 +263,9 @@ struct gralloc_drm_bo_t *gralloc_drm_bo_validate(struct gralloc_drm_t *drm,
        if (handle && unlikely(handle->data_owner != gralloc_drm_pid)) {
                struct gralloc_drm_bo_t *bo;
 
+               if (!create)
+                       return NULL;
+
                /* create the struct gralloc_drm_bo_t locally */
                if (handle->name)
                        bo = drm->drv->alloc(drm->drv, handle);
@@ -264,21 +285,12 @@ struct gralloc_drm_bo_t *gralloc_drm_bo_validate(struct gralloc_drm_t *drm,
 }
 
 /*
- * Destroy a bo.
+ * Unregister a bo.  It is no-op for bo created locally.
  */
-void gralloc_drm_bo_destroy(struct gralloc_drm_bo_t *bo)
+void gralloc_drm_bo_unregister(struct gralloc_drm_bo_t *bo)
 {
-       struct gralloc_drm_handle_t *handle = bo->handle;
-       int imported = bo->imported;
-
-       bo->drm->drv->free(bo->drm->drv, bo);
-       if (imported) {
-               handle->data_owner = 0;
-               handle->data = 0;
-       }
-       else {
-               free(handle);
-       }
+       if (bo->imported)
+               gralloc_drm_bo_destroy(bo);
 }
 
 /*
index 67f3598..3907dfd 100644 (file)
@@ -69,9 +69,16 @@ static inline int gralloc_drm_get_bpp(int format)
 }
 
 struct gralloc_drm_bo_t *gralloc_drm_bo_create(struct gralloc_drm_t *drm, int width, int height, int format, int usage);
-struct gralloc_drm_bo_t *gralloc_drm_bo_validate(struct gralloc_drm_t *drm, buffer_handle_t handle);
 void gralloc_drm_bo_destroy(struct gralloc_drm_bo_t *bo);
 
+struct gralloc_drm_bo_t *gralloc_drm_bo_register(struct gralloc_drm_t *drm, buffer_handle_t handle, int create);
+void gralloc_drm_bo_unregister(struct gralloc_drm_bo_t *bo);
+
+static inline struct gralloc_drm_bo_t *gralloc_drm_bo_validate(struct gralloc_drm_t *drm, buffer_handle_t handle)
+{
+       return gralloc_drm_bo_register(drm, handle, 0);
+}
+
 int gralloc_drm_bo_map(struct gralloc_drm_bo_t *bo, int x, int y, int w, int h, int enable_write, void **addr);
 void gralloc_drm_bo_unmap(struct gralloc_drm_bo_t *bo);
 buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stride);