tbm_module: use module instead of bufmgr 00/259700/1
authorSooChan Lim <sc1.lim@samsung.com>
Thu, 10 Jun 2021 06:22:28 +0000 (15:22 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Fri, 11 Jun 2021 00:50:04 +0000 (09:50 +0900)
set the information to tbm_module and
copy the information of tbm_module to bufmgr.
During the refactoring, the module infomation
in the bufmgr will be removed.

Change-Id: I94c9c121acf6af5bd8dea6377dd71fb29ee31eb6

src/tbm_bufmgr.c
src/tbm_module.c

index 4f6ece3..703cf40 100644 (file)
@@ -754,6 +754,10 @@ tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *native_display)
 
                        bufmgr->auth_wl_socket_created = 1;
                        bufmgr->auth_fd = fd;
+
+                       // TODO: this duplication will be removed after refactoring tbm_module
+                       bufmgr->module->auth_wl_socket_created = 1;
+                       bufmgr->module->bufmgr->auth_fd = fd;
                }
        } else if (bufmgr->backend_module_data) {
                if (!bufmgr->bufmgr_func->bufmgr_bind_native_display) {
index 8031385..f490d64 100644 (file)
@@ -53,8 +53,42 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 /* LCOV_EXCL_START */
 
+static void
+_tbm_module_copy_data_to_bufmgr(tbm_module *module, tbm_bufmgr bufmgr, int reset)
+{
+       if (!reset) {
+               bufmgr->module_data = module->module_data;
+               bufmgr->backend = module->backend;
+
+               bufmgr->backend_module_data = module->backend_module_data;
+               bufmgr->bufmgr_data = module->bufmgr_data;
+               bufmgr->bufmgr_func = module->bufmgr_func;
+               bufmgr->bo_func = module->bo_func;
+
+               bufmgr->use_hal_tbm = module->use_hal_tbm;
+               bufmgr->auth_wl_socket_created = module->auth_wl_socket_created;
+               bufmgr->auth_fd = module->auth_fd;
+               bufmgr->hal_backend = module->hal_backend;
+               bufmgr->hal_bufmgr = module->hal_bufmgr;
+       } else {
+               bufmgr->module_data = NULL;
+               bufmgr->backend = NULL;
+
+               bufmgr->backend_module_data = NULL;
+               bufmgr->bufmgr_data = NULL;
+               bufmgr->bufmgr_func = NULL;
+               bufmgr->bo_func = NULL;
+
+               bufmgr->use_hal_tbm = 0;
+               bufmgr->auth_wl_socket_created = 0;
+               bufmgr->auth_fd = -1;
+               bufmgr->hal_backend = NULL;
+               bufmgr->hal_bufmgr = NULL;
+       }
+}
+
 static int
-_tbm_backend_load_hal_tbm(tbm_bufmgr bufmgr)
+_tbm_backend_load_hal_tbm(tbm_module *module)
 {
        hal_tbm_backend *hal_backend = NULL;
        hal_tbm_bufmgr_capability capability;
@@ -120,12 +154,13 @@ _tbm_backend_load_hal_tbm(tbm_bufmgr bufmgr)
                TBM_ERR("The tbm backend has to get TBM_BUFMGR_CAPABILITY_SHARE_FD. ");
                goto get_backend_fail;
        }
-       bufmgr->capabilities = capability;
 
-       bufmgr->hal_backend = hal_backend;
-       bufmgr->hal_bufmgr = hal_bufmgr;
+       module->bufmgr->capabilities = capability;
+
+       module->hal_backend = hal_backend;
+       module->hal_bufmgr = hal_bufmgr;
 
-       bufmgr->use_hal_tbm = 1;
+       module->use_hal_tbm = 1;
 
        TBM_INFO("use HAL-TBM_API");
 
@@ -210,7 +245,7 @@ _tbm_backend_check_bufmgr_bo(tbm_backend_bo_func *bo_func)
 }
 
 static int
-_tbm_backend_load_module(tbm_bufmgr bufmgr, const char *file)
+_tbm_backend_load_module(tbm_module *module, const char *file)
 {
        char path[PATH_MAX] = {0, };
        void *module_data = NULL;
@@ -266,40 +301,40 @@ _tbm_backend_load_module(tbm_bufmgr bufmgr, const char *file)
                goto err;
        }
 
-       bufmgr_data = backend_module_data->init(bufmgr, &error);
+       bufmgr_data = backend_module_data->init((tbm_bufmgr)module, &error);
        if (!bufmgr_data) {
                TBM_ERR("Fail to init module(%s)\n", file);
                goto err;
        }
 
        /* check the mandatory symbols of the backend module */
-       if (!_tbm_backend_check_bufmgr_func(bufmgr->bufmgr_func)) {
+       if (!_tbm_backend_check_bufmgr_func(module->bufmgr_func)) {
                TBM_ERR("Fail to check the bufmgr_func symboles.");
                goto err;
        }
 
-       if (!_tbm_backend_check_bufmgr_bo(bufmgr->bo_func)) {
+       if (!_tbm_backend_check_bufmgr_bo(module->bo_func)) {
                TBM_ERR("Fail to check the bufmgr_bo symboles.");
                goto err;
        }
 
        /* get the capability */
-       bufmgr->capabilities = bufmgr->bufmgr_func->bufmgr_get_capabilities(bufmgr_data, &error);
-       if (bufmgr->capabilities == TBM_BUFMGR_CAPABILITY_NONE) {
+       module->bufmgr->capabilities = module->bufmgr->bufmgr_func->bufmgr_get_capabilities(bufmgr_data, &error);
+       if (module->bufmgr->capabilities == TBM_BUFMGR_CAPABILITY_NONE) {
                TBM_ERR("The capabilities of the backend module is TBM_BUFMGR_CAPABILITY_NONE.");
                TBM_ERR("TBM_BUFMGR_CAPABILITY_SHARE_FD is the essential capability.");
                goto err;
        }
 
-       if (!(bufmgr->capabilities & TBM_BUFMGR_CAPABILITY_SHARE_FD)) {
+       if (!(module->bufmgr->capabilities & TBM_BUFMGR_CAPABILITY_SHARE_FD)) {
                TBM_ERR("The capabilities of the backend module had no TBM_BUFMGR_CAPABILITY_SHARE_FD.");
                TBM_ERR("The tbm backend has to get TBM_BUFMGR_CAPABILITY_SHARE_FD. ");
                goto err;
        }
 
-       bufmgr->module_data = module_data;
-       bufmgr->backend_module_data = backend_module_data;
-       bufmgr->bufmgr_data = bufmgr_data;
+       module->module_data = module_data;
+       module->backend_module_data = backend_module_data;
+       module->bufmgr_data = bufmgr_data;
 
        TBM_INFO("Success to load module(%s)\n", file);
 
@@ -307,7 +342,7 @@ _tbm_backend_load_module(tbm_bufmgr bufmgr, const char *file)
 
 err:
        if (bufmgr_data)
-               bufmgr->backend_module_data->deinit(bufmgr_data);
+               module->backend_module_data->deinit(bufmgr_data);
        if (module_data)
                dlclose(module_data);
 
@@ -315,7 +350,7 @@ err:
 }
 
 static int
-_tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file)
+_tbm_backend_load_bufmgr_module(tbm_module *module, int fd, const char *file)
 {
        char path[PATH_MAX] = {0, };
        TBMModuleVersionInfo *vers;
@@ -354,17 +389,17 @@ _tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file)
                goto err;
        }
 
-       if (!init(bufmgr, fd)) {
+       if (!init((tbm_bufmgr)module, fd)) {
                TBM_ERR("Fail to init module(%s)\n", file);
                goto err;
        }
 
-       if (!bufmgr->backend || !bufmgr->backend->priv) {
+       if (!module->backend || !module->backend->priv) {
                TBM_ERR("Error: module(%s) wrong operation. Check backend or backend's priv.\n", file);
                goto err;
        }
 
-       bufmgr->module_data = module_data;
+       module->module_data = module_data;
 
        TBM_DBG("Success to load module(%s)\n", file);
 
@@ -392,21 +427,21 @@ tbm_module_load(tbm_bufmgr bufmgr, int fd)
        module->bufmgr = bufmgr;
 
        /* try to load the hal-tbm backend module */
-       ret = _tbm_backend_load_hal_tbm(bufmgr);
+       ret = _tbm_backend_load_hal_tbm(module);
        if (ret) {
                module->type = TBM_MODULE_TYPE_HAL_TBM;
-               return module;
+               goto done;
        }
 
        /* try to load the new backend module */
-       ret = _tbm_backend_load_module(bufmgr, DEFAULT_LIB);
+       ret = _tbm_backend_load_module(module, DEFAULT_LIB);
        if (ret) {
                module->type = TBM_MODULE_TYPE_TBM_BACKEND;
-               return module;
+               goto done;
        }
 
        /* try to load the old(deprecated) backend mdoule */
-       ret = _tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB);
+       ret = _tbm_backend_load_bufmgr_module(module, fd, DEFAULT_LIB);
        if (ret) {
                module->type = TBM_MODULE_TYPE_BUFMGR_BACKEND;
                return module;
@@ -416,7 +451,8 @@ tbm_module_load(tbm_bufmgr bufmgr, int fd)
        n = scandir(BUFMGR_MODULE_DIR, &namelist, 0, alphasort);
        if (n < 0) {
                TBM_ERR("no files : %s\n", BUFMGR_MODULE_DIR);
-               return 0;
+               tbm_module_unload(module);
+               return NULL;
        }
 
        while (n--) {
@@ -424,11 +460,11 @@ tbm_module_load(tbm_bufmgr bufmgr, int fd)
                        const char *p = strstr(namelist[n]->d_name, SUFFIX_LIB);
 
                        if (p && !strcmp(p, SUFFIX_LIB)) {
-                               ret = _tbm_backend_load_module(bufmgr, namelist[n]->d_name);
+                               ret = _tbm_backend_load_module(module, namelist[n]->d_name);
                                if (ret)
                                        module->type = TBM_MODULE_TYPE_TBM_BACKEND;
                                else {
-                                       ret = _tbm_bufmgr_load_module(bufmgr, fd, namelist[n]->d_name);
+                                       ret = _tbm_backend_load_bufmgr_module(module, fd, namelist[n]->d_name);
                                        module->type = TBM_MODULE_TYPE_BUFMGR_BACKEND;
                                }
                        }
@@ -444,45 +480,48 @@ tbm_module_load(tbm_bufmgr bufmgr, int fd)
                module = NULL;
        }
 
+done:
+       if (module)
+               _tbm_module_copy_data_to_bufmgr(module, module->bufmgr, 0);
+
        return module;
 }
 
 void
 tbm_module_unload(tbm_module *module)
 {
-       tbm_bufmgr bufmgr = module->bufmgr;
-
-       if (bufmgr->use_hal_tbm) {
-               if (bufmgr->auth_wl_socket_created) {
+       if (module->use_hal_tbm) {
+               if (module->auth_wl_socket_created) {
                        tbm_drm_helper_wl_auth_server_deinit();
-                       close(bufmgr->auth_fd);
-                       tbm_drm_helper_unset_tbm_master_fd();
+                       close(module->auth_fd);
                }
+               tbm_drm_helper_unset_tbm_master_fd();
                tbm_drm_helper_unset_fd();
 
-               hal_tbm_put_backend(bufmgr->hal_backend);
-               bufmgr->hal_backend = NULL;
-               bufmgr->hal_bufmgr = NULL;
-               bufmgr->use_hal_tbm = 0;
+               hal_tbm_put_backend(module->hal_backend);
+               module->hal_backend = NULL;
+               module->hal_bufmgr = NULL;
+               module->use_hal_tbm = 0;
        } else {
-               if (bufmgr->backend_module_data) {
-                       /* deinit and backend destroys the backend func and data */
-                       bufmgr->backend_module_data->deinit(bufmgr->bufmgr_data);
-                       bufmgr->bo_func = NULL;
-                       bufmgr->bufmgr_func = NULL;
-                       bufmgr->bufmgr_data = NULL;
-                       bufmgr->backend_module_data = NULL;
+               if (module->backend_module_data) {
+                       module->backend_module_data->deinit(module->bufmgr_data);
+                       module->bo_func = NULL;
+                       module->bufmgr_func = NULL;
+                       module->bufmgr_data = NULL;
+                       module->backend_module_data = NULL;
                } else {
-                       /* destroy bufmgr priv */
-                       bufmgr->backend->bufmgr_deinit(bufmgr->backend->priv);
-                       bufmgr->backend->priv = NULL;
-                       tbm_backend_free(bufmgr->backend);
-                       bufmgr->backend = NULL;
+                       module->backend->bufmgr_deinit(module->backend->priv);
+                       module->backend->priv = NULL;
+                       tbm_backend_free(module->backend);
+                       module->backend = NULL;
                }
 
-               dlclose(bufmgr->module_data);
+               dlclose(module->module_data);
        }
 
+       _tbm_module_copy_data_to_bufmgr(module, module->bufmgr, 1);
+       module->bufmgr = NULL;
+
        free(module);
 }