From d4c9ef86e4cf1d6e95dc5a0d41fac81df13f1e51 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 24 Aug 2020 11:27:56 -0700 Subject: [PATCH] virgl: move vrend_state.inited to global_state We want a centralized place to initialize different subsystems (vrend, winsys, resource/context tables). This is the first step. Signed-off-by: Chia-I Wu Reviewed-by: Gurchetan Singh --- src/virglrenderer.c | 39 +++++++++++++++++++++++++++++---------- src/vrend_renderer.c | 18 ------------------ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/virglrenderer.c b/src/virglrenderer.c index 89cb382..30065e4 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -46,6 +46,8 @@ struct global_state { void *cookie; const struct virgl_renderer_callbacks *cbs; + + bool vrend_initialized; }; static struct global_state state; @@ -431,20 +433,24 @@ void *virgl_renderer_get_cursor_data(uint32_t resource_id, uint32_t *width, uint void virgl_renderer_poll(void) { - vrend_renderer_check_fences(); + if (state.vrend_initialized) + vrend_renderer_check_fences(); } void virgl_renderer_cleanup(UNUSED void *cookie) { - vrend_renderer_fini(); + if (state.vrend_initialized) + vrend_renderer_fini(); + virgl_context_table_cleanup(); vrend_winsys_cleanup(); + + memset(&state, 0, sizeof(state)); } int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks *cbs) { int drm_fd = -1; - uint32_t renderer_flags = 0; int ret; if (!cookie || !cbs) @@ -468,12 +474,21 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks if (virgl_context_table_init()) return -1; - if (flags & VIRGL_RENDERER_THREAD_SYNC) - renderer_flags |= VREND_USE_THREAD_SYNC; - if (flags & VIRGL_RENDERER_USE_EXTERNAL_BLOB) - renderer_flags |= VREND_USE_EXTERNAL_BLOB; + if (!state.vrend_initialized) { + uint32_t renderer_flags = 0; - return vrend_renderer_init(&vrend_cbs, renderer_flags); + if (flags & VIRGL_RENDERER_THREAD_SYNC) + renderer_flags |= VREND_USE_THREAD_SYNC; + if (flags & VIRGL_RENDERER_USE_EXTERNAL_BLOB) + renderer_flags |= VREND_USE_EXTERNAL_BLOB; + + ret = vrend_renderer_init(&vrend_cbs, renderer_flags); + if (ret) + return ret; + state.vrend_initialized = true; + } + + return 0; } int virgl_renderer_get_fd_for_texture(uint32_t tex_id, int *fd) @@ -488,12 +503,16 @@ int virgl_renderer_get_fd_for_texture2(uint32_t tex_id, int *fd, int *stride, in void virgl_renderer_reset(void) { - vrend_renderer_reset(); + if (state.vrend_initialized) + vrend_renderer_reset(); } int virgl_renderer_get_poll_fd(void) { - return vrend_renderer_get_poll_fd(); + if (state.vrend_initialized) + return vrend_renderer_get_poll_fd(); + + return -1; } virgl_debug_callback_type virgl_set_debug_callback(virgl_debug_callback_type cb) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index b178242..70c789d 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -278,7 +278,6 @@ struct global_renderer_state { struct vrend_context *current_hw_ctx; struct list_head waiting_query_list; - bool inited; bool finishing; bool use_gles; bool use_core_profile; @@ -5938,10 +5937,6 @@ int vrend_renderer_init(const struct vrend_if_cbs *cbs, uint32_t flags) virgl_gl_context gl_context; struct virgl_gl_ctx_param ctx_params; - if (vrend_state.inited) - return 0; - - vrend_state.inited = true; virgl_resource_table_init(vrend_renderer_get_pipe_callbacks()); vrend_clicbs = cbs; @@ -6057,9 +6052,6 @@ int vrend_renderer_init(const struct vrend_if_cbs *cbs, uint32_t flags) void vrend_renderer_fini(void) { - if (!vrend_state.inited) - return; - vrend_state.finishing = true; vrend_free_sync_thread(); @@ -6077,7 +6069,6 @@ vrend_renderer_fini(void) vrend_state.current_ctx = NULL; vrend_state.current_hw_ctx = NULL; - vrend_state.inited = false; vrend_state.finishing = false; } @@ -8972,9 +8963,6 @@ void vrend_renderer_check_fences(void) uint32_t latest_id = 0; GLenum glret; - if (!vrend_state.inited) - return; - if (vrend_state.sync_thread) { flush_eventfd(vrend_state.eventfd); pipe_mutex_lock(vrend_state.fence_mutex); @@ -10470,9 +10458,6 @@ static void vrend_reset_fences(void) void vrend_renderer_reset(void) { - if (!vrend_state.inited) - return; - if (vrend_state.sync_thread) { vrend_free_sync_thread(); vrend_state.stop_sync_thread = false; @@ -10490,9 +10475,6 @@ void vrend_renderer_reset(void) int vrend_renderer_get_poll_fd(void) { - if (!vrend_state.inited) - return -1; - return vrend_state.eventfd; }