tizen 2.4 release
[framework/graphics/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_flag1;
220 #define _BIND_FLAG1_BIT_gl_array_buffer_binding               FLAG_BIT_0
221 #define _BIND_FLAG1_BIT_gl_element_array_buffer_binding       FLAG_BIT_1
222 #define _BIND_FLAG1_BIT_gl_framebuffer_binding                FLAG_BIT_2
223 #define _BIND_FLAG1_BIT_gl_renderbuffer_binding               FLAG_BIT_3
224 #define _BIND_FLAG1_BIT_gl_framebuffer_binding_read           FLAG_BIT_4
225 #define _BIND_FLAG1_BIT_gl_framebuffer_binding_draw           FLAG_BIT_5
226
227         unsigned char           _bind_flag2;
228 #define _BIND_FLAG2_BIT_gl_copy_read_buffer_binding           FLAG_BIT_0
229 #define _BIND_FLAG2_BIT_gl_copy_write_buffer_binding          FLAG_BIT_1
230 #define _BIND_FLAG2_BIT_gl_pixel_pack_buffer_binding          FLAG_BIT_2
231 #define _BIND_FLAG2_BIT_gl_pixel_unpack_buffer_binding        FLAG_BIT_3
232 #define _BIND_FLAG2_BIT_gl_transform_feedback_buffer_binding  FLAG_BIT_4
233 #define _BIND_FLAG2_BIT_gl_uniform_buffer_binding             FLAG_BIT_5
234
235         unsigned char           _enable_flag1;
236 #define _ENABLE_FLAG1_BIT_gl_blend        FLAG_BIT_0
237 #define _ENABLE_FLAG1_BIT_gl_cull_face    FLAG_BIT_1
238 #define _ENABLE_FLAG1_BIT_gl_depth_test   FLAG_BIT_2
239 #define _ENABLE_FLAG1_BIT_gl_dither       FLAG_BIT_3
240
241         unsigned char           _enable_flag2;
242 #define _ENABLE_FLAG2_BIT_gl_polygon_offset_fill       FLAG_BIT_0
243 #define _ENABLE_FLAG2_BIT_gl_sample_alpha_to_coverage  FLAG_BIT_1
244 #define _ENABLE_FLAG2_BIT_gl_sample_coverage           FLAG_BIT_2
245 #define _ENABLE_FLAG2_BIT_gl_scissor_test              FLAG_BIT_3
246 #define _ENABLE_FLAG2_BIT_gl_stencil_test              FLAG_BIT_4
247
248         unsigned char           _enable_flag3;
249 #define _ENABLE_FLAG3_BIT_gl_primitive_restart_fixed_index  FLAG_BIT_0
250 #define _ENABLE_FLAG3_BIT_gl_rasterizer_discard             FLAG_BIT_1
251
252         unsigned char           _clear_flag1;
253 #define _CLEAR_FLAG1_BIT_gl_viewport            FLAG_BIT_0
254 #define _CLEAR_FLAG1_BIT_gl_current_program     FLAG_BIT_1
255 #define _CLEAR_FLAG1_BIT_gl_color_clear_value   FLAG_BIT_2
256
257         unsigned char           _clear_flag2;
258 #define _CLEAR_FLAG2_BIT_gl_color_writemask     FLAG_BIT_0
259 #define _CLEAR_FLAG2_BIT_gl_depth_range         FLAG_BIT_1
260 #define _CLEAR_FLAG2_BIT_gl_depth_clear_value   FLAG_BIT_2
261 #define _CLEAR_FLAG2_BIT_gl_depth_func          FLAG_BIT_3
262 #define _CLEAR_FLAG2_BIT_gl_depth_writemask     FLAG_BIT_4
263 #define _CLEAR_FLAG2_BIT_gl_cull_face_mode      FLAG_BIT_5
264
265         unsigned char           _tex_flag1;
266 #define _TEX_FLAG1_BIT_gl_active_texture         FLAG_BIT_0
267 #define _TEX_FLAG1_BIT_gl_generate_mipmap_hint   FLAG_BIT_1
268 #define _TEX_FLAG1_BIT_gl_tex_2d_state           FLAG_BIT_2
269 #define _TEX_FLAG1_BIT_gl_tex_3d_state           FLAG_BIT_3
270 #define _TEX_FLAG1_BIT_gl_tex_2d_array_state     FLAG_BIT_4
271 #define _TEX_FLAG1_BIT_gl_tex_cube_state         FLAG_BIT_5
272 #define _TEX_FLAG1_BIT_gl_tex_external_oes_state FLAG_BIT_6
273
274         unsigned char           _blend_flag;
275 #define _BLEND_FLAG_BIT_gl_blend_color           FLAG_BIT_0
276 #define _BLEND_FLAG_BIT_gl_blend_src_rgb         FLAG_BIT_1
277 #define _BLEND_FLAG_BIT_gl_blend_src_alpha       FLAG_BIT_2
278 #define _BLEND_FLAG_BIT_gl_blend_dst_rgb         FLAG_BIT_3
279 #define _BLEND_FLAG_BIT_gl_blend_dst_alpha       FLAG_BIT_4
280 #define _BLEND_FLAG_BIT_gl_blend_equation_rgb    FLAG_BIT_5
281 #define _BLEND_FLAG_BIT_gl_blend_equation_alpha  FLAG_BIT_6
282
283         unsigned char           _stencil_flag1;
284 #define _STENCIL_FLAG1_BIT_gl_stencil_func              FLAG_BIT_0
285 #define _STENCIL_FLAG1_BIT_gl_stencil_ref               FLAG_BIT_1
286 #define _STENCIL_FLAG1_BIT_gl_stencil_value_mask        FLAG_BIT_2
287 #define _STENCIL_FLAG1_BIT_gl_stencil_fail              FLAG_BIT_3
288 #define _STENCIL_FLAG1_BIT_gl_stencil_pass_depth_fail   FLAG_BIT_4
289 #define _STENCIL_FLAG1_BIT_gl_stencil_pass_depth_pass   FLAG_BIT_5
290 #define _STENCIL_FLAG1_BIT_gl_stencil_writemask         FLAG_BIT_6
291
292         unsigned char           _stencil_flag2;
293 #define _STENCIL_FLAG2_BIT_gl_stencil_back_func              FLAG_BIT_0
294 #define _STENCIL_FLAG2_BIT_gl_stencil_back_ref               FLAG_BIT_1
295 #define _STENCIL_FLAG2_BIT_gl_stencil_back_value_mask        FLAG_BIT_2
296 #define _STENCIL_FLAG2_BIT_gl_stencil_back_fail              FLAG_BIT_3
297 #define _STENCIL_FLAG2_BIT_gl_stencil_back_pass_depth_fail   FLAG_BIT_4
298 #define _STENCIL_FLAG2_BIT_gl_stencil_back_pass_depth_pass   FLAG_BIT_5
299 #define _STENCIL_FLAG2_BIT_gl_stencil_back_writemask         FLAG_BIT_6
300 #define _STENCIL_FLAG2_BIT_gl_stencil_clear_value            FLAG_BIT_7
301
302         unsigned char           _pixel_flag1;
303 #define _PIXEL_FLAG1_BIT_gl_pack_row_length      FLAG_BIT_0
304 #define _PIXEL_FLAG1_BIT_gl_pack_skip_rows       FLAG_BIT_1
305 #define _PIXEL_FLAG1_BIT_gl_pack_skip_pixels     FLAG_BIT_2
306 #define _PIXEL_FLAG1_BIT_gl_pack_alignment       FLAG_BIT_3
307
308         unsigned char           _pixel_flag2;
309 #define _PIXEL_FLAG2_BIT_gl_unpack_row_length      FLAG_BIT_0
310 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_rows       FLAG_BIT_1
311 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_pixels     FLAG_BIT_2
312 #define _PIXEL_FLAG2_BIT_gl_unpack_alignment       FLAG_BIT_3
313 #define _PIXEL_FLAG2_BIT_gl_unpack_image_height    FLAG_BIT_4
314 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_images     FLAG_BIT_5
315
316         unsigned char           _misc_flag1;
317 #define _MISC_FLAG1_BIT_gl_front_face                        FLAG_BIT_0
318 #define _MISC_FLAG1_BIT_gl_line_width                        FLAG_BIT_1
319 #define _MISC_FLAG1_BIT_gl_polygon_offset_factor             FLAG_BIT_2
320 #define _MISC_FLAG1_BIT_gl_polygon_offset_units              FLAG_BIT_3
321 #define _MISC_FLAG1_BIT_gl_sample_coverage_value             FLAG_BIT_4
322 #define _MISC_FLAG1_BIT_gl_sample_coverage_invert            FLAG_BIT_5
323 #define _MISC_FLAG1_BIT_gl_fragment_shader_derivative_hint   FLAG_BIT_6
324
325         unsigned char           _misc_flag2;
326 #define _MISC_FLAG2_BIT_gl_scissor_box                       FLAG_BIT_0
327
328         unsigned char           _misc_flag3;
329 #define _MISC_FLAG3_BIT_gl_read_buffer                       FLAG_BIT_0
330 #define _MISC_FLAG3_BIT_gl_draw_buffers                      FLAG_BIT_1
331 #define _MISC_FLAG3_BIT_gl_vertex_array_binding              FLAG_BIT_2
332 #define _MISC_FLAG3_BIT_gl_transform_feedback_binding        FLAG_BIT_3
333 #define _MISC_FLAG3_BIT_gl_transform_feedback                FLAG_BIT_4
334
335         unsigned char           _vattrib_flag;
336 #define _VATTRIB_FLAG_BIT_gl_vertex_attrib_value             FLAG_BIT_0
337 #define _VATTRIB_FLAG_BIT_gl_vertex_array                    FLAG_BIT_1
338
339         GL_Object_State         ostate;
340
341         GLenum                  gl_error;
342
343         // General state
344 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)     TYPE NAME[ARRAY_SIZE];
345 # include "coregl_fastpath_state.h"
346 #undef GLUE_STATE
347 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)     unsigned char NAME##_used;
348 # include "coregl_fastpath_state.h"
349 #undef GLUE_STATE
350
351 } GLGlueContext;
352
353 typedef struct _GLGlueContext_List
354 {
355         GLGlueContext              *gctx;
356         struct _GLGlueContext_List *prev;
357         struct _GLGlueContext_List *next;
358 } GLGlueContext_List;
359
360 extern GLGlueContext_List *gctx_list;
361
362 extern GLGlueContext *initial_ctx;
363
364 extern void                init_modules_fastpath();
365 extern void                deinit_modules_fastpath();
366 extern void                init_modules_tstate_fastpath(GLThreadState *tstate);
367 extern void                deinit_modules_tstate_fastpath(GLThreadState *tstate);
368
369 extern void                fastpath_apply_overrides();
370 extern void                fastpath_apply_overrides_egl(int enable);
371 extern void                fastpath_apply_overrides_gl(int enable);
372
373 extern int                 fastpath_init_context_states(GLGlueContext *ctx);
374 extern int                 fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx);
375
376 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
377 extern void                fastpath_dump_context_states(GLGlueContext *ctx, int force_output);
378 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
379
380 // Context state functions
381 extern int                 fastpath_add_context_state_to_list(const void *data, const int datalen, GLContextState *cstate, Mutex *mtx);
382 extern int                 fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx);
383 extern GLContextState     *fastpath_get_context_state_from_list(const void *data, const int datalen, Mutex *mtx);
384
385 // Shared object state functions
386 extern void                fastpath_ostate_init(GL_Object_State *ostate);
387 extern void                fastpath_sostate_init(GL_Shared_Object_State *ostate);
388 extern void                fastpath_ostate_deinit(GL_Object_State *ostate);
389 extern void                fastpath_sostate_deinit(GL_Shared_Object_State *ostate);
390 extern GLuint              fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type, GLuint name);
391 extern GLuint              fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
392 extern GLuint              fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type, GLuint name);
393 extern GLuint              fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name);
394 extern GLint               fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
395 extern GLint               fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag);
396 extern GLvoid             *fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
397
398 // GL context management functions
399 extern void                fastpath_release_gl_context(GLGlueContext *gctx);
400
401 // State query functions
402 extern void                fastpath_state_get_draw_buffers(GLenum *params);
403
404 #endif // COREGL_FASTPATH_H
405