Commit f6097e45 authored by Thomas Guillem's avatar Thomas Guillem

gl: add vlc_gl_Hold

vlc_gl_t can now be ref counted.
parent 1172b7c3
......@@ -78,6 +78,7 @@ enum {
VLC_API vlc_gl_t *vlc_gl_Create(struct vout_window_t *, unsigned, const char *) VLC_USED;
VLC_API void vlc_gl_Destroy(vlc_gl_t *);
VLC_API void vlc_gl_Hold(vlc_gl_t *);
static inline int vlc_gl_MakeCurrent(vlc_gl_t *gl)
{
......
......@@ -691,6 +691,7 @@ vlc_fifo_GetCount
vlc_fifo_GetBytes
vlc_gl_Create
vlc_gl_Destroy
vlc_gl_Hold
vlc_gl_surface_Create
vlc_gl_surface_CheckSize
vlc_gl_surface_Destroy
......
......@@ -26,10 +26,16 @@
#include <stdlib.h>
#include <vlc_common.h>
#include <vlc_atomic.h>
#include <vlc_opengl.h>
#include "libvlc.h"
#include <vlc_modules.h>
struct vlc_gl_priv_t
{
vlc_gl_t gl;
atomic_uint ref_count;
};
#undef vlc_gl_Create
/**
* Creates an OpenGL context (and its underlying surface).
......@@ -45,7 +51,7 @@ vlc_gl_t *vlc_gl_Create(struct vout_window_t *wnd, unsigned flags,
const char *name)
{
vlc_object_t *parent = (vlc_object_t *)wnd;
vlc_gl_t *gl;
struct vlc_gl_priv_t *glpriv;
const char *type;
switch (flags /*& VLC_OPENGL_API_MASK*/)
......@@ -60,23 +66,33 @@ vlc_gl_t *vlc_gl_Create(struct vout_window_t *wnd, unsigned flags,
return NULL;
}
gl = vlc_custom_create(parent, sizeof (*gl), "gl");
if (unlikely(gl == NULL))
glpriv = vlc_custom_create(parent, sizeof (*glpriv), "gl");
if (unlikely(glpriv == NULL))
return NULL;
gl->surface = wnd;
gl->module = module_need(gl, type, name, true);
if (gl->module == NULL)
glpriv->gl.surface = wnd;
glpriv->gl.module = module_need(&glpriv->gl, type, name, true);
if (glpriv->gl.module == NULL)
{
vlc_object_release(gl);
vlc_object_release(&glpriv->gl);
return NULL;
}
atomic_init(&glpriv->ref_count, 1);
return gl;
return &glpriv->gl;
}
void vlc_gl_Hold(vlc_gl_t *gl)
{
struct vlc_gl_priv_t *glpriv = (struct vlc_gl_priv_t *)gl;
atomic_fetch_add(&glpriv->ref_count, 1);
}
void vlc_gl_Destroy(vlc_gl_t *gl)
{
struct vlc_gl_priv_t *glpriv = (struct vlc_gl_priv_t *)gl;
if (atomic_fetch_sub(&glpriv->ref_count, 1) != 1)
return;
module_unneed(gl, gl->module);
vlc_object_release(gl);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment