[NativeTBMSurface] Seperated by colorspace. 20/144620/2
authorWonsik, Jung <sidein@samsung.com>
Wed, 8 Mar 2017 05:18:36 +0000 (14:18 +0900)
committerjoogab yun <joogab.yun@samsung.com>
Thu, 17 Aug 2017 08:41:17 +0000 (08:41 +0000)
To create RGBA_Image for NativeTBMSurface, the related code is seperated by tbm format.
So, Getting format internal function is added and seperated the code.

Change-Id: I8f3d5c07fa1b0e5b6dc722ab0e083267cacc2bd4

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 372cc0b..87bf1d1 100644 (file)
@@ -237,7 +237,6 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
    Image_Entry *ie = image;
    RGBA_Image *im = image, *im2 = NULL;
    void *wl_buf = NULL;
-   int stride = -1;
 
    if (!im || !ns) return im;
 
@@ -277,11 +276,41 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
                                  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);
+        Evas_Colorspace cs = _evas_native_tbm_surface_colorspace_get(NULL, ns);
+        if (cs == EVAS_COLORSPACE_ARGB8888)
+          {
+             im2 = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(),
+                                                       ie->w, ie->h, NULL, ie->flags.alpha,
+                                                       EVAS_COLORSPACE_ARGB8888);
+          }
+        else
+          {
+            int stride = _evas_native_tbm_surface_stride_get(NULL, ns);
+            if (stride > -1)
+              {
+                 /**
+                  * To support various color format in Native TBM Surface,
+                  * Cache Image should have both im->image.data and cs.data memory.
+                  * In default, evas_cache_image_copied_data is callled with his colorspace.
+                  * In the case, cs.data is allocated and free, then re-allocated.
+                  * To optimize, we have two options.
+                  * One of them, evas_cache_image_copied_data is called with EVAS_COLORSPACE_ARGB8888
+                  * The other option, evas_cache_image_data is called with his colorspace
+                  * and evas_cache_image_surface_alloc should be called.
+                  * Then, new Cache Image's cs should be set with EVAS_COLORSPACE_ARGB8888.
+                  * Because of allocation cs.data in _evas_native_tbm_surface_image_set()
+                  * In current, first option is used.
+                  **/
+                 im2 = (RGBA_Image *)evas_cache_image_copied_data(evas_common_image_cache_get(),
+                                                                 stride, ie->h, NULL, ie->flags.alpha,
+                                                                 EVAS_COLORSPACE_ARGB8888);
+             }
+            else
+              {
+                 ERR("Fail to get stride");
+                 return im;
+              }
+          }
      }
    else
      im2 = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(),
index c7819d7..fd7851e 100644 (file)
@@ -80,5 +80,6 @@ EAPI void *_evas_native_tbm_surface_image_set(void *data, void *image, void *nat
 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);
+EAPI Evas_Colorspace   _evas_native_tbm_surface_colorspace_get(void *data EINA_UNUSED, void *native);
 
 #endif //_EVAS_NATIVE_COMMON_H
index d030fec..074007b 100644 (file)
@@ -305,7 +305,53 @@ _evas_native_tbm_surface_stride_get(void *data EINA_UNUSED, void *native)
 
    stride = info.planes[0].stride;
    return stride;
- }
+}
+
+EAPI Evas_Colorspace
+_evas_native_tbm_surface_colorspace_get(void *data EINA_UNUSED, void *native)
+{
+   Evas_Native_Surface *ns = native;
+   tbm_surface_info_s info;
+   tbm_format format;
+   Evas_Colorspace cs;
+
+   if (!ns)
+     return -1;
+
+   if (sym_tbm_surface_get_info(ns->data.tbm.buffer, &info))
+     return -1;
+
+   format = info.format;
+
+   // Handle all possible format here :"(
+   switch (format)
+     {
+      case TBM_FORMAT_RGBA8888:
+      case TBM_FORMAT_RGBX8888:
+      case TBM_FORMAT_BGRA8888:
+      case TBM_FORMAT_ARGB8888:
+      case TBM_FORMAT_ABGR8888:
+      case TBM_FORMAT_XRGB8888:
+         cs = EVAS_COLORSPACE_ARGB8888;
+         break;
+         /* borrowing code from emotion here */
+      case TBM_FORMAT_YVU420: /* EVAS_COLORSPACE_YCBCR422P601_PL */
+         cs = EVAS_COLORSPACE_YCBCR422P601_PL;
+         break;
+      case TBM_FORMAT_YUV420: /* EVAS_COLORSPACE_YCBCR422P601_PL */
+         cs = EVAS_COLORSPACE_YCBCR422P601_PL;
+         break;
+      case TBM_FORMAT_NV12: /* EVAS_COLORSPACE_YCBCR420NV12601_PL */
+         cs = EVAS_COLORSPACE_YCBCR420NV12601_PL;
+         break;
+      default:
+         ERR("not supported format");
+         cs = EVAS_COLORSPACE_ARGB8888;
+         break;
+     }
+
+   return cs;
+}
 
 EAPI void *
 _evas_native_tbm_surface_image_set(void *data, void *image, void *native)
index 580db1f..489a514 100644 (file)
@@ -230,7 +230,6 @@ 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;
 
@@ -267,11 +266,41 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
 
    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);
+       Evas_Colorspace cs = _evas_native_tbm_surface_colorspace_get(NULL, ns);
+       if (cs == EVAS_COLORSPACE_ARGB8888)
+         {
+            im2 = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(),
+                                                      ie->w, ie->h, NULL, ie->flags.alpha,
+                                                      EVAS_COLORSPACE_ARGB8888);
+         }
+       else
+         {
+           int stride = _evas_native_tbm_surface_stride_get(NULL, ns);
+           if (stride > -1)
+             {
+                /**
+                 * To support various color format in Native TBM Surface,
+                 * Cache Image should have both im->image.data and cs.data memory.
+                 * In default, evas_cache_image_copied_data is callled with his colorspace.
+                 * In the case, cs.data is allocated and free, then re-allocated.
+                 * To optimize, we have two options.
+                 * One of them, evas_cache_image_copied_data is called with EVAS_COLORSPACE_ARGB8888
+                 * The other option, evas_cache_image_data is called with his colorspace
+                 * and evas_cache_image_surface_alloc should be called.
+                 * Then, new Cache Image's cs should be set with EVAS_COLORSPACE_ARGB8888.
+                 * Because of allocation cs.data in _evas_native_tbm_surface_image_set()
+                 * In current, first option is used.
+                 **/
+                im2 = (RGBA_Image *)evas_cache_image_copied_data(evas_common_image_cache_get(),
+                                                                stride, ie->h, NULL, ie->flags.alpha,
+                                                                EVAS_COLORSPACE_ARGB8888);
+            }
+           else
+             {
+                ERR("Fail to get stride");
+                return im;
+             }
+         }
      }
    else
      {
index 1960b77..345af3e 100644 (file)
@@ -683,7 +683,6 @@ 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)
@@ -727,11 +726,41 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
                                  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);
+       Evas_Colorspace cs = _evas_native_tbm_surface_colorspace_get(NULL, ns);
+       if (cs == EVAS_COLORSPACE_ARGB8888)
+         {
+            ie2 = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(),
+                                                      ie->w, ie->h, NULL, ie->flags.alpha,
+                                                      EVAS_COLORSPACE_ARGB8888);
+         }
+       else
+         {
+           int stride = _evas_native_tbm_surface_stride_get(NULL, ns);
+           if (stride > -1)
+             {
+                /**
+                 * To support various color format in Native TBM Surface,
+                 * Cache Image should have both im->image.data and cs.data memory.
+                 * In default, evas_cache_image_copied_data is callled with his colorspace.
+                 * In the case, cs.data is allocated and free, then re-allocated.
+                 * To optimize, we have two options.
+                 * One of them, evas_cache_image_copied_data is called with EVAS_COLORSPACE_ARGB8888
+                 * The other option, evas_cache_image_data is called with his colorspace
+                 * and evas_cache_image_surface_alloc should be called.
+                 * Then, new Cache Image's cs should be set with EVAS_COLORSPACE_ARGB8888.
+                 * Because of allocation cs.data in _evas_native_tbm_surface_image_set()
+                 * In current, first option is used.
+                 **/
+                ie2 = (RGBA_Image *)evas_cache_image_copied_data(evas_common_image_cache_get(),
+                                                                stride, ie->h, NULL, ie->flags.alpha,
+                                                                EVAS_COLORSPACE_ARGB8888);
+            }
+           else
+             {
+                ERR("Fail to get stride");
+                return im;
+             }
+         }
      }
    else
      ie2 = evas_cache_image_data(evas_common_image_cache_get(),
index 9cb2196..eea31e7 100644 (file)
@@ -296,7 +296,6 @@ 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;
 
@@ -335,11 +334,41 @@ eng_image_native_set(void *data EINA_UNUSED, void *image, void *native)
                                       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);
+             Evas_Colorspace cs = _evas_native_tbm_surface_colorspace_get(NULL, ns);
+             if (cs == EVAS_COLORSPACE_ARGB8888)
+               {
+                  im2 = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(),
+                                                            ie->w, ie->h, NULL, ie->flags.alpha,
+                                                            EVAS_COLORSPACE_ARGB8888);
+               }
+             else
+               {
+                  int stride = _evas_native_tbm_surface_stride_get(NULL, ns);
+                  if (stride > -1)
+                    {
+                       /**
+                        * To support various color format in Native TBM Surface,
+                        * Cache Image should have both im->image.data and cs.data memory.
+                        * In default, evas_cache_image_copied_data is callled with his colorspace.
+                        * In the case, cs.data is allocated and free, then re-allocated.
+                        * To optimize, we have two options.
+                        * One of them, evas_cache_image_copied_data is called with EVAS_COLORSPACE_ARGB8888
+                        * The other option, evas_cache_image_data is called with his colorspace
+                        * and evas_cache_image_surface_alloc should be called.
+                        * Then, new Cache Image's cs should be set with EVAS_COLORSPACE_ARGB8888.
+                        * Because of allocation cs.data in _evas_native_tbm_surface_image_set()
+                        * In current, first option is used.
+                        **/
+                       im2 = (RGBA_Image *)evas_cache_image_copied_data(evas_common_image_cache_get(),
+                                                                       stride, ie->h, NULL, ie->flags.alpha,
+                                                                       EVAS_COLORSPACE_ARGB8888);
+                   }
+                  else
+                    {
+                       ERR("Fail to get stride");
+                       return im;
+                    }
+               }
           }
         else
           im2 = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(),