summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/egl/common/egl_g3d.c
diff options
context:
space:
mode:
authorChia-I Wu <olv@lunarg.com>2010-06-29 14:58:33 +0800
committerChia-I Wu <olv@lunarg.com>2010-06-29 17:16:20 +0800
commitd5ab243d5a5bacbd2ba615d40f13c8ab37364745 (patch)
treebbf3c92d3c512e0d12eab3a7036c60c8e2cf7171 /src/gallium/state_trackers/egl/common/egl_g3d.c
parentd8e0e114567ec19fd59f974080a418dc959cc9b6 (diff)
st/egl: Move module loading code to targets.
Several changes are made. libegl.a no longer defines _eglMain. It defines functions to create and destroy a _EGLDriver instead. The creation function is called by the targets. It takes an egl_g3d_loader as its argument. The loader is defined by the targets and is in charge of creating st_api and pipe_screen. This allows us to move the module loading code to targets. Lastly, the modules are now loaded as the respective contexts are created.
Diffstat (limited to 'src/gallium/state_trackers/egl/common/egl_g3d.c')
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d.c112
1 files changed, 52 insertions, 60 deletions
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c
index 36354dd42e..494d6dd8b6 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.c
@@ -35,34 +35,10 @@
#include "egl_g3d.h"
#include "egl_g3d_api.h"
#include "egl_g3d_st.h"
+#include "egl_g3d_loader.h"
#include "native.h"
/**
- * Initialize the state trackers.
- */
-static void
-egl_g3d_init_st(_EGLDriver *drv)
-{
- struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
- EGLint i;
-
- /* already initialized */
- if (gdrv->api_mask)
- return;
-
- egl_g3d_init_st_apis(gdrv->stapis);
- for (i = 0; i < ST_API_COUNT; i++) {
- if (gdrv->stapis[i])
- gdrv->api_mask |= egl_g3d_st_api_bit(i);
- }
-
- if (gdrv->api_mask)
- _eglLog(_EGL_DEBUG, "Driver API mask: 0x%x", gdrv->api_mask);
- else
- _eglLog(_EGL_WARNING, "No supported client API");
-}
-
-/**
* Get the native platform.
*/
static const struct native_platform *
@@ -323,7 +299,6 @@ egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy,
_EGLConfig *conf, const struct native_config *nconf,
enum pipe_format depth_stencil_format)
{
- struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
struct egl_g3d_config *gconf = egl_g3d_config(conf);
EGLint buffer_mask, api_mask;
EGLBoolean valid;
@@ -347,7 +322,7 @@ egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy,
gconf->stvis.render_buffer = (buffer_mask & ST_ATTACHMENT_BACK_LEFT_MASK) ?
ST_ATTACHMENT_BACK_LEFT : ST_ATTACHMENT_FRONT_LEFT;
- api_mask = gdrv->api_mask;;
+ api_mask = dpy->ClientAPIsMask;
/* this is required by EGL, not by OpenGL ES */
if (nconf->window_bit &&
gconf->stvis.render_buffer != ST_ATTACHMENT_BACK_LEFT)
@@ -472,8 +447,26 @@ egl_g3d_invalid_surface(struct native_display *ndpy,
gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gsurf->stfbi);
}
+static struct pipe_screen *
+egl_g3d_new_drm_screen(struct native_display *ndpy, const char *name, int fd)
+{
+ _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data;
+ struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+ return gdpy->loader->create_drm_screen(name, fd);
+}
+
+static struct pipe_screen *
+egl_g3d_new_sw_screen(struct native_display *ndpy, struct sw_winsys *ws)
+{
+ _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data;
+ struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+ return gdpy->loader->create_sw_screen(ws);
+}
+
static struct native_event_handler egl_g3d_native_event_handler = {
- egl_g3d_invalid_surface
+ egl_g3d_invalid_surface,
+ egl_g3d_new_drm_screen,
+ egl_g3d_new_sw_screen
};
static EGLBoolean
@@ -529,20 +522,25 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
_eglError(EGL_BAD_ALLOC, "eglInitialize");
goto fail;
}
+ gdpy->loader = gdrv->loader;
dpy->DriverData = gdpy;
_eglLog(_EGL_INFO, "use %s for display %p", nplat->name, dpy->PlatformDisplay);
gdpy->native = nplat->create_display(dpy->PlatformDisplay,
- &egl_g3d_native_event_handler);
+ &egl_g3d_native_event_handler, (void *) dpy);
if (!gdpy->native) {
_eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
goto fail;
}
- gdpy->native->user_data = (void *) dpy;
-
- egl_g3d_init_st(&gdrv->base);
- dpy->ClientAPIsMask = gdrv->api_mask;
+ if (gdpy->loader->api_mask & (1 << ST_API_OPENGL))
+ dpy->ClientAPIsMask |= EGL_OPENGL_BIT;
+ if (gdpy->loader->api_mask & (1 << ST_API_OPENGL_ES1))
+ dpy->ClientAPIsMask |= EGL_OPENGL_ES_BIT;
+ if (gdpy->loader->api_mask & (1 << ST_API_OPENGL_ES2))
+ dpy->ClientAPIsMask |= EGL_OPENGL_ES2_BIT;
+ if (gdpy->loader->api_mask & (1 << ST_API_OPENVG))
+ dpy->ClientAPIsMask |= EGL_OPENVG_BIT;
gdpy->smapi = egl_g3d_create_st_manager(dpy);
if (!gdpy->smapi) {
@@ -583,22 +581,15 @@ static _EGLProc
egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname)
{
struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
- _EGLProc proc;
- EGLint i;
+ struct st_api *stapi = NULL;
- /* in case this is called before a display is initialized */
- egl_g3d_init_st(&gdrv->base);
-
- for (i = 0; i < ST_API_COUNT; i++) {
- struct st_api *stapi = gdrv->stapis[i];
- if (stapi) {
- proc = (_EGLProc) stapi->get_proc_address(stapi, procname);
- if (proc)
- return proc;
- }
- }
+ if (procname && procname[0] == 'v' && procname[1] == 'g')
+ stapi = gdrv->loader->get_st_api(ST_API_OPENVG);
+ else if (procname && procname[0] == 'g' && procname[1] == 'l')
+ stapi = gdrv->loader->guess_gl_api();
- return (_EGLProc) NULL;
+ return (_EGLProc) ((stapi) ?
+ stapi->get_proc_address(stapi, procname) : NULL);
}
static EGLint
@@ -628,18 +619,8 @@ egl_g3d_probe(_EGLDriver *drv, _EGLDisplay *dpy)
return score;
}
-static void
-egl_g3d_unload(_EGLDriver *drv)
-{
- struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
-
- egl_g3d_destroy_st_apis();
- egl_g3d_destroy_probe(drv, NULL);
- FREE(gdrv);
-}
-
_EGLDriver *
-_eglMain(const char *args)
+egl_g3d_create_driver(const struct egl_g3d_loader *loader)
{
struct egl_g3d_driver *gdrv;
@@ -647,17 +628,28 @@ _eglMain(const char *args)
if (!gdrv)
return NULL;
+ gdrv->loader = loader;
+
egl_g3d_init_driver_api(&gdrv->base);
gdrv->base.API.Initialize = egl_g3d_initialize;
gdrv->base.API.Terminate = egl_g3d_terminate;
gdrv->base.API.GetProcAddress = egl_g3d_get_proc_address;
- gdrv->base.Name = "Gallium";
gdrv->base.Probe = egl_g3d_probe;
- gdrv->base.Unload = egl_g3d_unload;
/* the key is " EGL G3D" */
gdrv->probe_key = 0x0E61063D;
+ /* to be filled by the caller */
+ gdrv->base.Name = NULL;
+ gdrv->base.Unload = NULL;
+
return &gdrv->base;
}
+
+void
+egl_g3d_destroy_driver(_EGLDriver *drv)
+{
+ struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+ FREE(gdrv);
+}