+ return flags;
+}
+
+/* LCOV_EXCL_START */
+tbm_error_e
+tbm_get_last_error(void)
+{
+ return tbm_last_error;
+}
+
+char *
+tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr)
+{
+ char app_name[255] = {0,}, title[512] = {0,};
+ tbm_surface_debug_data *debug_old_data = NULL;
+ char *str;
+ int len = 1024*4;
+ int c = 0;
+
+ pthread_mutex_lock(&gLock);
+
+ if (!TBM_BUFMGR_IS_VALID(bufmgr) || (bufmgr != gBufMgr)) {
+ TBM_LOG_E("invalid bufmgr\n");
+ pthread_mutex_unlock(&gLock);
+ return NULL;
+ }
+
+ str = malloc(len);
+ if (!str) {
+ TBM_LOG_E("Fail to allocate the string.\n");
+ pthread_mutex_unlock(&gLock);
+ return NULL;
+ }
+
+ TBM_SNRPRINTF(str, len, c, "\n");
+ _tbm_util_get_appname_from_pid(getpid(), app_name);
+ _tbm_util_get_appname_brief(app_name);
+ TBM_SNRPRINTF(str, len, c, "============TBM DEBUG: %s(%d)===========================\n",
+ app_name, getpid());
+
+ snprintf(title, 255, "%s", "no surface refcnt width height bpp size n_b n_p flags format app_name ");
+
+ if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
+ LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) {
+ strncat(title, " ", MAX_SIZE_N(title));
+ strncat(title, debug_old_data->key, MAX_SIZE_N(title));
+ }
+ }
+
+ TBM_SNRPRINTF(str, len, c, "[tbm_surface information]\n");
+ TBM_SNRPRINTF(str, len, c, "%s\n", title);
+
+ /* show the tbm_surface information in surf_list */
+ if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
+ tbm_surface_h surf = NULL;
+ int surf_cnt = 0;
+
+ LIST_FOR_EACH_ENTRY(surf, &bufmgr->surf_list, item_link) {
+ char data[512] = {0,};
+ unsigned int pid;
+ int i;
+
+ pid = _tbm_surface_internal_get_debug_pid(surf);
+ if (!pid) {
+ /* if pid is null, set the self_pid */
+ pid = getpid();
+ }
+
+ memset(app_name, 0x0, 255 * sizeof(char));
+ _tbm_util_get_appname_from_pid(pid, app_name);
+ _tbm_util_get_appname_brief(app_name);
+
+ snprintf(data, 255, "%-2d %-9p %-4d %-5u %-6u %-3u %-6u %-2d %-2d %-3d %-8s %-15s",
+ ++surf_cnt,
+ surf,
+ surf->refcnt,
+ surf->info.width,
+ surf->info.height,
+ surf->info.bpp,
+ surf->info.size / 1024,
+ surf->num_bos,
+ surf->num_planes,
+ surf->flags,
+ _tbm_surface_internal_format_to_str(surf->info.format) + 11,
+ app_name);
+
+ if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
+ LIST_FOR_EACH_ENTRY(debug_old_data, &bufmgr->debug_key_list, item_link) {
+ char *value;
+
+ strncat(data, " ", MAX_SIZE_N(title));
+
+ value = _tbm_surface_internal_get_debug_data(surf, debug_old_data->key);
+ if (value)
+ strncat(data, value, MAX_SIZE_N(title));
+ else
+ strncat(data, "none", MAX_SIZE_N(title));
+ }
+ }
+ TBM_SNRPRINTF(str, len, c, "%s\n", data);
+
+ for (i = 0; i < surf->num_bos; i++) {
+ TBM_SNRPRINTF(str, len, c, " bo:%-12p %-26d%-10d\n",
+ surf->bos[i],
+ surf->bos[i]->ref_cnt,
+ bufmgr->backend->bo_size(surf->bos[i]) / 1024);
+ }
+ }
+ } else
+ TBM_SNRPRINTF(str, len, c, " no tbm_surfaces.\n");
+ TBM_SNRPRINTF(str, len, c, "\n");
+
+ TBM_SNRPRINTF(str, len, c, "[tbm_bo information]\n");
+ TBM_SNRPRINTF(str, len, c, "no bo refcnt size lock_cnt map_cnt flags surface name\n");
+
+ /* show the tbm_bo information in bo_list */
+ if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
+ int bo_cnt = 0;
+ tbm_bo bo = NULL;
+
+ LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) {
+ TBM_SNRPRINTF(str, len, c, "%-4d%-11p %-4d %-6d %-5d %-4u %-3d %-11p %-4d\n",
+ ++bo_cnt,
+ bo,
+ bo->ref_cnt,
+ bufmgr->backend->bo_size(bo) / 1024,
+ bo->lock_cnt,
+ bo->map_cnt,
+ bo->flags,
+ bo->surface,
+ bufmgr->backend->bo_export(bo));
+ }
+ } else
+ TBM_SNRPRINTF(str, len, c, "no tbm_bos.\n");
+ TBM_SNRPRINTF(str, len, c, "\n");
+
+ TBM_SNRPRINTF(str, len, c, "===============================================================\n");
+
+ pthread_mutex_unlock(&gLock);
+
+ return str;
+}
+
+void
+tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
+{
+ char * str;
+ str = tbm_bufmgr_debug_tbm_info_get(bufmgr);
+ if (str) {
+ TBM_DEBUG(" %s", str);
+ free(str);
+ }
+}
+
+void
+tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff)
+{
+ _tbm_bufmgr_mutex_lock();
+
+ TBM_BUFMGR_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
+ TBM_BUFMGR_RETURN_IF_FAIL(bufmgr == gBufMgr);
+
+#ifdef TRACE
+ TBM_LOG_D("bufmgr=%p onoff=%d\n", bufmgr, onoff);
+ bTrace = onoff;
+#endif
+
+ _tbm_bufmgr_mutex_unlock();
+}
+
+void
+tbm_bufmgr_debug_dump_set_scale(double scale)
+{
+ pthread_mutex_lock(&gLock);
+ scale_factor = scale;
+ pthread_mutex_unlock(&gLock);