Add fpgl-call error handling when makecurrent=null (instead of assertion)
[platform/core/uifw/coregl.git] / src / coregl_wrappath.c
1 #include "coregl_wrappath.h"
2
3 #include <stdlib.h>
4 #include <string.h>
5 #include <sys/time.h>
6
7 // Symbol definition for override
8 #define _COREGL_SYMBOL(IS_EXTENSION, RET_TYPE, FUNC_NAME, PARAM_LIST)     RET_TYPE (*_COREGL_NAME_MANGLE(FUNC_NAME)) PARAM_LIST = NULL;
9 #include "headers/sym.h"
10 #undef _COREGL_SYMBOL
11
12 typedef struct _GLGlueFakeContext
13 {
14         GLuint gl_num_tex_units[1];
15         GLuint gl_num_vertex_attribs[1];
16 } GLGlueFakeContext;
17
18 GLGlueFakeContext initial_fake_ctx_real;
19 GLGlueFakeContext *initial_fake_ctx = &initial_fake_ctx_real;
20
21
22 static void
23 _get_texture_states(GLenum pname, GLint *params)
24 {
25         GLuint cur_active_tex = 0;
26
27         AST(initial_fake_ctx != NULL);
28
29         _sym_glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *)&cur_active_tex);
30         int i;
31         for (i = 0; i < initial_fake_ctx->gl_num_tex_units[0]; i++)
32         {
33                 _sym_glActiveTexture(GL_TEXTURE0 + i);
34                 _sym_glGetIntegerv(pname, &(((GLint *)params)[i]));
35         }
36         _sym_glActiveTexture(cur_active_tex);
37 }
38
39 void
40 init_wrap_gl()
41 {
42 }
43
44 void
45 free_wrap_gl()
46 {
47 }
48
49 void
50 dump_wrap_context_states(int force_output)
51 {
52         static struct timeval tv_last = { 0, 0 };
53
54         if (trace_state_flag != 1) return;
55
56         _sym_glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, (GLint *)initial_fake_ctx->gl_num_tex_units);
57         _sym_glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, (GLint *)initial_fake_ctx->gl_num_vertex_attribs);
58
59         if (!force_output)
60         {
61                 struct timeval tv_now = { 0, 0 };
62                 AST(gettimeofday(&tv_now, NULL) == 0);
63                 if (tv_now.tv_sec - tv_last.tv_sec < _COREGL_TRACE_OUTPUT_INTERVAL_SEC)
64                 {
65                         goto finish;
66                 }
67                 tv_last = tv_now;
68         }
69
70         LOG("\n");
71         LOG("\E[0;40;34m===================================================================================================================\E[0m\n");
72         LOG("\E[0;32;1m  State info \E[1;37;1m: (CURRENT BINDED CONTEXT)\E[0m\n");
73         LOG("\E[0;40;34m===================================================================================================================\E[0m\n");
74
75 #define PRINTF_CHAR_GLenum "%10d"
76 #define PRINTF_CHAR_GLboolean "%10d"
77 #define PRINTF_CHAR_GLint "%10d"
78 #define PRINTF_CHAR_GLsizei "%10u"
79 #define PRINTF_CHAR_GLuint "%10u"
80 #define PRINTF_CHAR_GLuintmask "0x%8X"
81
82 #define PRINTF_CHAR_GLclampf "%10.6f"
83 #define PRINTF_CHAR_GLfloat "%10.6f"
84
85 #define PRINTF_CHAR_GLvoidptr "%10p"
86
87 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
88
89 #define INITIAL_CTX initial_fake_ctx
90
91 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)  \
92    { \
93       TYPE valuedata[SIZE]; \
94       TYPE *value = NULL; \
95       value = valuedata; GET_STMT; value = valuedata; \
96       LOG("\E[0;37;1m %-30.30s : (\E[0m ", #NAME); \
97       for (int i = 0; i < SIZE; i++) \
98       { \
99          if (i > 0) { \
100             if (i % 4 == 0) \
101                LOG("\n %-30.30s     ", "");\
102             else \
103                LOG(", "); \
104          } \
105          LOG("["PRINTF_CHAR(TYPE)"]", value[i]); \
106       } \
107       LOG(" \E[0;37;1m)\E[0m\n"); \
108    }
109 # include "coregl_fastpath_state.h"
110 #undef GLUE_STATE
111
112         LOG("\E[0;40;34m===================================================================================================================\E[0m\n");
113         LOG("\n");
114
115 finish:
116         return;
117 }
118