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