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