package version up to 2.4.3
[platform/adaptation/spreadtrum/libtbm-sprd.git] / src / tbm_bufmgr_sprd.c
index f105c2d..46e278e 100644 (file)
@@ -956,7 +956,7 @@ tbm_sprd_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data,
 //             else if (plane_idx == 1)
                {
                        _offset = _size;
-                       _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2);
+                       _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV);
                        _align_height = SIZE_ALIGN(height / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
                        _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE);
                        _bo_idx = 0;
@@ -978,7 +978,7 @@ tbm_sprd_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data,
                //else if( plane_idx ==1 )
                {
                        _offset += _size;
-                       _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2);
+                       _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
                        _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
                        _bo_idx = 0;
                }
@@ -1778,6 +1778,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error)
        tbm_backend_bo_func *bo_func = NULL;
        int fp;
        tbm_error_e err;
+       int set_master = 0;
 
        if (!bufmgr) {
                TBM_ERR("bufmgr is null.\n");
@@ -1794,20 +1795,45 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error)
                return NULL;
        }
 
-       if (tbm_backend_bufmgr_query_display_server(bufmgr, &err)) {
-               bufmgr_sprd->fd = tbm_drm_helper_get_master_fd();
+       /* check the master_fd which already had opened */
+       bufmgr_sprd->fd = tbm_drm_helper_get_master_fd();
+       if (bufmgr_sprd->fd < 0) {
+               bufmgr_sprd->fd = _tbm_sprd_open_drm();
                if (bufmgr_sprd->fd < 0) {
-                       bufmgr_sprd->fd = _tbm_sprd_open_drm();
-                       if (bufmgr_sprd->fd < 0) {
-                               TBM_ERR("fail to open drm!\n");
+                       TBM_ERR("fail to open drm!\n");
+                       if (error)
+                               *error = TBM_ERROR_INVALID_OPERATION;
+                       goto fail_open_drm;
+               }
+
+               if (drmIsMaster(bufmgr_sprd->fd)) {
+                       tbm_drm_helper_set_tbm_master_fd(bufmgr_sprd->fd);
+                       set_master = 1;
+
+                       bufmgr_sprd->device_name = drmGetDeviceNameFromFd(bufmgr_sprd->fd);
+                       if (!bufmgr_sprd->device_name) {
+                               TBM_ERR("fail to get device name!\n");
+                               tbm_drm_helper_unset_tbm_master_fd();
+                               if (error)
+                                       *error = TBM_ERROR_INVALID_OPERATION;
+                               goto fail_get_device_name;
+                       }
+                       TBM_INFO("This is Master FD(%d) from open_drm.", bufmgr_sprd->fd);
+               } else {
+                       /* close the fd and get the authenticated fd from the master fd */
+                       close(bufmgr_sprd->fd);
+                       bufmgr_sprd->fd = -1;
+
+                       /* get the authenticated drm fd from the master fd */
+                       if (!tbm_drm_helper_get_auth_info(&(bufmgr_sprd->fd), &(bufmgr_sprd->device_name), NULL)) {
+                               TBM_ERR("fail to get auth drm info!\n");
                                if (error)
                                        *error = TBM_ERROR_INVALID_OPERATION;
-                               goto fail_open_drm;
+                               goto fail_get_auth_info;
                        }
+                       TBM_INFO("This is Authenticated FD(%d)", bufmgr_sprd->fd);
                }
-
-               tbm_drm_helper_set_tbm_master_fd(bufmgr_sprd->fd);
-
+       } else {
                bufmgr_sprd->device_name = drmGetDeviceNameFromFd(bufmgr_sprd->fd);
                if (!bufmgr_sprd->device_name) {
                        TBM_ERR("fail to get device name!\n");
@@ -1816,14 +1842,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error)
                                *error = TBM_ERROR_INVALID_OPERATION;
                        goto fail_get_device_name;
                }
-       } else {
-               if (!tbm_drm_helper_get_auth_info(&(bufmgr_sprd->fd), &(bufmgr_sprd->device_name), NULL)) {
-                       TBM_ERR("fail to get auth drm info!\n");
-                       if (error)
-                               *error = TBM_ERROR_INVALID_OPERATION;
-                       goto fail_get_auth_info;
-               }
-
+               TBM_INFO("This is Master FD from tbm_drm_helper_get_master_fd(%d)", bufmgr_sprd->fd);
        }
        tbm_drm_helper_set_fd(bufmgr_sprd->fd);
 
@@ -1926,7 +1945,7 @@ fail_alloc_bufmgr_func:
        if (bufmgr_sprd->hashBos)
                drmHashDestroy(bufmgr_sprd->hashBos);
 fail_init_cache_state:
-       if (tbm_backend_bufmgr_query_display_server(bufmgr, &err))
+       if (set_master)
                tbm_drm_helper_unset_tbm_master_fd();
        tbm_drm_helper_unset_fd();
        if (bufmgr_sprd->device_name)
@@ -1942,7 +1961,7 @@ fail_open_drm:
 tbm_backend_module tbm_backend_module_data = {
        "sprd",
        "Samsung",
-       TBM_BACKEND_ABI_VERSION_2_0,
+       TBM_BACKEND_ABI_VERSION_3_0,
        tbm_sprd_init,
        tbm_sprd_deinit
 };