Commit 79b21876 authored by Filip Roséen's avatar Filip Roséen Committed by Thomas Guillem

vlc_opengl: refactor vlc_gl_t creation

Given that there are places in the codebase that just require a
created object of type vlc_gl_t ("gl"), these changes split the object
creation into two functions:

 - vlc_gl_Create: a simple wrapper around vlc_custom_create
 - vlc_gl_ModuleCreate: creates a vlc_gl_t with an associated
                        module/surface.

refs #17795
Signed-off-by: Thomas Guillem's avatarThomas Guillem <thomas@gllm.fr>
parent 10028dde
......@@ -58,7 +58,27 @@ enum {
VLC_OPENGL_ES2,
};
VLC_API vlc_gl_t *vlc_gl_Create(struct vout_window_t *, unsigned, const char *) VLC_USED;
/**
* Create a VLC OpenGL object
*
* @note The allocated resource, if any, shall be released
* with a call to \ref vlc_gl_Destroy.
* @return a created object on success, NULL on failure.
**/
VLC_API vlc_gl_t *vlc_gl_Create(vlc_object_t* parent);
/**
* Creates a VLC OpenGL object with associated surface and module
*
* @note In most cases, you should vlc_gl_MakeCurrent() afterward.
*
* @param wnd window to use as OpenGL surface
* @param flags OpenGL context type
* @param name module name (or NULL for auto)
* @return a new context, or NULL on failure
*/
VLC_API vlc_gl_t *vlc_gl_ModuleCreate(struct vout_window_t *wnd, unsigned flags,
const char *name) VLC_USED;
VLC_API void vlc_gl_Destroy(vlc_gl_t *);
static inline int vlc_gl_MakeCurrent(vlc_gl_t *gl)
......
......@@ -107,7 +107,7 @@ static int Open (vlc_object_t *obj)
goto error;
}
sys->gl = vlc_gl_Create (surface, API, "$" MODULE_VARNAME);
sys->gl = vlc_gl_ModuleCreate (surface, API, "$" MODULE_VARNAME);
if (sys->gl == NULL)
goto error;
......
......@@ -691,6 +691,7 @@ vlc_fifo_GetCount
vlc_fifo_GetBytes
vlc_gl_Create
vlc_gl_Destroy
vlc_gl_ModuleCreate
vlc_gl_surface_Create
vlc_gl_surface_CheckSize
vlc_gl_surface_Destroy
......
......@@ -29,47 +29,43 @@
#include <vlc_opengl.h>
#include "libvlc.h"
#include <vlc_modules.h>
#include <vlc_vout_window.h>
#undef vlc_gl_Create
/**
* Creates an OpenGL context (and its underlying surface).
*
* @note In most cases, you should vlc_gl_MakeCurrent() afterward.
*
* @param wnd window to use as OpenGL surface
* @param flags OpenGL context type
* @param name module name (or NULL for auto)
* @return a new context, or NULL on failure
*/
vlc_gl_t *vlc_gl_Create(struct vout_window_t *wnd, unsigned flags,
const char *name)
vlc_gl_t *vlc_gl_Create(vlc_object_t* parent)
{
vlc_object_t *parent = (vlc_object_t *)wnd;
vlc_gl_t *gl;
const char *type;
return vlc_custom_create(parent, sizeof(vlc_gl_t), "gl");
}
switch (flags /*& VLC_OPENGL_API_MASK*/)
vlc_gl_t *vlc_gl_ModuleCreate(struct vout_window_t *wnd, unsigned flags,
const char *module_name)
{
const char *module_type;
switch (flags)
{
case VLC_OPENGL:
type = "opengl";
module_type = "opengl";
break;
case VLC_OPENGL_ES:
type = "opengl es";
module_type = "opengl es";
break;
case VLC_OPENGL_ES2:
type = "opengl es2";
module_type = "opengl es2";
break;
default:
return NULL;
}
gl = vlc_custom_create(parent, sizeof (*gl), "gl");
if (unlikely(gl == NULL))
vlc_gl_t *gl = vlc_gl_Create(VLC_OBJECT(wnd));
if( unlikely( !gl ) )
return NULL;
gl->surface = wnd;
gl->module = module_need(gl, type, name, true);
if (gl->module == NULL)
gl->module = module_need(gl, module_type, module_name, true);
if (gl->module == NULL )
{
vlc_object_release(gl);
return NULL;
......@@ -80,12 +76,11 @@ vlc_gl_t *vlc_gl_Create(struct vout_window_t *wnd, unsigned flags,
void vlc_gl_Destroy(vlc_gl_t *gl)
{
module_unneed(gl, gl->module);
if(gl->module)
module_unneed(gl, gl->module);
vlc_object_release(gl);
}
#include <vlc_vout_window.h>
typedef struct vlc_gl_surface
{
int width;
......@@ -130,7 +125,7 @@ vlc_gl_t *vlc_gl_surface_Create(vlc_object_t *obj,
*wp = surface;
/* TODO: support ES? */
vlc_gl_t *gl = vlc_gl_Create(surface, VLC_OPENGL, NULL);
vlc_gl_t *gl = vlc_gl_ModuleCreate(surface, VLC_OPENGL, NULL);
if (gl == NULL) {
vout_window_Delete(surface);
return NULL;
......
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