if (!bo)
return -EINVAL;
- if (gralloc_drm_bo_need_fb(bo))
- gralloc_drm_bo_rm_fb(bo);
- gralloc_drm_bo_destroy(bo);
+ gralloc_drm_bo_decref(bo);
return 0;
}
err = gralloc_drm_bo_add_fb(bo);
if (err) {
ALOGE("failed to add fb");
- gralloc_drm_bo_destroy(bo);
+ gralloc_drm_bo_decref(bo);
return err;
}
}
return -EINVAL;
if (bo->imported)
- gralloc_drm_bo_destroy(bo);
+ gralloc_drm_bo_decref(bo);
return 0;
}
bo->drm = drm;
bo->imported = 0;
bo->handle = handle;
+ bo->fb_id = 0;
+ bo->refcount = 1;
handle->data_owner = gralloc_drm_get_pid();
handle->data = (int) bo;
/*
* Destroy a bo.
*/
-void gralloc_drm_bo_destroy(struct gralloc_drm_bo_t *bo)
+static void gralloc_drm_bo_destroy(struct gralloc_drm_bo_t *bo)
{
struct gralloc_drm_handle_t *handle = bo->handle;
int imported = bo->imported;
+ /* gralloc still has a reference */
+ if (bo->refcount)
+ return;
+
+ gralloc_drm_bo_rm_fb(bo);
+
bo->drm->drv->free(bo->drm->drv, bo);
if (imported) {
handle->data_owner = 0;
}
/*
+ * Decrease refcount, if no refs anymore then destroy.
+ */
+void gralloc_drm_bo_decref(struct gralloc_drm_bo_t *bo)
+{
+ if (!--bo->refcount)
+ gralloc_drm_bo_destroy(bo);
+}
+
+/*
* Return the bo of a registered handle.
*/
struct gralloc_drm_bo_t *gralloc_drm_bo_from_handle(buffer_handle_t handle)
int gralloc_drm_handle_unregister(buffer_handle_t handle);
struct gralloc_drm_bo_t *gralloc_drm_bo_create(struct gralloc_drm_t *drm, int width, int height, int format, int usage);
-void gralloc_drm_bo_destroy(struct gralloc_drm_bo_t *bo);
+void gralloc_drm_bo_decref(struct gralloc_drm_bo_t *bo);
struct gralloc_drm_bo_t *gralloc_drm_bo_from_handle(buffer_handle_t handle);
buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stride);
drm->fb_format,
GRALLOC_USAGE_HW_FB);
if (front && gralloc_drm_bo_add_fb(front)) {
- gralloc_drm_bo_destroy(front);
+ gralloc_drm_bo_decref(front);
front = NULL;
}
&drm->current_front : &drm->next_front;
if (*bo)
- gralloc_drm_bo_destroy(*bo);
+ gralloc_drm_bo_decref(*bo);
*bo = NULL;
}
break;
int lock_count;
int locked_for;
+
+ unsigned int refcount;
};
struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_pipe(int fd, const char *name);