Commit e41f98e9 authored by Steve Lhomme's avatar Steve Lhomme
Browse files

display: use an optional callback to set the viewpoint

In the future it may be called directly from the thread generating the event to
lower the latency.
parent 9e369fcb
......@@ -214,11 +214,6 @@ enum vout_display_query {
* is necessary
*/
VOUT_DISPLAY_CHANGE_SOURCE_CROP,
/**
* Notifies a change of VR/360° viewpoint.
*/
VOUT_DISPLAY_CHANGE_VIEWPOINT, /* const vlc_viewpoint_t * */
};
/**
......@@ -359,6 +354,15 @@ struct vout_display_t {
*/
int (*control)(vout_display_t *, int query, va_list);
/**
* Notifies a change of VR/360° viewpoint.
*
* May be NULL.
*
* \param vp viewpoint to use on the next render
*/
int (*set_viewpoint)(vout_display_t *, const vlc_viewpoint_t *vp);
/**
* Destroys the display.
*/
......
......@@ -107,6 +107,17 @@ struct gl_sys
VLCCAOpenGLLayer *cgLayer;
};
static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
{
vout_display_sys_t *sys = vd->sys;
if (OpenglLock(sys->gl))
return VLC_EGENERIC;
int ret = vout_display_opengl_SetViewpoint(sys->vgl, vp);
OpenglUnlock(sys->gl);
return ret;
}
/*****************************************************************************
* Open: This function allocates and initializes the OpenGL vout method.
*****************************************************************************/
......@@ -201,6 +212,7 @@ static int Open (vout_display_t *vd, const vout_display_cfg_t *cfg,
vd->prepare = PictureRender;
vd->display = PictureDisplay;
vd->control = Control;
vd->set_viewpoint = SetViewpoint;
vd->close = Close;
if (OSX_SIERRA_AND_HIGHER) {
......@@ -341,19 +353,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
return VLC_SUCCESS;
}
case VOUT_DISPLAY_CHANGE_VIEWPOINT:
{
int ret;
if (OpenglLock(sys->gl))
return VLC_EGENERIC;
ret = vout_display_opengl_SetViewpoint(sys->vgl,
va_arg(ap, const vlc_viewpoint_t*));
OpenglUnlock(sys->gl);
return ret;
}
case VOUT_DISPLAY_RESET_PICTURES:
vlc_assert_unreachable ();
default:
......
......@@ -144,6 +144,13 @@ static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
return dlsym(RTLD_DEFAULT, name);
}
static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
{
vout_display_sys_t *sys = vd->sys;
struct gl_sys *glsys = sys->gl->sys;
return vout_display_opengl_SetViewpoint (glsys->vgl, vp);
}
static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
video_format_t *fmt, vlc_video_context *context)
{
......@@ -212,6 +219,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
vd->prepare = PictureRender;
vd->display = PictureDisplay;
vd->control = Control;
vd->set_viewpoint = SetViewpoint;
vd->close = Close;
return VLC_SUCCESS;
......@@ -273,10 +281,6 @@ static int Control(vout_display_t *vd, int query, va_list ap)
return VLC_SUCCESS;
}
case VOUT_DISPLAY_CHANGE_VIEWPOINT:
return vout_display_opengl_SetViewpoint(glsys->vgl,
va_arg(ap, const vlc_viewpoint_t*));
case VOUT_DISPLAY_RESET_PICTURES:
vlc_assert_unreachable ();
default:
......
......@@ -131,6 +131,12 @@ static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
return dlsym(RTLD_DEFAULT, name);
}
static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
{
vout_display_sys_t *sys = vd->sys;
return vout_display_opengl_SetViewpoint (sys->vgl, vp);
}
static int Open (vout_display_t *vd, const vout_display_cfg_t *cfg,
video_format_t *fmt, vlc_video_context *context)
{
......@@ -244,6 +250,7 @@ static int Open (vout_display_t *vd, const vout_display_cfg_t *cfg,
vd->prepare = PictureRender;
vd->display = PictureDisplay;
vd->control = Control;
vd->set_viewpoint = SetViewpoint;
vd->close = Close;
/* */
......@@ -387,10 +394,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
return VLC_SUCCESS;
}
case VOUT_DISPLAY_CHANGE_VIEWPOINT:
return vout_display_opengl_SetViewpoint (sys->vgl,
va_arg(ap, const vlc_viewpoint_t*));
case VOUT_DISPLAY_RESET_PICTURES:
vlc_assert_unreachable ();
default:
......
......@@ -87,6 +87,12 @@ static void PictureRender (vout_display_t *, picture_t *, subpicture_t *, vlc_ti
static void PictureDisplay (vout_display_t *, picture_t *);
static int Control (vout_display_t *, int, va_list);
static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
{
vout_display_sys_t *sys = vd->sys;
return vout_display_opengl_SetViewpoint (sys->vgl, vp);
}
/**
* Allocates a surface and an OpenGL context for video output.
*/
......@@ -152,6 +158,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
vd->prepare = PictureRender;
vd->display = PictureDisplay;
vd->control = Control;
vd->set_viewpoint = SetViewpoint;
vd->close = Close;
return VLC_SUCCESS;
......@@ -258,9 +265,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
sys->place_changed = true;
return VLC_SUCCESS;
}
case VOUT_DISPLAY_CHANGE_VIEWPOINT:
return vout_display_opengl_SetViewpoint (sys->vgl,
va_arg(ap, const vlc_viewpoint_t*));
default:
msg_Err (vd, "Unknown request %d", query);
}
......
......@@ -291,6 +291,19 @@ static void UpdateSize(vout_display_t *vd)
#endif
}
static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *viewpoint)
{
vout_display_sys_t *sys = vd->sys;
if ( sys->picQuad.pVertexShaderConstants )
{
d3d11_device_lock( sys->d3d_dev );
D3D11_UpdateViewpoint( vd, sys->d3d_dev, &sys->picQuad, viewpoint,
(float) vd->cfg->display.width / vd->cfg->display.height );
d3d11_device_unlock( sys->d3d_dev );
}
return VLC_SUCCESS;
}
static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
video_format_t *fmtp, vlc_video_context *context)
{
......@@ -380,6 +393,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
vd->prepare = Prepare;
vd->display = Display;
vd->control = Control;
vd->set_viewpoint = SetViewpoint;
vd->close = Close;
msg_Dbg(vd, "Direct3D11 Open Succeeded");
......@@ -402,22 +416,10 @@ static void Close(vout_display_t *vd)
}
static int Control(vout_display_t *vd, int query, va_list args)
{
VLC_UNUSED(args);
vout_display_sys_t *sys = vd->sys;
int res = CommonControl( vd, &sys->area, &sys->sys, query );
if (query == VOUT_DISPLAY_CHANGE_VIEWPOINT)
{
if ( sys->picQuad.pVertexShaderConstants )
{
const vlc_viewpoint_t *viewpoint = va_arg(args, const vlc_viewpoint_t*);
d3d11_device_lock( sys->d3d_dev );
D3D11_UpdateViewpoint( vd, sys->d3d_dev, &sys->picQuad, viewpoint,
(float) vd->cfg->display.width / vd->cfg->display.height );
d3d11_device_unlock( sys->d3d_dev );
res = VLC_SUCCESS;
}
}
if ( sys->area.place_changed )
{
UpdateSize(vd);
......
......@@ -78,14 +78,16 @@ struct vout_display_sys_t
static void Prepare(vout_display_t *, picture_t *, subpicture_t *, vlc_tick_t);
static void Display(vout_display_t *, picture_t *);
static int Control(vout_display_t *vd, int query, va_list args)
static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
{
vout_display_sys_t *sys = vd->sys;
return vout_display_opengl_SetViewpoint(sys->vgl, vp);
}
if (query == VOUT_DISPLAY_CHANGE_VIEWPOINT)
return vout_display_opengl_SetViewpoint(sys->vgl,
va_arg(args, const vlc_viewpoint_t*));
static int Control(vout_display_t *vd, int query, va_list args)
{
VLC_UNUSED(args);
vout_display_sys_t *sys = vd->sys;
return CommonControl(vd, &sys->area, &sys->sys, query);
}
......@@ -166,6 +168,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
vd->prepare = Prepare;
vd->display = Display;
vd->control = Control;
vd->set_viewpoint = SetViewpoint;
vd->close = Close;
return VLC_SUCCESS;
......
......@@ -685,10 +685,12 @@ void vout_SetDisplayViewpoint(vout_display_t *vd,
osys->cfg.viewpoint = *p_viewpoint;
if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_VIEWPOINT,
&osys->cfg.viewpoint)) {
msg_Err(vd, "Failed to change Viewpoint");
osys->cfg.viewpoint = old_vp;
if (vd->set_viewpoint)
{
if (vd->set_viewpoint(vd, &osys->cfg.viewpoint)) {
msg_Err(vd, "Failed to change Viewpoint");
osys->cfg.viewpoint = old_vp;
}
}
}
}
......
Supports Markdown
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