From 3c3c8f1c0cef947c3896c0a026072670eebe0997 Mon Sep 17 00:00:00 2001 From: Igor Mitsyanko Date: Thu, 18 Oct 2012 11:13:07 +0400 Subject: [PATCH] YaGL: let EGL driver handle host openGL library Signed-off-by: Igor Mitsyanko --- hw/yagl_drivers/egl_glx/yagl_egl_glx.c | 37 ++++++++++++++---------------- hw/yagl_drivers/gles1_ogl/yagl_gles1_ogl.c | 23 +------------------ hw/yagl_drivers/gles1_ogl/yagl_gles1_ogl.h | 3 ++- hw/yagl_drivers/gles2_ogl/yagl_gles2_ogl.c | 23 +------------------ hw/yagl_drivers/gles2_ogl/yagl_gles2_ogl.h | 3 ++- hw/yagl_egl_driver.c | 5 ++++ hw/yagl_egl_driver.h | 3 +++ hw/yagl_server.c | 2 +- 8 files changed, 32 insertions(+), 67 deletions(-) diff --git a/hw/yagl_drivers/egl_glx/yagl_egl_glx.c b/hw/yagl_drivers/egl_glx/yagl_egl_glx.c index e6f6963..70260e0 100644 --- a/hw/yagl_drivers/egl_glx/yagl_egl_glx.c +++ b/hw/yagl_drivers/egl_glx/yagl_egl_glx.c @@ -19,8 +19,8 @@ (proc_type)egl_glx->glXGetProcAddress((const GLubyte*)#proc_name); \ if (!egl_glx->proc_name) { \ YAGL_LOG_ERROR("Unable to get symbol: %s", \ - yagl_dyn_lib_get_error(egl_glx->dyn_lib)); \ - goto fail2; \ + yagl_dyn_lib_get_error(egl_driver->dyn_lib)); \ + goto fail; \ } \ } while (0) @@ -63,8 +63,6 @@ struct yagl_egl_glx { struct yagl_egl_driver base; - struct yagl_dyn_lib *dyn_lib; - /* GLX 1.0 */ GLXCREATECONTEXTPROC glXCreateContext; GLXDESTROYCONTEXTPROC glXDestroyContext; @@ -548,8 +546,6 @@ static void yagl_egl_glx_destroy(struct yagl_egl_driver *driver) YAGL_LOG_FUNC_ENTER_NPT(yagl_egl_glx_destroy, NULL); - yagl_dyn_lib_destroy(egl_glx->dyn_lib); - yagl_egl_driver_cleanup(&egl_glx->base); g_free(egl_glx); @@ -559,38 +555,41 @@ static void yagl_egl_glx_destroy(struct yagl_egl_driver *driver) struct yagl_egl_driver *yagl_egl_glx_create(void) { + struct yagl_egl_driver *egl_driver; struct yagl_egl_glx *egl_glx; YAGL_LOG_FUNC_ENTER_NPT(yagl_egl_glx_create, NULL); egl_glx = g_malloc0(sizeof(*egl_glx)); - yagl_egl_driver_init(&egl_glx->base); + egl_driver = &egl_glx->base; + + yagl_egl_driver_init(egl_driver); - egl_glx->dyn_lib = yagl_dyn_lib_create(); + egl_driver->dyn_lib = yagl_dyn_lib_create(); - if (!egl_glx->dyn_lib) { - goto fail1; + if (!egl_driver->dyn_lib) { + goto fail; } - if (!yagl_dyn_lib_load(egl_glx->dyn_lib, "libGL.so.1")) { + if (!yagl_dyn_lib_load(egl_driver->dyn_lib, "libGL.so.1")) { YAGL_LOG_ERROR("Unable to load libGL.so.1: %s", - yagl_dyn_lib_get_error(egl_glx->dyn_lib)); - goto fail2; + yagl_dyn_lib_get_error(egl_driver->dyn_lib)); + goto fail; } egl_glx->glXGetProcAddress = - yagl_dyn_lib_get_sym(egl_glx->dyn_lib, "glXGetProcAddress"); + yagl_dyn_lib_get_sym(egl_driver->dyn_lib, "glXGetProcAddress"); if (!egl_glx->glXGetProcAddress) { egl_glx->glXGetProcAddress = - yagl_dyn_lib_get_sym(egl_glx->dyn_lib, "glXGetProcAddressARB"); + yagl_dyn_lib_get_sym(egl_driver->dyn_lib, "glXGetProcAddressARB"); } if (!egl_glx->glXGetProcAddress) { YAGL_LOG_ERROR("Unable to get symbol: %s", - yagl_dyn_lib_get_error(egl_glx->dyn_lib)); - goto fail2; + yagl_dyn_lib_get_error(egl_driver->dyn_lib)); + goto fail; } /* GLX 1.0 */ @@ -630,9 +629,7 @@ struct yagl_egl_driver *yagl_egl_glx_create(void) return &egl_glx->base; -fail2: - yagl_dyn_lib_destroy(egl_glx->dyn_lib); -fail1: +fail: yagl_egl_driver_cleanup(&egl_glx->base); g_free(egl_glx); diff --git a/hw/yagl_drivers/gles1_ogl/yagl_gles1_ogl.c b/hw/yagl_drivers/gles1_ogl/yagl_gles1_ogl.c index 6a917a6..61c89e6 100644 --- a/hw/yagl_drivers/gles1_ogl/yagl_gles1_ogl.c +++ b/hw/yagl_drivers/gles1_ogl/yagl_gles1_ogl.c @@ -21,8 +21,6 @@ struct yagl_gles1_ogl { struct yagl_gles1_driver base; - struct yagl_dyn_lib *dyn_lib; - struct yagl_gles_ogl *gles_ogl; YAGL_GLES_OGL_PROC2(glAlphaFunc, GLenum, GLclampf, func, ref) @@ -230,8 +228,6 @@ static void yagl_gles1_ogl_destroy(struct yagl_gles1_driver *driver) yagl_gles_ogl_destroy(gles1_ogl->gles_ogl); - yagl_dyn_lib_destroy(gles1_ogl->dyn_lib); - yagl_gles1_driver_cleanup(&gles1_ogl->base); g_free(gles1_ogl); @@ -239,11 +235,10 @@ static void yagl_gles1_ogl_destroy(struct yagl_gles1_driver *driver) YAGL_LOG_FUNC_EXIT(NULL); } -struct yagl_gles1_driver *yagl_gles1_ogl_create(void) +struct yagl_gles1_driver *yagl_gles1_ogl_create(struct yagl_dyn_lib *dyn_lib) { struct yagl_gles1_ogl *gles1_ogl = NULL; PFNGLXGETPROCADDRESSPROC get_address = NULL; - struct yagl_dyn_lib *dyn_lib = NULL; struct yagl_gles_ogl *gles_ogl = NULL; YAGL_LOG_FUNC_ENTER_NPT(yagl_gles1_ogl_create, NULL); @@ -252,18 +247,6 @@ struct yagl_gles1_driver *yagl_gles1_ogl_create(void) yagl_gles1_driver_init(&gles1_ogl->base); - dyn_lib = yagl_dyn_lib_create(); - - if (!dyn_lib) { - goto fail; - } - - if (!yagl_dyn_lib_load(dyn_lib, "libGL.so.1")) { - YAGL_LOG_ERROR("Unable to load libGL.so.1: %s", - yagl_dyn_lib_get_error(dyn_lib)); - goto fail; - } - gles_ogl = yagl_gles_ogl_create(dyn_lib); if (!gles_ogl) { @@ -321,7 +304,6 @@ struct yagl_gles1_driver *yagl_gles1_ogl_create(void) YAGL_GLES_OGL_GET_PROC(gles1_ogl, glTexEnviv); YAGL_GLES_OGL_GET_PROC(gles1_ogl, glVertexPointer); - gles1_ogl->dyn_lib = dyn_lib; gles1_ogl->gles_ogl = gles_ogl; gles1_ogl->base.process_init = &yagl_gles1_ogl_process_init; gles1_ogl->base.destroy = &yagl_gles1_ogl_destroy; @@ -334,9 +316,6 @@ fail: if (gles_ogl) { yagl_gles_ogl_destroy(gles_ogl); } - if (dyn_lib) { - yagl_dyn_lib_destroy(dyn_lib); - } yagl_gles1_driver_cleanup(&gles1_ogl->base); g_free(gles1_ogl); diff --git a/hw/yagl_drivers/gles1_ogl/yagl_gles1_ogl.h b/hw/yagl_drivers/gles1_ogl/yagl_gles1_ogl.h index ef007d9..e7d9819 100644 --- a/hw/yagl_drivers/gles1_ogl/yagl_gles1_ogl.h +++ b/hw/yagl_drivers/gles1_ogl/yagl_gles1_ogl.h @@ -2,9 +2,10 @@ #define _QEMU_YAGL_GLES1_OGL_H #include "yagl_types.h" +#include "yagl_dyn_lib.h" struct yagl_gles1_driver; -struct yagl_gles1_driver *yagl_gles1_ogl_create(void); +struct yagl_gles1_driver *yagl_gles1_ogl_create(struct yagl_dyn_lib *dyn_lib); #endif diff --git a/hw/yagl_drivers/gles2_ogl/yagl_gles2_ogl.c b/hw/yagl_drivers/gles2_ogl/yagl_gles2_ogl.c index 8b96451..28487f3 100644 --- a/hw/yagl_drivers/gles2_ogl/yagl_gles2_ogl.c +++ b/hw/yagl_drivers/gles2_ogl/yagl_gles2_ogl.c @@ -21,8 +21,6 @@ struct yagl_gles2_ogl { struct yagl_gles2_driver base; - struct yagl_dyn_lib *dyn_lib; - struct yagl_gles_ogl *gles_ogl; YAGL_GLES_OGL_PROC2(glAttachShader, GLuint, GLuint, program, shader) @@ -305,8 +303,6 @@ static void yagl_gles2_ogl_destroy(struct yagl_gles2_driver *driver) yagl_gles_ogl_destroy(gles2_ogl->gles_ogl); - yagl_dyn_lib_destroy(gles2_ogl->dyn_lib); - yagl_gles2_driver_cleanup(&gles2_ogl->base); g_free(gles2_ogl); @@ -314,11 +310,10 @@ static void yagl_gles2_ogl_destroy(struct yagl_gles2_driver *driver) YAGL_LOG_FUNC_EXIT(NULL); } -struct yagl_gles2_driver *yagl_gles2_ogl_create(void) +struct yagl_gles2_driver *yagl_gles2_ogl_create(struct yagl_dyn_lib *dyn_lib) { struct yagl_gles2_ogl *gles2_ogl = NULL; PFNGLXGETPROCADDRESSPROC get_address = NULL; - struct yagl_dyn_lib *dyn_lib = NULL; struct yagl_gles_ogl *gles_ogl = NULL; YAGL_LOG_FUNC_ENTER_NPT(yagl_gles2_ogl_create, NULL); @@ -327,18 +322,6 @@ struct yagl_gles2_driver *yagl_gles2_ogl_create(void) yagl_gles2_driver_init(&gles2_ogl->base); - dyn_lib = yagl_dyn_lib_create(); - - if (!dyn_lib) { - goto fail; - } - - if (!yagl_dyn_lib_load(dyn_lib, "libGL.so.1")) { - YAGL_LOG_ERROR("Unable to load libGL.so.1: %s", - yagl_dyn_lib_get_error(dyn_lib)); - goto fail; - } - gles_ogl = yagl_gles_ogl_create(dyn_lib); if (!gles_ogl) { @@ -421,7 +404,6 @@ struct yagl_gles2_driver *yagl_gles2_ogl_create(void) YAGL_GLES_OGL_GET_PROC(gles2_ogl, glVertexAttrib4fv); YAGL_GLES_OGL_GET_PROC(gles2_ogl, glVertexAttribPointer); - gles2_ogl->dyn_lib = dyn_lib; gles2_ogl->gles_ogl = gles_ogl; gles2_ogl->base.process_init = &yagl_gles2_ogl_process_init; gles2_ogl->base.destroy = &yagl_gles2_ogl_destroy; @@ -434,9 +416,6 @@ fail: if (gles_ogl) { yagl_gles_ogl_destroy(gles_ogl); } - if (dyn_lib) { - yagl_dyn_lib_destroy(dyn_lib); - } yagl_gles2_driver_cleanup(&gles2_ogl->base); g_free(gles2_ogl); diff --git a/hw/yagl_drivers/gles2_ogl/yagl_gles2_ogl.h b/hw/yagl_drivers/gles2_ogl/yagl_gles2_ogl.h index feb52f5..b2a5ed6 100644 --- a/hw/yagl_drivers/gles2_ogl/yagl_gles2_ogl.h +++ b/hw/yagl_drivers/gles2_ogl/yagl_gles2_ogl.h @@ -2,9 +2,10 @@ #define _QEMU_YAGL_GLES2_OGL_H #include "yagl_types.h" +#include "yagl_dyn_lib.h" struct yagl_gles2_driver; -struct yagl_gles2_driver *yagl_gles2_ogl_create(void); +struct yagl_gles2_driver *yagl_gles2_ogl_create(struct yagl_dyn_lib *dyn_lib); #endif diff --git a/hw/yagl_egl_driver.c b/hw/yagl_egl_driver.c index eea6790..6ba3158 100644 --- a/hw/yagl_egl_driver.c +++ b/hw/yagl_egl_driver.c @@ -1,4 +1,5 @@ #include "yagl_egl_driver.h" +#include "yagl_dyn_lib.h" void yagl_egl_driver_ps_init(struct yagl_egl_driver_ps *driver_ps, struct yagl_egl_driver *driver, @@ -14,8 +15,12 @@ void yagl_egl_driver_ps_cleanup(struct yagl_egl_driver_ps *driver_ps) void yagl_egl_driver_init(struct yagl_egl_driver *driver) { + driver->dyn_lib = NULL; } void yagl_egl_driver_cleanup(struct yagl_egl_driver *driver) { + if (driver->dyn_lib) { + yagl_dyn_lib_destroy(driver->dyn_lib); + } } diff --git a/hw/yagl_egl_driver.h b/hw/yagl_egl_driver.h index 5575a31..e8a4004 100644 --- a/hw/yagl_egl_driver.h +++ b/hw/yagl_egl_driver.h @@ -2,6 +2,7 @@ #define _QEMU_YAGL_EGL_DRIVER_H #include "yagl_types.h" +#include "yagl_dyn_lib.h" #include struct yagl_thread_state; @@ -98,6 +99,8 @@ struct yagl_egl_driver struct yagl_process_state */*ps*/); void (*destroy)(struct yagl_egl_driver */*driver*/); + + struct yagl_dyn_lib *dyn_lib; }; #ifdef CONFIG_YAGL_EGL_GLX diff --git a/hw/yagl_server.c b/hw/yagl_server.c index 369db04..ef6936c 100644 --- a/hw/yagl_server.c +++ b/hw/yagl_server.c @@ -52,7 +52,7 @@ struct yagl_server_state *yagl_server_state_create(void) goto fail; } - gles2_driver = yagl_gles2_ogl_create(); + gles2_driver = yagl_gles2_ogl_create(egl_driver->dyn_lib); if (!gles2_driver) { goto fail; -- 2.7.4