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 <olvaffe@gmail.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 4 years ago
parent 0edca466f4
commit d4c9ef86e4
  1. 23
      src/virglrenderer.c
  2. 18
      src/vrend_renderer.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)
{
if (state.vrend_initialized)
vrend_renderer_check_fences();
}
void virgl_renderer_cleanup(UNUSED void *cookie)
{
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 (!state.vrend_initialized) {
uint32_t renderer_flags = 0;
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;
return vrend_renderer_init(&vrend_cbs, renderer_flags);
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)
{
if (state.vrend_initialized)
vrend_renderer_reset();
}
int virgl_renderer_get_poll_fd(void)
{
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)

@ -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;
}

Loading…
Cancel
Save