1 /**************************************************************************
5 Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
34 #include "tbm_bufmgr.h"
35 #include "tbm_bufmgr_int.h"
36 #include "tbm_bufmgr_backend.h"
37 #include "tbm_drm_helper.h"
40 #include <sys/resource.h>
51 static pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER;
52 static pthread_mutex_t tbm_bufmgr_lock = PTHREAD_MUTEX_INITIALIZER;
53 static double scale_factor = 0;
54 void _tbm_bufmgr_mutex_unlock(void);
56 //#define TBM_BUFMGR_INIT_TIME
58 #define MAX_SIZE_N(dest) (sizeof(dest) - strlen(dest) - 1)
61 #define TBM_BUFMGR_RETURN_IF_FAIL(cond) {\
63 TBM_ERR("'%s' failed.\n", #cond);\
64 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
65 _tbm_bufmgr_mutex_unlock();\
70 #define TBM_BUFMGR_RETURN_VAL_IF_FAIL(cond, val) {\
72 TBM_ERR("'%s' failed.\n", #cond);\
73 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);\
74 _tbm_bufmgr_mutex_unlock();\
82 _tbm_bufmgr_mutex_lock(void)
84 pthread_mutex_lock(&tbm_bufmgr_lock);
88 _tbm_bufmgr_mutex_unlock(void)
90 pthread_mutex_unlock(&tbm_bufmgr_lock);
94 _tbm_util_get_max_surface_size(int *w, int *h)
96 tbm_surface_info_s info;
97 tbm_surface_h surface = NULL;
103 if (gBufMgr == NULL || LIST_IS_EMPTY(&gBufMgr->surf_list))
106 LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link) {
107 if (tbm_surface_get_info(surface, &info) == TBM_SURFACE_ERROR_NONE) {
111 if (*h < info.height)
120 _tbm_util_get_appname_brief(char *brief)
124 char temp[255] = {0,};
125 char *saveptr = NULL;
127 token = strtok_r(brief, delim, &saveptr);
129 while (token != NULL) {
130 memset(temp, 0x00, 255 * sizeof(char));
131 strncpy(temp, token, 254 * sizeof(char));
132 token = strtok_r(NULL, delim, &saveptr);
135 snprintf(brief, sizeof(temp), "%s", temp);
139 _tbm_util_get_appname_from_pid(long pid, char *str)
141 char fn_cmdline[255] = {0, }, cmdline[255];
145 if (pid <= 0) return;
147 snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline", pid);
149 fp = fopen(fn_cmdline, "r");
151 TBM_ERR("cannot file open %s\n", fn_cmdline);
155 if (!fgets(cmdline, 255, fp)) {
156 TBM_ERR("fail to get appname for pid(%ld)\n", pid);
163 len = strlen(cmdline);
165 memset(cmdline, 0x00, 255);
169 snprintf(str, sizeof(cmdline), "%s", cmdline);
175 _tbm_bufmgr_init(int fd, int server)
177 #ifdef TBM_BUFMGR_INIT_TIME
178 struct timeval start_tv, end_tv;
182 #ifdef TBM_BUFMGR_INIT_TIME
183 /* get the start tv */
184 gettimeofday(&start_tv, NULL);
189 /* LCOV_EXCL_START */
191 env = getenv("TBM_TRACE");
193 trace_mask = atoi(env);
194 TBM_DBG("TBM_TRACE=%s\n", env);
199 pthread_mutex_lock(&gLock);
201 _tbm_set_last_result(TBM_ERROR_NONE);
204 TBM_WRN("!!!!!WARNING:: The tbm_bufmgr_init DOSE NOT use argument fd ANYMORE.\n");
205 TBM_WRN("!!!!!WARNING:: IT WILL BE CHANGED like tbm_bufmgr_init(int fd) --> tbm_bufmgr_init(void).\n");
209 /* initialize buffer manager */
211 gBufMgr->ref_count++;
212 TBM_DBG("reuse tbm_bufmgr(%p) ref_count(%d) fd(%d)\n", gBufMgr, gBufMgr->ref_count, gBufMgr->fd);
213 pthread_mutex_unlock(&gLock);
217 TBM_DBG("bufmgr init\n");
219 /* allocate bufmgr */
220 gBufMgr = calloc(1, sizeof(struct _tbm_bufmgr));
222 TBM_ERR("error: fail to alloc bufmgr fd(%d)\n", fd);
223 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
224 pthread_mutex_unlock(&gLock);
230 /* set the display_server flag before loading the backend module */
232 TBM_INFO("The tbm_bufmgr(%p) is used by display server. Need to bind the native_display.\n", gBufMgr);
233 gBufMgr->display_server = 1;
236 /* load bufmgr priv from env */
237 gBufMgr->module = tbm_module_load(gBufMgr, gBufMgr->fd);
238 if (!gBufMgr->module) {
239 TBM_ERR("error : Fail to load bufmgr backend\n");
240 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
243 pthread_mutex_unlock(&gLock);
249 gBufMgr->ref_count = 1;
251 TBM_INFO("create tizen bufmgr:%p ref_count:%d\n",
252 gBufMgr, gBufMgr->ref_count);
254 /* setup the bo_lock_type */
255 env = getenv("BUFMGR_LOCK_TYPE");
256 if (env && !strcmp(env, "always"))
257 gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS;
258 else if (env && !strcmp(env, "none"))
259 gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_NEVER;
260 else if (env && !strcmp(env, "once"))
261 gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ONCE;
263 gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS;
265 TBM_DBG("BUFMGR_LOCK_TYPE=%s\n", env ? env : "default:once");
267 /* intialize bo_list */
268 LIST_INITHEAD(&gBufMgr->bo_list);
270 /* intialize surf_list */
271 LIST_INITHEAD(&gBufMgr->surf_list);
273 /* intialize surf_queue_list */
274 LIST_INITHEAD(&gBufMgr->surf_queue_list);
276 /* intialize debug_key_list */
277 LIST_INITHEAD(&gBufMgr->debug_key_list);
279 #ifdef TBM_BUFMGR_INIT_TIME
281 gettimeofday(&end_tv, NULL);
282 TBM_INFO("tbm_bufmgr_init time: %ld ms", ((end_tv.tv_sec * 1000 + end_tv.tv_usec / 1000) - (start_tv.tv_sec * 1000 + start_tv.tv_usec / 1000)));
285 pthread_mutex_unlock(&gLock);
291 tbm_bufmgr_init(int fd)
295 bufmgr = _tbm_bufmgr_init(fd, 0);
301 tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
303 TBM_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
305 _tbm_bufmgr_mutex_lock();
306 pthread_mutex_lock(&gLock);
307 _tbm_set_last_result(TBM_ERROR_NONE);
310 TBM_ERR("gBufmgr already destroy: bufmgr:%p\n", bufmgr);
311 pthread_mutex_unlock(&gLock);
312 _tbm_bufmgr_mutex_unlock();
317 if (bufmgr->ref_count > 0) {
318 TBM_DBG("reduce a ref_count(%d) of tbm_bufmgr(%p)\n", bufmgr->ref_count, bufmgr);
319 pthread_mutex_unlock(&gLock);
320 _tbm_bufmgr_mutex_unlock();
324 /* destroy bo_list */
325 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
326 tbm_bo bo = NULL, tmp;
328 LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &bufmgr->bo_list, item_link) {
329 TBM_ERR("Un-freed bo(%p, ref:%d)\n", bo, bo->ref_cnt);
332 LIST_DELINIT(&bufmgr->bo_list);
335 /* destroy surf_list */
336 if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
337 tbm_surface_h surf = NULL, tmp;
339 LIST_FOR_EACH_ENTRY_SAFE(surf, tmp, &bufmgr->surf_list, item_link) {
340 TBM_ERR("Un-freed surf(%p, ref:%d)\n", surf, surf->refcnt);
341 tbm_surface_destroy(surf);
343 LIST_DELINIT(&bufmgr->surf_list);
346 tbm_module_unload(bufmgr->module);
351 TBM_INFO("destroy tbm_bufmgr(%p)\n", bufmgr);
356 pthread_mutex_unlock(&gLock);
357 _tbm_bufmgr_mutex_unlock();
361 tbm_bufmgr_get_capability(tbm_bufmgr bufmgr)
363 unsigned int capabilities = TBM_BUFMGR_CAPABILITY_NONE;
365 _tbm_bufmgr_mutex_lock();
366 _tbm_set_last_result(TBM_ERROR_NONE);
368 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), TBM_BUFMGR_CAPABILITY_NONE);
369 TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, TBM_BUFMGR_CAPABILITY_NONE);
371 capabilities = bufmgr->capabilities;
373 _tbm_bufmgr_mutex_unlock();
378 /* LCOV_EXCL_START */
380 tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr)
382 char app_name[255] = {0,}, title[512] = {0,};
383 tbm_surface_debug_data *debug_old_data = NULL;
391 pthread_mutex_lock(&gLock);
392 _tbm_set_last_result(TBM_ERROR_NONE);
394 if (!TBM_BUFMGR_IS_VALID(bufmgr) || (bufmgr != gBufMgr)) {
395 TBM_ERR("invalid bufmgr\n");
396 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
397 pthread_mutex_unlock(&gLock);
403 TBM_ERR("Fail to allocate the string.\n");
404 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
405 pthread_mutex_unlock(&gLock);
409 TBM_SNRPRINTF(str, len, c, "\n");
410 pid = syscall(SYS_getpid);
411 _tbm_util_get_appname_from_pid(pid, app_name);
412 _tbm_util_get_appname_brief(app_name);
413 TBM_SNRPRINTF(str, len, c, "===========================================TBM DEBUG: %s(%ld)===========================================\n",
416 snprintf(title, 255, "%s", "no surface refcnt width height bpp size n_b n_p flags format app_name ");
418 if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
419 LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) {
420 strncat(title, " ", MAX_SIZE_N(title));
421 strncat(title, debug_old_data->key, MAX_SIZE_N(title));
425 TBM_SNRPRINTF(str, len, c, "[tbm_surface information]\n");
426 TBM_SNRPRINTF(str, len, c, "%s\n", title);
428 /* show the tbm_surface information in surf_list */
429 if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
430 tbm_surface_h surf = NULL;
433 LIST_FOR_EACH_ENTRY(surf, &bufmgr->surf_list, item_link) {
434 char data[512] = {0,};
435 unsigned int surf_pid = 0;
438 surf_pid = _tbm_surface_internal_get_debug_pid(surf);
440 /* if pid is null, set the self_pid */
441 surf_pid = syscall(SYS_getpid);;
444 memset(app_name, 0x0, 255 * sizeof(char));
445 if (geteuid() == 0) {
446 _tbm_util_get_appname_from_pid(surf_pid, app_name);
447 _tbm_util_get_appname_brief(app_name);
449 snprintf(app_name, sizeof(app_name), "%d", surf_pid);
452 snprintf(data, 255, "%-3d %-11p %-5d %-6u %-7u %-4u %-7u %-3d %-3d %-8d %-9s %-22s",
459 surf->info.size / 1024,
463 _tbm_surface_internal_format_to_str(surf->info.format) + 11,
466 if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
467 LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) {
470 strncat(data, " ", MAX_SIZE_N(title));
472 value = _tbm_surface_internal_get_debug_data(surf, debug_old_data->key);
474 strncat(data, value, MAX_SIZE_N(title));
476 strncat(data, "none", MAX_SIZE_N(title));
479 TBM_SNRPRINTF(str, len, c, "%s\n", data);
481 for (i = 0; i < surf->num_bos; i++) {
482 if (bufmgr->use_hal_tbm) {
483 size = hal_tbm_bo_get_size((hal_tbm_bo *)surf->bos[i]->bo_data, (hal_tbm_error *)&error);
484 if (error != TBM_ERROR_NONE)
485 TBM_WRN("fail to get the size of bo.");
486 } else if (bufmgr->backend_module_data) {
487 size = bufmgr->bo_func->bo_get_size(surf->bos[i]->bo_data, &error);
488 if (error != TBM_ERROR_NONE)
489 TBM_WRN("fail to get the size of bo.");
491 size = bufmgr->backend->bo_size(surf->bos[i]);
492 TBM_SNRPRINTF(str, len, c, " bo:%-12p %-26d%-10d\n",
494 surf->bos[i]->ref_cnt,
499 TBM_SNRPRINTF(str, len, c, " no tbm_surfaces.\n");
500 TBM_SNRPRINTF(str, len, c, "\n");
502 TBM_SNRPRINTF(str, len, c, "[tbm_bo information]\n");
503 TBM_SNRPRINTF(str, len, c, "no bo refcnt size lock_cnt map_cnt flags surface name\n");
505 /* show the tbm_bo information in bo_list */
506 if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
511 LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) {
512 if (bo->bufmgr->use_hal_tbm) {
513 size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
514 if (error != TBM_ERROR_NONE)
515 TBM_WRN("fail to get the size of bo.");
516 key = (tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
517 } else if (bufmgr->backend_module_data) {
518 size = bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
519 if (error != TBM_ERROR_NONE)
520 TBM_WRN("fail to get the size of bo.");
521 key = bufmgr->bo_func->bo_export_key(bo->bo_data, &error);
522 if (error != TBM_ERROR_NONE)
523 TBM_WRN("fail to get the tdm_key of bo.");
525 size = bufmgr->backend->bo_size(bo);
526 key = bufmgr->backend->bo_export(bo);
528 TBM_SNRPRINTF(str, len, c, "%-3d %-11p %-5d %-7d %-6d %-5u %-7d %-11p %-4d\n",
540 TBM_SNRPRINTF(str, len, c, "no tbm_bos.\n");
541 TBM_SNRPRINTF(str, len, c, "\n");
543 TBM_SNRPRINTF(str, len, c, "========================================================================================================\n");
545 pthread_mutex_unlock(&gLock);
551 tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
554 str = tbm_bufmgr_debug_tbm_info_get(bufmgr);
562 tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff)
564 _tbm_bufmgr_mutex_lock();
565 _tbm_set_last_result(TBM_ERROR_NONE);
567 TBM_BUFMGR_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
568 TBM_BUFMGR_RETURN_IF_FAIL(bufmgr == gBufMgr);
571 TBM_LOG_D("bufmgr=%p onoff=%d\n", bufmgr, onoff);
575 _tbm_bufmgr_mutex_unlock();
579 tbm_bufmgr_debug_set_trace_mask(tbm_bufmgr bufmgr, tbm_bufmgr_debug_trace_mask mask, int set)
581 _tbm_bufmgr_mutex_lock();
582 _tbm_set_last_result(TBM_ERROR_NONE);
584 TBM_BUFMGR_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
585 TBM_BUFMGR_RETURN_IF_FAIL(bufmgr == gBufMgr);
590 TBM_INFO("bufmgr=%p sets the trace_mask=%d\n", bufmgr, mask);
591 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_BO)
592 TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_BO");
593 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL)
594 TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL");
595 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE)
596 TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE");
597 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE)
598 TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE");
599 } else if (set == 0) {
602 TBM_INFO("bufmgr=%p unsets the trace_mask=%d\n", bufmgr, mask);
603 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_BO)
604 TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_BO");
605 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL)
606 TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE_INTERNAL");
607 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE)
608 TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE");
609 if (trace_mask&TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE)
610 TBM_INFO(" TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE");
612 TBM_WRN("set value is wrong.(set=%d)", set);
615 _tbm_bufmgr_mutex_unlock();
619 tbm_bufmgr_debug_dump_set_scale(double scale)
621 pthread_mutex_lock(&gLock);
622 _tbm_set_last_result(TBM_ERROR_NONE);
623 scale_factor = scale;
624 pthread_mutex_unlock(&gLock);
628 tbm_bufmgr_debug_get_ref_count(void)
632 pthread_mutex_lock(&gLock);
634 _tbm_set_last_result(TBM_ERROR_NONE);
636 refcnt = (gBufMgr) ? gBufMgr->ref_count : 0;
638 pthread_mutex_unlock(&gLock);
644 tbm_bufmgr_debug_queue_dump(char *path, int count, int onoff)
646 pthread_mutex_lock(&gLock);
647 _tbm_set_last_result(TBM_ERROR_NONE);
650 TBM_DBG("count=%d onoff=%d\n", count, onoff);
652 tbm_surface_internal_dump_end();
657 TBM_ERR("path is null");
658 pthread_mutex_unlock(&gLock);
661 TBM_DBG("path=%s count=%d onoff=%d\n", path, count, onoff);
663 if (_tbm_util_get_max_surface_size(&w, &h) == 0) {
664 TBM_ERR("Fail to get tbm_surface size.\n");
665 pthread_mutex_unlock(&gLock);
669 tbm_surface_internal_dump_with_scale_start(path, w, h, count, scale_factor);
675 pthread_mutex_unlock(&gLock);
681 tbm_bufmgr_debug_dump_all(char *path)
684 tbm_surface_h surface = NULL;
686 pthread_mutex_lock(&gLock);
687 _tbm_set_last_result(TBM_ERROR_NONE);
690 TBM_ERR("path is null.\n");
691 pthread_mutex_unlock(&gLock);
695 TBM_DBG("path=%s\n", path);
697 count = _tbm_util_get_max_surface_size(&w, &h);
699 TBM_ERR("No tbm_surface.\n");
700 pthread_mutex_unlock(&gLock);
704 tbm_surface_internal_dump_with_scale_start(path, w, h, count, scale_factor);
707 LIST_FOR_EACH_ENTRY(surface, &gBufMgr->surf_list, item_link)
708 tbm_surface_internal_dump_buffer(surface, "dump_all");
710 tbm_surface_internal_dump_end();
712 pthread_mutex_unlock(&gLock);
717 /* internal function */
719 _tbm_bufmgr_get_bufmgr(void)
725 tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *native_display)
730 _tbm_bufmgr_mutex_lock();
731 _tbm_set_last_result(TBM_ERROR_NONE);
733 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
735 if (bufmgr->use_hal_tbm) {
736 if (hal_tbm_backend_has_drm_device(bufmgr->hal_backend, &ret)) {
737 int fd = tbm_drm_helper_get_fd(); // this must be the auth drm_fd.(master drm_fd);
739 TBM_ERR("error: tbm_bufmgr(%p) native_display(%p)\n", bufmgr, native_display);
740 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
741 _tbm_bufmgr_mutex_unlock();
745 // make the wayland server socket for sending the authenticated drm_fd to wayland clients.
746 if (!tbm_drm_helper_wl_auth_server_init(native_display, fd, NULL, 0)) {
747 TBM_ERR("error: tbm_drm_helper_wl_auth_server_init failed\n", bufmgr, native_display);
749 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
750 _tbm_bufmgr_mutex_unlock();
753 TBM_INFO("tbm creates a wayland socket for authentication of drm_fd.");
755 bufmgr->auth_wl_socket_created = 1;
756 bufmgr->auth_fd = fd;
758 // TODO: this duplication will be removed after refactoring tbm_module
759 bufmgr->module->auth_wl_socket_created = 1;
760 bufmgr->module->bufmgr->auth_fd = fd;
762 } else if (bufmgr->backend_module_data) {
763 if (!bufmgr->bufmgr_func->bufmgr_bind_native_display) {
764 TBM_WRN("skip: tbm_bufmgr(%p) native_display(%p)\n",
765 bufmgr, native_display);
766 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
767 _tbm_bufmgr_mutex_unlock();
771 error = bufmgr->bufmgr_func->bufmgr_bind_native_display(bufmgr->bufmgr_data, (tbm_native_display *)native_display);
772 if (error != TBM_ERROR_NONE) {
773 TBM_ERR("error: tbm_bufmgr(%p) native_display(%p) error(%d)\n",
774 bufmgr, native_display, error);
775 _tbm_set_last_result(error);
776 _tbm_bufmgr_mutex_unlock();
781 if (!bufmgr->backend->bufmgr_bind_native_display) {
782 TBM_WRN("skip: tbm_bufmgr(%p) native_display(%p)\n",
783 bufmgr, native_display);
784 _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
785 _tbm_bufmgr_mutex_unlock();
789 ret = bufmgr->backend->bufmgr_bind_native_display(bufmgr, native_display);
791 TBM_ERR("error: tbm_bufmgr(%p) native_display(%p)\n",
792 bufmgr, native_display);
793 _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
794 _tbm_bufmgr_mutex_unlock();
799 TBM_INFO("tbm_bufmgr(%p) native_display(%p)\n", bufmgr, native_display);
801 _tbm_bufmgr_mutex_unlock();
807 tbm_bufmgr_server_init(void)
811 bufmgr = _tbm_bufmgr_init(-1, 1);
817 tbm_bufmgr_set_bo_lock_type(tbm_bufmgr bufmgr, tbm_bufmgr_bo_lock_type bo_lock_type)
819 _tbm_bufmgr_mutex_lock();
820 _tbm_set_last_result(TBM_ERROR_NONE);
822 TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
823 TBM_BUFMGR_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, 0);
825 pthread_mutex_lock(&gLock);
826 gBufMgr->bo_lock_type = bo_lock_type;
827 pthread_mutex_unlock(&gLock);
829 TBM_INFO("The bo_lock_type of the bo is %d\n", bo_lock_type);
831 _tbm_bufmgr_mutex_unlock();
837 int tbm_bufmgr_get_fd_limit(void)
841 if (getrlimit(RLIMIT_NOFILE, &lim))
844 return (int)lim.rlim_cur;
847 tbm_bufmgr tbm_bufmgr_get(void)