Commit 85c1c62e authored by Gildas Bazin's avatar Gildas Bazin

* src/video_output/video_widgets.c: cleanup.

parent 0313ad5a
...@@ -39,20 +39,8 @@ ...@@ -39,20 +39,8 @@
*****************************************************************************/ *****************************************************************************/
static void DrawRect( subpicture_t *, int, int, int, int, short ); static void DrawRect( subpicture_t *, int, int, int, int, short );
static void DrawTriangle( subpicture_t *, int, int, int, int, short ); static void DrawTriangle( subpicture_t *, int, int, int, int, short );
static void CreatePicture( vout_thread_t *, subpicture_t * ); static void CreatePicture( spu_t *, subpicture_t *, int, int, int, int );
static subpicture_t *vout_CreateWidget( vout_thread_t *, int ); static subpicture_t *vout_CreateWidget( spu_t *, int );
static void FreeWidget( subpicture_t * );
/**
* Private data in a subpicture.
*/
struct subpicture_sys_t
{
int i_x;
int i_y;
int i_width;
int i_height;
};
/***************************************************************************** /*****************************************************************************
* Draws a rectangle at the given position in the subpic. * Draws a rectangle at the given position in the subpic.
...@@ -160,10 +148,9 @@ static void DrawTriangle( subpicture_t *p_subpic, int i_x1, int i_y1, ...@@ -160,10 +148,9 @@ static void DrawTriangle( subpicture_t *p_subpic, int i_x1, int i_y1,
/***************************************************************************** /*****************************************************************************
* Create Picture: creates subpicture region and picture * Create Picture: creates subpicture region and picture
*****************************************************************************/ *****************************************************************************/
static void CreatePicture( vout_thread_t *p_vout, subpicture_t *p_subpic ) static void CreatePicture( spu_t *p_spu, subpicture_t *p_subpic,
int i_x, int i_y, int i_width, int i_height )
{ {
subpicture_sys_t *p_widget = p_subpic->p_sys;
spu_t *p_spu = p_vout->p_spu;
uint8_t *p_y, *p_u, *p_v, *p_a; uint8_t *p_y, *p_u, *p_v, *p_a;
video_format_t fmt; video_format_t fmt;
int i_pitch; int i_pitch;
...@@ -172,8 +159,8 @@ static void CreatePicture( vout_thread_t *p_vout, subpicture_t *p_subpic ) ...@@ -172,8 +159,8 @@ static void CreatePicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
memset( &fmt, 0, sizeof(video_format_t) ); memset( &fmt, 0, sizeof(video_format_t) );
fmt.i_chroma = VLC_FOURCC('Y','U','V','A'); fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
fmt.i_aspect = VOUT_ASPECT_FACTOR; fmt.i_aspect = VOUT_ASPECT_FACTOR;
fmt.i_width = fmt.i_visible_width = p_widget->i_width; fmt.i_width = fmt.i_visible_width = i_width;
fmt.i_height = fmt.i_visible_height = p_widget->i_height; fmt.i_height = fmt.i_visible_height = i_height;
fmt.i_x_offset = fmt.i_y_offset = 0; fmt.i_x_offset = fmt.i_y_offset = 0;
p_subpic->p_region = p_subpic->pf_create_region( VLC_OBJECT(p_spu), &fmt ); p_subpic->p_region = p_subpic->pf_create_region( VLC_OBJECT(p_spu), &fmt );
if( !p_subpic->p_region ) if( !p_subpic->p_region )
...@@ -182,8 +169,8 @@ static void CreatePicture( vout_thread_t *p_vout, subpicture_t *p_subpic ) ...@@ -182,8 +169,8 @@ static void CreatePicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
return; return;
} }
p_subpic->p_region->i_x = p_widget->i_x; p_subpic->p_region->i_x = i_x;
p_subpic->p_region->i_y = p_widget->i_y; p_subpic->p_region->i_y = i_y;
p_y = p_subpic->p_region->picture.Y_PIXELS; p_y = p_subpic->p_region->picture.Y_PIXELS;
p_u = p_subpic->p_region->picture.U_PIXELS; p_u = p_subpic->p_region->picture.U_PIXELS;
p_v = p_subpic->p_region->picture.V_PIXELS; p_v = p_subpic->p_region->picture.V_PIXELS;
...@@ -200,37 +187,21 @@ static void CreatePicture( vout_thread_t *p_vout, subpicture_t *p_subpic ) ...@@ -200,37 +187,21 @@ static void CreatePicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
/***************************************************************************** /*****************************************************************************
* Creates and initializes an OSD widget. * Creates and initializes an OSD widget.
*****************************************************************************/ *****************************************************************************/
subpicture_t *vout_CreateWidget( vout_thread_t *p_vout, int i_channel ) subpicture_t *vout_CreateWidget( spu_t *p_spu, int i_channel )
{ {
subpicture_t *p_subpic; subpicture_t *p_subpic;
subpicture_sys_t *p_widget;
mtime_t i_now = mdate(); mtime_t i_now = mdate();
p_subpic = 0;
p_widget = 0;
/* Create and initialize a subpicture */ /* Create and initialize a subpicture */
p_subpic = spu_CreateSubpicture( p_vout->p_spu ); p_subpic = spu_CreateSubpicture( p_spu );
if( p_subpic == NULL ) if( p_subpic == NULL ) return NULL;
{
return NULL;
}
p_subpic->i_channel = i_channel; p_subpic->i_channel = i_channel;
p_subpic->pf_destroy = FreeWidget;
p_subpic->i_start = i_now; p_subpic->i_start = i_now;
p_subpic->i_stop = i_now + 1200000; p_subpic->i_stop = i_now + 1200000;
p_subpic->b_ephemer = VLC_TRUE; p_subpic->b_ephemer = VLC_TRUE;
p_subpic->b_fade = VLC_TRUE; p_subpic->b_fade = VLC_TRUE;
p_widget = malloc( sizeof(subpicture_sys_t) );
if( p_widget == NULL )
{
FreeWidget( p_subpic );
spu_DestroySubpicture( p_vout->p_spu, p_subpic );
return NULL;
}
p_subpic->p_sys = p_widget;
return p_subpic; return p_subpic;
} }
...@@ -244,63 +215,55 @@ void vout_OSDSlider( vlc_object_t *p_caller, int i_channel, int i_position, ...@@ -244,63 +215,55 @@ void vout_OSDSlider( vlc_object_t *p_caller, int i_channel, int i_position,
vout_thread_t *p_vout = vlc_object_find( p_caller, VLC_OBJECT_VOUT, vout_thread_t *p_vout = vlc_object_find( p_caller, VLC_OBJECT_VOUT,
FIND_ANYWHERE ); FIND_ANYWHERE );
subpicture_t *p_subpic; subpicture_t *p_subpic;
subpicture_sys_t *p_widget; int i_x_margin, i_y_margin, i_x, i_y, i_width, i_height;
int i_x_margin, i_y_margin;
if( p_vout == NULL || !config_GetInt( p_caller, "osd" ) || i_position < 0 ) if( p_vout == NULL || !config_GetInt( p_caller, "osd" ) || i_position < 0 )
{ {
return; return;
} }
p_subpic = vout_CreateWidget( p_vout, i_channel ); p_subpic = vout_CreateWidget( p_vout->p_spu, i_channel );
if( p_subpic == NULL ) if( p_subpic == NULL )
{ {
return; return;
} }
p_widget = p_subpic->p_sys;
i_y_margin = p_vout->render.i_height / 10; i_y_margin = p_vout->render.i_height / 10;
i_x_margin = i_y_margin; i_x_margin = i_y_margin;
if( i_type == OSD_HOR_SLIDER ) if( i_type == OSD_HOR_SLIDER )
{ {
p_widget->i_width = p_vout->render.i_width - 2 * i_x_margin; i_width = p_vout->render.i_width - 2 * i_x_margin;
p_widget->i_height = p_vout->render.i_height / 20; i_height = p_vout->render.i_height / 20;
p_widget->i_x = i_x_margin; i_x = i_x_margin;
p_widget->i_y = p_vout->render.i_height - i_y_margin - i_y = p_vout->render.i_height - i_y_margin - i_height;
p_widget->i_height;
} }
else else
{ {
p_widget->i_width = p_vout->render.i_width / 40; i_width = p_vout->render.i_width / 40;
p_widget->i_height = p_vout->render.i_height - 2 * i_y_margin; i_height = p_vout->render.i_height - 2 * i_y_margin;
p_widget->i_x = p_vout->render.i_width - i_x_margin - i_x = p_vout->render.i_width - i_x_margin - i_width;
p_widget->i_width; i_y = i_y_margin;
p_widget->i_y = i_y_margin;
} }
/* Create subpicture region and picture */ /* Create subpicture region and picture */
CreatePicture( p_vout, p_subpic ); CreatePicture( p_vout->p_spu, p_subpic, i_x, i_y, i_width, i_height );
if( i_type == OSD_HOR_SLIDER ) if( i_type == OSD_HOR_SLIDER )
{ {
int i_x_pos = ( p_widget->i_width - 2 ) * i_position / 100; int i_x_pos = ( i_width - 2 ) * i_position / 100;
DrawRect( p_subpic, i_x_pos - 1, 2, i_x_pos + 1, DrawRect( p_subpic, i_x_pos - 1, 2, i_x_pos + 1,
p_widget->i_height - 3, STYLE_FILLED ); i_height - 3, STYLE_FILLED );
DrawRect( p_subpic, 0, 0, p_widget->i_width - 1, DrawRect( p_subpic, 0, 0, i_width - 1, i_height - 1, STYLE_EMPTY );
p_widget->i_height - 1, STYLE_EMPTY );
} }
else if( i_type == OSD_VERT_SLIDER ) else if( i_type == OSD_VERT_SLIDER )
{ {
int i_y_pos = p_widget->i_height / 2; int i_y_pos = i_height / 2;
DrawRect( p_subpic, 2, p_widget->i_height - DrawRect( p_subpic, 2, i_height - ( i_height - 2 ) * i_position / 100,
( p_widget->i_height - 2 ) * i_position / 100, i_width - 3, i_height - 3, STYLE_FILLED );
p_widget->i_width - 3, p_widget->i_height - 3,
STYLE_FILLED );
DrawRect( p_subpic, 1, i_y_pos, 1, i_y_pos, STYLE_FILLED ); DrawRect( p_subpic, 1, i_y_pos, 1, i_y_pos, STYLE_FILLED );
DrawRect( p_subpic, p_widget->i_width - 2, i_y_pos, DrawRect( p_subpic, i_width - 2, i_y_pos,
p_widget->i_width - 2, i_y_pos, STYLE_FILLED ); i_width - 2, i_y_pos, STYLE_FILLED );
DrawRect( p_subpic, 0, 0, p_widget->i_width - 1, DrawRect( p_subpic, 0, 0, i_width - 1, i_height - 1, STYLE_EMPTY );
p_widget->i_height - 1, STYLE_EMPTY );
} }
spu_DisplaySubpicture( p_vout->p_spu, p_subpic ); spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
...@@ -318,56 +281,52 @@ void vout_OSDIcon( vlc_object_t *p_caller, int i_channel, short i_type ) ...@@ -318,56 +281,52 @@ void vout_OSDIcon( vlc_object_t *p_caller, int i_channel, short i_type )
vout_thread_t *p_vout = vlc_object_find( p_caller, VLC_OBJECT_VOUT, vout_thread_t *p_vout = vlc_object_find( p_caller, VLC_OBJECT_VOUT,
FIND_ANYWHERE ); FIND_ANYWHERE );
subpicture_t *p_subpic; subpicture_t *p_subpic;
subpicture_sys_t *p_widget; int i_x_margin, i_y_margin, i_x, i_y, i_width, i_height;
int i_x_margin, i_y_margin;
if( p_vout == NULL || !config_GetInt( p_caller, "osd" ) ) if( p_vout == NULL || !config_GetInt( p_caller, "osd" ) )
{ {
return; return;
} }
p_subpic = vout_CreateWidget( p_vout, i_channel ); p_subpic = vout_CreateWidget( p_vout->p_spu, i_channel );
if( p_subpic == NULL ) if( p_subpic == NULL )
{ {
return; return;
} }
p_widget = p_subpic->p_sys;
i_y_margin = p_vout->render.i_height / 15; i_y_margin = p_vout->render.i_height / 15;
i_x_margin = i_y_margin; i_x_margin = i_y_margin;
p_widget->i_width = p_vout->render.i_width / 20; i_width = p_vout->render.i_width / 20;
p_widget->i_height = p_widget->i_width; i_height = i_width;
p_widget->i_x = p_vout->render.i_width - i_x_margin - i_x = p_vout->render.i_width - i_x_margin - i_width;
p_widget->i_width; i_y = i_y_margin;
p_widget->i_y = i_y_margin;
/* Create subpicture region and picture */ /* Create subpicture region and picture */
CreatePicture( p_vout, p_subpic ); CreatePicture( p_vout->p_spu, p_subpic, i_x, i_y, i_width, i_height );
if( i_type == OSD_PAUSE_ICON ) if( i_type == OSD_PAUSE_ICON )
{ {
int i_bar_width = p_widget->i_width / 3; int i_bar_width = i_width / 3;
DrawRect( p_subpic, 0, 0, i_bar_width - 1, DrawRect( p_subpic, 0, 0, i_bar_width - 1, i_height -1, STYLE_FILLED );
p_widget->i_height - 1, STYLE_FILLED ); DrawRect( p_subpic, i_width - i_bar_width, 0,
DrawRect( p_subpic, p_widget->i_width - i_bar_width, 0, i_width - 1, i_height - 1, STYLE_FILLED );
p_widget->i_width - 1, p_widget->i_height - 1, STYLE_FILLED );
} }
else if( i_type == OSD_PLAY_ICON ) else if( i_type == OSD_PLAY_ICON )
{ {
int i_mid = p_widget->i_height >> 1; int i_mid = i_height >> 1;
int i_delta = ( p_widget->i_width - i_mid ) >> 1; int i_delta = ( i_width - i_mid ) >> 1;
int i_y2 = ( ( p_widget->i_height - 1 ) >> 1 ) * 2; int i_y2 = ( ( i_height - 1 ) >> 1 ) * 2;
DrawTriangle( p_subpic, i_delta, 0, p_widget->i_width - i_delta, i_y2, DrawTriangle( p_subpic, i_delta, 0, i_width - i_delta, i_y2,
STYLE_FILLED ); STYLE_FILLED );
} }
else if( i_type == OSD_SPEAKER_ICON || i_type == OSD_MUTE_ICON ) else if( i_type == OSD_SPEAKER_ICON || i_type == OSD_MUTE_ICON )
{ {
int i_mid = p_widget->i_height >> 1; int i_mid = i_height >> 1;
int i_delta = ( p_widget->i_width - i_mid ) >> 1; int i_delta = ( i_width - i_mid ) >> 1;
int i_y2 = ( ( p_widget->i_height - 1 ) >> 1 ) * 2; int i_y2 = ( ( i_height - 1 ) >> 1 ) * 2;
DrawRect( p_subpic, i_delta, i_mid / 2, p_widget->i_width - i_delta, DrawRect( p_subpic, i_delta, i_mid / 2, i_width - i_delta,
p_widget->i_height - 1 - i_mid / 2, STYLE_FILLED ); i_height - 1 - i_mid / 2, STYLE_FILLED );
DrawTriangle( p_subpic, p_widget->i_width - i_delta, 0, i_delta, i_y2, DrawTriangle( p_subpic, i_width - i_delta, 0, i_delta, i_y2,
STYLE_FILLED ); STYLE_FILLED );
if( i_type == OSD_MUTE_ICON ) if( i_type == OSD_MUTE_ICON )
{ {
...@@ -376,7 +335,7 @@ void vout_OSDIcon( vlc_object_t *p_caller, int i_channel, short i_type ) ...@@ -376,7 +335,7 @@ void vout_OSDIcon( vlc_object_t *p_caller, int i_channel, short i_type )
int i; int i;
for( i = 1; i < i_pitch; i++ ) for( i = 1; i < i_pitch; i++ )
{ {
int k = i + ( p_widget->i_height - i - 1 ) * i_pitch; int k = i + ( i_height - i - 1 ) * i_pitch;
p_a[ k ] = 0xff - p_a[ k ]; p_a[ k ] = 0xff - p_a[ k ];
} }
} }
...@@ -387,15 +346,3 @@ void vout_OSDIcon( vlc_object_t *p_caller, int i_channel, short i_type ) ...@@ -387,15 +346,3 @@ void vout_OSDIcon( vlc_object_t *p_caller, int i_channel, short i_type )
vlc_object_release( p_vout ); vlc_object_release( p_vout );
return; return;
} }
/**
* Frees the widget.
*/
static void FreeWidget( subpicture_t *p_subpic )
{
subpicture_sys_t *p_widget = p_subpic->p_sys;
if( p_subpic->p_sys == NULL ) return;
free( p_widget );
}
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