+ return bpp;
+}
+
+int
+tbm_surface_internal_is_valid(tbm_surface_h surface)
+{
+ int ret = 0;
+
+ _tbm_surface_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
+ /* Return silently if surface is null. */
+ if (!surface) {
+ _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
+ _tbm_surface_mutex_unlock();
+ return 0;
+ }
+
+ ret = _tbm_surface_internal_is_valid(surface);
+
+ _tbm_surface_mutex_unlock();
+
+ return ret;
+}
+
+int
+tbm_surface_internal_query_supported_formats(uint32_t **formats,
+ uint32_t *num)
+{
+ struct _tbm_bufmgr *bufmgr;
+ int ret = 0;
+ bool bufmgr_initialized = false;
+ tbm_error_e error;
+
+ _tbm_surface_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
+ TBM_SURFACE_RETURN_VAL_IF_FAIL(formats, 0);
+ TBM_SURFACE_RETURN_VAL_IF_FAIL(num, 0);
+
+ if (!g_surface_bufmgr) {
+ _init_surface_bufmgr();
+ LIST_INITHEAD(&g_surface_bufmgr->surf_list);
+ bufmgr_initialized = true;
+ }
+
+ bufmgr = g_surface_bufmgr;
+
+ if (bufmgr->backend_module_data) {
+ if (!bufmgr->bufmgr_func->bufmgr_get_supported_formats) {
+ _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
+ goto fail;
+ }
+
+ error = bufmgr->bufmgr_func->bufmgr_get_supported_formats(bufmgr->bufmgr_data, formats, num);
+ if (error != TBM_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ TBM_ERR("Fail to surface_supported_format. error(%d)\n", error);
+ goto fail;
+ /* LCOV_EXCL_START */
+ }
+ ret = 1;
+ } else {
+ if (!bufmgr->backend->surface_supported_format) {
+ _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
+ goto fail;
+ }
+
+ ret = bufmgr->backend->surface_supported_format(formats, num);
+ if (!ret) {
+ /* LCOV_EXCL_START */
+ TBM_ERR("Fail to surface_supported_format.\n");
+ _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
+ goto fail;
+ /* LCOV_EXCL_START */
+ }
+ }
+
+ TBM_TRACE_SURFACE_INTERNAL("tbm_bufmgr(%p) format num(%u)\n", g_surface_bufmgr, *num);
+
+ if (bufmgr_initialized) {
+ LIST_DELINIT(&g_surface_bufmgr->surf_list);
+ _deinit_surface_bufmgr();
+ }
+
+ _tbm_surface_mutex_unlock();
+
+ return ret;
+
+/* LCOV_EXCL_START */
+fail:
+ if (bufmgr_initialized) {
+ LIST_DELINIT(&g_surface_bufmgr->surf_list);
+ _deinit_surface_bufmgr();
+ }
+ _tbm_surface_mutex_unlock();
+
+ TBM_ERR("error: tbm_bufmgr(%p)\n", g_surface_bufmgr);
+
+ return 0;
+/* LCOV_EXCL_STOP */
+}
+
+int
+tbm_surface_internal_get_num_planes(tbm_format format)
+{
+ int num_planes = 0;
+
+ _tbm_surface_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
+ num_planes = _tbm_surface_internal_get_num_planes(format);
+ if (!num_planes) {
+ TBM_ERR("error: tbm_error(%s)\n", tbm_error_str(tbm_get_last_error()));
+ _tbm_surface_mutex_unlock();
+ return 0;
+ }
+
+ TBM_TRACE_SURFACE_INTERNAL("tbm_format(%s) num_planes(%d)\n", _tbm_surface_internal_format_to_str(format), num_planes);
+
+ _tbm_surface_mutex_unlock();
+
+ return num_planes;
+}
+
+int
+tbm_surface_internal_get_bpp(tbm_format format)
+{
+ int bpp = 0;
+
+ _tbm_surface_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
+ bpp = _tbm_surface_internal_get_bpp(format);
+ if (!bpp) {
+ TBM_ERR("error: tbm_error(%s)\n", tbm_error_str(tbm_get_last_error()));
+ _tbm_surface_mutex_unlock();
+ return 0;
+ }
+
+ _tbm_surface_mutex_unlock();
+
+ TBM_TRACE_SURFACE_INTERNAL("tbm_format(%s) bpp(%d)\n", _tbm_surface_internal_format_to_str(format), bpp);