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
Image_Entry *ie = image;
RGBA_Image *im = image, *im2 = NULL;
void *wl_buf = NULL;
- int stride = -1;
if (!im || !ns) return im;
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(),
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
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)
Evas_Native_Surface *ns = native;
Image_Entry *ie = image;
RGBA_Image *im = image, *im2 = NULL;
- int stride = -1;
if (!im) return im;
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
{
Evas_Native_Surface *ns = native;
Image_Entry *ie = image, *ie2 = NULL;
RGBA_Image *im = image;
- int stride = -1;
if (!im) return NULL;
if (!ns)
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(),
RGBA_Image *im = image;
RGBA_Image *im2 = NULL;
void *wl_buf = NULL;
- int stride = -1;
if (!im) return im;
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(),