Skip to content

Commit

Permalink
opengl: add an alpha config to the activate cb
Browse files Browse the repository at this point in the history
  • Loading branch information
tguillem authored and jbkempf committed Mar 5, 2023
1 parent 09d8638 commit 9155b08
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 44 deletions.
19 changes: 15 additions & 4 deletions include/vlc_opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ enum vlc_gl_api_type {
VLC_OPENGL_ES2,
};

typedef int (*vlc_gl_activate)(vlc_gl_t *, unsigned width, unsigned height);
struct vlc_gl_cfg
{
bool need_alpha; /* False by default */
};

typedef int (*vlc_gl_activate)(vlc_gl_t *, unsigned width, unsigned height,
const struct vlc_gl_cfg *cfg);

#define set_callback_opengl_common(activate) \
{ \
Expand Down Expand Up @@ -122,14 +128,17 @@ struct vlc_gl_t
* @param cfg initial configuration (including window to use as OpenGL surface)
* @param flags OpenGL context type
* @param name module name (or NULL for auto)
* @param gl_cfg OpenGL configuration (or NULL for default)
* @return a new context, or NULL on failure
*/
VLC_API vlc_gl_t *vlc_gl_Create(const struct vout_display_cfg *cfg,
unsigned flags, const char *name) VLC_USED;
unsigned flags, const char *name,
const struct vlc_gl_cfg *gl_cfg) VLC_USED;
VLC_API vlc_gl_t *vlc_gl_CreateOffscreen(vlc_object_t *parent,
struct vlc_decoder_device *device,
unsigned width, unsigned height,
unsigned flags, const char *name);
unsigned flags, const char *name,
const struct vlc_gl_cfg *gl_cfg);

VLC_API void vlc_gl_Delete(vlc_gl_t *);

Expand Down Expand Up @@ -184,7 +193,9 @@ static inline void *vlc_gl_GetProcAddress(vlc_gl_t *gl, const char *name)

VLC_API vlc_gl_t *vlc_gl_surface_Create(vlc_object_t *,
const struct vlc_window_cfg *,
struct vlc_window **) VLC_USED;
struct vlc_window **,
const struct vlc_gl_cfg *) VLC_USED;

VLC_API bool vlc_gl_surface_CheckSize(vlc_gl_t *, unsigned *w, unsigned *h);
VLC_API void vlc_gl_surface_Destroy(vlc_gl_t *);

Expand Down
9 changes: 8 additions & 1 deletion modules/video_filter/egl_pbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,15 @@ static void Close( vlc_gl_t *gl )
vlc_egl_display_Delete(sys->vlc_display);
}

static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
static int Open(vlc_gl_t *gl, unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg)
{
if (gl_cfg->need_alpha)
{
msg_Err(gl, "Cannot support alpha yet");
return VLC_ENOTSUP;
}

struct vlc_gl_pbuffer *sys = vlc_obj_malloc(&gl->obj, sizeof *sys);
if (sys == NULL)
return VLC_ENOMEM;
Expand Down
9 changes: 8 additions & 1 deletion modules/video_filter/egl_surfacetexture.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,15 @@ static int InitPicturePool(vlc_gl_t *gl)
return VLC_EGENERIC;
}

static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
static int Open(vlc_gl_t *gl, unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg)
{
if (gl_cfg->need_alpha)
{
msg_Err(gl, "Cannot support alpha yet");
return VLC_ENOTSUP;
}

if (gl->device == NULL || gl->device->type != VLC_DECODER_DEVICE_AWINDOW)
{
msg_Err(gl, "Wrong decoder device");
Expand Down
2 changes: 1 addition & 1 deletion modules/video_filter/opengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static int Open( vlc_object_t *obj )

struct vlc_decoder_device *device = filter_HoldDecoderDevice(filter);
sys->gl = vlc_gl_CreateOffscreen(obj, device, width, height, VLCGLAPI,
NULL);
NULL, NULL);

/* The vlc_gl_t instance must have hold the device if it needs it. */
if (device)
Expand Down
2 changes: 1 addition & 1 deletion modules/video_output/android/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ static void ClearSurface(vout_display_t *vd)
{
/* Clear the surface to black with OpenGL ES 2 */
char *modlist = var_InheritString(sys->embed, "gles2");
vlc_gl_t *gl = vlc_gl_Create(vd->cfg, VLC_OPENGL_ES2, modlist);
vlc_gl_t *gl = vlc_gl_Create(vd->cfg, VLC_OPENGL_ES2, modlist, NULL);
free(modlist);
if (gl == NULL)
return;
Expand Down
9 changes: 8 additions & 1 deletion modules/video_output/apple/VLCCVOpenGLProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,15 @@ - (void)dealloc

@end

static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
static int Open(vlc_gl_t *gl, unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg)
{
if (gl_cfg->need_alpha)
{
msg_Err(gl, "Cannot support alpha yet");
return VLC_ENOTSUP;
}

VLCCVOpenGLProvider *sys = [[VLCCVOpenGLProvider alloc] initWithGL:gl width:width height:height];
if (sys == nil)
return VLC_EGENERIC;;
Expand Down
9 changes: 8 additions & 1 deletion modules/video_output/apple/VLCOpenGLES2VideoView.m
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,17 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event



static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
static int Open(vlc_gl_t *gl, unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg)
{
vlc_window_t *wnd = gl->surface;

if (gl_cfg->need_alpha)
{
msg_Err(gl, "Cannot support alpha yet");
return VLC_ENOTSUP;
}

/* We only support UIView container window. */
if (wnd->type != VLC_WINDOW_TYPE_NSOBJECT)
return VLC_EGENERIC;
Expand Down
9 changes: 8 additions & 1 deletion modules/video_output/glx.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,17 @@ static void Close(vlc_gl_t *gl)
free(sys);
}

static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
static int Open(vlc_gl_t *gl, unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg)
{
vlc_object_t *obj = VLC_OBJECT(gl);

if (gl_cfg->need_alpha)
{
msg_Err(gl, "Cannot support alpha yet");
return VLC_ENOTSUP;
}

if (gl->surface->type != VLC_WINDOW_TYPE_XID || !vlc_xlib_init (obj))
return VLC_EGENERIC;

Expand Down
2 changes: 1 addition & 1 deletion modules/video_output/libplacebo/instance_opengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static int InitInstance(vlc_placebo_t *pl, const vout_display_cfg_t *cfg)
bool current = false;

char *name = var_InheritString(pl, MODULE_VARNAME);
sys->gl = vlc_gl_Create(cfg, API, name);
sys->gl = vlc_gl_Create(cfg, API, name, NULL);
free(name);
if (!sys->gl || vlc_gl_MakeCurrent(sys->gl) != VLC_SUCCESS)
goto error;
Expand Down
2 changes: 1 addition & 1 deletion modules/video_output/opengl/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static int Open(vout_display_t *vd,
}
#endif

sys->gl = vlc_gl_Create(vd->cfg, API, gl_name);
sys->gl = vlc_gl_Create(vd->cfg, API, gl_name, NULL);
free(gl_name);
if (sys->gl == NULL)
goto error;
Expand Down
19 changes: 14 additions & 5 deletions modules/video_output/opengl/egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,15 @@ static void InitEGL(void)
* Probe EGL display availability
*/
static int Open(vlc_gl_t *gl, const struct gl_api *api,
unsigned width, unsigned height)
unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg)
{
if (gl_cfg->need_alpha)
{
msg_Err(gl, "Cannot support alpha yet");
return VLC_ENOTSUP;
}

InitEGL();

int ret = VLC_EGENERIC;
Expand Down Expand Up @@ -699,22 +706,24 @@ static int Open(vlc_gl_t *gl, const struct gl_api *api,
return ret;
}

static int OpenGLES2(vlc_gl_t *gl, unsigned width, unsigned height)
static int OpenGLES2(vlc_gl_t *gl, unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg)
{
static const struct gl_api api = {
"OpenGL_ES", EGL_OPENGL_ES_API, 4, EGL_OPENGL_ES2_BIT,
{ EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE },
};
return Open(gl, &api, width, height);
return Open(gl, &api, width, height, gl_cfg);
}

static int OpenGL(vlc_gl_t *gl, unsigned width, unsigned height)
static int OpenGL(vlc_gl_t *gl, unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg)
{
static const struct gl_api api = {
"OpenGL", EGL_OPENGL_API, 4, EGL_OPENGL_BIT,
{ EGL_NONE },
};
return Open(gl, &api, width, height);
return Open(gl, &api, width, height, gl_cfg);
}

#ifdef USE_PLATFORM_XCB
Expand Down
9 changes: 8 additions & 1 deletion modules/video_output/vgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ static void Close(vlc_gl_t *gl)
} \
} while( 0 )

static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
static int Open(vlc_gl_t *gl, unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg)
{
vout_display_sys_t * sys;

Expand All @@ -131,6 +132,12 @@ static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
engineType != libvlc_video_engine_gles2 )
return VLC_ENOTSUP;

if (gl_cfg->need_alpha)
{
msg_Err(gl, "Cannot support alpha yet");
return VLC_ENOTSUP;
}

/* Allocate structure */
gl->sys = sys = vlc_obj_calloc(VLC_OBJECT(gl), 1, sizeof(*sys));
if( !sys )
Expand Down
2 changes: 1 addition & 1 deletion modules/video_output/win32/glwin32.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static int Open(vout_display_t *vd,
goto error;

char *modlist = var_InheritString(embed_cfg.window, "gl");
sys->gl = vlc_gl_Create(&embed_cfg, VLC_OPENGL, modlist);
sys->gl = vlc_gl_Create(&embed_cfg, VLC_OPENGL, modlist, NULL);
free(modlist);
if (!sys->gl)
{
Expand Down
12 changes: 10 additions & 2 deletions modules/video_output/win32/wgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
/*****************************************************************************
* Module descriptor
*****************************************************************************/
static int Open(vlc_gl_t *, unsigned width, unsigned height);
static int Open(vlc_gl_t *, unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg);
static void Close(vlc_gl_t *);

#define HW_GPU_AFFINITY_TEXT N_("GPU affinity")
Expand Down Expand Up @@ -148,10 +149,17 @@ static void DestroyGPUAffinityDC(vlc_gl_t *gl) {
fncDeleteDCNV(sys->affinityHDC);
}

static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
static int Open(vlc_gl_t *gl, unsigned width, unsigned height,
const struct vlc_gl_cfg *gl_cfg)
{
vout_display_sys_t *sys;

if (gl_cfg->need_alpha)
{
msg_Err(gl, "Cannot support alpha yet");
return VLC_ENOTSUP;
}

/* Allocate structure */
gl->sys = sys = calloc(1, sizeof(*sys));
if (!sys)
Expand Down
2 changes: 1 addition & 1 deletion modules/visualization/glspectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static int Open(vlc_object_t * p_this)
.height = var_InheritInteger(p_filter, "glspectrum-height"),
};

p_sys->gl = vlc_gl_surface_Create(p_this, &cfg, NULL);
p_sys->gl = vlc_gl_surface_Create(p_this, &cfg, NULL, NULL);
if (p_sys->gl == NULL)
return VLC_EGENERIC;

Expand Down
2 changes: 1 addition & 1 deletion modules/visualization/projectm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static int Open( vlc_object_t * p_this )
cfg.width = var_CreateGetInteger( p_filter, "projectm-width" );
cfg.height = var_CreateGetInteger( p_filter, "projectm-height" );

p_sys->gl = vlc_gl_surface_Create( VLC_OBJECT(p_filter), &cfg, NULL );
p_sys->gl = vlc_gl_surface_Create( VLC_OBJECT(p_filter), &cfg, NULL, NULL );
if( p_sys->gl == NULL )
goto error;

Expand Down
2 changes: 1 addition & 1 deletion modules/visualization/vsxu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static int Open( vlc_object_t * p_this )
cfg.width = var_InheritInteger( p_filter, "vsxu-width" );
cfg.height = var_InheritInteger( p_filter, "vsxu-height" );

p_sys->gl = vlc_gl_surface_Create( VLC_OBJECT(p_filter), &cfg, NULL );
p_sys->gl = vlc_gl_surface_Create( VLC_OBJECT(p_filter), &cfg, NULL, NULL);
if( p_sys->gl == NULL )
goto error;

Expand Down
27 changes: 20 additions & 7 deletions src/video_output/opengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include "libvlc.h"
#include <vlc_modules.h>

static const struct vlc_gl_cfg gl_cfg_default = {
.need_alpha = false
};

struct vlc_gl_priv_t
{
vlc_gl_t gl;
Expand All @@ -44,20 +48,24 @@ static int vlc_gl_start(void *func, bool forced, va_list ap)
vlc_gl_t *gl = va_arg(ap, vlc_gl_t *);
unsigned width = va_arg(ap, unsigned);
unsigned height = va_arg(ap, unsigned);
const struct vlc_gl_cfg *gl_cfg = va_arg(ap, const struct vlc_gl_cfg *);

int ret = activate(gl, width, height);
int ret = activate(gl, width, height, gl_cfg);
if (ret)
vlc_objres_clear(VLC_OBJECT(gl));
(void) forced;
return ret;
}

vlc_gl_t *vlc_gl_Create(const struct vout_display_cfg *restrict cfg,
unsigned flags, const char *name)
unsigned flags, const char *name,
const struct vlc_gl_cfg * gl_cfg)
{
vlc_window_t *wnd = cfg->window;
struct vlc_gl_priv_t *glpriv;
const char *type;
if (gl_cfg == NULL)
gl_cfg = &gl_cfg_default;

enum vlc_gl_api_type api_type;

Expand Down Expand Up @@ -85,7 +93,8 @@ vlc_gl_t *vlc_gl_Create(const struct vout_display_cfg *restrict cfg,
gl->device = NULL;

gl->module = vlc_module_load(gl, type, name, true, vlc_gl_start, gl,
cfg->display.width, cfg->display.height);
cfg->display.width, cfg->display.height,
gl_cfg);
if (gl->module == NULL)
{
vlc_object_delete(gl);
Expand All @@ -104,12 +113,15 @@ vlc_gl_t *vlc_gl_Create(const struct vout_display_cfg *restrict cfg,
vlc_gl_t *vlc_gl_CreateOffscreen(vlc_object_t *parent,
struct vlc_decoder_device *device,
unsigned width, unsigned height,
unsigned flags, const char *name)
unsigned flags, const char *name,
const struct vlc_gl_cfg *gl_cfg)
{
struct vlc_gl_priv_t *glpriv;
const char *type;

enum vlc_gl_api_type api_type;
if (gl_cfg == NULL)
gl_cfg = &gl_cfg_default;

switch (flags /*& VLC_OPENGL_API_MASK*/)
{
Expand Down Expand Up @@ -140,7 +152,7 @@ vlc_gl_t *vlc_gl_CreateOffscreen(vlc_object_t *parent,
gl->surface = NULL;
gl->device = device ? vlc_decoder_device_Hold(device) : NULL;
gl->module = vlc_module_load(gl, type, name, true, vlc_gl_start, gl, width,
height);
height, gl_cfg);
if (gl->module == NULL)
{
vlc_object_delete(gl);
Expand Down Expand Up @@ -199,7 +211,8 @@ static void vlc_gl_surface_ResizeNotify(vlc_window_t *surface,

vlc_gl_t *vlc_gl_surface_Create(vlc_object_t *obj,
const vlc_window_cfg_t *cfg,
struct vlc_window **restrict wp)
struct vlc_window **restrict wp,
const struct vlc_gl_cfg *gl_cfg)
{
vlc_gl_surface_t *sys = malloc(sizeof (*sys));
if (unlikely(sys == NULL))
Expand Down Expand Up @@ -244,7 +257,7 @@ vlc_gl_t *vlc_gl_surface_Create(vlc_object_t *obj,
}
vlc_mutex_unlock(&sys->lock);

vlc_gl_t *gl = vlc_gl_Create(&dcfg, VLC_OPENGL, NULL);
vlc_gl_t *gl = vlc_gl_Create(&dcfg, VLC_OPENGL, NULL, gl_cfg);
if (gl == NULL) {
vlc_window_Disable(surface);
vlc_window_Delete(surface);
Expand Down
Loading

0 comments on commit 9155b08

Please sign in to comment.