external/gbm_gralloc
修订版 | 28b45dc78151b791c3815fd8c696feccb5f78e04 (tree) |
---|---|
时间 | 2017-09-07 01:45:05 |
作者 | Rob Herring <robh@kern...> |
Commiter | Rob Herring |
Rework unregister/free code
It is not necessary to track imported buffers nor ref count them and
doing so is broken when native handles are cloned. So remove all the
related code and separate the unregister and free code paths.
Signed-off-by: Rob Herring <robh@kernel.org>
@@ -228,7 +228,9 @@ static int gbm_mod_free_gpu0(alloc_device_t *dev, buffer_handle_t handle) | ||
228 | 228 | goto unlock; |
229 | 229 | } |
230 | 230 | |
231 | - gralloc_gbm_bo_decref(bo); | |
231 | + gbm_free(bo); | |
232 | + native_handle_close(handle); | |
233 | + delete handle; | |
232 | 234 | |
233 | 235 | unlock: |
234 | 236 | pthread_mutex_unlock(&dmod->mutex); |
@@ -52,12 +52,8 @@ struct gralloc_gbm_bo_t { | ||
52 | 52 | |
53 | 53 | struct gralloc_gbm_handle_t *handle; |
54 | 54 | |
55 | - int imported; /* the handle is from a remote proces when true */ | |
56 | - | |
57 | 55 | int lock_count; |
58 | 56 | int locked_for; |
59 | - | |
60 | - unsigned int refcount; | |
61 | 57 | }; |
62 | 58 | |
63 | 59 | static int32_t gralloc_gbm_pid = 0; |
@@ -211,7 +207,7 @@ static struct gralloc_gbm_bo_t *gbm_alloc(struct gbm_device *gbm, | ||
211 | 207 | return buf; |
212 | 208 | } |
213 | 209 | |
214 | -static void gbm_free(struct gralloc_gbm_bo_t *bo) | |
210 | +void gbm_free(struct gralloc_gbm_bo_t *bo) | |
215 | 211 | { |
216 | 212 | gbm_bo_destroy(bo->bo); |
217 | 213 | delete bo; |
@@ -318,11 +314,8 @@ static struct gralloc_gbm_bo_t *validate_handle(buffer_handle_t _handle, | ||
318 | 314 | ALOGV("handle: pfd=%d\n", handle->prime_fd); |
319 | 315 | |
320 | 316 | bo = gbm_import(gbm, handle); |
321 | - if (bo) { | |
322 | - bo->imported = 1; | |
317 | + if (bo) | |
323 | 318 | bo->handle = handle; |
324 | - bo->refcount = 1; | |
325 | - } | |
326 | 319 | |
327 | 320 | handle->data_owner = gralloc_gbm_get_pid(); |
328 | 321 | handle->data = bo; |
@@ -343,14 +336,16 @@ int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm) | ||
343 | 336 | */ |
344 | 337 | int gralloc_gbm_handle_unregister(buffer_handle_t handle) |
345 | 338 | { |
339 | + struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
346 | 340 | struct gralloc_gbm_bo_t *bo; |
347 | 341 | |
348 | 342 | bo = validate_handle(handle, NULL); |
349 | 343 | if (!bo) |
350 | 344 | return -EINVAL; |
351 | 345 | |
352 | - if (bo->imported) | |
353 | - gralloc_gbm_bo_decref(bo); | |
346 | + gbm_free(bo); | |
347 | + gbm_handle->data_owner = 0; | |
348 | + gbm_handle->data = 0; | |
354 | 349 | |
355 | 350 | return 0; |
356 | 351 | } |
@@ -400,9 +395,7 @@ struct gralloc_gbm_bo_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | ||
400 | 395 | return NULL; |
401 | 396 | } |
402 | 397 | |
403 | - bo->imported = 0; | |
404 | 398 | bo->handle = handle; |
405 | - bo->refcount = 1; | |
406 | 399 | |
407 | 400 | handle->data_owner = gralloc_gbm_get_pid(); |
408 | 401 | handle->data = bo; |
@@ -411,38 +404,6 @@ struct gralloc_gbm_bo_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | ||
411 | 404 | } |
412 | 405 | |
413 | 406 | /* |
414 | - * Destroy a bo. | |
415 | - */ | |
416 | -static void gralloc_gbm_bo_destroy(struct gralloc_gbm_bo_t *bo) | |
417 | -{ | |
418 | - struct gralloc_gbm_handle_t *handle = bo->handle; | |
419 | - int imported = bo->imported; | |
420 | - | |
421 | - /* gralloc still has a reference */ | |
422 | - if (bo->refcount) | |
423 | - return; | |
424 | - | |
425 | - gbm_free(bo); | |
426 | - if (imported) { | |
427 | - handle->data_owner = 0; | |
428 | - handle->data = 0; | |
429 | - } | |
430 | - else { | |
431 | - native_handle_close(handle); | |
432 | - delete handle; | |
433 | - } | |
434 | -} | |
435 | - | |
436 | -/* | |
437 | - * Decrease refcount, if no refs anymore then destroy. | |
438 | - */ | |
439 | -void gralloc_gbm_bo_decref(struct gralloc_gbm_bo_t *bo) | |
440 | -{ | |
441 | - if (!--bo->refcount) | |
442 | - gralloc_gbm_bo_destroy(bo); | |
443 | -} | |
444 | - | |
445 | -/* | |
446 | 407 | * Return the bo of a registered handle. |
447 | 408 | */ |
448 | 409 | struct gralloc_gbm_bo_t *gralloc_gbm_bo_from_handle(buffer_handle_t handle) |
@@ -40,7 +40,7 @@ int gralloc_gbm_handle_unregister(buffer_handle_t handle); | ||
40 | 40 | |
41 | 41 | struct gralloc_gbm_bo_t *gralloc_gbm_bo_create(struct gbm_device *gbm, |
42 | 42 | int width, int height, int format, int usage); |
43 | -void gralloc_gbm_bo_decref(struct gralloc_gbm_bo_t *bo); | |
43 | +void gbm_free(struct gralloc_gbm_bo_t *bo); | |
44 | 44 | |
45 | 45 | struct gralloc_gbm_bo_t *gralloc_gbm_bo_from_handle(buffer_handle_t handle); |
46 | 46 | buffer_handle_t gralloc_gbm_bo_get_handle(struct gralloc_gbm_bo_t *bo); |