4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
8 * Vitaliy Cherepanov <v.cherepanov@samsung.com>
10 * This library is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU Lesser General Public License as published by the
12 * Free Software Foundation; either version 2.1 of the License, or (at your option)
15 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
16 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software Foundation, Inc., 51
22 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 #include "da_gles20.h"
32 #include "common_probe_init.h"
33 #include "real_functions.h"
36 Evas_GL_API *__gl_api;
37 void (*real_glGetVertexAttribfv)(GLuint index, GLenum pname, GLfloat *params);
38 void (*real_glGetIntegerv)(GLenum pname, GLint * params);
39 void (*real_glGetProgramiv)(GLuint program, GLenum pname, GLint *params);
40 void (*real_glGetShaderiv)(GLuint shader, GLenum pname, GLint *params);
41 void (*real_glGetActiveAttrib)(GLuint program, GLuint index, GLsizei bufSize,
42 GLsizei *length, GLint *size, GLenum *type,
44 void (*real_glGetActiveUniform)(GLuint program, GLuint index, GLsizei bufSize,
45 GLsizei *length, GLint *size, GLenum *type,
47 void (*real_glGetShaderSource)(GLuint shader, GLsizei bufSize, GLsizei *length,
49 void (*real_glGetBufferParameteriv)(GLenum target, GLenum value, GLint *data);
51 void __gl_dummy_function()
53 PRINTERR("call of dummy gl function!!!");
56 void set_real_func(const char *func_name, void **func_pointer,
62 if (lib_handle[id] == NULL)
63 lib_handle[id] = dlopen(lib_string[id], RTLD_LAZY);
68 probe_terminate_with_err("dlopen failed", func_name, id);
70 faddr = dlsym(_id, func_name);
71 if (faddr == NULL || dlerror() != NULL) {
72 PRINTWRN("[set_real_function] function <%s> not found in lib <%s>; dummy function will be seted",
73 func_name, lib_string[id]);
74 faddr = __gl_dummy_function;
77 memcpy(func_pointer, &faddr, sizeof(faddr));
80 #define INIT_REAL_GL(func)\
82 set_real_func(#func, (void **)&real##_##func, LIBGLES20); \
85 int __init_gl_functions__(void)
90 /* init real call functions */
91 INIT_REAL_GL(glGetVertexAttribfv);
92 INIT_REAL_GL(glGetProgramiv);
93 INIT_REAL_GL(glGetShaderiv);
94 INIT_REAL_GL(glGetActiveAttrib);
95 INIT_REAL_GL(glGetActiveUniform);
96 INIT_REAL_GL(glGetShaderSource);
97 INIT_REAL_GL(glGetIntegerv);
98 INIT_REAL_GL(glGetBufferParameteriv);
103 void probe_terminate_with_err(const char *msg, const char *func_name,
106 char error_msg[1024];
107 const char *lib_name = "unknown";
109 if (id != LIB_NO && id < NUM_ORIGINAL_LIBRARY)
110 lib_name = lib_string[id];
111 snprintf(error_msg, sizeof(error_msg), "%s : [%s], %s\n", msg,
112 func_name, lib_name);
120 ////////////////////////////////////////////////////////////////////////////
121 //egl init probe function
123 // func_name - original function name for dlsym search
124 // func_pointer - original function pointer (return)
127 // search original function by name
128 // function have no return becouse on error it terminates main application
136 void init_probe_egl(__attribute__ ((unused))const char *func_name, void **func_pointer,
137 __attribute__ ((unused))ORIGINAL_LIBRARY id)
140 *func_pointer = (void *)dummy;
143 void init_probe_egl(const char *func_name, void **func_pointer,
148 (gProbeBlockCount++);
149 if (lib_handle[id] == ((void *)0)) {
150 lib_handle[id] = dlopen(lib_string[id],
151 RTLD_LAZY | RTLD_GLOBAL);
153 if (lib_handle[id] == ((void *)0))
154 probe_terminate_with_err("dlopen failed", func_name, id);
156 faddr = dlsym(lib_handle[id], func_name);
157 if (faddr == NULL || dlerror() != NULL)
158 probe_terminate_with_err("dlsym failed", func_name, id);
159 memcpy(func_pointer, &faddr, sizeof(faddr));
160 (gProbeBlockCount--);
164 void init_probe_gl(const char *func_name, void **func_pointer,
165 ORIGINAL_LIBRARY id, int blockresult, int32_t vAPI_ID)
168 probeInfo_t tempProbeInfo;
171 if (lib_handle[id] == ((void *)0)) {
172 lib_handle[id] = dlopen(lib_string[id], RTLD_LAZY);
173 if (lib_handle[id] == ((void *)0))
174 probe_terminate_with_err("dlopen failed", func_name,
177 setProbePoint(&tempProbeInfo);
178 if (blockresult != 0) {
180 char maxValString[64];
182 real_glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVal[0]);
183 real_glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
185 snprintf(maxValString, sizeof(maxValString), "%d,%d", maxVal[0], maxVal[1]);
187 PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, "", 0);
188 PACK_COMMON_END('p', 1, 0, 0);
189 PACK_GL_ADD(APITYPE_INIT, 0, maxValString);
194 faddr = dlsym(lib_handle[id], func_name);
195 if (faddr == NULL || dlerror() != NULL)
196 probe_terminate_with_err("function not found in lib", func_name,
199 memcpy(func_pointer, &faddr, sizeof(faddr));