[Title] Refactored symbol macros
[platform/core/uifw/coregl.git] / src / modules / fastpath / coregl_fastpath.h
1 #ifndef COREGL_FASTPATH_H
2 #define COREGL_FASTPATH_H
3
4 #include "../coregl_module.h"
5
6 #ifndef COREGL_USE_MODULE_FASTPATH
7 #error "COREGL_USE_MODULE_FASTPATH must defined!!!"
8 #endif
9
10 #define MY_MODULE_ID              COREGL_MODULE_FASTPATH
11 #define MY_MODULE_TSTATE         Fastpath_ThreadState
12
13 #include "../../coregl_internal.h"
14 #include "../../coregl_export.h"
15
16 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     extern RET_TYPE (*_orig_fastpath_##FUNC_NAME) PARAM_LIST;
17 # include "../../headers/sym.h"
18 #undef _COREGL_SYMBOL
19
20 // Symbol definition for fastpath
21 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     extern RET_TYPE (fastpath_##FUNC_NAME) PARAM_LIST;
22 # include "../../headers/sym.h"
23 #undef _COREGL_SYMBOL
24
25 #define COREGL_FASTPATH_TRACE_ALL
26
27 #ifdef COREGL_FASTPATH_TRACE_ALL
28 #define COREGL_FASTPATH_TRACE_CONTEXT_INFO   // Context state & thread state & Glue-context info
29 #define COREGL_FASTPATH_TRACE_STATE_INFO     // Glue-context state info
30 #endif
31
32
33 #define _COREGL_FASTPATH_FUNC_BEGIN()
34
35 #define _COREGL_FASTPATH_FUNC_END()
36
37
38 #define FLAG_BIT_0      0x01
39 #define FLAG_BIT_1      0x02
40 #define FLAG_BIT_2      0x04
41 #define FLAG_BIT_3      0x08
42 #define FLAG_BIT_4      0x10
43 #define FLAG_BIT_5      0x20
44 #define FLAG_BIT_6      0x40
45 #define FLAG_BIT_7      0x80
46
47 #define MAX_TEXTURE_UNITS 32
48 #define MAX_VERTEX_ATTRIBS 64
49 #define MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 64
50 #define MAX_UNIFORM_BUFFER_BINDINGS 64
51
52 typedef enum _Fastpath_Opt_Flag
53 {
54     FP_UNKNOWN_PATH,
55     FP_NORMAL_PATH,
56     FP_FAST_PATH
57 } Fastpath_Opt_Flag;
58
59 extern Fastpath_Opt_Flag   fp_opt;
60 extern int                 debug_nofp;
61
62 typedef struct _GLContextState
63 {
64         int                      ref_count;
65         GLContext               *rctx;
66         GLDisplay               *rdpy;
67         void                    *data;
68 } GLContextState;
69
70 typedef struct _Fastpath_ThreadState
71 {
72         EGLenum                  binded_api;
73         GLContextState          *cstate;
74         GLSurface               *rsurf_draw;
75         GLSurface               *rsurf_read;
76 } Fastpath_ThreadState;
77
78 typedef struct _GLContext_List
79 {
80         void                    *option;
81         int                      option_len;
82         int                      thread_id;
83         GLContextState          *cstate;
84         struct _GLContext_List *next;
85 } GLContext_List;
86
87 extern GLContext_List      *glctx_list;
88
89 extern Mutex                ctx_list_access_mutex;
90
91 typedef struct
92 {
93         GLuint   tex_id;
94 } GL_Texture_State;
95
96 typedef struct
97 {
98         GLboolean    modified;
99         GLboolean    enabled;
100         GLuint       buf_id;
101         GLint        size;
102         GLenum       type;
103         GLboolean    normalized;
104         GLsizei      stride;
105         const void  *pointer;
106 } GL_Vertex_Array_State;
107
108 typedef struct
109 {
110         GLboolean   modified;
111         GLfloat     value[4];
112 } GL_Vertex_Attrib;
113
114
115 #define MAGIC_GLFAST                0x73777770
116 #define GL_OBJECT_HASH_BASE        (1 << 10)
117
118 #define GL_OBJECT_ID_LIMIT         0xFFFFFF
119
120 #define GL_Object_Type                     int
121 #define GL_OBJECT_TYPE_QUERY               0x0
122 #define GL_OBJECT_TYPE_TEXTURE             0x1000000
123 #define GL_OBJECT_TYPE_BUFFER              0x2000000
124 #define GL_OBJECT_TYPE_FRAMEBUFFER         0x3000000
125 #define GL_OBJECT_TYPE_RENDERBUFFER        0x4000000
126 #define GL_OBJECT_TYPE_PROGRAM             0x5000000
127 #define GL_OBJECT_TYPE_VERTEXARRAY         0x6000000
128 #define GL_OBJECT_TYPE_SAMPLER             0x7000000
129 #define GL_OBJECT_TYPE_TRANSFORMFEEDBACK   0x8000000
130 #define GL_OBJECT_TYPE_UNKNOWN             0xFFFFFFF
131
132 typedef struct _GL_Object
133 {
134         GLuint                            id;
135         GLuint                            real_id;
136         GLint                             ref_count;
137         GLvoid                            *tag;
138
139         struct _GL_Shared_Object_State  *parent;
140 } GL_Object;
141
142 typedef struct _GL_Object_Hash
143 {
144         GLuint                           hash_key;
145         GL_Object                        *item;
146         struct _GL_Object_Hash          *next;
147 } GL_Object_Hash;
148
149 typedef struct _GL_Object_Hash_Base
150 {
151         GLuint                            hash_size;
152         GLuint                            item_size;
153         GLuint                            last_id;
154         GLuint                            is_looped;
155         GL_Object_Hash                  **hash_field;
156 } GL_Object_Hash_Base;
157
158 typedef struct _GL_Shared_Object_State
159 {
160         Mutex                    access_mutex;
161         Mutex                    real_access_mutex;
162         int                      ref_count;
163         General_Trace_List      *using_gctxs;
164
165         GL_Object_Hash_Base      texture;
166         GL_Object_Hash_Base      buffer;
167         GL_Object_Hash_Base      renderbuffer;
168         GL_Object_Hash_Base      program;
169         GL_Object_Hash_Base      sampler;
170
171         GL_Object_Hash_Base      texture_real;
172         GL_Object_Hash_Base      buffer_real;
173         GL_Object_Hash_Base      renderbuffer_real;
174         GL_Object_Hash_Base      program_real;
175         GL_Object_Hash_Base      sampler_real;
176 } GL_Shared_Object_State;
177
178 typedef struct _GL_Object_State
179 {
180         GL_Shared_Object_State  *shared;
181
182         GL_Object_Hash_Base      query;
183         GL_Object_Hash_Base      framebuffer;
184         GL_Object_Hash_Base      vertexarray;
185         GL_Object_Hash_Base      transformfeedback;
186
187         GL_Object_Hash_Base      query_real;
188         GL_Object_Hash_Base      framebuffer_real;
189         GL_Object_Hash_Base      vertexarray_real;
190         GL_Object_Hash_Base      transformfeedback_real;
191 } GL_Object_State;
192
193 typedef struct _GLGlueContext
194 {
195         int                     magic;
196         int                     initialized;
197         int                     surface_attached;
198
199         int                                                     ref_count;
200         int                                                     is_destroyed;
201
202         double                  glversion;
203
204         int                                                     used_count;
205
206         GLDisplay              *rdpy;
207         GLContextState         *cstate;
208         int                     thread_id;
209
210         void                   *real_ctx_option;
211         int                     real_ctx_option_len;
212
213         void                   *real_ctx_sharable_option;
214         int                     real_ctx_sharable_option_len;
215
216
217
218
219         unsigned char           _bind_flag;
220 #define _BIND_FLAG_BIT_gl_array_buffer_binding               FLAG_BIT_0
221 #define _BIND_FLAG_BIT_gl_copy_read_buffer_binding           FLAG_BIT_1
222 #define _BIND_FLAG_BIT_gl_copy_write_buffer_binding          FLAG_BIT_1
223 #define _BIND_FLAG_BIT_gl_element_array_buffer_binding       FLAG_BIT_1
224 #define _BIND_FLAG_BIT_gl_pixel_pack_buffer_binding          FLAG_BIT_1
225 #define _BIND_FLAG_BIT_gl_pixel_unpack_buffer_binding        FLAG_BIT_1
226 #define _BIND_FLAG_BIT_gl_transform_feedback_buffer_binding  FLAG_BIT_1
227 #define _BIND_FLAG_BIT_gl_uniform_buffer_binding             FLAG_BIT_1
228 #define _BIND_FLAG_BIT_gl_framebuffer_binding                FLAG_BIT_2
229 #define _BIND_FLAG_BIT_gl_renderbuffer_binding               FLAG_BIT_3
230 #define _BIND_FLAG_BIT_gl_framebuffer_binding_read           FLAG_BIT_4
231 #define _BIND_FLAG_BIT_gl_framebuffer_binding_draw           FLAG_BIT_5
232
233         unsigned char           _enable_flag1;
234 #define _ENABLE_FLAG1_BIT_gl_blend        FLAG_BIT_0
235 #define _ENABLE_FLAG1_BIT_gl_cull_face    FLAG_BIT_1
236 #define _ENABLE_FLAG1_BIT_gl_depth_test   FLAG_BIT_2
237 #define _ENABLE_FLAG1_BIT_gl_dither       FLAG_BIT_3
238
239         unsigned char           _enable_flag2;
240 #define _ENABLE_FLAG2_BIT_gl_polygon_offset_fill       FLAG_BIT_0
241 #define _ENABLE_FLAG2_BIT_gl_sample_alpha_to_coverage  FLAG_BIT_1
242 #define _ENABLE_FLAG2_BIT_gl_sample_coverage           FLAG_BIT_2
243 #define _ENABLE_FLAG2_BIT_gl_scissor_test              FLAG_BIT_3
244 #define _ENABLE_FLAG2_BIT_gl_stencil_test              FLAG_BIT_4
245
246         unsigned char           _enable_flag3;
247 #define _ENABLE_FLAG3_BIT_gl_primitive_restart_fixed_index  FLAG_BIT_0
248 #define _ENABLE_FLAG3_BIT_gl_rasterizer_discard             FLAG_BIT_1
249
250         unsigned char           _clear_flag1;
251 #define _CLEAR_FLAG1_BIT_gl_viewport            FLAG_BIT_0
252 #define _CLEAR_FLAG1_BIT_gl_current_program     FLAG_BIT_1
253 #define _CLEAR_FLAG1_BIT_gl_color_clear_value   FLAG_BIT_2
254
255         unsigned char           _clear_flag2;
256 #define _CLEAR_FLAG2_BIT_gl_color_writemask     FLAG_BIT_0
257 #define _CLEAR_FLAG2_BIT_gl_depth_range         FLAG_BIT_1
258 #define _CLEAR_FLAG2_BIT_gl_depth_clear_value   FLAG_BIT_2
259 #define _CLEAR_FLAG2_BIT_gl_depth_func          FLAG_BIT_3
260 #define _CLEAR_FLAG2_BIT_gl_depth_writemask     FLAG_BIT_4
261 #define _CLEAR_FLAG2_BIT_gl_cull_face_mode      FLAG_BIT_5
262
263         unsigned char           _tex_flag1;
264 #define _TEX_FLAG1_BIT_gl_active_texture         FLAG_BIT_0
265 #define _TEX_FLAG1_BIT_gl_generate_mipmap_hint   FLAG_BIT_1
266 #define _TEX_FLAG1_BIT_gl_tex_2d_state           FLAG_BIT_2
267 #define _TEX_FLAG1_BIT_gl_tex_3d_state           FLAG_BIT_3
268 #define _TEX_FLAG1_BIT_gl_tex_2d_array_state     FLAG_BIT_4
269 #define _TEX_FLAG1_BIT_gl_tex_cube_state         FLAG_BIT_5
270
271         unsigned char           _blend_flag;
272 #define _BLEND_FLAG_BIT_gl_blend_color           FLAG_BIT_0
273 #define _BLEND_FLAG_BIT_gl_blend_src_rgb         FLAG_BIT_1
274 #define _BLEND_FLAG_BIT_gl_blend_src_alpha       FLAG_BIT_2
275 #define _BLEND_FLAG_BIT_gl_blend_dst_rgb         FLAG_BIT_3
276 #define _BLEND_FLAG_BIT_gl_blend_dst_alpha       FLAG_BIT_4
277 #define _BLEND_FLAG_BIT_gl_blend_equation_rgb    FLAG_BIT_5
278 #define _BLEND_FLAG_BIT_gl_blend_equation_alpha  FLAG_BIT_6
279
280         unsigned char           _stencil_flag1;
281 #define _STENCIL_FLAG1_BIT_gl_stencil_func              FLAG_BIT_0
282 #define _STENCIL_FLAG1_BIT_gl_stencil_ref               FLAG_BIT_1
283 #define _STENCIL_FLAG1_BIT_gl_stencil_value_mask        FLAG_BIT_2
284 #define _STENCIL_FLAG1_BIT_gl_stencil_fail              FLAG_BIT_3
285 #define _STENCIL_FLAG1_BIT_gl_stencil_pass_depth_fail   FLAG_BIT_4
286 #define _STENCIL_FLAG1_BIT_gl_stencil_pass_depth_pass   FLAG_BIT_5
287 #define _STENCIL_FLAG1_BIT_gl_stencil_writemask         FLAG_BIT_6
288
289         unsigned char           _stencil_flag2;
290 #define _STENCIL_FLAG2_BIT_gl_stencil_back_func              FLAG_BIT_0
291 #define _STENCIL_FLAG2_BIT_gl_stencil_back_ref               FLAG_BIT_1
292 #define _STENCIL_FLAG2_BIT_gl_stencil_back_value_mask        FLAG_BIT_2
293 #define _STENCIL_FLAG2_BIT_gl_stencil_back_fail              FLAG_BIT_3
294 #define _STENCIL_FLAG2_BIT_gl_stencil_back_pass_depth_fail   FLAG_BIT_4
295 #define _STENCIL_FLAG2_BIT_gl_stencil_back_pass_depth_pass   FLAG_BIT_5
296 #define _STENCIL_FLAG2_BIT_gl_stencil_back_writemask         FLAG_BIT_6
297 #define _STENCIL_FLAG2_BIT_gl_stencil_clear_value            FLAG_BIT_7
298
299         unsigned char           _pixel_flag1;
300 #define _PIXEL_FLAG1_BIT_gl_pack_row_length      FLAG_BIT_0
301 #define _PIXEL_FLAG1_BIT_gl_pack_skip_rows       FLAG_BIT_1
302 #define _PIXEL_FLAG1_BIT_gl_pack_skip_pixels     FLAG_BIT_2
303 #define _PIXEL_FLAG1_BIT_gl_pack_alignment       FLAG_BIT_3
304
305         unsigned char           _pixel_flag2;
306 #define _PIXEL_FLAG2_BIT_gl_unpack_row_length      FLAG_BIT_0
307 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_rows       FLAG_BIT_1
308 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_pixels     FLAG_BIT_2
309 #define _PIXEL_FLAG2_BIT_gl_unpack_alignment       FLAG_BIT_3
310 #define _PIXEL_FLAG2_BIT_gl_unpack_image_height    FLAG_BIT_4
311 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_images     FLAG_BIT_5
312
313         unsigned char           _misc_flag1;
314 #define _MISC_FLAG1_BIT_gl_front_face                        FLAG_BIT_0
315 #define _MISC_FLAG1_BIT_gl_line_width                        FLAG_BIT_1
316 #define _MISC_FLAG1_BIT_gl_polygon_offset_factor             FLAG_BIT_2
317 #define _MISC_FLAG1_BIT_gl_polygon_offset_units              FLAG_BIT_3
318 #define _MISC_FLAG1_BIT_gl_sample_coverage_value             FLAG_BIT_4
319 #define _MISC_FLAG1_BIT_gl_sample_coverage_invert            FLAG_BIT_5
320 #define _MISC_FLAG1_BIT_gl_fragment_shader_derivative_hint   FLAG_BIT_6
321
322         unsigned char           _misc_flag2;
323 #define _MISC_FLAG2_BIT_gl_scissor_box                       FLAG_BIT_0
324
325         unsigned char           _misc_flag3;
326 #define _MISC_FLAG3_BIT_gl_read_buffer                       FLAG_BIT_0
327 #define _MISC_FLAG3_BIT_gl_draw_buffers                      FLAG_BIT_1
328 #define _MISC_FLAG3_BIT_gl_vertex_array_binding              FLAG_BIT_2
329 #define _MISC_FLAG3_BIT_gl_transform_feedback_binding        FLAG_BIT_3
330 #define _MISC_FLAG3_BIT_gl_transform_feedback                FLAG_BIT_4
331
332         unsigned char           _vattrib_flag;
333 #define _VATTRIB_FLAG_BIT_gl_vertex_attrib_value             FLAG_BIT_0
334 #define _VATTRIB_FLAG_BIT_gl_vertex_array                    FLAG_BIT_1
335
336         GL_Object_State         ostate;
337
338         GLenum                  gl_error;
339
340         // General state
341 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)     TYPE NAME[ARRAY_SIZE];
342 # include "coregl_fastpath_state.h"
343 #undef GLUE_STATE
344 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)     unsigned char NAME##_used;
345 # include "coregl_fastpath_state.h"
346 #undef GLUE_STATE
347
348 } GLGlueContext;
349
350 typedef struct _GLGlueContext_List
351 {
352         GLGlueContext              *gctx;
353         struct _GLGlueContext_List *prev;
354         struct _GLGlueContext_List *next;
355 } GLGlueContext_List;
356
357 extern GLGlueContext_List *gctx_list;
358
359 extern GLGlueContext *initial_ctx;
360
361 extern void                init_modules_fastpath();
362 extern void                deinit_modules_fastpath();
363 extern void                init_modules_tstate_fastpath(GLThreadState *tstate);
364 extern void                deinit_modules_tstate_fastpath(GLThreadState *tstate);
365
366 extern void                fastpath_apply_overrides();
367 extern void                fastpath_apply_overrides_egl(int enable);
368 extern void                fastpath_apply_overrides_gl(int enable);
369
370 extern int                 fastpath_init_context_states(GLGlueContext *ctx);
371 extern int                 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx);
372
373 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
374 extern void                fastpath_dump_context_states(GLGlueContext *ctx, int force_output);
375 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
376
377 // Context state functions
378 extern int                 fastpath_add_context_state_to_list(const void *data, const int datalen, GLContextState *cstate, Mutex *mtx);
379 extern int                 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx);
380 extern GLContextState     *fastpath_get_context_state_from_list(const void *data, const int datalen, Mutex *mtx);
381
382 // Shared object state functions
383 extern void                fastpath_ostate_init(GL_Object_State *ostate);
384 extern void                fastpath_sostate_init(GL_Shared_Object_State *ostate);
385 extern void                fastpath_ostate_deinit(GL_Object_State *ostate);
386 extern void                fastpath_sostate_deinit(GL_Shared_Object_State *ostate);
387 extern GLuint              fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type, GLuint name);
388 extern GLuint              fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
389 extern GLuint              fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type, GLuint name);
390 extern GLuint              fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name);
391 extern GLint               fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
392 extern GLint               fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag);
393 extern GLvoid             *fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
394
395 // GL context management functions
396 extern void                fastpath_release_gl_context(GLGlueContext *gctx);
397
398 // State query functions
399 extern void                fastpath_state_get_draw_buffers(GLenum *params);
400
401 #endif // COREGL_FASTPATH_H
402