From 45aecf01144341fa1c536f6d5131ae36c374066e Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 24 Jun 2011 12:13:02 +0900 Subject: st/egl: drop guess_gl_api from egl_g3d_loader It is not used and confusing. --- src/gallium/targets/egl-static/egl.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/gallium/targets/egl-static/egl.c') diff --git a/src/gallium/targets/egl-static/egl.c b/src/gallium/targets/egl-static/egl.c index e617ff50208..7e926cf0fa1 100644 --- a/src/gallium/targets/egl-static/egl.c +++ b/src/gallium/targets/egl-static/egl.c @@ -52,12 +52,6 @@ get_st_api(enum st_api_type api) return stmod->stapi; } -static struct st_api * -guess_gl_api(enum st_profile_type profile) -{ - return get_st_api(ST_API_OPENGL); -} - static struct pipe_screen * create_drm_screen(const char *name, int fd) { @@ -79,7 +73,6 @@ loader_init(void) egl_g3d_loader.profile_masks[i] = egl_st_get_profile_mask(i); egl_g3d_loader.get_st_api = get_st_api; - egl_g3d_loader.guess_gl_api = guess_gl_api; egl_g3d_loader.create_drm_screen = create_drm_screen; egl_g3d_loader.create_sw_screen = create_sw_screen; -- cgit v1.2.3 From a000745f80f695cfa0cd1dc206869eeb5f87f36f Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 20 Jun 2011 12:36:02 +0900 Subject: targets/egl-static: add support for driver lookup Use pci id to driver map to look up the driver name. This is based on a433755ec5c48088a0d8a340851a1a8be9e58897. --- src/gallium/targets/egl-static/egl.c | 82 ++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'src/gallium/targets/egl-static/egl.c') diff --git a/src/gallium/targets/egl-static/egl.c b/src/gallium/targets/egl-static/egl.c index 7e926cf0fa1..eee97a5ca05 100644 --- a/src/gallium/targets/egl-static/egl.c +++ b/src/gallium/targets/egl-static/egl.c @@ -28,6 +28,14 @@ #include "common/egl_g3d_loader.h" #include "egldriver.h" +#include "egllog.h" + +#ifdef HAVE_LIBUDEV +#include +#include +#define DRIVER_MAP_GALLIUM_ONLY +#include "pci_ids/pci_id_driver_map.h" +#endif #include "egl_pipe.h" #include "egl_st.h" @@ -52,9 +60,83 @@ get_st_api(enum st_api_type api) return stmod->stapi; } +static const char * +drm_fd_get_screen_name(int fd) +{ +#ifdef HAVE_LIBUDEV + struct udev *udev; + struct udev_device *device, *parent; + struct stat buf; + const char *pci_id; + int vendor_id, chip_id, idx = -1, i; + + udev = udev_new(); + if (fstat(fd, &buf) < 0) { + _eglLog(_EGL_WARNING, "failed to stat fd %d", fd); + return NULL; + } + + device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev); + if (device == NULL) { + _eglLog(_EGL_WARNING, + "could not create udev device for fd %d", fd); + return NULL; + } + + parent = udev_device_get_parent(device); + if (parent == NULL) { + _eglLog(_EGL_WARNING, "could not get parent device"); + goto out; + } + + pci_id = udev_device_get_property_value(parent, "PCI_ID"); + if (pci_id == NULL || + sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) { + _eglLog(_EGL_WARNING, "malformed or no PCI ID"); + goto out; + } + + /* find the driver index */ + for (idx = 0; driver_map[idx].driver; idx++) { + if (vendor_id != driver_map[idx].vendor_id) + continue; + + if (driver_map[idx].num_chips_ids == -1) + goto out; + + for (i = 0; i < driver_map[idx].num_chips_ids; i++) { + if (driver_map[idx].chip_ids[i] == chip_id) + goto out; + } + } + +out: + udev_device_unref(device); + udev_unref(udev); + + if (idx >= 0) { + _eglLog((driver_map[idx].driver) ? _EGL_INFO : _EGL_WARNING, + "pci id for fd %d: %04x:%04x, driver %s", + fd, vendor_id, chip_id, driver_map[idx].driver); + + return driver_map[idx].driver; + } +#endif + + _eglLog(_EGL_WARNING, "failed to get driver name for fd %d", fd); + + return NULL; +} + static struct pipe_screen * create_drm_screen(const char *name, int fd) { + if (!name) { + name = drm_fd_get_screen_name(fd); + if (!name) + return NULL; + } + return egl_pipe_create_drm_screen(name, fd); } -- cgit v1.2.3 From 7451bffad41a8ab7c61c9799b351c031852eb780 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 23 Jun 2011 20:08:53 +0900 Subject: targets/egl-static: allow st/mesa to be dynamically loaded When shared glapi is not enabled, there are two glapi providers and we cannot decide which one to link to at build time. It results in unresolved symbols in st/mesa. This commit makes st/mesa a loadable module when shared glapi is not enabled, and hopes that the apps will link to one of the glapi providers (GL or GLES). --- src/gallium/targets/egl-static/egl.c | 2 +- src/gallium/targets/egl-static/egl_st.c | 127 +++++++++++++++++++++++++++----- src/gallium/targets/egl-static/egl_st.h | 3 + src/gallium/targets/egl-static/st_GL.c | 35 +++++++++ 4 files changed, 148 insertions(+), 19 deletions(-) create mode 100644 src/gallium/targets/egl-static/st_GL.c (limited to 'src/gallium/targets/egl-static/egl.c') diff --git a/src/gallium/targets/egl-static/egl.c b/src/gallium/targets/egl-static/egl.c index eee97a5ca05..2caad0e1ee0 100644 --- a/src/gallium/targets/egl-static/egl.c +++ b/src/gallium/targets/egl-static/egl.c @@ -170,7 +170,7 @@ loader_fini(void) struct st_module *stmod = &st_modules[i]; if (stmod->stapi) { - stmod->stapi->destroy(stmod->stapi); + egl_st_destroy_api(stmod->stapi); stmod->stapi = NULL; } stmod->initialized = FALSE; diff --git a/src/gallium/targets/egl-static/egl_st.c b/src/gallium/targets/egl-static/egl_st.c index 3db52621def..81d7bb47568 100644 --- a/src/gallium/targets/egl-static/egl_st.c +++ b/src/gallium/targets/egl-static/egl_st.c @@ -29,52 +29,143 @@ #include "state_tracker/st_api.h" #include "egl_st.h" -/* for st/mesa */ +#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2 #include "state_tracker/st_gl_api.h" -/* for st/vega */ +#endif + +#if FEATURE_VG #include "vg_api.h" +#endif + +#if _EGL_EXTERNAL_GL + +#include "util/u_string.h" +#include "util/u_dl.h" +#include "egldriver.h" +#include "egllog.h" + +static struct util_dl_library *egl_st_gl_lib; + +static EGLBoolean +dlopen_gl_lib_cb(const char *dir, size_t len, void *callback_data) +{ + const char *name = (const char *) callback_data; + char path[1024]; + int ret; + + if (len) { + ret = util_snprintf(path, sizeof(path), "%.*s/%s" UTIL_DL_EXT, + len, dir, name); + } + else { + ret = util_snprintf(path, sizeof(path), "%s" UTIL_DL_EXT, name); + } + + if (ret > 0 && ret < sizeof(path)) { + egl_st_gl_lib = util_dl_open(path); + if (egl_st_gl_lib) + _eglLog(_EGL_DEBUG, "loaded %s", path); + } + + return !egl_st_gl_lib; +} static struct st_api * -st_GL_create_api(void) +load_gl(const char *name, const char *procname) { -#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2 - return st_gl_api_create(); -#else - return NULL; -#endif + struct st_api *(*create_api)(void); + struct st_api *stapi = NULL; + + _eglSearchPathForEach(dlopen_gl_lib_cb, (void *) name); + if (!egl_st_gl_lib) + return NULL; + + create_api = (struct st_api *(*)(void)) + util_dl_get_proc_address(egl_st_gl_lib, procname); + if (create_api) + stapi = create_api(); + + if (!stapi) { + util_dl_close(egl_st_gl_lib); + egl_st_gl_lib = NULL; + } + + return stapi; } static struct st_api * -st_OpenVG_create_api(void) +egl_st_load_gl(void) { -#if FEATURE_VG - return (struct st_api *) vg_api_get(); -#else - return NULL; -#endif + const char module[] = "st_GL"; + const char symbol[] = "st_api_create_OpenGL"; + struct st_api *stapi; + + stapi = load_gl(module, symbol); + + /* try again with libglapi.so loaded */ + if (!stapi) { + struct util_dl_library *glapi = util_dl_open("libglapi" UTIL_DL_EXT); + + if (glapi) { + _eglLog(_EGL_DEBUG, "retry with libglapi" UTIL_DL_EXT " loaded"); + + stapi = load_gl(module, symbol); + util_dl_close(glapi); + } + } + if (!stapi) + _eglLog(_EGL_WARNING, "unable to load %s" UTIL_DL_EXT, module); + + return stapi; } +#endif /* _EGL_EXTERNAL_GL */ + struct st_api * egl_st_create_api(enum st_api_type api) { - struct st_api *stapi; + struct st_api *stapi = NULL; switch (api) { case ST_API_OPENGL: - stapi = st_GL_create_api(); +#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2 +#if _EGL_EXTERNAL_GL + stapi = egl_st_load_gl(); +#else + stapi = st_gl_api_create(); +#endif +#endif break; case ST_API_OPENVG: - stapi = st_OpenVG_create_api(); +#if FEATURE_VG + stapi = (struct st_api *) vg_api_get(); +#endif break; default: assert(!"Unknown API Type\n"); - stapi = NULL; break; } return stapi; } +void +egl_st_destroy_api(struct st_api *stapi) +{ +#if _EGL_EXTERNAL_GL + boolean is_gl = (stapi->api == ST_API_OPENGL); + + stapi->destroy(stapi); + + if (is_gl) { + util_dl_close(egl_st_gl_lib); + egl_st_gl_lib = NULL; + } +#else + stapi->destroy(stapi); +#endif +} + uint egl_st_get_profile_mask(enum st_api_type api) { diff --git a/src/gallium/targets/egl-static/egl_st.h b/src/gallium/targets/egl-static/egl_st.h index ba82faf0b0e..7a3773c6ba2 100644 --- a/src/gallium/targets/egl-static/egl_st.h +++ b/src/gallium/targets/egl-static/egl_st.h @@ -34,6 +34,9 @@ struct st_api * egl_st_create_api(enum st_api_type api); +void +egl_st_destroy_api(struct st_api *stapi); + uint egl_st_get_profile_mask(enum st_api_type api); diff --git a/src/gallium/targets/egl-static/st_GL.c b/src/gallium/targets/egl-static/st_GL.c new file mode 100644 index 00000000000..d9ca834c267 --- /dev/null +++ b/src/gallium/targets/egl-static/st_GL.c @@ -0,0 +1,35 @@ +/* + * Mesa 3-D graphics library + * Version: 7.10 + * + * Copyright (C) 2011 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ +#include "state_tracker/st_gl_api.h" +#include "pipe/p_compiler.h" + +PUBLIC struct st_api * +st_api_create_OpenGL(void) +{ + return st_gl_api_create(); +} -- cgit v1.2.3 From 450f48627684c6ea1472b4fdd51c6fc121f2bc9c Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 26 Jun 2011 07:58:16 +0900 Subject: targets/egl-static: refactor drm_fd_get_screen_name Add drm_fd_get_pci_id to get the PCI ID. Fix a leak with udev on error. --- src/gallium/targets/egl-static/egl.c | 81 +++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 28 deletions(-) (limited to 'src/gallium/targets/egl-static/egl.c') diff --git a/src/gallium/targets/egl-static/egl.c b/src/gallium/targets/egl-static/egl.c index 2caad0e1ee0..9b59ebd60f2 100644 --- a/src/gallium/targets/egl-static/egl.c +++ b/src/gallium/targets/egl-static/egl.c @@ -31,7 +31,7 @@ #include "egllog.h" #ifdef HAVE_LIBUDEV -#include +#include /* for sscanf */ #include #define DRIVER_MAP_GALLIUM_ONLY #include "pci_ids/pci_id_driver_map.h" @@ -60,27 +60,29 @@ get_st_api(enum st_api_type api) return stmod->stapi; } -static const char * -drm_fd_get_screen_name(int fd) -{ #ifdef HAVE_LIBUDEV - struct udev *udev; - struct udev_device *device, *parent; + +static boolean +drm_fd_get_pci_id(int fd, int *vendor_id, int *chip_id) +{ + struct udev *udev = NULL; + struct udev_device *device = NULL, *parent; struct stat buf; const char *pci_id; - int vendor_id, chip_id, idx = -1, i; + + *chip_id = -1; udev = udev_new(); if (fstat(fd, &buf) < 0) { _eglLog(_EGL_WARNING, "failed to stat fd %d", fd); - return NULL; + goto out; } device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev); if (device == NULL) { _eglLog(_EGL_WARNING, "could not create udev device for fd %d", fd); - return NULL; + goto out; } parent = udev_device_get_parent(device); @@ -91,41 +93,64 @@ drm_fd_get_screen_name(int fd) pci_id = udev_device_get_property_value(parent, "PCI_ID"); if (pci_id == NULL || - sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) { + sscanf(pci_id, "%x:%x", vendor_id, chip_id) != 2) { _eglLog(_EGL_WARNING, "malformed or no PCI ID"); + *chip_id = -1; goto out; } - /* find the driver index */ +out: + if (device) + udev_device_unref(device); + if (udev) + udev_unref(udev); + + return (*chip_id >= 0); +} + +#else + +static boolean +drm_fd_get_pci_id(int fd, int *vendor_id, int *chip_id) +{ + return FALSE; +} + +#endif /* HAVE_LIBUDEV */ + +static const char * +drm_fd_get_screen_name(int fd) +{ + int vendor_id, chip_id; + int idx, i; + + if (!drm_fd_get_pci_id(fd, &vendor_id, &chip_id)) { + _eglLog(_EGL_WARNING, "failed to get driver name for fd %d", fd); + return NULL; + } + for (idx = 0; driver_map[idx].driver; idx++) { if (vendor_id != driver_map[idx].vendor_id) continue; + /* done if no chip id */ if (driver_map[idx].num_chips_ids == -1) - goto out; + break; for (i = 0; i < driver_map[idx].num_chips_ids; i++) { if (driver_map[idx].chip_ids[i] == chip_id) - goto out; + break; } + /* matched! */ + if (i < driver_map[idx].num_chips_ids) + break; } -out: - udev_device_unref(device); - udev_unref(udev); - - if (idx >= 0) { - _eglLog((driver_map[idx].driver) ? _EGL_INFO : _EGL_WARNING, - "pci id for fd %d: %04x:%04x, driver %s", - fd, vendor_id, chip_id, driver_map[idx].driver); - - return driver_map[idx].driver; - } -#endif - - _eglLog(_EGL_WARNING, "failed to get driver name for fd %d", fd); + _eglLog((driver_map[idx].driver) ? _EGL_INFO : _EGL_WARNING, + "pci id for fd %d: %04x:%04x, driver %s", + fd, vendor_id, chip_id, driver_map[idx].driver); - return NULL; + return driver_map[idx].driver; } static struct pipe_screen * -- cgit v1.2.3 From a1cadf2b5c3b8f2e33207e81ee4d1476b5f87805 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 26 Jun 2011 18:03:15 +0900 Subject: targets/egl-static: fix building without libudev MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to José for pointing out. --- src/gallium/targets/egl-static/egl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gallium/targets/egl-static/egl.c') diff --git a/src/gallium/targets/egl-static/egl.c b/src/gallium/targets/egl-static/egl.c index 9b59ebd60f2..568f5498dd4 100644 --- a/src/gallium/targets/egl-static/egl.c +++ b/src/gallium/targets/egl-static/egl.c @@ -33,9 +33,10 @@ #ifdef HAVE_LIBUDEV #include /* for sscanf */ #include +#endif + #define DRIVER_MAP_GALLIUM_ONLY #include "pci_ids/pci_id_driver_map.h" -#endif #include "egl_pipe.h" #include "egl_st.h" -- cgit v1.2.3