From 5df70a5abe90dac8730ffd2cd1f2daf420fe6cf2 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 20 Jul 2020 16:38:40 -0700 Subject: [PATCH] vrend: move gl context functions to winsys Signed-off-by: Chia-I Wu Reviewed-by: Gurchetan Singh --- src/virglrenderer.c | 35 +++++++++-------------------------- src/vrend_winsys.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/vrend_winsys.h | 8 ++++++++ 3 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/virglrenderer.c b/src/virglrenderer.c index 2c8c358..8f9c90b 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -388,14 +388,9 @@ static virgl_renderer_gl_context create_gl_context(int scanout_idx, struct virgl { struct virgl_renderer_gl_ctx_param vparam; -#ifdef HAVE_EPOXY_EGL_H - if (use_context == CONTEXT_EGL) - return virgl_egl_create_context(egl, param); -#endif -#ifdef HAVE_EPOXY_GLX_H - if (use_context == CONTEXT_GLX) - return virgl_glx_create_context(glx_info, param); -#endif + if (use_context != CONTEXT_NONE) + return vrend_winsys_create_context(param); + vparam.version = 1; vparam.shared = param->shared; vparam.major_ver = param->major_ver; @@ -405,31 +400,19 @@ static virgl_renderer_gl_context create_gl_context(int scanout_idx, struct virgl static void destroy_gl_context(virgl_renderer_gl_context ctx) { -#ifdef HAVE_EPOXY_EGL_H - if (use_context == CONTEXT_EGL) { - virgl_egl_destroy_context(egl, ctx); + if (use_context != CONTEXT_NONE) { + vrend_winsys_destroy_context(ctx); return; } -#endif -#ifdef HAVE_EPOXY_GLX_H - if (use_context == CONTEXT_GLX) { - virgl_glx_destroy_context(glx_info, ctx); - return; - } -#endif + rcbs->destroy_gl_context(dev_cookie, ctx); } static int make_current(virgl_renderer_gl_context ctx) { -#ifdef HAVE_EPOXY_EGL_H - if (use_context == CONTEXT_EGL) - return virgl_egl_make_context_current(egl, ctx); -#endif -#ifdef HAVE_EPOXY_GLX_H - if (use_context == CONTEXT_GLX) - return virgl_glx_make_context_current(glx_info, ctx); -#endif + if (use_context != CONTEXT_NONE) + return vrend_winsys_make_context_current(ctx); + return rcbs->make_current(dev_cookie, 0, ctx); } diff --git a/src/vrend_winsys.c b/src/vrend_winsys.c index bfb1c8b..062ca90 100644 --- a/src/vrend_winsys.c +++ b/src/vrend_winsys.c @@ -37,6 +37,48 @@ struct virgl_gbm *gbm = NULL; struct virgl_glx *glx_info = NULL; #endif +virgl_renderer_gl_context vrend_winsys_create_context(struct virgl_gl_ctx_param *param) +{ +#ifdef HAVE_EPOXY_EGL_H + if (use_context == CONTEXT_EGL) + return virgl_egl_create_context(egl, param); +#endif +#ifdef HAVE_EPOXY_GLX_H + if (use_context == CONTEXT_GLX) + return virgl_glx_create_context(glx_info, param); +#endif + return NULL; +} + +void vrend_winsys_destroy_context(virgl_renderer_gl_context ctx) +{ +#ifdef HAVE_EPOXY_EGL_H + if (use_context == CONTEXT_EGL) { + virgl_egl_destroy_context(egl, ctx); + return; + } +#endif +#ifdef HAVE_EPOXY_GLX_H + if (use_context == CONTEXT_GLX) { + virgl_glx_destroy_context(glx_info, ctx); + return; + } +#endif +} + +int vrend_winsys_make_context_current(virgl_renderer_gl_context ctx) +{ +#ifdef HAVE_EPOXY_EGL_H + if (use_context == CONTEXT_EGL) + return virgl_egl_make_context_current(egl, ctx); +#endif +#ifdef HAVE_EPOXY_GLX_H + if (use_context == CONTEXT_GLX) + return virgl_glx_make_context_current(glx_info, ctx); +#endif + return -1; +} + int vrend_winsys_has_gl_colorspace(void) { bool egl_colorspace = false; diff --git a/src/vrend_winsys.h b/src/vrend_winsys.h index b59db24..7bc08e4 100644 --- a/src/vrend_winsys.h +++ b/src/vrend_winsys.h @@ -36,12 +36,16 @@ #include "vrend_winsys_glx.h" #endif +#include "virglrenderer.h" + enum { CONTEXT_NONE, CONTEXT_EGL, CONTEXT_GLX }; +struct virgl_gl_ctx_param; + extern int use_context; #ifdef HAVE_EPOXY_EGL_H @@ -53,6 +57,10 @@ extern struct virgl_gbm *gbm; extern struct virgl_glx *glx_info; #endif +virgl_renderer_gl_context vrend_winsys_create_context(struct virgl_gl_ctx_param *param); +void vrend_winsys_destroy_context(virgl_renderer_gl_context ctx); +int vrend_winsys_make_context_current(virgl_renderer_gl_context ctx); + int vrend_winsys_has_gl_colorspace(void); #endif /* VREND_WINSYS_H */