Remove unused int64, int32 hash key for fixing Svace warning
[platform/core/uifw/libtpl-egl.git] / src / tpl_utils.h
1 #ifndef TPL_UTILS_H
2 #define TPL_UTILS_H
3
4 #include "tpl.h"
5 #include <stdlib.h>
6 #include <assert.h>
7 #include <pthread.h>
8 #include <string.h>
9 #include <unistd.h>
10
11 #if defined(__GNUC__) && __GNUC__ >= 4
12 #   define TPL_API __attribute__ ((visibility("default")))
13 #else
14 #   define TPL_API
15 #endif
16 #define TPL_ASSERT(expr) assert(expr)
17 #define TPL_INLINE __inline__
18 #define TPL_IGNORE(x) (void)x
19
20 #ifdef ARM_ATOMIC_OPERATION
21 #define TPL_DMB() __asm__ volatile("dmb sy" : : : "memory")
22 #else /* ARM_ATOMIC_OPERATION */
23 #define TPL_DMB() __asm__ volatile("" : : : "memory")
24 #endif /* ARM_ATOMIC_OPERATION */
25
26 #if (TTRACE_ENABLE)
27 #include <ttrace.h>
28 #define TRACE_BEGIN(name,...) traceBegin(TTRACE_TAG_GRAPHICS, name, ##__VA_ARGS__)
29 #define TRACE_END() traceEnd(TTRACE_TAG_GRAPHICS)
30 #define TRACE_ASYNC_BEGIN(key, name,...) traceAsyncBegin(TTRACE_TAG_GRAPHICS, key, name, ##__VA_ARGS__)
31 #define TRACE_ASYNC_END(key, name,...) traceAsyncEnd(TTRACE_TAG_GRAPHICS, key, name, ##__VA_ARGS__)
32 #define TRACE_COUNTER(value, name,...) traceCounter(TTRACE_TAG_GRAPHICS, value, name, ##__VA_ARGS__)
33 #define TRACE_MARK(name,...) traceMark(TTRACE_TAG_GRAPHICS, name, ##__VA_ARGS__)
34 #else /* TTRACE_ENABLE */
35 #define TRACE_BEGIN(name,...)
36 #define TRACE_END()
37 #define TRACE_ASYNC_BEGIN(key, name,...)
38 #define TRACE_ASYNC_END(key, name,...)
39 #define TRACE_COUNTER(value, name,...)
40 #define TRACE_MARK(name,...)
41 #endif /* TTRACE_ENABLE */
42
43 #ifndef NDEBUG
44 #include <stdio.h>
45 #include <unistd.h>
46 #include <sys/syscall.h>
47 #include <sys/types.h>
48 #include <sys/stat.h>
49 #include <signal.h>
50
51 #include <tbm_surface.h>
52 #include <tbm_surface_internal.h>
53
54 /* 0:uninitialized, 1:initialized,no log, 2:user log */
55 extern unsigned int tpl_log_lvl;
56 extern unsigned int tpl_log_initialized;
57 extern unsigned int tpl_getenv_enabled;
58 extern unsigned int tpl_dump_lvl;
59
60 inline char *tpl_getenv(const char *name)
61 {
62         if (tpl_getenv_enabled)
63                 return getenv(name);
64         else
65                 return NULL;
66 }
67
68
69 #define FONT_DEFAULT    "\033[0m"       /* for reset to default color */
70 #define FONT_RED                "\033[31m"      /* for error logs */
71 #define FONT_YELLOW             "\033[33m"      /* for warning logs */
72 #define FONT_GREEN              "\033[32m"      /* for frontend API logs */
73 #define FONT_BLUE               "\033[34m"      /* for backend logs */
74 #define FONT_MAGENTA    "\033[35m"      /* for debug logs */
75 #define FONT_CYAN               "\033[36m"      /* for thread logs */
76 #define BG_COLOR_GREEN  "\033[0;42m"
77
78 #ifdef DLOG_DEFAULT_ENABLE
79 #define LOG_TAG "TPL"
80 #include <dlog.h>
81 #endif
82
83 #ifdef DLOG_DEFAULT_ENABLE
84 #define tpl_log_f(t, f, x...)   LOGI(FONT_GREEN t FONT_DEFAULT " " f, ##x)
85 #define tpl_log_b(t, f, x...)   LOGI(FONT_BLUE t FONT_DEFAULT " " f, ##x)
86 #define tpl_log_d(t, f, x...)   LOGI(FONT_MAGENTA t FONT_DEFAULT " " f, ##x)
87 #define tpl_log_t(t, f, x...)   LOGI(FONT_CYAN t FONT_DEFAULT " " f, ##x)
88 #define tpl_log_i(t, f, x...)   LOGI(BG_COLOR_GREEN t FONT_DEFAULT " " f, ##x)
89 #define tpl_log_e(t, f, x...)   LOGE(FONT_RED t " " f FONT_DEFAULT, ##x)
90 #define tpl_log_w(t, f, x...)   LOGW(FONT_YELLOW t " " f FONT_DEFAULT, ##x)
91 #else /* DLOG_DEFAULT_ENABLE */
92 #define tpl_log_f(t, f, x...)                                                                                   \
93         fprintf(stderr, FONT_GREEN t FONT_DEFAULT "[(tid:%li)(%s)] " f "\n",    \
94                         syscall(SYS_gettid), __func__, ##x)
95 #define tpl_log_b(t, f, x...)                                                                                   \
96         fprintf(stderr, FONT_BLUE t FONT_DEFAULT "[(tid:%li)(%s)] " f "\n",     \
97                         syscall(SYS_gettid), __func__, ##x)
98 #define tpl_log_d(t, f, x...)                                                                                   \
99         fprintf(stderr, FONT_MAGENTA t FONT_DEFAULT "[(tid:%li)(%s)] " f "\n",\
100                         syscall(SYS_gettid), __func__, ##x)
101 #define tpl_log_t(t, f, x...)                                                                                   \
102         fprintf(stderr, FONT_CYAN t FONT_DEFAULT "[(tid:%li)(%s)]" f "\n",      \
103                         syscall(SYS_gettid), __func__, ##x)
104 #define tpl_log_i(t, f, x...)                                                                                   \
105         fprintf(stderr, BG_COLOR_GREEN t FONT_DEFAULT "[(tid:%li)(%s)]" f "\n", \
106                         syscall(SYS_gettid), __func__, ##x)
107 #define tpl_log_e(t, f, x...)                                                                                   \
108         fprintf(stderr, FONT_RED t "[(tid:%li)(%s)] " f FONT_DEFAULT "\n",      \
109                         syscall(SYS_gettid), __func__, ##x)
110 #define tpl_log_w(t, f, x...)                                                                                   \
111         fprintf(stderr, FONT_YELLOW t "[(tid:%li)(%s)] " f FONT_DEFAULT "\n",\
112                         syscall(SYS_gettid), __func__, ##x)
113 #endif /* DLOG_DEFAULT_ENABLE */
114
115 #define TPL_INFO(tag, f, x...)  tpl_log_i(tag, f, ##x)
116 #define TPL_ERR(f, x...)                tpl_log_e("[TPL_ERROR]", f, ##x)
117 #define TPL_WARN(f, x...)               tpl_log_w("[TPL_WARNING]", f, ##x)
118
119 #ifdef LOG_DEFAULT_ENABLE
120 #define TPL_LOG_F(f, x...)              tpl_log_f("[TPL_F]", f, ##x)
121 #define TPL_LOG_B(b, f, x...)   tpl_log_b("[TPL_" b "]", f, ##x)
122 #define TPL_DEBUG(f, x...)              tpl_log_d("[TPL_DEBUG]", f, ##x)
123 #define TPL_LOG_T(b, f, x...)                                                   \
124         {                                                                                                       \
125                 if ((int)getpid() != (int)syscall(SYS_gettid))  \
126                         tpl_log_t("[TPL_" b "_T]", f, ##x);                     \
127                 else                                                                                    \
128                         tpl_log_b("[TPL_" b "]", f, ##x);                       \
129         }
130 #else /* LOG_DEFAULT_ENABLE */
131 /*
132  * TPL_LOG_LEVEL
133  * export TPL_LOG_LEVEL=[lvl]
134  * -1: uninitialized.
135  * 0: initialized but do not print any log.
136  * 1: enable only frontend API logs. TPL_LOG_F
137  * 2: enable also backend API logs. TPL_LOG_B (detail info about window system)
138  * 3: enable also debug logs. TPL_DEBUG
139  * 4: enable only debug logs. TPL_DEBUG
140  */
141 #define LOG_INIT()                                                                              \
142         {                                                                                                       \
143                 if (!tpl_log_initialized)                                               \
144                 {                                                                                               \
145                         char *env = tpl_getenv("TPL_LOG_LEVEL");                \
146                         if (env == NULL)                                                        \
147                                 tpl_log_lvl = 0;                                                \
148                         else                                                                            \
149                                 tpl_log_lvl = atoi(env);                                \
150                         tpl_log_initialized = 1;                                        \
151                 }                                                                                               \
152         }
153
154 #define TPL_LOG_F(f, x...)                                                              \
155         {                                                                                                       \
156                 LOG_INIT();                                                                             \
157                 if (tpl_log_lvl > 0 && tpl_log_lvl < 4)                 \
158                         tpl_log_f("[TPL_F]", f, ##x);                           \
159         }
160
161 #define TPL_LOG_B(b, f, x...)                                                   \
162         {                                                                                                       \
163                 LOG_INIT();                                                                             \
164                 if (tpl_log_lvl > 1 && tpl_log_lvl < 4)                 \
165                         tpl_log_b("[TPL_" b "]", f, ##x);                       \
166         }
167
168 #define TPL_LOG_T(b, f, x...)                                                   \
169         {                                                                                                       \
170                 LOG_INIT();                                                                             \
171                 if (tpl_log_lvl > 1 && tpl_log_lvl < 4) {               \
172                         if ((int)getpid() != (int)syscall(SYS_gettid))  \
173                                 tpl_log_t("[TPL_" b "_T]", f, ##x);                     \
174                         else                                                                                    \
175                                 tpl_log_b("[TPL_" b "]", f, ##x);                       \
176                 }                                                                                               \
177         }
178
179 #define TPL_DEBUG(f, x...)                                                              \
180         {                                                                                                       \
181                 LOG_INIT();                                                                             \
182                 if (tpl_log_lvl > 2)                                                    \
183                         tpl_log_d("[TPL_DEBUG]", f, ##x);                       \
184         }
185 #endif /* LOG_DEFAULT_ENABLE */
186 #else /* NDEBUG */
187 #define TPL_LOG_F(f, x...)
188 #define TPL_LOG_B(b, f, x...)
189 #define TPL_DEBUG(f, x...)
190 #define TPL_ERR(f, x...)
191 #define TPL_WARN(f, x...)
192 #endif
193
194
195 #define TPL_CHECK_ON_NULL_RETURN(exp)                                                   \
196         {                                                                                                                       \
197                 if ((exp) == NULL)                                                                              \
198                 {                                                                                                               \
199                         TPL_ERR("%s", "check failed: " # exp " == NULL");       \
200                         return;                                                                                         \
201                 }                                                                                                               \
202         }
203
204 #define TPL_CHECK_ON_NULL_RETURN_VAL(exp, val)                                  \
205         {                                                                                                                       \
206                 if ((exp) == NULL)                                                                              \
207                 {                                                                                                               \
208                         TPL_ERR("%s", "check failed: " # exp " == NULL");       \
209                         return (val);                                                                           \
210                 }                                                                                                               \
211         }
212
213 #define TPL_CHECK_ON_NULL_GOTO(exp, label)                                              \
214         {                                                                                                                       \
215                 if ((exp) == NULL)                                                                              \
216                 {                                                                                                               \
217                         TPL_ERR("%s", "check failed: " # exp " == NULL");       \
218                         goto label;                                                                                     \
219                 }                                                                                                               \
220         }
221
222 #define TPL_CHECK_ON_TRUE_RETURN(exp)                                                   \
223         {                                                                                                                       \
224                 if (exp)                                                                                                \
225                 {                                                                                                               \
226                         TPL_ERR("%s", "check failed: " # exp " is true");       \
227                         return;                                                                                         \
228                 }                                                                                                               \
229         }
230
231 #define TPL_CHECK_ON_TRUE_RETURN_VAL(exp, val)                                  \
232         {                                                                                                                       \
233                 if (exp)                                                                                                \
234                 {                                                                                                               \
235                         TPL_ERR("%s", "check failed: " # exp " is true");       \
236                         return val;                                                                                     \
237                 }                                                                                                               \
238         }
239
240 #define TPL_CHECK_ON_TRUE_GOTO(exp, label)                                      \
241         {                                                                                                                       \
242                 if (exp)                                                                                                \
243                 {                                                                                                               \
244                         TPL_ERR("%s", "check failed: " # exp " is true");   \
245                         goto label;                                                                                     \
246                 }                                                                                                               \
247         }
248
249 #define TPL_CHECK_ON_FALSE_RETURN(exp)                                                  \
250         {                                                                                                                       \
251                 if (!(exp))                                                                                             \
252                 {                                                                                                               \
253                         TPL_ERR("%s", "check failed: " # exp " is false");      \
254                         return;                                                                                         \
255                 }                                                                                                               \
256         }
257
258 #define TPL_CHECK_ON_FALSE_RETURN_VAL(exp, val)                                 \
259         {                                                                                                                       \
260                 if (!(exp))                                                                                             \
261                 {                                                                                                               \
262                         TPL_ERR("%s", "check failed: " # exp " is false");      \
263                         return val;                                                                                     \
264                 }                                                                                                               \
265         }
266
267 #define TPL_CHECK_ON_FALSE_GOTO(exp, label)                                             \
268         {                                                                                                                       \
269                 if (!(exp))                                                                                             \
270                 {                                                                                                               \
271                         TPL_ERR("%s", "check failed: " # exp " is false");      \
272                         goto label;                                                                                     \
273                 }                                                                                                               \
274         }
275
276 #define TPL_CHECK_ON_FALSE_ASSERT_FAIL(exp, mesg)       \
277         {                                                                                               \
278                 if (!(exp))                                                                     \
279                 {                                                                                       \
280                         TPL_ERR("%s", mesg);                                    \
281                         assert(0);                                                              \
282                 }                                                                                       \
283         }
284
285 #ifdef DEFAULT_DUMP_ENABLE
286 #define TPL_IMAGE_DUMP __tpl_util_image_dump
287 #else
288 #define TPL_IMAGE_DUMP(data, width, height)                                                                                             \
289         {                                                                                                                                                                       \
290                 if (tpl_dump_lvl != 0)                                                                                                                  \
291                 {                                                                                                                                                               \
292                         __tpl_util_image_dump(data, width, height);                                                                     \
293                 }                                                                                                                                                               \
294                 else                                                                                                                                                    \
295                 {                                                                                                                                                               \
296                         char *env = tpl_getenv("TPL_DUMP_LEVEL");                                                                               \
297                         if (env == NULL)                                                                                                                        \
298                                 tpl_dump_lvl = 0;                                                                                                               \
299                         else                                                                                                                                            \
300                                 tpl_dump_lvl = atoi(env);                                                                                               \
301                                                                                                                                                                                 \
302                         if (tpl_dump_lvl != 0)                                                                                                          \
303                                 __tpl_util_image_dump(data, width, height);                                                             \
304                 }                                                                                                                                                               \
305         }
306 #endif
307
308 typedef struct _tpl_list_node   tpl_list_node_t;
309 typedef struct _tpl_list        tpl_list_t;
310 typedef struct tpl_util_map_entry tpl_util_map_entry_t;
311 typedef struct tpl_util_map tpl_util_map_t;
312 typedef struct tpl_util_key tpl_util_key_t;
313
314 typedef int (*tpl_util_hash_func_t)(const tpl_util_key_t key, int key_length);
315 typedef int (*tpl_util_key_length_func_t)(const tpl_util_key_t key);
316 typedef int (*tpl_util_key_compare_func_t)(const tpl_util_key_t key0,
317                 int key0_length,
318                 const tpl_util_key_t key1,
319                 int key1_length);
320
321 enum _tpl_occurrence {
322         TPL_FIRST,
323         TPL_LAST,
324         TPL_ALL
325 };
326
327 struct tpl_util_key {
328         void *ptr; /*pointer key or user defined key(string)*/
329 };
330
331 struct _tpl_list_node {
332         tpl_list_node_t *prev;
333         tpl_list_node_t *next;
334         void *data;
335         tpl_list_t *list;
336 };
337
338 struct _tpl_list {
339         tpl_list_node_t head;
340         tpl_list_node_t tail;
341         int count;
342 };
343
344 struct tpl_util_map {
345         tpl_util_hash_func_t hash_func;
346         tpl_util_key_length_func_t key_length_func;
347         tpl_util_key_compare_func_t key_compare_func;
348         int bucket_bits;
349         int bucket_size;
350         int bucket_mask;
351         tpl_util_map_entry_t **buckets;
352 };
353
354 void tpl_util_map_init(tpl_util_map_t *map, int bucket_bits,
355                                            tpl_util_hash_func_t hash_func,
356                                            tpl_util_key_length_func_t key_length_func,
357                                            tpl_util_key_compare_func_t key_compare_func,
358                                            void *buckets);
359
360 void tpl_util_map_pointer_init(tpl_util_map_t *map, int bucket_bits,
361                                                            void *buckets);
362
363 void tpl_util_map_fini(tpl_util_map_t *map);
364
365 tpl_util_map_t *
366 tpl_util_map_create(int bucket_bits, tpl_util_hash_func_t hash_func,
367                                         tpl_util_key_length_func_t key_length_func,
368                                         tpl_util_key_compare_func_t key_compare_func);
369
370 tpl_util_map_t *tpl_util_map_pointer_create(int bucket_bits);
371
372 void tpl_util_map_destroy(tpl_util_map_t *map);
373
374 void tpl_util_map_clear(tpl_util_map_t *map);
375
376 void *tpl_util_map_get(tpl_util_map_t *map, const tpl_util_key_t key);
377
378 void
379 tpl_util_map_set(tpl_util_map_t *map, const tpl_util_key_t key, void *data,
380                                  tpl_free_func_t free_func);
381
382 static TPL_INLINE int
383 __tpl_list_get_count(const tpl_list_t *list)
384 {
385         TPL_ASSERT(list);
386
387         return list->count;
388 }
389
390 static TPL_INLINE tpl_bool_t
391 __tpl_list_is_empty(const tpl_list_t *list)
392 {
393         TPL_ASSERT(list);
394
395         return list->count == 0;
396 }
397
398 static TPL_INLINE void
399 __tpl_list_init(tpl_list_t *list)
400 {
401         TPL_ASSERT(list);
402
403         list->head.list = list;
404         list->tail.list = list;
405
406         list->head.prev = NULL;
407         list->head.next = &list->tail;
408         list->tail.prev = &list->head;
409         list->tail.next = NULL;
410
411         list->count = 0;
412 }
413
414 static TPL_INLINE void
415 __tpl_list_fini(tpl_list_t *list, tpl_free_func_t func)
416 {
417         tpl_list_node_t *node;
418
419         TPL_ASSERT(list);
420
421         node = list->head.next;
422
423         while (node != &list->tail) {
424                 tpl_list_node_t *free_node = node;
425                 node = node->next;
426
427                 TPL_ASSERT(free_node);
428
429                 if (func) func(free_node->data);
430
431                 free(free_node);
432         }
433
434         __tpl_list_init(list);
435 }
436
437 static TPL_INLINE tpl_list_t *
438 __tpl_list_alloc()
439 {
440         tpl_list_t *list;
441
442         list = (tpl_list_t *) malloc(sizeof(tpl_list_t));
443         if (!list) return NULL;
444
445         __tpl_list_init(list);
446
447         return list;
448 }
449
450 static TPL_INLINE void
451 __tpl_list_free(tpl_list_t *list, tpl_free_func_t func)
452 {
453         TPL_ASSERT(list);
454
455         __tpl_list_fini(list, func);
456         free(list);
457 }
458
459 static TPL_INLINE void *
460 __tpl_list_node_get_data(const tpl_list_node_t *node)
461 {
462         TPL_ASSERT(node);
463
464         return node->data;
465 }
466
467 static TPL_INLINE tpl_list_node_t *
468 __tpl_list_get_front_node(tpl_list_t *list)
469 {
470         TPL_ASSERT(list);
471
472         if (__tpl_list_is_empty(list)) return NULL;
473
474         return list->head.next;
475 }
476
477 static TPL_INLINE tpl_list_node_t *
478 __tpl_list_get_back_node(tpl_list_t *list)
479 {
480         TPL_ASSERT(list);
481
482         if (__tpl_list_is_empty(list)) return NULL;
483
484         return list->tail.prev;
485 }
486
487 static TPL_INLINE tpl_list_node_t *
488 __tpl_list_node_prev(tpl_list_node_t *node)
489 {
490         TPL_ASSERT(node);
491         TPL_ASSERT(node->list);
492
493         if (node->prev != &node->list->head)
494                 return (tpl_list_node_t *)node->prev;
495
496         return NULL;
497 }
498
499 static TPL_INLINE tpl_list_node_t *
500 __tpl_list_node_next(tpl_list_node_t *node)
501 {
502         TPL_ASSERT(node);
503         TPL_ASSERT(node->list);
504
505         if (node->next != &node->list->tail)
506                 return node->next;
507
508         return NULL;
509 }
510
511 static TPL_INLINE void *
512 __tpl_list_get_front(const tpl_list_t *list)
513 {
514         TPL_ASSERT(list);
515
516         if (__tpl_list_is_empty(list))
517                 return NULL;
518
519         TPL_ASSERT(list->head.next);
520
521         return list->head.next->data;
522 }
523
524 static TPL_INLINE void *
525 __tpl_list_get_back(const tpl_list_t *list)
526 {
527         TPL_ASSERT(list);
528
529         if (__tpl_list_is_empty(list)) return NULL;
530
531         TPL_ASSERT(list->tail.prev);
532
533         return list->tail.prev->data;
534 }
535
536 static TPL_INLINE void
537 __tpl_list_remove(tpl_list_node_t *node, tpl_free_func_t func)
538 {
539         TPL_ASSERT(node);
540         TPL_ASSERT(node->prev);
541         TPL_ASSERT(node->next);
542
543         node->prev->next = node->next;
544         node->next->prev = node->prev;
545
546         if (func) func(node->data);
547
548         node->list->count--;
549         free(node);
550 }
551
552 static TPL_INLINE tpl_result_t
553 __tpl_list_insert(tpl_list_node_t *pos, void *data)
554 {
555         tpl_list_node_t *node = (tpl_list_node_t *)malloc(sizeof(tpl_list_node_t));
556         if (!node) {
557                 TPL_ERR("Failed to allocate new tpl_list_node_t.");
558                 return TPL_ERROR_OUT_OF_MEMORY;
559         }
560
561         node->data = data;
562         node->list = pos->list;
563
564         pos->next->prev = node;
565         node->next = pos->next;
566
567         pos->next = node;
568         node->prev = pos;
569
570         pos->list->count++;
571
572         return TPL_ERROR_NONE;
573 }
574
575 static TPL_INLINE tpl_list_node_t *
576 __tpl_list_find_node(tpl_list_t *list, void *data, int occurrence,
577                                          tpl_free_func_t func)
578 {
579         tpl_list_node_t *node = NULL;
580         tpl_list_node_t *res_node = NULL;
581
582         TPL_ASSERT(list);
583
584         if (occurrence == TPL_FIRST) {
585                 node = list->head.next;
586
587                 while (node != &list->tail) {
588                         tpl_list_node_t *curr;
589
590                         curr = node;
591                         node = node->next;
592
593                         TPL_ASSERT(curr);
594                         TPL_ASSERT(node);
595
596                         if (curr->data == data) {
597                                 res_node = curr;
598                                 break;
599                         }
600                 }
601         } else if (occurrence == TPL_LAST) {
602                 node = list->tail.prev;
603
604                 while (node != &list->head) {
605                         tpl_list_node_t *curr;
606
607                         curr = node;
608                         node = node->prev;
609
610                         TPL_ASSERT(curr);
611                         TPL_ASSERT(node);
612
613                         if (curr->data == data) {
614                                 res_node = curr;
615                                 break;
616                         }
617                 }
618         }
619
620         return res_node;
621 }
622
623 static TPL_INLINE void
624 __tpl_list_remove_data(tpl_list_t *list, void *data, int occurrence,
625                                            tpl_free_func_t func)
626 {
627         tpl_list_node_t *node;
628
629         TPL_ASSERT(list);
630
631         if (occurrence == TPL_FIRST) {
632                 node = list->head.next;
633
634                 while (node != &list->tail) {
635                         tpl_list_node_t *curr;
636
637                         curr = node;
638                         node = node->next;
639
640                         TPL_ASSERT(curr);
641                         TPL_ASSERT(node);
642
643                         if (curr->data == data) {
644                                 __tpl_list_remove(curr, func);
645                                 return;
646                         }
647                 }
648         } else if (occurrence == TPL_LAST) {
649                 node = list->tail.prev;
650
651                 while (node != &list->head) {
652                         tpl_list_node_t *curr;
653
654                         curr = node;
655                         node = node->prev;
656
657                         TPL_ASSERT(curr);
658                         TPL_ASSERT(node);
659
660                         if (curr->data == data) {
661                                 __tpl_list_remove(curr, func);
662                                 return;
663                         }
664                 }
665         } else if (occurrence == TPL_ALL) {
666                 node = list->head.next;
667
668                 while (node != &list->tail) {
669                         tpl_list_node_t *curr;
670
671                         curr = node;
672                         node = node->next;
673
674                         TPL_ASSERT(curr);
675                         TPL_ASSERT(node);
676
677                         if (curr->data == data)
678                                 __tpl_list_remove(curr, func);
679                 }
680         }
681 }
682
683 static TPL_INLINE void
684 __tpl_list_push_front(tpl_list_t *list, void *data)
685 {
686         TPL_ASSERT(list);
687
688         __tpl_list_insert(&list->head, data);
689 }
690
691 static TPL_INLINE tpl_result_t
692 __tpl_list_push_back(tpl_list_t *list, void *data)
693 {
694         TPL_ASSERT(list);
695
696         return __tpl_list_insert(list->tail.prev, data);
697 }
698
699 static TPL_INLINE void *
700 __tpl_list_pop_front(tpl_list_t *list, tpl_free_func_t func)
701 {
702         void *data;
703
704         TPL_ASSERT(list);
705
706         if (__tpl_list_is_empty(list)) return NULL;
707
708         data = list->head.next->data;
709         __tpl_list_remove(list->head.next, func);
710
711         return data;
712 }
713
714 static TPL_INLINE void *
715 tpl_list_pop_back(tpl_list_t *list, tpl_free_func_t func)
716 {
717         void *data;
718
719         TPL_ASSERT(list);
720
721         if (__tpl_list_is_empty(list)) return NULL;
722
723         data = list->tail.prev->data;
724         __tpl_list_remove(list->tail.prev, func);
725
726         return data;
727 }
728
729 static TPL_INLINE void
730 __tpl_util_image_dump(void *data, int width, int height)
731 {
732         char path_name[20] = "/tmp";
733
734         tbm_surface_internal_dump_start(path_name, width, height, 1);
735         tbm_surface_internal_dump_buffer((tbm_surface_h)data, "png");
736         tbm_surface_internal_dump_end();
737 }
738 #endif /* TPL_UTILS_H */