[Title] Implemented fastpath for OpenGL ES 3.0 (FINAL)
[platform/core/uifw/coregl.git] / src / coregl_internal.h
1 #ifndef COREGL_INTERNAL_H
2 #define COREGL_INTERNAL_H
3
4 #include <stdio.h>
5
6 #include "coregl.h"
7
8 #include "modules/coregl_module.h"
9
10 #define unlikely(x) __builtin_expect(x, 0)
11
12 // Symbol definition for real
13 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST)     extern RET_TYPE (*_sym_##FUNC_NAME) PARAM_LIST;
14 # include "headers/sym.h"
15 #undef _COREGL_SYMBOL
16
17 #define COREGL_DEBUG
18
19 #define LOG_TAG "CoreGL"
20 #include <dlog.h>
21
22 ///////////////////////////////////////
23 // Disable dlog for debugging urgent issues //
24 #ifdef COREGL_DEBUG
25 # undef LOGE
26 # define LOGE(...) fprintf(stderr, __VA_ARGS__)
27 # undef LOGW
28 # define LOGW(...) fprintf(stderr, __VA_ARGS__)
29 # undef LOGD
30 # define LOGD(...) fprintf(stderr, __VA_ARGS__)
31 #endif
32 ///////////////////////////////////////
33
34 # define COREGL_ERR(...) \
35      LOGE(" "__VA_ARGS__)
36 # define COREGL_WRN(...) \
37      LOGW(" "__VA_ARGS__)
38 # ifdef COREGL_DEBUG
39 #  define COREGL_DBG(...) \
40      LOGD(" "__VA_ARGS__)
41 # else
42 #  define COREGL_DBG(...)
43 # endif
44
45 # define COREGL_LOG(...) \
46      LOGD(" "__VA_ARGS__)
47
48
49 # define TRACE(...) \
50      if (trace_fp != NULL) \
51        fprintf(trace_fp, __VA_ARGS__); \
52      else \
53        LOGD(" "__VA_ARGS__)
54
55 # define TRACE_END() \
56      if (trace_fp != NULL) \
57        fflush(trace_fp)
58 #define _COREGL_TRACE_OUTPUT_INTERVAL_SEC 5
59
60 static inline GLint GET_INT_FROM_FLOAT(GLfloat value) { return *((GLint *)&value); }
61 static inline GLuint GET_UINT_FROM_FLOAT(GLfloat value) { return *((GLint *)&value); }
62
63
64 #ifdef COREGL_DEBUG
65 # define AST(expr) \
66      if (!(expr)) { LOGE("\E[40;31;1m%s(%d) error. '"#expr"'\E[0m\n", __func__, __LINE__); }
67 #else
68 # define AST(expr) \
69      if (expr)
70 #endif
71
72 typedef GLvoid *     GLvoidptr;
73 typedef GLuint       GLuintmask;
74
75 #define _COREGL_INT_INIT_VALUE -3
76
77 #define COREGL_OVERRIDE_API(mangle, func, prefix) \
78         mangle##func = prefix##func
79
80 typedef EGLSurface     GLSurface;
81 typedef EGLDisplay     GLDisplay;
82 typedef EGLContext     GLContext;
83
84 #define COREGL_GL_NO_CONTEXT EGL_NO_CONTEXT
85
86 typedef struct _GLThreadState
87 {
88         int                      thread_id;
89         void                    *module_data[COREGL_MAX_MODULES];
90 } GLThreadState;
91
92 extern void                *glue_lib_handle;
93 extern void                *egl_lib_handle;
94
95 #include "coregl_thread_pthread.h"
96
97 typedef struct _General_Trace_List
98 {
99         void                          *value;
100         struct _General_Trace_List    *next;
101 } General_Trace_List;
102
103 extern General_Trace_List  *thread_trace_list;
104 extern Mutex                general_trace_lists_access_mutex;
105
106 extern FILE               *trace_fp;
107
108 extern int                 trace_api_flag;
109 extern int                 trace_api_all_flag;
110 extern int                 trace_api_frame_flag;
111 extern int                 trace_mem_flag;
112 extern int                 trace_mem_all_flag;
113 extern int                 trace_ctx_flag;
114 extern int                 trace_ctx_force_flag;
115 extern int                 trace_state_flag;
116 extern int                 trace_surface_flag;
117 extern int                 trace_surface_sequence_sort_flag;
118 extern int                 trace_surface_filter_period_begin;
119 extern int                 trace_surface_filter_period_end;
120 extern int                 trace_surface_filter_type;
121 extern int                 trace_surface_filter_handle;
122 extern int                 trace_surface_filter_size_w;
123 extern int                 trace_surface_filter_size_h;
124 extern int                 trace_surface_print_only_flag;
125
126 #define USE_TRACEPATH           (trace_api_flag == 1 || trace_ctx_flag == 1 || trace_state_flag == 1 || trace_mem_flag == 1 || trace_surface_flag == 1)
127
128 // Environment functions
129 extern const char         *get_env_setting(const char *name);
130
131 // Main utility functions
132 extern int                 init_new_thread_state();
133
134 // Thread functions
135 extern int                 mutex_init(Mutex *mt);
136 extern int                 mutex_lock(Mutex *mt);
137 extern int                 mutex_unlock(Mutex *mt);
138 extern int                 get_current_thread();
139 extern int                 set_current_thread_state(GLThreadState *tstate);
140 extern GLThreadState      *get_current_thread_state();
141
142
143 // Override functions
144 extern void                init_export();
145 extern void                deinit_export();
146
147 // Module interfaces
148 extern void                init_modules();
149 extern void                deinit_modules();
150 extern void                reset_modules_override();
151 extern void                init_modules_tstate(GLThreadState *tstate);
152 extern void                deinit_modules_tstate(GLThreadState *tstate);
153
154
155 // Debug & Trace functions
156 extern int                 add_to_general_trace_list(General_Trace_List **gtl, void *value);
157 extern int                 remove_from_general_trace_list(General_Trace_List **gtl, void *value);
158
159 #endif // COREGL_INTERNAL_H
160