package version up to 1.16.11
[platform/core/uifw/libtdm.git] / src / tdm_pp.c
1 /**************************************************************************
2  *
3  * libtdm
4  *
5  * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6  *
7  * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8  *          JinYoung Jeon <jy0.jeon@samsung.com>,
9  *          Taeheon Kim <th908.kim@samsung.com>,
10  *          YoungJun Cho <yj44.cho@samsung.com>,
11  *          SooChan Lim <sc1.lim@samsung.com>,
12  *          Boram Park <boram1288.park@samsung.com>
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the
16  * "Software"), to deal in the Software without restriction, including
17  * without limitation the rights to use, copy, modify, merge, publish,
18  * distribute, sub license, and/or sell copies of the Software, and to
19  * permit persons to whom the Software is furnished to do so, subject to
20  * the following conditions:
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34 **************************************************************************/
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #include "tdm_private.h"
41
42 #define PP_FUNC_ENTRY() \
43         tdm_private_module *private_module; \
44         tdm_func_pp *func_pp; \
45         tdm_private_display *private_display; \
46         tdm_private_pp *private_pp; \
47         tdm_error ret = TDM_ERROR_NONE; \
48         TDM_RETURN_VAL_IF_FAIL(pp != NULL, TDM_ERROR_INVALID_PARAMETER); \
49         private_pp = (tdm_private_pp*)pp; \
50         private_display = private_pp->private_display; \
51         private_module = private_pp->private_module; \
52         func_pp = &private_module->func_pp
53
54 static void
55 _tdm_pp_print_list(struct list_head *list)
56 {
57         tdm_pp_private_buffer *b = NULL;
58         char str[512], *p;
59         int len = sizeof(str);
60
61         TDM_RETURN_IF_FAIL(list != NULL);
62
63         str[0] = '\0';
64         p = str;
65         LIST_FOR_EACH_ENTRY(b, list, link) {
66                 if (len > 0) {
67                         tbm_bo src_bo = tbm_surface_internal_get_bo(b->src, 0);
68                         tbm_bo dst_bo = tbm_surface_internal_get_bo(b->dst, 0);
69                         int src_flags = tbm_bo_get_flags(src_bo);
70                         int dst_flags = tbm_bo_get_flags(dst_bo);
71                         int l = snprintf(p, len, " (%p[bo_flags:%x], %p[bo_flags:%x])",
72                                                          b->src, src_flags, b->dst, dst_flags);
73                         p += l;
74                         len -= l;
75                 } else
76                         break;
77         }
78
79         TDM_INFO("\t %s", str);
80 }
81
82 static tdm_pp_private_buffer *
83 _tdm_pp_find_tbm_buffers(struct list_head *list, tbm_surface_h src, tbm_surface_h dst)
84 {
85         tdm_pp_private_buffer *b = NULL, *bb = NULL;
86
87         LIST_FOR_EACH_ENTRY_SAFE(b, bb, list, link) {
88                 if (b->src == src && b->dst == dst)
89                         return b;
90         }
91
92         return NULL;
93 }
94
95 static tdm_pp_private_buffer *
96 _tdm_pp_find_buffer(struct list_head *list, tdm_pp_private_buffer *pp_buffer)
97 {
98         tdm_pp_private_buffer *b = NULL, *bb = NULL;
99
100         LIST_FOR_EACH_ENTRY_SAFE(b, bb, list, link) {
101                 if (b == pp_buffer)
102                         return b;
103         }
104
105         return NULL;
106 }
107
108 static void
109 _tdm_pp_thread_cb_done(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data)
110 {
111         tdm_thread_cb_pp_done *pp_done = (tdm_thread_cb_pp_done *)cb_base;
112         tdm_private_pp *private_pp = object;
113         tdm_pp_private_buffer *pp_buffer = NULL, *first_entry = NULL;
114         tbm_surface_h src;
115         tbm_surface_h dst;
116
117         TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
118
119         assert(private_pp->owner_tid == syscall(SYS_gettid));
120
121         src = pp_done->src;
122         dst = pp_done->dst;
123
124         if (tdm_debug_dump & TDM_DUMP_FLAG_PP) {
125                 /* LCOV_EXCL_START */
126                 char str[TDM_PATH_LEN];
127                 static int i;
128                 snprintf(str, TDM_PATH_LEN, "pp_dst_%03d", i++);
129                 tdm_helper_dump_buffer_str(dst, tdm_debug_dump_dir, str);
130                 /* LCOV_EXCL_STOP */
131         }
132
133         if (!LIST_IS_EMPTY(&private_pp->buffer_list)) {
134                 first_entry = container_of((&private_pp->buffer_list)->next, pp_buffer, link);
135                 if (first_entry->src != src || first_entry->dst != dst)
136                         TDM_ERR("buffer(%p,%p) is skipped", first_entry->src, first_entry->dst);
137         } else {
138                 TDM_NEVER_GET_HERE();
139         }
140
141         if ((pp_buffer = _tdm_pp_find_tbm_buffers(&private_pp->buffer_list, src, dst))) {
142                 LIST_DEL(&pp_buffer->link);
143                 LIST_DELINIT(&pp_buffer->commit_link);
144
145                 if (tdm_debug_module & TDM_DEBUG_BUFFER)
146                         TDM_INFO("pp(%p) done: src(%p) dst(%p)", private_pp, src, dst);
147
148                 if (tdm_ttrace_module & TDM_TTRACE_PP) {
149                         tbm_bo bo = tbm_surface_internal_get_bo(dst, 0);
150                         TDM_TRACE_ASYNC_END((intptr_t)private_pp, "[PP] %d", tbm_bo_export(bo));
151                 }
152
153                 _pthread_mutex_unlock(&private_display->lock);
154                 if (private_pp->done_func)
155                         private_pp->done_func(private_pp, src, dst, private_pp->done_user_data);
156                 tdm_buffer_unref_backend(src);
157                 tdm_buffer_unref_backend(dst);
158                 _pthread_mutex_lock(&private_display->lock);
159
160                 free(pp_buffer);
161         }
162 }
163
164 static void
165 _tdm_pp_cb_done(tdm_pp *pp_module, tbm_surface_h src, tbm_surface_h dst, void *user_data)
166 {
167         tdm_thread_cb_pp_done pp_done;
168         tdm_private_pp *private_pp = user_data;
169         tdm_error ret;
170
171         TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
172
173         memset(&pp_done, 0, sizeof pp_done);
174         pp_done.base.type = TDM_THREAD_CB_PP_DONE;
175         pp_done.base.length = sizeof pp_done;
176         pp_done.base.object_stamp = private_pp->stamp;
177         pp_done.base.data = NULL;
178         pp_done.base.sync = 0;
179         pp_done.src = src;
180         pp_done.dst = dst;
181
182         ret = tdm_thread_cb_call(private_pp, &pp_done.base, 1);
183         TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
184 }
185
186 static void *
187 _tdm_pp_find_object(tdm_private_display *private_display, double stamp)
188 {
189         tdm_private_module *private_module = NULL;
190         tdm_private_pp *private_pp = NULL;
191
192         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), NULL);
193
194         LIST_FOR_EACH_ENTRY(private_module, &private_display->module_list, link) {
195                 LIST_FOR_EACH_ENTRY(private_pp, &private_module->pp_list, link) {
196                         if (private_pp->stamp == stamp)
197                                 return private_pp;
198                 }
199         }
200
201         return NULL;
202 }
203
204 INTERN tdm_error
205 tdm_pp_init(tdm_private_display *private_display)
206 {
207         tdm_thread_cb_set_find_func(TDM_THREAD_CB_PP_DONE, _tdm_pp_find_object);
208
209         return TDM_ERROR_NONE;
210 }
211
212 INTERN tdm_private_pp *
213 tdm_pp_create_internal(tdm_private_module *private_module, tdm_error *error)
214 {
215         tdm_private_display *private_display;
216         tdm_func_display *func_display;
217         tdm_func_pp *func_pp;
218         tdm_private_pp *private_pp = NULL;
219         tdm_pp *pp_module = NULL;
220         tdm_error ret = TDM_ERROR_NONE;
221
222         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), NULL);
223         TDM_RETURN_VAL_IF_FAIL(private_module != NULL, NULL);
224
225         private_display = private_module->private_display;
226         func_display = &private_module->func_display;
227         func_pp = &private_module->func_pp;
228
229         if (!(private_module->capabilities & TDM_DISPLAY_CAPABILITY_PP)) {
230                 /* LCOV_EXCL_START */
231                 TDM_ERR("backedn(%s) no pp capability", private_module->module_data->name);
232                 if (error)
233                         *error = TDM_ERROR_NO_CAPABILITY;
234                 return NULL;
235                 /* LCOV_EXCL_STOP */
236         }
237
238         pp_module = func_display->display_create_pp(private_module->bdata, &ret);
239         if (ret != TDM_ERROR_NONE) {
240                 /* LCOV_EXCL_START */
241                 if (error)
242                         *error = ret;
243                 return NULL;
244                 /* LCOV_EXCL_STOP */
245         }
246
247         private_pp = calloc(1, sizeof(tdm_private_pp));
248         if (!private_pp) {
249                 /* LCOV_EXCL_START */
250                 TDM_ERR("failed: alloc memory");
251                 func_pp->pp_destroy(pp_module);
252                 if (error)
253                         *error = TDM_ERROR_OUT_OF_MEMORY;
254                 return NULL;
255                 /* LCOV_EXCL_STOP */
256         }
257
258         ret = tdm_thread_cb_add(private_pp, TDM_THREAD_CB_PP_DONE, NULL, _tdm_pp_thread_cb_done, NULL);
259         if (ret != TDM_ERROR_NONE) {
260                 TDM_ERR("pp tdm_thread_cb_add failed");
261                 func_pp->pp_destroy(pp_module);
262                 free(private_pp);
263                 if (error)
264                         *error = ret;
265                 return NULL;
266         }
267
268         ret = func_pp->pp_set_done_handler(pp_module, _tdm_pp_cb_done, private_pp);
269         if (ret != TDM_ERROR_NONE) {
270                 /* LCOV_EXCL_START */
271                 TDM_ERR("spp(%p) et pp_done_handler failed", private_pp);
272                 func_pp->pp_destroy(pp_module);
273                 free(private_pp);
274                 if (error)
275                         *error = ret;
276                 return NULL;
277                 /* LCOV_EXCL_STOP */
278         }
279
280         private_pp->stamp = tdm_helper_get_time();
281         while (_tdm_pp_find_object(private_display, private_pp->stamp))
282                 private_pp->stamp++;
283
284         LIST_ADD(&private_pp->link, &private_module->pp_list);
285         private_pp->private_display = private_module->private_display;
286         private_pp->private_module = private_module;
287         private_pp->pp_module = pp_module;
288         private_pp->owner_tid = syscall(SYS_gettid);
289
290         LIST_INITHEAD(&private_pp->pending_buffer_list);
291         LIST_INITHEAD(&private_pp->buffer_list);
292
293         if (error)
294                 *error = TDM_ERROR_NONE;
295
296         return private_pp;
297 }
298
299 INTERN void
300 tdm_pp_destroy_internal(tdm_private_pp *private_pp)
301 {
302         tdm_private_display *private_display;
303         tdm_private_module *private_module;
304         tdm_func_pp *func_pp;
305         tdm_pp_private_buffer *b = NULL, *bb = NULL;
306         struct list_head clone_list;
307
308         TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
309
310         if (!private_pp)
311                 return;
312
313         tdm_thread_cb_remove(private_pp, TDM_THREAD_CB_PP_DONE, NULL, _tdm_pp_thread_cb_done, NULL);
314
315         private_display = private_pp->private_display;
316         private_module = private_pp->private_module;
317         func_pp = &private_module->func_pp;
318
319         LIST_DEL(&private_pp->link);
320
321         func_pp->pp_destroy(private_pp->pp_module);
322
323         if (!LIST_IS_EMPTY(&private_pp->pending_buffer_list)) {
324                 TDM_WRN("pp(%p) not finished:", private_pp);
325                 _tdm_pp_print_list(&private_pp->pending_buffer_list);
326
327                 LIST_INITHEAD(&clone_list);
328                 LIST_FOR_EACH_ENTRY_SAFE(b, bb, &private_pp->pending_buffer_list, link) {
329                         LIST_DEL(&b->link);
330                         LIST_ADDTAIL(&b->link, &clone_list);
331                 }
332
333                 _pthread_mutex_unlock(&private_display->lock);
334                 LIST_FOR_EACH_ENTRY_SAFE(b, bb, &clone_list, link) {
335                         LIST_DEL(&b->link);
336
337                         if (tdm_ttrace_module & TDM_TTRACE_PP) {
338                                 tbm_bo bo = tbm_surface_internal_get_bo(b->dst, 0);
339                                 TDM_TRACE_ASYNC_END((intptr_t)private_pp, "[PP] %d", tbm_bo_export(bo));
340                         }
341
342                         tdm_buffer_unref_backend(b->src);
343                         tdm_buffer_unref_backend(b->dst);
344                         free(b);
345                 }
346                 _pthread_mutex_lock(&private_display->lock);
347         }
348
349         if (!LIST_IS_EMPTY(&private_pp->buffer_list)) {
350                 TDM_WRN("pp(%p) not finished:", private_pp);
351                 _tdm_pp_print_list(&private_pp->buffer_list);
352
353                 LIST_INITHEAD(&clone_list);
354                 LIST_FOR_EACH_ENTRY_SAFE(b, bb, &private_pp->buffer_list, link) {
355                         LIST_DEL(&b->link);
356                         LIST_ADDTAIL(&b->link, &clone_list);
357                 }
358
359                 _pthread_mutex_unlock(&private_display->lock);
360                 LIST_FOR_EACH_ENTRY_SAFE(b, bb, &clone_list, link) {
361                         LIST_DEL(&b->link);
362
363                         if (tdm_ttrace_module & TDM_TTRACE_PP) {
364                                 tbm_bo bo = tbm_surface_internal_get_bo(b->dst, 0);
365                                 TDM_TRACE_ASYNC_END((intptr_t)private_pp, "[PP] %d", tbm_bo_export(bo));
366                         }
367
368                         tdm_buffer_unref_backend(b->src);
369                         tdm_buffer_unref_backend(b->dst);
370                         free(b);
371                 }
372                 _pthread_mutex_lock(&private_display->lock);
373         }
374
375         private_pp->stamp = 0;
376         free(private_pp);
377 }
378
379 EXTERN void
380 tdm_pp_destroy(tdm_pp *pp)
381 {
382         tdm_private_pp *private_pp = pp;
383         tdm_private_display *private_display;
384
385         if (!private_pp)
386                 return;
387
388         private_display = private_pp->private_display;
389
390         _pthread_mutex_lock(&private_display->lock);
391         tdm_pp_destroy_internal(private_pp);
392         _pthread_mutex_unlock(&private_display->lock);
393 }
394
395 EXTERN tdm_error
396 tdm_pp_set_info(tdm_pp *pp, tdm_info_pp *info)
397 {
398         PP_FUNC_ENTRY();
399
400         TDM_RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER);
401
402         _pthread_mutex_lock(&private_display->lock);
403
404         if (!func_pp->pp_set_info) {
405                 /* LCOV_EXCL_START */
406                 _pthread_mutex_unlock(&private_display->lock);
407                 TDM_DBG("failed: not implemented!!");
408                 return TDM_ERROR_NOT_IMPLEMENTED;
409                 /* LCOV_EXCL_STOP */
410         }
411
412         TDM_INFO("pp(%p) info: src(%ux%u %u,%u %ux%u %c%c%c%c) dst(%ux%u %u,%u %ux%u %c%c%c%c) trans(%d) sync(%d) flags(%x)",
413                          private_pp, info->src_config.size.h, info->src_config.size.v,
414                          info->src_config.pos.x, info->src_config.pos.y,
415                          info->src_config.pos.w, info->src_config.pos.h,
416                          FOURCC_STR(info->src_config.format),
417                          info->dst_config.size.h, info->dst_config.size.v,
418                          info->dst_config.pos.x, info->dst_config.pos.y,
419                          info->dst_config.pos.w, info->dst_config.pos.h,
420                          FOURCC_STR(info->dst_config.format),
421                          info->transform, info->sync, info->flags);
422
423         ret = func_pp->pp_set_info(private_pp->pp_module, info);
424         TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
425
426         private_pp->info = *info;
427
428         _pthread_mutex_unlock(&private_display->lock);
429
430         return ret;
431 }
432
433 EXTERN tdm_error
434 tdm_pp_set_done_handler(tdm_pp *pp, tdm_pp_done_handler func, void *user_data)
435 {
436         tdm_private_display *private_display;
437         tdm_private_pp *private_pp;
438         tdm_error ret = TDM_ERROR_NONE;
439
440         TDM_RETURN_VAL_IF_FAIL(pp != NULL, TDM_ERROR_INVALID_PARAMETER);
441
442         private_pp = (tdm_private_pp*)pp;
443         private_display = private_pp->private_display;
444
445         TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
446
447         _pthread_mutex_lock(&private_display->lock);
448
449         private_pp->done_func = func;
450         private_pp->done_user_data = user_data;
451
452         _pthread_mutex_unlock(&private_display->lock);
453
454         return ret;
455 }
456
457 EXTERN tdm_error
458 tdm_pp_attach(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst)
459 {
460         tdm_pp_private_buffer *pp_buffer;
461
462         PP_FUNC_ENTRY();
463
464         TDM_RETURN_VAL_IF_FAIL(src != NULL, TDM_ERROR_INVALID_PARAMETER);
465         TDM_RETURN_VAL_IF_FAIL(dst != NULL, TDM_ERROR_INVALID_PARAMETER);
466
467         _pthread_mutex_lock(&private_display->lock);
468
469         if (!func_pp->pp_attach) {
470                 /* LCOV_EXCL_START */
471                 _pthread_mutex_unlock(&private_display->lock);
472                 TDM_DBG("failed: not implemented!!");
473                 return TDM_ERROR_NOT_IMPLEMENTED;
474                 /* LCOV_EXCL_STOP */
475         }
476
477         if (tdm_module_check_abi(private_module, 1, 2) &&
478                 private_module->caps_pp.max_attach_count > 0) {
479                 /* LCOV_EXCL_START */
480                 int length = LIST_LENGTH(&private_pp->pending_buffer_list) +
481                                          LIST_LENGTH(&private_pp->buffer_list);
482                 if (length >= private_module->caps_pp.max_attach_count) {
483                         _pthread_mutex_unlock(&private_display->lock);
484                         TDM_DBG("failed: backend(%s) too many attached!! max_attach_count(%d)",
485                                         private_module->module_data->name, private_module->caps_pp.max_attach_count);
486                         return TDM_ERROR_BAD_REQUEST;
487                 }
488                 /* LCOV_EXCL_STOP */
489         }
490
491         if (tdm_debug_dump & TDM_DUMP_FLAG_PP) {
492                 /* LCOV_EXCL_START */
493                 char str[TDM_PATH_LEN];
494                 static int i;
495                 snprintf(str, TDM_PATH_LEN, "pp_src_%03d", i++);
496                 tdm_helper_dump_buffer_str(src, tdm_debug_dump_dir, str);
497                 /* LCOV_EXCL_STOP */
498         }
499
500         pp_buffer = calloc(1, sizeof * pp_buffer);
501         if (!pp_buffer) {
502                 /* LCOV_EXCL_START */
503                 _pthread_mutex_unlock(&private_display->lock);
504                 TDM_ERR("alloc failed");
505                 return TDM_ERROR_OUT_OF_MEMORY;
506                 /* LCOV_EXCL_STOP */
507         }
508
509         ret = func_pp->pp_attach(private_pp->pp_module, src, dst);
510         TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
511
512         if (ret != TDM_ERROR_NONE) {
513                 /* LCOV_EXCL_START */
514                 free(pp_buffer);
515                 _pthread_mutex_unlock(&private_display->lock);
516                 TDM_ERR("attach failed");
517                 return ret;
518                 /* LCOV_EXCL_STOP */
519         }
520
521         LIST_ADDTAIL(&pp_buffer->link, &private_pp->pending_buffer_list);
522         pp_buffer->src = tdm_buffer_ref_backend(src);
523         pp_buffer->dst = tdm_buffer_ref_backend(dst);
524
525         if (tdm_debug_module & TDM_DEBUG_BUFFER) {
526                 TDM_INFO("pp(%p) attached:", private_pp);
527                 _tdm_pp_print_list(&private_pp->pending_buffer_list);
528         }
529
530         if (tdm_ttrace_module & TDM_TTRACE_PP) {
531                 tbm_bo bo = tbm_surface_internal_get_bo(dst, 0);
532                 TDM_TRACE_ASYNC_BEGIN((intptr_t)pp, "[PP] %d", tbm_bo_export(bo));
533         }
534
535         _pthread_mutex_unlock(&private_display->lock);
536
537         return ret;
538 }
539
540 EXTERN tdm_error
541 tdm_pp_commit(tdm_pp *pp)
542 {
543         tdm_pp_private_buffer *b = NULL, *bb = NULL;
544         struct list_head commit_buffer_list;
545
546         PP_FUNC_ENTRY();
547
548         _pthread_mutex_lock(&private_display->lock);
549
550         if (!func_pp->pp_commit) {
551                 /* LCOV_EXCL_START */
552                 _pthread_mutex_unlock(&private_display->lock);
553                 TDM_DBG("failed: not implemented!!");
554                 return TDM_ERROR_NOT_IMPLEMENTED;
555                 /* LCOV_EXCL_STOP */
556         }
557
558         LIST_INITHEAD(&commit_buffer_list);
559
560         LIST_FOR_EACH_ENTRY_SAFE(b, bb, &private_pp->pending_buffer_list, link) {
561                 LIST_DEL(&b->link);
562                 LIST_ADDTAIL(&b->link, &private_pp->buffer_list);
563                 LIST_ADDTAIL(&b->commit_link, &commit_buffer_list);
564         }
565
566         ret = func_pp->pp_commit(private_pp->pp_module);
567         TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
568
569         LIST_FOR_EACH_ENTRY_SAFE(b, bb, &commit_buffer_list, commit_link) {
570                 LIST_DELINIT(&b->commit_link);
571
572                 if (!_tdm_pp_find_buffer(&private_pp->buffer_list, b))
573                         continue;
574
575                 if (ret != TDM_ERROR_NONE) {
576                         /* Not to call the user release handler when failed.
577                          * Do we have to call this function here really?
578                          * User better use set_done_handler to know when pp is done. Using
579                          * buffer_release_handler is not good.
580                          */
581                         tdm_buffer_remove_release_handler_internal(b->src);
582                         tdm_buffer_remove_release_handler_internal(b->dst);
583
584                         _pthread_mutex_unlock(&private_display->lock);
585                         tdm_buffer_unref_backend(b->src);
586                         tdm_buffer_unref_backend(b->dst);
587                         _pthread_mutex_lock(&private_display->lock);
588                         LIST_DEL(&b->link);
589
590                         free(b);
591                 }
592         }
593
594         _pthread_mutex_unlock(&private_display->lock);
595
596         return ret;
597 }