+int
+tbm_module_support_surface_data(tbm_module *module)
+{
+ tbm_error_e error = TBM_ERROR_NONE;
+ tbm_surface_data *surface_data = NULL;
+
+ TBM_RETURN_VAL_IF_FAIL(module, 0);
+
+ // check once support_surface_data or not.
+ if (module->check_surface_data) {
+ // return the value which already set.
+ return module->support_surface_data;
+ }
+
+ // check this only once
+ module->check_surface_data = 1;
+
+ if (module->type != TBM_MODULE_TYPE_HAL_TBM)
+ goto done;
+
+ // Assume that the hal-tbm supports the hal surface apis if tbm_module_alloc_surface_data succeed.
+ surface_data = tbm_module_alloc_surface_data(module, 10, 10, TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT, &error);
+ if (!surface_data)
+ goto done;
+ free(surface_data);
+
+ module->support_surface_data = 1;
+
+done:
+ return module->support_surface_data;
+}
+
+
+tbm_surface_data *
+tbm_module_alloc_surface_data(tbm_module *module, int width, int height, int format, int flags, tbm_error_e *error)
+{
+ tbm_surface_data *surface_data = NULL;
+
+ TBM_RETURN_VAL_SET_ERR_IF_FAIL(module, NULL, *error, TBM_ERROR_INVALID_PARAMETER);
+ TBM_RETURN_VAL_SET_ERR_IF_FAIL(module->type == TBM_MODULE_TYPE_HAL_TBM, NULL, *error, TBM_ERROR_INVALID_OPERATION);
+
+ surface_data = calloc(1, sizeof(struct _tbm_surface_data));
+ if (!surface_data) {
+ TBM_ERR("memory allocation failed.");
+ *error = TBM_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+
+ surface_data->hal_surface = hal_tbm_bufmgr_alloc_surface(module->hal_bufmgr,
+ (uint32_t)width,
+ (uint32_t)height,
+ (hal_tbm_format)format,
+ (hal_tbm_bo_memory_type)flags,
+ NULL,
+ 0,
+ (hal_tbm_error *)error);
+ if (!surface_data->hal_surface) {
+ if (*error != TBM_ERROR_NOT_SUPPORTED) // do not print the error message when it is not supported.
+ TBM_ERR("hal_tbm_bufmgr_alloc_surface failed.");
+ free(surface_data);
+ return NULL;
+ }
+
+ surface_data->module = module;
+
+ return surface_data;
+}
+
+tbm_surface_data *
+tbm_module_import_surface_data(tbm_module *module, int width, int height, int format, tbm_surface_buffer_data *buffer_data, tbm_error_e *error)
+{
+ tbm_surface_data *surface_data = NULL;
+
+ TBM_RETURN_VAL_SET_ERR_IF_FAIL(module, NULL, *error, TBM_ERROR_INVALID_PARAMETER);
+ TBM_RETURN_VAL_SET_ERR_IF_FAIL(module->type == TBM_MODULE_TYPE_HAL_TBM, NULL, *error, TBM_ERROR_INVALID_OPERATION);
+
+ surface_data = calloc(1, sizeof(struct _tbm_surface_data));
+ if (!surface_data) {
+ TBM_ERR("memory allocation failed.");
+ *error = TBM_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+
+ surface_data->hal_surface = hal_tbm_bufmgr_import_surface(module->hal_bufmgr,
+ (uint32_t)width,
+ (uint32_t)height,
+ (hal_tbm_format)format,
+ (hal_tbm_surface_buffer_data *)buffer_data,
+ (hal_tbm_error *)error);
+ if (!surface_data->hal_surface) {
+ TBM_ERR("hal_tbm_bufmgr_import_surface failed. width:%d height:%d format:%d error:%s",
+ width, height, format, tbm_error_str(*error));
+ free(surface_data);
+ return NULL;
+ }
+
+ surface_data->module = module;
+
+ return surface_data;
+}
+
+tbm_bo_data *
+tbm_module_alloc_bo_data(tbm_module *module, tbm_bo bo, int size, int flags, tbm_error_e *error)