Export ds_tizen_pixel_format_convert_tbm_to_drm
[platform/core/uifw/libds-tizen.git] / src / shared / pixel_format.c
1 #include <inttypes.h>
2 #include <drm_fourcc.h>
3 #include <tbm_type.h>
4
5 #include <wayland-util.h>
6 #include <libds/log.h>
7 #include "pixel_format.h"
8
9 #ifdef ARRAY_LENGTH
10 #undef ARRAY_LENGTH
11 #endif
12
13 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
14
15 struct ds_tbm_format
16 {
17     uint32_t drm_format;
18     uint32_t tbm_format;
19 };
20
21 static const struct ds_tbm_format formats[] =
22 {
23     {
24         .drm_format = DRM_FORMAT_ARGB8888,
25         .tbm_format = TBM_FORMAT_ARGB8888,
26     },
27     {
28         .drm_format = DRM_FORMAT_XRGB8888,
29         .tbm_format = TBM_FORMAT_XRGB8888,
30     },
31     /* TODO more format */
32 };
33
34 uint32_t
35 convert_drm_format_to_tbm(uint32_t fmt)
36 {
37     size_t i;
38
39     for (i = 0; i < ARRAY_LENGTH(formats); i++) {
40         if (formats[i].drm_format == fmt)
41             return formats[i].tbm_format;
42     }
43
44     ds_err("DRM format 0x%"PRIX32" has no TBM equivalent", fmt);
45
46     return 0;
47 }
48
49 uint32_t
50 convert_tbm_format_to_drm(uint32_t fmt)
51 {
52     size_t i;
53
54     for (i = 0; i < ARRAY_LENGTH(formats); i++) {
55         if (formats[i].tbm_format == fmt)
56             return formats[i].drm_format;
57     }
58
59     ds_err("TBM format 0x%"PRIX32" has no DRM equivalent", fmt);
60
61     return 0;
62 }
63
64 WL_EXPORT uint32_t
65 ds_tizen_pixel_format_convert_tbm_to_drm(uint32_t tbm_format)
66 {
67     return convert_tbm_format_to_drm(tbm_format);
68 }