[FIX] malloc probing from ld lib
[platform/core/system/swap-probe.git] / probe_graphics / da_gl_api_init.c
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Vitaliy Cherepanov <v.cherepanov@samsung.com>
9  *
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)
13  * any later version.
14  *
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.
19  *
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
23  *
24  * Contributors:
25  * - S-Core Co., Ltd
26  *
27  */
28
29 #include <unistd.h>
30 #include "da_gles20.h"
31 #include "binproto.h"
32 #include "common_probe_init.h"
33 #include "real_functions.h"
34
35 /* GL __local_* functions prototypes */
36 #define X(func) extern void __local_##func(void);
37 #include "da_gl_api_func_list.h"
38         GL_ALL_FUNCTIONS;
39 #undef X
40 /* --------------------------------- */
41
42
43 static bool __gl_api_initialized = 0;
44 Evas_GL_API *__gl_api = NULL;
45
46 void __init_gl_api__(void)
47 {
48         if (__gl_api == NULL)
49                 __gl_api = real_malloc(sizeof(*__gl_api));
50         memset(__gl_api, 0, sizeof(*__gl_api));
51 }
52
53 void save_orig_gl_api_list(Evas_GL_API *api)
54 {
55         /* TODO make this check more pretty */
56         if (__gl_api_initialized == 0) {
57                 memcpy(__gl_api, api, sizeof(*api));
58                 __gl_api_initialized = 1;
59         }
60 }
61
62 /* IMPORTANT this code must be right before change_gl_api_list function!
63  *
64  * next define is GL api replacing by probe functions
65  *
66  */
67 #define X(func) \
68         do {                                                    \
69                 api->func = (typeof(api->func)) __local_##func; \
70                 if (api->func == NULL)                          \
71                         PRINTWRN("api->%s not setted", #func);  \
72         } while(0);
73 #include "da_gl_api_func_list.h"
74 /* --------------------------------------------------------------------- */
75
76 void change_gl_api_list(Evas_GL_API *api)
77 {
78         /* change links */
79         GL_ALL_FUNCTIONS;
80 }
81
82 #undef X