2 * Mesa 3-D graphics library
5 * Copyright (C) 2011 LunarG Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Chia-I Wu <olv@lunarg.com>
28 #include "util/u_debug.h"
29 #include "state_tracker/st_api.h"
32 #if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2
33 #include "state_tracker/st_gl_api.h"
42 #include "util/u_string.h"
43 #include "util/u_dl.h"
44 #include "egldriver.h"
47 static struct util_dl_library
*egl_st_gl_lib
;
50 dlopen_gl_lib_cb(const char *dir
, size_t len
, void *callback_data
)
52 const char *name
= (const char *) callback_data
;
57 assert(len
<= INT_MAX
&& "path is insanely long!");
58 ret
= util_snprintf(path
, sizeof(path
), "%.*s/%s" UTIL_DL_EXT
,
62 ret
= util_snprintf(path
, sizeof(path
), "%s" UTIL_DL_EXT
, name
);
65 if (ret
> 0 && ret
< sizeof(path
)) {
66 egl_st_gl_lib
= util_dl_open(path
);
68 _eglLog(_EGL_DEBUG
, "loaded %s", path
);
71 return !egl_st_gl_lib
;
74 static struct st_api
*
75 load_gl(const char *name
, const char *procname
)
77 struct st_api
*(*create_api
)(void);
78 struct st_api
*stapi
= NULL
;
80 _eglSearchPathForEach(dlopen_gl_lib_cb
, (void *) name
);
84 create_api
= (struct st_api
*(*)(void))
85 util_dl_get_proc_address(egl_st_gl_lib
, procname
);
90 util_dl_close(egl_st_gl_lib
);
97 static struct st_api
*
100 const char module
[] = "st_GL";
101 const char symbol
[] = "st_api_create_OpenGL";
102 struct st_api
*stapi
;
104 stapi
= load_gl(module
, symbol
);
106 /* try again with libglapi.so loaded */
108 struct util_dl_library
*glapi
= util_dl_open("libglapi" UTIL_DL_EXT
);
111 _eglLog(_EGL_DEBUG
, "retry with libglapi" UTIL_DL_EXT
" loaded");
113 stapi
= load_gl(module
, symbol
);
114 util_dl_close(glapi
);
118 _eglLog(_EGL_WARNING
, "unable to load %s" UTIL_DL_EXT
, module
);
123 #endif /* _EGL_EXTERNAL_GL */
126 egl_st_create_api(enum st_api_type api
)
128 struct st_api
*stapi
= NULL
;
132 #if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2
134 stapi
= egl_st_load_gl();
136 stapi
= st_gl_api_create();
142 stapi
= (struct st_api
*) vg_api_get();
146 assert(!"Unknown API Type\n");
154 egl_st_destroy_api(struct st_api
*stapi
)
157 boolean is_gl
= (stapi
->api
== ST_API_OPENGL
);
159 stapi
->destroy(stapi
);
162 util_dl_close(egl_st_gl_lib
);
163 egl_st_gl_lib
= NULL
;
166 stapi
->destroy(stapi
);
171 egl_st_get_profile_mask(enum st_api_type api
)
178 mask
|= ST_PROFILE_DEFAULT_MASK
;
181 mask
|= ST_PROFILE_OPENGL_ES1_MASK
;
184 mask
|= ST_PROFILE_OPENGL_ES2_MASK
;
189 mask
|= ST_PROFILE_DEFAULT_MASK
;