diff options
author | wm4 <wm4@nowhere> | 2013-03-04 00:38:04 +0100 |
---|---|---|
committer | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2013-05-12 15:27:54 +0200 |
commit | d0924ae5a87121d91d59259661dd262eb03becd6 (patch) | |
tree | 484a7d71bffcad37bd903755596121247b047848 /video | |
parent | 4ee0d0882030aaf11b11386018c10a9e336c7c7d (diff) | |
download | mpv-d0924ae5a87121d91d59259661dd262eb03becd6.tar.bz2 mpv-d0924ae5a87121d91d59259661dd262eb03becd6.tar.xz |
gl_common: add some sort of locking API
Some OpenGL implementations on some platforms require that a context
is current only on one thread. For this reason, mpgl_lock() and
mpgl_unlock() take care of this as well for convenience.
Each backend that needs thread safety should provide it's own locking strategy
inside of `set_current`.
Diffstat (limited to 'video')
-rw-r--r-- | video/out/gl_common.c | 27 | ||||
-rw-r--r-- | video/out/gl_common.h | 8 |
2 files changed, 35 insertions, 0 deletions
diff --git a/video/out/gl_common.c b/video/out/gl_common.c index 685258406a..39fb592df4 100644 --- a/video/out/gl_common.c +++ b/video/out/gl_common.c @@ -940,6 +940,33 @@ void mpgl_uninit(MPGLContext *ctx) talloc_free(ctx); } +void mpgl_set_context(MPGLContext *ctx) +{ + if (ctx->set_current) + ctx->set_current(ctx, true); +} + +void mpgl_unset_context(MPGLContext *ctx) +{ + if (ctx->set_current) + ctx->set_current(ctx, false); +} + +void mpgl_lock(MPGLContext *ctx) +{ + mpgl_set_context(ctx); +} + +void mpgl_unlock(MPGLContext *ctx) +{ + mpgl_unset_context(ctx); +} + +bool mpgl_is_thread_safe(MPGLContext *ctx) +{ + return !!ctx->set_current; +} + void mp_log_source(int mod, int lev, const char *src) { int line = 1; diff --git a/video/out/gl_common.h b/video/out/gl_common.h index 1f28d87855..18d1cf8879 100644 --- a/video/out/gl_common.h +++ b/video/out/gl_common.h @@ -26,6 +26,7 @@ #include <stdio.h> #include <stdint.h> +#include <stdbool.h> #include "config.h" #include "core/mp_msg.h" @@ -111,6 +112,7 @@ typedef struct MPGLContext { int (*vo_init)(struct vo *vo); void (*vo_uninit)(struct vo *vo); void (*releaseGlContext)(struct MPGLContext *); + void (*set_current)(struct MPGLContext *, bool current); // Resize the window, or create a new window if there isn't one yet. // On the first call, it creates a GL context according to what's specified @@ -136,6 +138,12 @@ typedef struct MPGLContext { MPGLContext *mpgl_init(struct vo *vo, const char *backend_name); void mpgl_uninit(MPGLContext *ctx); +void mpgl_lock(MPGLContext *ctx); +void mpgl_unlock(MPGLContext *ctx); +void mpgl_set_context(MPGLContext *ctx); +void mpgl_unset_context(MPGLContext *ctx); +bool mpgl_is_thread_safe(MPGLContext *ctx); + // Create a VO window and create a GL context on it. // (Calls config_window_gl3 or config_window+setGlWindow.) // gl_caps: bitfield of MPGL_CAP_* (required GL version and feature set) |