]> git.sesse.net Git - vlc/blobdiff - src/video_output/video_widgets.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / video_output / video_widgets.c
index 674f4f92fd9677452a07493f2d338dd2f3eab203..5d3e21be9f3f154ae85c408e8ec599fe04112e16 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * video_widgets.c : OSD widgets manipulation functions
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004-2010 the VideoLAN team
  * $Id$
  *
  * Author: Yoann Peronneau <yoann@videolan.org>
+ *         Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                                /* free() */
-#include <vlc/vout.h>
-#include <osd.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <assert.h>
+
+#include <vlc_common.h>
+#include <vlc_vout.h>
+#include <vlc_vout_osd.h>
+
+#include <vlc_filter.h>
 
 #define STYLE_EMPTY 0
 #define STYLE_FILLED 1
 
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static void DrawRect( vout_thread_t *, subpicture_t *, int, int, int, int,
-                      short );
-static void DrawTriangle( vout_thread_t *, subpicture_t *, int, int, int, int,
-                          short );
-static void Render    ( vout_thread_t *, picture_t *, const subpicture_t * );
-static void RenderI420( vout_thread_t *, picture_t *, const subpicture_t *,
-                        int );
-static void RenderYUY2( vout_thread_t *, picture_t *, const subpicture_t *,
-                        int );
-static void RenderRV32( vout_thread_t *, picture_t *, const subpicture_t *,
-                        int );
-static subpicture_t *vout_CreateWidget( vout_thread_t *, int );
-static void FreeWidget( subpicture_t * );
-
 /**
- * Private data in a subpicture.
+ * Draws a rectangle at the given position in the region.
+ * It may be filled (fill == STYLE_FILLED) or empty (fill == STYLE_EMPTY).
  */
-struct subpicture_sys_t
+static void DrawRect(subpicture_region_t *r, int fill,
+                     int x1, int y1, int x2, int y2)
 {
-    int     i_x;
-    int     i_y;
-    int     i_width;
-    int     i_height;
-    uint8_t *p_pic;
-};
+    uint8_t *a    = r->p_picture->A_PIXELS;
+    int     pitch = r->p_picture->A_PITCH;
 
-/*****************************************************************************
- * Draws a rectangle at the given position in the subpic.
- * It may be filled (fill == STYLE_FILLED) or empty (fill == STYLE_EMPTY).
- *****************************************************************************/
-static void DrawRect( vout_thread_t *p_vout, subpicture_t *p_subpic,
-                      int i_x1, int i_y1, int i_x2, int i_y2, short fill )
-{
-    int x, y;
-    subpicture_sys_t *p_widget = p_subpic->p_sys;
-
-    if( fill == STYLE_FILLED )
-    {
-        for( y = i_y1; y <= i_y2; y++ )
-        {
-            for( x = i_x1; x <= i_x2; x++ )
-            {
-                p_widget->p_pic[ x + p_widget->i_width * y ] = 1;
-            }
+    if (fill == STYLE_FILLED) {
+        for (int y = y1; y <= y2; y++) {
+            for (int x = x1; x <= x2; x++)
+                a[x + pitch * y] = 0xff;
         }
-    }
-    else
-    {
-        for( y = i_y1; y <= i_y2; y++ )
-        {
-            p_widget->p_pic[ i_x1 + p_widget->i_width * y ] = 1;
-            p_widget->p_pic[ i_x2 + p_widget->i_width * y ] = 1;
+    } else {
+        for (int y = y1; y <= y2; y++) {
+            a[x1 + pitch * y] = 0xff;
+            a[x2 + pitch * y] = 0xff;
         }
-        for( x = i_x1; x <= i_x2; x++ )
-        {
-            p_widget->p_pic[ x + p_widget->i_width * i_y1 ] = 1;
-            p_widget->p_pic[ x + p_widget->i_width * i_y2 ] = 1;
+        for (int x = x1; x <= x2; x++) {
+            a[x + pitch * y1] = 0xff;
+            a[x + pitch * y2] = 0xff;
         }
     }
 }
 
-/*****************************************************************************
- * Draws a triangle at the given position in the subpic.
+/**
+ * Draws a triangle at the given position in the region.
  * It may be filled (fill == STYLE_FILLED) or empty (fill == STYLE_EMPTY).
- *****************************************************************************/
-static void DrawTriangle( vout_thread_t *p_vout, subpicture_t *p_subpic,
-                          int i_x1, int i_y1, int i_x2, int i_y2, short fill )
+ */
+static void DrawTriangle(subpicture_region_t *r, int fill,
+                         int x1, int y1, int x2, int y2)
 {
-    int x, y, i_mid, h;
-    subpicture_sys_t *p_widget = p_subpic->p_sys;
-
-    i_mid = i_y1 + ( ( i_y2 - i_y1 ) >> 1 );
-
-    if( i_x2 >= i_x1 )
-    {
-        if( fill == STYLE_FILLED )
-        {
-            for( y = i_y1; y <= i_mid; y++ )
-            {
-                h = y - i_y1;
-                for( x = i_x1; x <= i_x1 + h && x <= i_x2; x++ )
-                {
-                    p_widget->p_pic[ x + p_widget->i_width * y ] = 1;
-                    p_widget->p_pic[ x + p_widget->i_width * ( i_y2 - h ) ] = 1;
+    uint8_t *a    = r->p_picture->A_PIXELS;
+    int     pitch = r->p_picture->A_PITCH;
+    const int mid = y1 + (y2 - y1) / 2;
+
+    /* TODO factorize it */
+    if (x2 >= x1) {
+        if (fill == STYLE_FILLED) {
+            for (int y = y1; y <= mid; y++) {
+                int h = y - y1;
+                for (int x = x1; x <= x1 + h && x <= x2; x++) {
+                    a[x + pitch * y         ] = 0xff;
+                    a[x + pitch * (y2 - h)] = 0xff;
                 }
             }
-        }
-        else
-        {
-            for( y = i_y1; y <= i_mid; y++ )
-            {
-                h = y - i_y1;
-                p_widget->p_pic[ i_x1 + p_widget->i_width * y ] = 1;
-                p_widget->p_pic[ i_x1 + h + p_widget->i_width * y ] = 1;
-                p_widget->p_pic[ i_x1 + p_widget->i_width * ( i_y2 - h ) ] = 1;
-                p_widget->p_pic[ i_x1 + h + p_widget->i_width * ( i_y2 - h ) ] = 1;
+        } else {
+            for (int y = y1; y <= mid; y++) {
+                int h = y - y1;
+                a[x1 +     pitch * y         ] = 0xff;
+                a[x1 + h + pitch * y         ] = 0xff;
+                a[x1 +     pitch * (y2 - h)] = 0xff;
+                a[x1 + h + pitch * (y2 - h)] = 0xff;
             }
         }
-    }
-    else
-    {
-        if( fill == STYLE_FILLED )
-        {
-            for( y = i_y1; y <= i_mid; y++ )
-            {
-                h = y - i_y1;
-                for( x = i_x1; x >= i_x1 - h && x >= i_x2; x-- )
-                {
-                    p_widget->p_pic[ x + p_widget->i_width * y ] = 1;
-                    p_widget->p_pic[ x + p_widget->i_width * ( i_y2 - h ) ] = 1;
+    } else {
+        if( fill == STYLE_FILLED) {
+            for (int y = y1; y <= mid; y++) {
+                int h = y - y1;
+                for (int x = x1; x >= x1 - h && x >= x2; x--) {
+                    a[x + pitch * y       ] = 0xff;
+                    a[x + pitch * (y2 - h)] = 0xff;
                 }
             }
-        }
-        else
-        {
-            for( y = i_y1; y <= i_mid; y++ )
-            {
-                h = y - i_y1;
-                p_widget->p_pic[ i_x1 + p_widget->i_width * y ] = 1;
-                p_widget->p_pic[ i_x1 - h + p_widget->i_width * y ] = 1;
-                p_widget->p_pic[ i_x1 + p_widget->i_width * ( i_y2 - h ) ] = 1;
-                p_widget->p_pic[ i_x1 - h + p_widget->i_width * ( i_y2 - h ) ] = 1;
+        } else {
+            for (int y = y1; y <= mid; y++) {
+                int h = y - y1;
+                a[ x1 +     pitch * y       ] = 0xff;
+                a[ x1 - h + pitch * y       ] = 0xff;
+                a[ x1 +     pitch * (y2 - h)] = 0xff;
+                a[ x1 - h + pitch * (y2 - h)] = 0xff;
             }
         }
     }
 }
 
-/*****************************************************************************
- * Render: place widget in picture
- *****************************************************************************
- * This function merges the previously drawn widget into a picture
- *****************************************************************************/
-static void Render( vout_thread_t *p_vout, picture_t *p_pic,
-                    const subpicture_t *p_subpic )
+/**
+ * Create a region with a white transparent picture.
+ */
+static subpicture_region_t *OSDRegion(int x, int y, int width, int height)
 {
-    int i_fade_alpha = 255;
-    mtime_t i_fade_start = ( p_subpic->i_stop + p_subpic->i_start ) / 2;
-    mtime_t i_now = mdate();
-
-    if( i_now >= i_fade_start )
-    {
-        i_fade_alpha = 255 * ( p_subpic->i_stop - i_now ) /
-                       ( p_subpic->i_stop - i_fade_start );
-    }
-
-    switch( p_vout->output.i_chroma )
-    {
-        /* I420 target, no scaling */
-        case VLC_FOURCC('I','4','2','0'):
-        case VLC_FOURCC('I','Y','U','V'):
-        case VLC_FOURCC('Y','V','1','2'):
-            RenderI420( p_vout, p_pic, p_subpic, i_fade_alpha );
-            break;
-        /* RV32 target, scaling */
-        case VLC_FOURCC('R','V','2','4'):
-        case VLC_FOURCC('R','V','3','2'):
-            RenderRV32( p_vout, p_pic, p_subpic, i_fade_alpha );
-            break;
-        /* NVidia or BeOS overlay, no scaling */
-        case VLC_FOURCC('Y','U','Y','2'):
-            RenderYUY2( p_vout, p_pic, p_subpic, i_fade_alpha );
-            break;
-
-        default:
-            msg_Err( p_vout, "unknown chroma, can't render SPU" );
-            break;
+    video_format_t fmt;
+    video_format_Init(&fmt, VLC_CODEC_YUVA);
+    fmt.i_width          =
+    fmt.i_visible_width  = width;
+    fmt.i_height         =
+    fmt.i_visible_height = height;
+    fmt.i_sar_num        = 0;
+    fmt.i_sar_den        = 1;
+
+    subpicture_region_t *r = subpicture_region_New(&fmt);
+    if (!r)
+        return NULL;
+    r->i_x = x;
+    r->i_y = y;
+
+    for (int i = 0; i < r->p_picture->i_planes; i++) {
+        plane_t *p = &r->p_picture->p[i];
+        int colors[PICTURE_PLANE_MAX] = {
+            0xff, 0x80, 0x80, 0x00
+        };
+        memset(p->p_pixels, colors[i], p->i_pitch * height);
     }
+    return r;
 }
 
 /**
- * Draw a widget on a I420 (or similar) picture
+ * Create the region for an OSD slider.
+ * Types are: OSD_HOR_SLIDER and OSD_VERT_SLIDER.
  */
-static void RenderI420( vout_thread_t *p_vout, picture_t *p_pic,
-                    const subpicture_t *p_subpic, int i_fade_alpha )
+static subpicture_region_t *OSDSlider(int type, int position,
+                                      const video_format_t *fmt)
 {
-    subpicture_sys_t *p_widget = p_subpic->p_sys;
-    int i_plane, x, y, pen_x, pen_y;
-
-    for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
-    {
-        uint8_t *p_in = p_pic->p[ i_plane ].p_pixels;
-        int i_pic_pitch = p_pic->p[ i_plane ].i_pitch;
-
-        if ( i_plane == 0 )
-        {
-            pen_x = p_widget->i_x;
-            pen_y = p_widget->i_y;
-#define alpha p_widget->p_pic[ x + y * p_widget->i_width ] * i_fade_alpha
-#define pixel p_in[ ( pen_y + y ) * i_pic_pitch + pen_x + x ]
-            for( y = 0; y < p_widget->i_height; y++ )
-            {
-                for( x = 0; x < p_widget->i_width; x++ )
-                {
-                    if( alpha == 0 ) continue;
-                    pen_y--;
-                    pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 );
-                    pen_y++; pen_x--;
-                    pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 );
-                    pen_x += 2;
-                    pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 );
-                    pen_y++; pen_x--;
-                    pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 );
-                    pen_y--;
-                }
-            }
-            for( y = 0; y < p_widget->i_height; y++ )
-            {
-                for( x = 0; x < p_widget->i_width; x++ )
-                {
-                    pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 ) +
-                            ( 255 * alpha >> 8 );
-                 }
-             }
-#undef alpha
-#undef pixel
-        }
-        else
-        {
-            pen_x = p_widget->i_x >> 1;
-            pen_y = p_widget->i_y >> 1;
-#define alpha p_widget->p_pic[ x + y * p_widget->i_width ] * i_fade_alpha
-#define pixel p_in[ ( pen_y + (y >> 1) ) * i_pic_pitch + pen_x + (x >> 1) ]
-            for( y = 0; y < p_widget->i_height; y+=2 )
-            {
-                for( x = 0; x < p_widget->i_width; x+=2 )
-                {
-                    if( alpha == 0 ) continue;
-                    pixel = ( ( pixel * ( 0xFF - alpha ) ) >> 8 ) +
-                        ( 0x80 * alpha >> 8 );
-                }
-            }
-#undef alpha
-#undef pixel
-        }
+    const int size = __MAX(fmt->i_visible_width, fmt->i_visible_height);
+    const int margin = size * 0.10;
+
+    int x, y;
+    int width, height;
+    if (type == OSD_HOR_SLIDER) {
+        width  = __MAX(fmt->i_visible_width - 2 * margin, 1);
+        height = __MAX(fmt->i_visible_height * 0.05,      1);
+        x      = __MIN(fmt->i_x_offset + margin, fmt->i_visible_width - width);
+        y      = __MAX(fmt->i_y_offset + fmt->i_visible_height - margin, 0);
+    } else {
+        width  = __MAX(fmt->i_visible_width * 0.025,       1);
+        height = __MAX(fmt->i_visible_height - 2 * margin, 1);
+        x      = __MAX(fmt->i_x_offset + fmt->i_visible_width - margin, 0);
+        y      = __MIN(fmt->i_y_offset + margin, fmt->i_visible_height - height);
     }
 
-}
+    subpicture_region_t *r = OSDRegion(x, y, width, height);
+    if( !r)
+        return NULL;
 
-/**
- * Draw a widget on a YUY2 picture
- */
-static void RenderYUY2( vout_thread_t *p_vout, picture_t *p_pic,
-                        const subpicture_t *p_subpic, int i_fade_alpha )
-{
-    subpicture_sys_t *p_widget = p_subpic->p_sys;
-    int x, y, pen_x, pen_y;
-    uint8_t *p_in = p_pic->p[0].p_pixels;
-    int i_pic_pitch = p_pic->p[0].i_pitch;
-
-    pen_x = p_widget->i_x;
-    pen_y = p_widget->i_y;
-#define alpha p_widget->p_pic[ x + y * p_widget->i_width ] * i_fade_alpha
-#define pixel p_in[ ( pen_y + y ) * i_pic_pitch + 2 * ( pen_x + x ) ]
-    for( y = 0; y < p_widget->i_height; y++ )
-    {
-        for( x = 0; x < p_widget->i_width; x++ )
-        {
-            pen_y--;
-            pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 );
-            pen_y++; pen_x--;
-            pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 );
-            pen_x += 2;
-            pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 );
-            pen_y++; pen_x--;
-            pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 );
-            pen_y--;
-        }
+    if (type == OSD_HOR_SLIDER) {
+        int pos_x = (width - 2) * position / 100;
+        DrawRect(r, STYLE_FILLED, pos_x - 1, 2, pos_x + 1, height - 3);
+        DrawRect(r, STYLE_EMPTY,  0,         0, width - 1, height - 1);
+    } else {
+        int pos_mid = height / 2;
+        int pos_y   = height - (height - 2) * position / 100;
+        DrawRect(r, STYLE_FILLED, 2,         pos_y,   width - 3, height - 3);
+        DrawRect(r, STYLE_FILLED, 1,         pos_mid, 1,         pos_mid   );
+        DrawRect(r, STYLE_FILLED, width - 2, pos_mid, width - 2, pos_mid   );
+        DrawRect(r, STYLE_EMPTY,  0,         0,       width - 1, height - 1);
     }
-    for( y = 0; y < p_widget->i_height; y++ )
-    {
-        for( x = 0; x < p_widget->i_width; x++ )
-        {
-            pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 ) +
-                    ( 255 * alpha >> 8 );
-         }
-     }
-#undef alpha
-#undef pixel
+    return r;
 }
 
 /**
- * Draw a widget on a RV32 picture
+ * Create the region for an OSD slider.
+ * Types are: OSD_PLAY_ICON, OSD_PAUSE_ICON, OSD_SPEAKER_ICON, OSD_MUTE_ICON
  */
-static void RenderRV32( vout_thread_t *p_vout, picture_t *p_pic,
-                    const subpicture_t *p_subpic, int i_fade_alpha )
+static subpicture_region_t *OSDIcon(int type, const video_format_t *fmt)
 {
-    subpicture_sys_t *p_widget = p_subpic->p_sys;
-    int x, y, pen_x, pen_y;
-    uint8_t *p_in = p_pic->p[0].p_pixels;
-    int i_pic_pitch = p_pic->p[0].i_pitch;
-
-    pen_x = p_widget->i_x;
-    pen_y = p_widget->i_y;
-
-#define alpha p_widget->p_pic[ x + y * p_widget->i_width ] * i_fade_alpha
-#define pixel( c ) p_in[ ( pen_y + y ) * i_pic_pitch + 4 * ( pen_x + x ) + c ]
-    for(y = 0; y < p_widget->i_height; y++ )
-    {
-        for( x = 0; x < p_widget->i_width; x++ )
-        {
-            pen_y--;
-            pixel( 0 ) = ( ( pixel( 0 ) * ( 255 - alpha ) ) >> 8 );
-            pixel( 1 ) = ( ( pixel( 1 ) * ( 255 - alpha ) ) >> 8 );
-            pixel( 2 ) = ( ( pixel( 2 ) * ( 255 - alpha ) ) >> 8 );
-            pen_y++; pen_x--;
-            pixel( 0 ) = ( ( pixel( 0 ) * ( 255 - alpha ) ) >> 8 );
-            pixel( 1 ) = ( ( pixel( 1 ) * ( 255 - alpha ) ) >> 8 );
-            pixel( 2 ) = ( ( pixel( 2 ) * ( 255 - alpha ) ) >> 8 );
-            pen_x += 2;
-            pixel( 0 ) = ( ( pixel( 0 ) * ( 255 - alpha ) ) >> 8 );
-            pixel( 1 ) = ( ( pixel( 1 ) * ( 255 - alpha ) ) >> 8 );
-            pixel( 2 ) = ( ( pixel( 2 ) * ( 255 - alpha ) ) >> 8 );
-            pen_y++; pen_x--;
-            pixel( 0 ) = ( ( pixel( 0 ) * ( 255 - alpha ) ) >> 8 );
-            pixel( 1 ) = ( ( pixel( 1 ) * ( 255 - alpha ) ) >> 8 );
-            pixel( 2 ) = ( ( pixel( 2 ) * ( 255 - alpha ) ) >> 8 );
-            pen_y--;
-        }
-    }
-    for(y = 0; y < p_widget->i_height; y++ )
-    {
-        for( x = 0; x < p_widget->i_width; x++ )
-        {
-            pixel( 0 ) = ( ( pixel( 0 ) * ( 255 - alpha ) ) >> 8 ) +
-                ( 255 * alpha >> 8 );
-            pixel( 1 ) = ( ( pixel( 1 ) * ( 255 - alpha ) ) >> 8 ) +
-                ( 255 * alpha >> 8 );
-            pixel( 2 ) = ( ( pixel( 2 ) * ( 255 - alpha ) ) >> 8 ) +
-                ( 255 * alpha >> 8 );
+    const float size_ratio   = 0.05;
+    const float margin_ratio = 0.07;
+
+    const int size   = __MAX(fmt->i_visible_width, fmt->i_visible_height);
+    const int width  = size * size_ratio;
+    const int height = size * size_ratio;
+    const int x      = fmt->i_x_offset + fmt->i_visible_width - margin_ratio * size - width;
+    const int y      = fmt->i_y_offset                        + margin_ratio * size;
+
+    subpicture_region_t *r = OSDRegion(__MAX(x, 0),
+                                       __MIN(y, (int)fmt->i_visible_height - height),
+                                       width, height);
+    if (!r)
+        return NULL;
+
+    if (type == OSD_PAUSE_ICON) {
+        int bar_width = width / 3;
+        DrawRect(r, STYLE_FILLED, 0, 0, bar_width - 1, height -1);
+        DrawRect(r, STYLE_FILLED, width - bar_width, 0, width - 1, height - 1);
+    } else if (type == OSD_PLAY_ICON) {
+        int mid   = height >> 1;
+        int delta = (width - mid) >> 1;
+        int y2    = ((height - 1) >> 1) * 2;
+        DrawTriangle(r, STYLE_FILLED, delta, 0, width - delta, y2);
+    } else {
+        int mid   = height >> 1;
+        int delta = (width - mid) >> 1;
+        int y2    = ((height - 1) >> 1) * 2;
+        DrawRect(r, STYLE_FILLED, delta, mid / 2, width - delta, height - 1 - mid / 2);
+        DrawTriangle(r, STYLE_FILLED, width - delta, 0, delta, y2);
+        if (type == OSD_MUTE_ICON) {
+            uint8_t *a    = r->p_picture->A_PIXELS;
+            int     pitch = r->p_picture->A_PITCH;
+            for (int i = 1; i < pitch; i++) {
+                int k = i + (height - i - 1) * pitch;
+                a[k] = 0xff - a[k];
+            }
         }
     }
-#undef alpha
-#undef pixel
+    return r;
 }
 
-/*****************************************************************************
- * Creates and initializes an OSD widget.
- *****************************************************************************/
-subpicture_t *vout_CreateWidget( vout_thread_t *p_vout, int i_channel )
+struct subpicture_updater_sys_t {
+    int type;
+    int position;
+};
+
+static int OSDWidgetValidate(subpicture_t *subpic,
+                           bool has_src_changed, const video_format_t *fmt_src,
+                           bool has_dst_changed, const video_format_t *fmt_dst,
+                           mtime_t ts)
 {
-    subpicture_t *p_subpic;
-    subpicture_sys_t *p_widget;
-    mtime_t i_now = mdate();
-
-    p_subpic = 0;
-    p_widget = 0;
-
-    /* Create and initialize a subpicture */
-    p_subpic = vout_CreateSubPicture( p_vout, i_channel, GRAPH_CONTENT,
-                                      MEMORY_SUBPICTURE );
-    if( p_subpic == NULL )
-    {
-        return NULL;
-    }
-    p_subpic->pf_render = Render;
-    p_subpic->pf_destroy = FreeWidget;
-    p_subpic->i_start = i_now;
-    p_subpic->i_stop = i_now + 1200000;
-    p_subpic->b_ephemer = VLC_FALSE;
-
-    p_widget = malloc( sizeof(subpicture_sys_t) );
-    if( p_widget == NULL )
-    {
-        FreeWidget( p_subpic );
-        vout_DestroySubPicture( p_vout, p_subpic );
-        return NULL;
-    }
-    p_subpic->p_sys = p_widget;
+    VLC_UNUSED(subpic); VLC_UNUSED(ts); VLC_UNUSED(fmt_src);
+    VLC_UNUSED(has_dst_changed); VLC_UNUSED(fmt_dst);
 
-    return p_subpic;
+    if (!has_src_changed && !has_dst_changed)
+        return VLC_SUCCESS;
+    return VLC_EGENERIC;
 }
 
-/*****************************************************************************
- * Displays an OSD slider.
- * Types are: OSD_HOR_SLIDER and OSD_VERT_SLIDER.
- *****************************************************************************/
-void vout_OSDSlider( vlc_object_t *p_caller, int i_channel, int i_position,
-                     short i_type )
+static void OSDWidgetUpdate(subpicture_t *subpic,
+                          const video_format_t *fmt_src,
+                          const video_format_t *fmt_dst,
+                          mtime_t ts)
 {
-    vout_thread_t *p_vout = vlc_object_find( p_caller, VLC_OBJECT_VOUT,
-                                             FIND_ANYWHERE );
-    subpicture_t *p_subpic;
-    subpicture_sys_t *p_widget;
-    int i_x_margin, i_y_margin;
-
-    if( p_vout == NULL || !config_GetInt( p_caller, "osd" ) || i_position < 0 )
-    {
-        return;
-    }
+    subpicture_updater_sys_t *sys = subpic->updater.p_sys;
+    VLC_UNUSED(fmt_dst); VLC_UNUSED(ts);
 
-    p_subpic = vout_CreateWidget( p_vout, i_channel );
-    if( p_subpic == NULL )
-    {
-        return;
-    }
-    p_widget = p_subpic->p_sys;
-
-    i_y_margin = p_vout->render.i_height / 10;
-    i_x_margin = i_y_margin;
-    if( i_type == OSD_HOR_SLIDER )
-    {
-        p_widget->i_width = p_vout->render.i_width - 2 * i_x_margin;
-        p_widget->i_height = p_vout->render.i_height / 20;
-        p_widget->i_x = i_x_margin;
-        p_widget->i_y = p_vout->render.i_height - i_y_margin -
-                        p_widget->i_height;
-    }
+    subpic->i_original_picture_width  = fmt_src->i_width;
+    subpic->i_original_picture_height = fmt_src->i_height;
+    if (sys->type == OSD_HOR_SLIDER || sys->type == OSD_VERT_SLIDER)
+        subpic->p_region = OSDSlider(sys->type, sys->position, fmt_src);
     else
-    {
-        p_widget->i_width = p_vout->render.i_width / 40;
-        p_widget->i_height = p_vout->render.i_height - 2 * i_y_margin;
-        p_widget->i_x = p_vout->render.i_width - i_x_margin -
-                        p_widget->i_width;
-        p_widget->i_y = i_y_margin;
-    }
-
-    p_widget->p_pic = (uint8_t *)malloc( p_widget->i_width *
-                                         p_widget->i_height );
-    if( p_widget->p_pic == NULL )
-    {
-        FreeWidget( p_subpic );
-        vout_DestroySubPicture( p_vout, p_subpic );
-        return;
-    }
-    memset( p_widget->p_pic, 0, p_widget->i_width * p_widget->i_height );
-
-    if( i_type == OSD_HOR_SLIDER )
-    {
-        int i_x_pos = ( p_widget->i_width - 2 ) * i_position / 100;
-        int i_y_pos = p_widget->i_height / 2;
-        DrawRect( p_vout, p_subpic, i_x_pos - 1, 2, i_x_pos + 1,
-                  p_widget->i_height - 3, STYLE_FILLED );
-        DrawRect( p_vout, p_subpic, 0, 0, p_widget->i_width - 1,
-                  p_widget->i_height - 1, STYLE_EMPTY );
-    }
-    else if( i_type == OSD_VERT_SLIDER )
-    {
-        int i_y_pos = p_widget->i_height / 2;
-        DrawRect( p_vout, p_subpic, 2, p_widget->i_height -
-                  ( p_widget->i_height - 2 ) * i_position / 100,
-                  p_widget->i_width - 3, p_widget->i_height - 3,
-                  STYLE_FILLED );
-        DrawRect( p_vout, p_subpic, 1, i_y_pos, 1, i_y_pos, STYLE_FILLED );
-        DrawRect( p_vout, p_subpic, p_widget->i_width - 2, i_y_pos,
-                  p_widget->i_width - 2, i_y_pos, STYLE_FILLED );
-        DrawRect( p_vout, p_subpic, 0, 0, p_widget->i_width - 1,
-                  p_widget->i_height - 1, STYLE_EMPTY );
-    }
-
-    vout_DisplaySubPicture( p_vout, p_subpic );
+        subpic->p_region = OSDIcon(sys->type, fmt_src);
+}
 
-    vlc_object_release( p_vout );
-    return;
+static void OSDWidgetDestroy(subpicture_t *subpic)
+{
+    free(subpic->updater.p_sys);
 }
 
-/*****************************************************************************
- * Displays an OSD icon.
- * Types are: OSD_PLAY_ICON, OSD_PAUSE_ICON, OSD_SPEAKER_ICON, OSD_MUTE_ICON
- *****************************************************************************/
-void vout_OSDIcon( vlc_object_t *p_caller, short i_type )
+static void OSDWidget(vout_thread_t *vout, int channel, int type, int position)
 {
-    vout_thread_t *p_vout = vlc_object_find( p_caller, VLC_OBJECT_VOUT,
-                                             FIND_ANYWHERE );
-    subpicture_t *p_subpic;
-    subpicture_sys_t *p_widget;
-    int i_x_margin, i_y_margin, i_channel;
-
-    if( p_vout == NULL || !config_GetInt( p_caller, "osd" ) )
-    {
+    if (!var_InheritBool(vout, "osd"))
         return;
-    }
+    if (type == OSD_HOR_SLIDER || type == OSD_VERT_SLIDER)
+        position = __MIN(__MAX(position, 0), 100);
 
-    switch( i_type )
-    {
-        case OSD_SPEAKER_ICON:
-            i_channel = VOLUME_CHAN;
-            break;
-        default:
-            i_channel = SOLO_CHAN;
-            break;
-    }
-
-    p_subpic = vout_CreateWidget( p_vout, i_channel );
-    if( p_subpic == NULL )
-    {
+    subpicture_updater_sys_t *sys = malloc(sizeof(*sys));
+    if (!sys)
         return;
-    }
-    p_widget = p_subpic->p_sys;
-
-    i_y_margin = p_vout->render.i_height / 15;
-    i_x_margin = i_y_margin;
-    p_widget->i_width = p_vout->render.i_width / 20;
-    p_widget->i_height = p_widget->i_width;
-    p_widget->i_x = p_vout->render.i_width - i_x_margin -
-                    p_widget->i_width;
-    p_widget->i_y = i_y_margin;
-
-    p_widget->p_pic = (uint8_t *)malloc( p_widget->i_width *
-                                         p_widget->i_height );
-    if( p_widget->p_pic == NULL )
-    {
-        FreeWidget( p_subpic );
-        vout_DestroySubPicture( p_vout, p_subpic );
+    sys->type     = type;
+    sys->position = position;
+
+    subpicture_updater_t updater = {
+        .pf_validate = OSDWidgetValidate,
+        .pf_update   = OSDWidgetUpdate,
+        .pf_destroy  = OSDWidgetDestroy,
+        .p_sys       = sys,
+    };
+    subpicture_t *subpic = subpicture_New(&updater);
+    if (!subpic) {
+        free(sys);
         return;
     }
-    memset( p_widget->p_pic, 0, p_widget->i_width * p_widget->i_height );
-
-    if( i_type == OSD_PAUSE_ICON )
-    {
-        int i_bar_width = p_widget->i_width / 3;
-        DrawRect( p_vout, p_subpic, 0, 0, i_bar_width - 1,
-                  p_widget->i_height - 1, STYLE_FILLED );
-        DrawRect( p_vout, p_subpic, p_widget->i_width - i_bar_width, 0,
-                  p_widget->i_width - 1, p_widget->i_height - 1, STYLE_FILLED );
-    }
-    else if( i_type == OSD_PLAY_ICON )
-    {
-        int i_mid = p_widget->i_height >> 1;
-        int i_delta = ( p_widget->i_width - i_mid ) >> 1;
-        int i_y2 = ( ( p_widget->i_height - 1 ) >> 1 ) * 2;
-        DrawTriangle( p_vout, p_subpic, i_delta, 0,
-                      p_widget->i_width - i_delta, i_y2, STYLE_FILLED );
-    }
-    else if( i_type == OSD_SPEAKER_ICON || i_type == OSD_MUTE_ICON )
-    {
-        int i_mid = p_widget->i_height >> 1;
-        int i_delta = ( p_widget->i_width - i_mid ) >> 1;
-        int i_y2 = ( ( p_widget->i_height - 1 ) >> 1 ) * 2;
-        DrawRect( p_vout, p_subpic, i_delta, i_mid / 2,
-                  p_widget->i_width - i_delta,
-                  p_widget->i_height - 1 - i_mid / 2, STYLE_FILLED );
-        DrawTriangle( p_vout, p_subpic, p_widget->i_width - i_delta, 0,
-                      i_delta, i_y2, STYLE_FILLED );
-        if( i_type == OSD_MUTE_ICON )
-        {
-            int i;
-            for( i = 1; i < p_widget->i_width; i++ )
-            {
-                int k = i + ( p_widget->i_height - i - 1 ) * p_widget->i_width;
-                p_widget->p_pic[ k ] = 1 - p_widget->p_pic[ k ];
-            }
-        }
-    }
 
-    vout_DisplaySubPicture( p_vout, p_subpic );
+    subpic->i_channel  = channel;
+    subpic->i_start    = mdate();
+    subpic->i_stop     = subpic->i_start + 1200000;
+    subpic->b_ephemer  = true;
+    subpic->b_absolute = true;
+    subpic->b_fade     = true;
 
-    vlc_object_release( p_vout );
-    return;
+    vout_PutSubpicture(vout, subpic);
 }
 
-/**
- * Frees the widget.
- */
-static void FreeWidget( subpicture_t *p_subpic )
+void vout_OSDSlider(vout_thread_t *vout, int channel, int position, short type)
 {
-    subpicture_sys_t *p_widget = p_subpic->p_sys;
-
-    if( p_subpic->p_sys == NULL ) return;
+    OSDWidget(vout, channel, type, position);
+}
 
-    if( p_widget->p_pic != NULL )
-    {
-        free( p_widget->p_pic );
-    }
-    free( p_widget );
+void vout_OSDIcon(vout_thread_t *vout, int channel, short type )
+{
+    OSDWidget(vout, channel, type, 0);
 }
+