[NativeTBMSurface] Add _evas_native_tbm_init/shutdown 19/144619/2
authorWonsik, Jung <sidein@samsung.com>
Wed, 8 Mar 2017 01:27:55 +0000 (10:27 +0900)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Thu, 17 Aug 2017 08:40:19 +0000 (08:40 +0000)
Add _evas_native_tbm_inti/shutdown to evas_native_tbm.c
In addition, one more patch is added to fix stride mismatch
and allocate image data for converting from yuv to rgb.
This patchset are  oriented by JP's and Minkyung patch
---------------------------------------------------------------------------------
Author: Jean-Philippe Andre <jp.andre@samsung.com>  2016-03-09 16:18:34
Committer: Jean-Philippe Andre <jp.andre@samsung.com>  2016-03-15 11:11:59
    Evas engines: Add internal functions for native images
----------------------------------------------------------------------------------
Author: Minkyoung Kim <mer.kim@samsung.com>  2016-03-31 15:55:15
Committer: Jean-Philippe Andre <jp.andre@samsung.com>  2016-04-01 12:09:06
    evas : remove native.func.data variable and data argument of native calblacks.
-----------------------------------------------------------------------------------

Change-Id: Ic75402b307cb5548ba3ebe5e387c281b23d83307

src/modules/evas/engines/drm/evas_engine.c
src/modules/evas/engines/software_generic/evas_native_common.h
src/modules/evas/engines/software_generic/evas_native_tbm.c
src/modules/evas/engines/software_tbm/evas_engine.c
src/modules/evas/engines/software_x11/evas_engine.c
src/modules/evas/engines/wayland_shm/evas_engine.c

index a30a698..372cc0b 100644 (file)
@@ -18,8 +18,6 @@ struct _Render_Engine
    Render_Engine_Software_Generic generic;
 };
 
-Evas_Native_Tbm_Surface_Image_Set_Call  glsym_evas_native_tbm_surface_image_set = NULL;
-
 /* For wl_buffer's native set */
 static void *tbm_server_lib = NULL;
 typedef struct _tbm_surface * tbm_surface_h;
@@ -119,13 +117,6 @@ _symbols(void)
        fail = 1;                            \
      }
 
-   // Get function pointer to native_common that is now provided through the link of SW_Generic.
-   LINK2GENERIC(evas_native_tbm_surface_image_set);
-   if (fail == 1)
-     {
-       ERR("fail to dlsym about evas_native_tbm_surface_image_set symbol");
-       return;
-     }
    tbm_server_lib = dlopen(wayland_tbm_server_lib, RTLD_LOCAL | RTLD_LAZY);
    if (tbm_server_lib)
      {
@@ -167,6 +158,12 @@ eng_setup(Evas *evas, void *einfo)
         /* try to create a new render_engine */
         if (!(re = _output_setup(info, epd->output.w, epd->output.h)))
           return 0;
+
+        /* init tbm native surface lib */
+        if (re)
+          {
+             _evas_native_tbm_init();
+          }
      }
    else
      {
@@ -207,6 +204,9 @@ eng_output_free(void *data)
         free(re);
      }
 
+   /* shutdown tbm native surface lib */
+   _evas_native_tbm_shutdown();
+
    if (tbm_server_lib)
      {
        dlclose(tbm_server_lib);
@@ -235,8 +235,9 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
 {
    Evas_Native_Surface *ns = native;
    Image_Entry *ie = image;
-   RGBA_Image *im = image, *im2;
+   RGBA_Image *im = image, *im2 = NULL;
    void *wl_buf = NULL;
+   int stride = -1;
 
    if (!im || !ns) return im;
 
@@ -274,6 +275,14 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
                                  ie->w, ie->h,
                                  ns->data.x11.visual, 1,
                                  EVAS_COLORSPACE_ARGB8888);
+   else if (ns->type == EVAS_NATIVE_SURFACE_TBM)
+     {
+        stride = _evas_native_tbm_surface_stride_get(NULL, ns);
+        if (stride > -1)
+          im2 = (RGBA_Image *)evas_cache_image_copied_data(evas_common_image_cache_get(),
+                                                    stride, ie->h, NULL, ie->flags.alpha,
+                                                    EVAS_COLORSPACE_ARGB8888);
+     }
    else
      im2 = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(),
                                  ie->w, ie->h,
@@ -296,21 +305,18 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
 
    if (ns->type == EVAS_NATIVE_SURFACE_TBM)
      {
-        if (glsym_evas_native_tbm_surface_image_set)
-          return glsym_evas_native_tbm_surface_image_set(NULL, im, ns);
-        else
-          return NULL;
+        return _evas_native_tbm_surface_image_set(NULL, im, ns);
      }
    else if (ns->type == EVAS_NATIVE_SURFACE_WL)
      {
        // TODO  : need the code for all wl_buffer type
        // For TBM surface
-       if (glsym_wayland_tbm_server_get_surface && glsym_evas_native_tbm_surface_image_set)
+       if (glsym_wayland_tbm_server_get_surface)
          {
             tbm_surface_h _tbm_surface;
 
             _tbm_surface = glsym_wayland_tbm_server_get_surface(NULL,ns->data.wl.legacy_buffer);
-            return glsym_evas_native_tbm_surface_image_set(_tbm_surface, im, ns);
+            return _evas_native_tbm_surface_image_set(_tbm_surface, im, ns);
          }
        else
          {
index 24db735..c7819d7 100644 (file)
@@ -76,8 +76,9 @@ struct _Native
    } ns_data; /**< Choose one union data according to your surface in Evas Engine. */
 };
 
-EAPI void * evas_native_tbm_surface_image_set(void *data, void *image, void *native);
-
-typedef void *(*Evas_Native_Tbm_Surface_Image_Set_Call)(void *data, void *image, void *native);
+EAPI void *_evas_native_tbm_surface_image_set(void *data, void *image, void *native);
+EAPI int   _evas_native_tbm_init(void);
+EAPI void  _evas_native_tbm_shutdown(void);
+EAPI int   _evas_native_tbm_surface_stride_get(void *data, void *native);
 
 #endif //_EVAS_NATIVE_COMMON_H
index cca5e1d..d030fec 100644 (file)
@@ -69,14 +69,15 @@ static int (*sym_tbm_surface_map) (tbm_surface_h surface, int opt, tbm_surface_i
 static int (*sym_tbm_surface_unmap) (tbm_surface_h surface) = NULL;
 static void (*sym_tbm_surface_internal_unref) (tbm_surface_h surface) = NULL;
 static void (*sym_tbm_surface_internal_ref) (tbm_surface_h surface) = NULL;
+static int (*sym_tbm_surface_get_info) (tbm_surface_h surface, tbm_surface_info_s *info) = NULL;
 
-static Eina_Bool
-tbm_init(void)
+EAPI int
+_evas_native_tbm_init(void)
 {
    if (tbm_lib)
      {
         tbm_ref++;
-        return EINA_TRUE;
+        return tbm_ref;
      }
 
    const char *tbm_libs[] =
@@ -85,7 +86,6 @@ tbm_init(void)
       "libtbm.so.0",
       NULL,
    };
-
    int i, fail;
 #define SYM(lib, xx)                            \
   do {                                          \
@@ -104,6 +104,7 @@ tbm_init(void)
              fail = 0;
              SYM(tbm_lib, tbm_surface_map);
              SYM(tbm_lib, tbm_surface_unmap);
+             SYM(tbm_lib, tbm_surface_get_info);
              SYM(tbm_lib, tbm_surface_internal_unref);
              SYM(tbm_lib, tbm_surface_internal_ref);
              if (fail)
@@ -114,19 +115,18 @@ tbm_init(void)
              else break;
           }
      }
-   if (!tbm_lib) return EINA_FALSE;
+   if (!tbm_lib) return 0;
 
    tbm_ref++;
-   return EINA_TRUE;
+   return tbm_ref;
 }
 
-static void
-tbm_shutdown(void)
+EAPI void
+_evas_native_tbm_shutdown(void)
 {
    if (tbm_ref > 0)
      {
         tbm_ref--;
-
         if (tbm_ref == 0)
           {
              if (tbm_lib)
@@ -177,18 +177,18 @@ _evas_video_i420(unsigned char *evas_data, const unsigned char *source_data, uns
 
    rows = (const unsigned char **)evas_data;
 
-   stride_y = EVAS_ROUND_UP_4(w);
-   stride_uv = EVAS_ROUND_UP_8(w) / 2;
+   stride_y = w;
+   stride_uv = w / 2;
 
    for (i = 0; i < rh; i++)
      rows[i] = &source_data[i * stride_y];
 
-   for (j = 0; j < (rh / 2); j++, i++)
+   for (j = 0; j < ((rh + 1) / 2); j++, i++)
      rows[i] = &source_data[h * stride_y + j * stride_uv];
 
    for (j = 0; j < (rh / 2); j++, i++)
      rows[i] = &source_data[h * stride_y +
-                            (rh / 2) * stride_uv +
+                            ((rh + 1) / 2) * stride_uv +
                             j * stride_uv];
 }
 
@@ -232,8 +232,6 @@ _native_bind_cb(void *data EINA_UNUSED, void *image, int x EINA_UNUSED, int y EI
         ERR("Fail to tbm_surface_map()");
         return;
      }
-
-   im->image.data = (DATA32 *)info.planes[0].ptr;
 }
 
 static void
@@ -251,7 +249,7 @@ _native_unbind_cb(void *data EINA_UNUSED, void *image)
    else if (n->ns.type == EVAS_NATIVE_SURFACE_WL)
      tbm_surf = n->ns_data.wl_surface.tbm_surface;
    else
-      return;
+     return;
 
    if (sym_tbm_surface_unmap(tbm_surf))
      {
@@ -278,7 +276,7 @@ _native_free_cb(void *data EINA_UNUSED, void *image)
      tbm_surf = NULL;
 
    if (tbm_surf)
-      sym_tbm_surface_internal_unref(tbm_surf);
+     sym_tbm_surface_internal_unref(tbm_surf);
 
    im->native.data        = NULL;
    im->native.func.bind   = NULL;
@@ -287,11 +285,30 @@ _native_free_cb(void *data EINA_UNUSED, void *image)
    im->native.func.data   = NULL;
    free(n);
 
-   tbm_shutdown();
+   /*
+   _evas_native_tbm_shutdown();
+   */
 }
 
+EAPI int
+_evas_native_tbm_surface_stride_get(void *data EINA_UNUSED, void *native)
+{
+   Evas_Native_Surface *ns = native;
+   tbm_surface_info_s info;
+   int stride;
+
+   if (!ns)
+     return -1;
+
+   if (sym_tbm_surface_get_info(ns->data.tbm.buffer, &info))
+     return -1;
+
+   stride = info.planes[0].stride;
+   return stride;
+ }
+
 EAPI void *
-evas_native_tbm_surface_image_set(void *data, void *image, void *native)
+_evas_native_tbm_surface_image_set(void *data, void *image, void *native)
 {
    Evas_Native_Surface *ns = native;
    RGBA_Image *im = image;
@@ -316,11 +333,13 @@ evas_native_tbm_surface_image_set(void *data, void *image, void *native)
 
         if (!tbm_surf) return NULL;
 
-        if (!tbm_init())
+        /*
+        if (!_evas_native_tbm_init())
           {
              ERR("Could not initialize TBM!");
              return NULL;
           }
+        */
 
         n = calloc(1, sizeof(Native));
         if (!n) return NULL;
@@ -363,17 +382,17 @@ evas_native_tbm_surface_image_set(void *data, void *image, void *native)
               /* borrowing code from emotion here */
            case TBM_FORMAT_YVU420: /* EVAS_COLORSPACE_YCBCR422P601_PL */
               evas_cache_image_colorspace(&im->cache_entry, EVAS_COLORSPACE_YCBCR422P601_PL);
-              _evas_video_yv12(im->cs.data, pixels_data, w, h, h);
+              _evas_video_yv12(im->cs.data, pixels_data, stride, h, h);
               evas_common_image_colorspace_dirty(im);
               break;
            case TBM_FORMAT_YUV420: /* EVAS_COLORSPACE_YCBCR422P601_PL */
               evas_cache_image_colorspace(&im->cache_entry, EVAS_COLORSPACE_YCBCR422P601_PL);
-              _evas_video_i420(im->cs.data, pixels_data, w, h, h);
+              _evas_video_i420(im->cs.data, pixels_data, stride, h, h);
               evas_common_image_colorspace_dirty(im);
               break;
            case TBM_FORMAT_NV12: /* EVAS_COLORSPACE_YCBCR420NV12601_PL */
               evas_cache_image_colorspace(&im->cache_entry, EVAS_COLORSPACE_YCBCR420NV12601_PL);
-              _evas_video_nv12(im->cs.data, pixels_data, w, h, h);
+              _evas_video_nv12(im->cs.data, pixels_data, stride, h, h);
               evas_common_image_colorspace_dirty(im);
               break;
               /* Not planning to handle those in software */
index 3251a3a..580db1f 100644 (file)
@@ -156,9 +156,14 @@ eng_setup(Evas *eo_evas, void *info)
         re = _render_engine_ouput_setup(einfo, epd->output.w, epd->output.h);
 
         if (re)
-          re->generic.ob->info = einfo;
+          {
+             re->generic.ob->info = einfo;
+             /* init tbm native surface lib */
+             _evas_native_tbm_init();
+          }
         else
           goto err;
+
      }
    else
      {
@@ -207,6 +212,9 @@ eng_output_free(void *data)
         free(re);
      }
 
+   /* shutdown tbm native surface lib */
+   _evas_native_tbm_shutdown();
+
    if (tbm_server_lib)
      {
        dlclose(tbm_server_lib);
@@ -222,6 +230,7 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
    Evas_Native_Surface *ns = native;
    Image_Entry *ie = image;
    RGBA_Image *im = image, *im2 = NULL;
+   int stride = -1;
 
    if (!im) return im;
 
@@ -256,6 +265,22 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
                                                  EVAS_COLORSPACE_ARGB8888);
      }
 
+   if (ns->type == EVAS_NATIVE_SURFACE_TBM)
+     {
+        stride = _evas_native_tbm_surface_stride_get(NULL, ns);
+        if (stride > -1)
+          im2 = (RGBA_Image *)evas_cache_image_copied_data(evas_common_image_cache_get(),
+                                                    stride, ie->h, NULL, ie->flags.alpha,
+                                                    EVAS_COLORSPACE_ARGB8888);
+     }
+   else
+     {
+        im2 = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(),
+                                 ie->w, ie->h,
+                                 NULL, 1,
+                                 EVAS_COLORSPACE_ARGB8888);
+     }
+
    if (im->native.data)
       {
          if (im->native.func.free)
@@ -275,7 +300,7 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
 
    if (ns->type == EVAS_NATIVE_SURFACE_TBM)
      {
-          return evas_native_tbm_surface_image_set(NULL, im, ns);
+          return _evas_native_tbm_surface_image_set(NULL, im, ns);
      }
    else if (ns->type == EVAS_NATIVE_SURFACE_WL)
      {
@@ -290,7 +315,7 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
 
             tbm_surface_get_info(_tbm_surface, &info);
 
-            return evas_native_tbm_surface_image_set(_tbm_surface, im, ns);
+            return _evas_native_tbm_surface_image_set(_tbm_surface, im, ns);
          }
        else
          {
index 70ba970..1960b77 100644 (file)
@@ -32,7 +32,6 @@
 # include <dlfcn.h>
 #endif
 
-Evas_Native_Tbm_Surface_Image_Set_Call  glsym_evas_native_tbm_surface_image_set = NULL;
 int _evas_engine_soft_x11_log_dom = -1;
 
 /* function tables - filled in later (func and parent func) */
@@ -431,9 +430,6 @@ _symbols(void)
 #define LINK2GENERIC(sym) \
    glsym_##sym = dlsym(RTLD_DEFAULT, #sym);
 
-   // Get function pointer to native_common that is now provided through the link of SW_Generic.
-   LINK2GENERIC(evas_native_tbm_surface_image_set);
-
    done = 1;
 }
 
@@ -538,6 +534,11 @@ eng_setup(Evas *eo_e, void *in)
 #endif
 
         e->engine.data.output = re;
+        /* init tbm native surface lib */
+        if (re)
+          {
+             _evas_native_tbm_init();
+          }
      }
    else
      {
@@ -618,6 +619,7 @@ eng_setup(Evas *eo_e, void *in)
         /* if ((re) && (re->ob)) re->ob->onebuf = ponebuf; */
      }
    if (!e->engine.data.output) return 0;
+
    if (!e->engine.data.context)
      {
         e->engine.data.context =
@@ -643,6 +645,9 @@ eng_output_free(void *data)
         free(re);
      }
 
+   /* shutdown tbm native surface lib */
+   _evas_native_tbm_shutdown();
+
    evas_common_shutdown();
 }
 
@@ -678,6 +683,7 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
    Evas_Native_Surface *ns = native;
    Image_Entry *ie = image, *ie2 = NULL;
    RGBA_Image *im = image;
+   int stride = -1;
 
    if (!im) return NULL;
    if (!ns)
@@ -719,6 +725,14 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
      ie2 = evas_cache_image_data(evas_common_image_cache_get(),
                                  ie->w, ie->h, ns->data.evasgl.surface, 1,
                                  EVAS_COLORSPACE_ARGB8888);
+   else if (ns->type == EVAS_NATIVE_SURFACE_TBM)
+     {
+        stride = _evas_native_tbm_surface_stride_get(NULL, ns);
+        if (stride > -1)
+          ie2 = (RGBA_Image *)evas_cache_image_copied_data(evas_common_image_cache_get(),
+                                                    stride, ie->h, NULL, ie->flags.alpha,
+                                                    EVAS_COLORSPACE_ARGB8888);
+     }
    else
      ie2 = evas_cache_image_data(evas_common_image_cache_get(),
                                  ie->w, ie->h, NULL, ie->flags.alpha,
@@ -753,7 +767,7 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
      }
    else if (ns->type == EVAS_NATIVE_SURFACE_TBM)
      {
-        return glsym_evas_native_tbm_surface_image_set(re->generic.ob, ie, ns);
+        return evas_native_tbm_surface_image_set(re->generic.ob, ie, ns);
      }
    else if (ns->type == EVAS_NATIVE_SURFACE_EVASGL)
      {
index da4eb24..9cb2196 100644 (file)
@@ -17,8 +17,6 @@ int _evas_engine_way_shm_log_dom = -1;
 /* evas function tables - filled in later (func and parent func) */
 static Evas_Func func, pfunc;
 
-Evas_Native_Tbm_Surface_Image_Set_Call  glsym_evas_native_tbm_surface_image_set = NULL;
-
 /* For wl_buffer's native set */
 static void *tbm_server_lib = NULL;
 typedef struct _tbm_surface * tbm_surface_h;
@@ -105,13 +103,6 @@ _symbols(void)
         fail = 1;                             \
      }
 
-   // Get function pointer to native_common that is now provided through the link of SW_Generic.
-   LINK2GENERIC(RTLD_DEFAULT, evas_native_tbm_surface_image_set);
-   if (fail == 1)
-     {
-        ERR("fail to dlsym about evas_native_tbm_surface_image_set symbol");
-        return;
-     }
    tbm_server_lib = dlopen(wayland_tbm_server_lib, RTLD_LOCAL | RTLD_LAZY);
    if (tbm_server_lib)
      {
@@ -188,7 +179,11 @@ eng_setup(Evas *eo_evas, void *info)
         re = _render_engine_swapbuf_setup(epd->output.w, epd->output.h, einfo);
 
         if (re)
-          re->generic.ob->info = einfo;
+          {
+             re->generic.ob->info = einfo;
+             /* init tbm native surface lib */
+             _evas_native_tbm_init();
+          }
         else
           goto err;
      }
@@ -238,6 +233,9 @@ eng_output_free(void *data)
         free(re);
      }
 
+   /* shutdown tbm native surface lib */
+   _evas_native_tbm_shutdown();
+
    if (tbm_server_lib)
      {
        dlclose(tbm_server_lib);
@@ -298,6 +296,7 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
    RGBA_Image *im = image;
    RGBA_Image *im2 = NULL;
    void *wl_buf = NULL;
+   int stride = -1;
 
    if (!im) return im;
 
@@ -334,6 +333,14 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
                                       ie->w, ie->h,
                                       ns->data.x11.visual, 1,
                                       EVAS_COLORSPACE_ARGB8888);
+        else if (ns->type == EVAS_NATIVE_SURFACE_TBM)
+          {
+             stride = _evas_native_tbm_surface_stride_get(NULL, ns);
+             if (stride > -1)
+               im2 = (RGBA_Image *)evas_cache_image_copied_data(evas_common_image_cache_get(),
+                                                         stride, ie->h, NULL, ie->flags.alpha,
+                                                         EVAS_COLORSPACE_ARGB8888);
+          }
         else
           im2 = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(),
                                       ie->w, ie->h,
@@ -359,21 +366,18 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
 
    if (ns->type == EVAS_NATIVE_SURFACE_TBM)
      {
-        if (glsym_evas_native_tbm_surface_image_set)
-          return glsym_evas_native_tbm_surface_image_set(NULL, im, ns);
-        else
-          return NULL;
+        return _evas_native_tbm_surface_image_set(NULL, im, ns);
      }
    else if (ns->type == EVAS_NATIVE_SURFACE_WL)
      {
        // TODO  : need the code for all wl_buffer type
        // First of all, for TBM surface
-       if (glsym_wayland_tbm_server_get_surface && glsym_evas_native_tbm_surface_image_set)
+       if (glsym_wayland_tbm_server_get_surface)
          {
             tbm_surface_h _tbm_surface;
 
             _tbm_surface = glsym_wayland_tbm_server_get_surface(NULL,ns->data.wl.legacy_buffer);
-            return glsym_evas_native_tbm_surface_image_set(_tbm_surface, im, ns);
+            return _evas_native_tbm_surface_image_set(_tbm_surface, im, ns);
          }
        else
          {