Merge pull request #3478 from bparker06/gl_thread_current

make GLX context current when managing font textures with threaded video
This commit is contained in:
Twinaphex 2016-08-31 14:56:46 +02:00 committed by GitHub
commit d678273b0b
8 changed files with 52 additions and 0 deletions

View File

@ -625,4 +625,5 @@ const gfx_ctx_driver_t gfx_ctx_android = {
#else
NULL
#endif
,NULL
};

View File

@ -258,5 +258,6 @@ const gfx_ctx_driver_t gfx_ctx_khr_display = {
gfx_ctx_khr_display_set_flags,
NULL,
gfx_ctx_khr_display_get_context_data,
NULL
};

View File

@ -1177,4 +1177,5 @@ const gfx_ctx_driver_t gfx_ctx_wayland = {
#else
NULL
#endif
,NULL
};

View File

@ -705,5 +705,6 @@ const gfx_ctx_driver_t gfx_ctx_wgl = {
#else
NULL,
#endif
NULL
};

View File

@ -69,6 +69,8 @@ static enum gfx_ctx_api x_api;
static PFNGLXCREATECONTEXTATTRIBSARBPROC glx_create_context_attribs;
#endif
static gfx_ctx_x_data_t *current_context_data = NULL;
static int x_nul_handler(Display *dpy, XErrorEvent *event)
{
(void)dpy;
@ -341,6 +343,8 @@ static void *gfx_ctx_x_init(void *data)
if (!x)
return NULL;
current_context_data = x;
XInitThreads();
if (!x11_connect())
@ -913,6 +917,22 @@ static void gfx_ctx_x_set_flags(void *data, uint32_t flags)
x->core_hw_context_enable = true;
}
void gfx_ctx_x_make_current(bool release)
{
if (!current_context_data)
return;
if (release)
{
glXMakeContextCurrent(g_x11_dpy, None, None, NULL);
}
else
{
glXMakeContextCurrent(g_x11_dpy,
current_context_data->g_glx_win, current_context_data->g_glx_win, current_context_data->g_ctx);
}
}
const gfx_ctx_driver_t gfx_ctx_x = {
gfx_ctx_x_init,
gfx_ctx_x_destroy,
@ -947,5 +967,10 @@ const gfx_ctx_driver_t gfx_ctx_x = {
#else
NULL
#endif
#ifdef HAVE_OPENGL
,gfx_ctx_x_make_current
#else
,NULL
#endif
};

View File

@ -17,6 +17,7 @@
#include "../common/gl_common.h"
#include "../font_driver.h"
#include "../video_shader_driver.h"
#include "../video_context_driver.h"
#include <encodings/utf.h>
/* TODO: Move viewport side effects to the caller: it's a source of bugs. */
@ -142,6 +143,7 @@ static void *gl_raster_font_init_font(void *data,
{
const struct font_atlas *atlas = NULL;
gl_raster_t *font = (gl_raster_t*)calloc(1, sizeof(*font));
settings_t *settings = config_get_ptr();
if (!font)
return NULL;
@ -156,6 +158,9 @@ static void *gl_raster_font_init_font(void *data,
return NULL;
}
if (settings->video.threaded)
video_context_driver_make_current(false);
glGenTextures(1, &font->tex);
glBindTexture(GL_TEXTURE_2D, font->tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@ -185,12 +190,16 @@ error:
static void gl_raster_font_free_font(void *data)
{
gl_raster_t *font = (gl_raster_t*)data;
settings_t *settings = config_get_ptr();
if (!font)
return;
if (font->font_driver && font->font_data)
font->font_driver->free(font->font_data);
if (settings->video.threaded)
video_context_driver_make_current(false);
glDeleteTextures(1, &font->tex);
free(font);
}

View File

@ -328,6 +328,14 @@ bool video_context_driver_bind_hw_render(bool *enable)
return true;
}
void video_context_driver_make_current(bool release)
{
if (!current_video_context || !current_video_context->make_current)
return;
current_video_context->make_current(release);
}
bool video_context_driver_set(const gfx_ctx_driver_t *data)
{
if (!data)

View File

@ -163,6 +163,10 @@ typedef struct gfx_ctx_driver
* This is mostly relevant for graphics APIs such as Vulkan
* which do not have global context state. */
void *(*get_context_data)(void *data);
/* Optional. Makes driver context (only GLX right now)
* active for this thread. */
void (*make_current)(bool release);
} gfx_ctx_driver_t;
typedef struct gfx_ctx_flags
@ -280,6 +284,8 @@ bool video_context_driver_get_video_output_next(void);
bool video_context_driver_bind_hw_render(bool *enable);
void video_context_driver_make_current(bool restore);
bool video_context_driver_set(const gfx_ctx_driver_t *data);
void video_context_driver_destroy(void);