summaryrefslogtreecommitdiffstats
path: root/libvo
diff options
context:
space:
mode:
authorUoti Urpala <uau@symbol.nonexistent.invalid>2008-06-24 01:53:58 +0300
committerUoti Urpala <uau@symbol.nonexistent.invalid>2008-06-24 01:53:58 +0300
commita232f564d3f271277135276281c03cca7807ef16 (patch)
tree63c0ebd5b39094e2cc24da83a4e5ce889964b003 /libvo
parentde560e8167c21a8fd9ea34f5f42f377102d65232 (diff)
downloadmpv-a232f564d3f271277135276281c03cca7807ef16.tar.bz2
mpv-a232f564d3f271277135276281c03cca7807ef16.tar.xz
Create a context struct for OSD state
This commit creates the struct and passes it to some functions that needs to access OSD state but does not yet move much data from globals to it. vf_expand accesses the OSD state for rendering purposes outside of the normal OSD draw time. The way this currently works is suboptimal, but I did not attempt to clean it up now. To keep things working the same way vf_expand needs to know the address of the state object to be able to access the data even in the functions that should normally not need it. For that purpose this commit adds a VFCTRL to tell vf_expand the address of the object.
Diffstat (limited to 'libvo')
-rw-r--r--libvo/old_vo_wrapper.c10
-rw-r--r--libvo/old_vo_wrapper.h4
-rw-r--r--libvo/sub.c43
-rw-r--r--libvo/sub.h27
-rw-r--r--libvo/video_out.c4
-rw-r--r--libvo/video_out.h5
-rw-r--r--libvo/vo_aa.c17
-rw-r--r--libvo/vo_xv.c4
8 files changed, 73 insertions, 41 deletions
diff --git a/libvo/old_vo_wrapper.c b/libvo/old_vo_wrapper.c
index 825f6da0ee..57d1145f53 100644
--- a/libvo/old_vo_wrapper.c
+++ b/libvo/old_vo_wrapper.c
@@ -23,6 +23,7 @@
#include "sub.h"
struct vo *global_vo;
+struct osd_state *global_osd;
int old_vo_preinit(struct vo *vo, const char *arg)
{
@@ -59,8 +60,9 @@ int old_vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[],
}
-void old_vo_draw_osd(struct vo *vo)
+void old_vo_draw_osd(struct vo *vo, struct osd_state *osd)
{
+ global_osd = osd;
vo->driver->old_functions->draw_osd();
}
@@ -94,6 +96,10 @@ static void draw_alpha_wrapper(void *ctx, int x0, int y0, int w, int h,
void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride))
{
- osd_draw_text(dxs, dys, draw_alpha_wrapper, draw_alpha);
+ osd_draw_text(global_osd, dxs, dys, draw_alpha_wrapper, draw_alpha);
}
+int vo_update_osd(int dxs, int dys)
+{
+ return osd_update(global_osd, dxs, dys);
+}
diff --git a/libvo/old_vo_wrapper.h b/libvo/old_vo_wrapper.h
index b81f065497..e7e98fdad6 100644
--- a/libvo/old_vo_wrapper.h
+++ b/libvo/old_vo_wrapper.h
@@ -5,6 +5,7 @@
#include "video_out.h"
extern struct vo *global_vo;
+extern struct osd_state *global_osd;
int old_vo_preinit(struct vo *vo, const char *);
int old_vo_config(struct vo *vo, uint32_t width, uint32_t height,
@@ -14,11 +15,12 @@ int old_vo_control(struct vo *vo, uint32_t request, void *data);
int old_vo_draw_frame(struct vo *vo, uint8_t *src[]);
int old_vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[],
int w, int h, int x, int y);
-void old_vo_draw_osd(struct vo *vo);
+void old_vo_draw_osd(struct vo *vo, struct osd_state *osd);
void old_vo_flip_page(struct vo *vo);
void old_vo_check_events(struct vo *vo);
void old_vo_uninit(struct vo *vo);
void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
+int vo_update_osd(int dxs, int dys);
#endif
diff --git a/libvo/sub.c b/libvo/sub.c
index 7093a4e8f8..d3d52067d9 100644
--- a/libvo/sub.c
+++ b/libvo/sub.c
@@ -19,6 +19,7 @@
#include "osdep/timer.h"
#endif
+#include "talloc.h"
#include "mplayer.h"
#include "mp_msg.h"
#include "help_mp.h"
@@ -72,7 +73,6 @@ char * const sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "",
font_desc_t* vo_font=NULL;
font_desc_t* sub_font=NULL;
-unsigned char* vo_osd_text=NULL;
#ifdef HAVE_TV_TELETEXT
void* vo_osd_teletext_page=NULL;
int vo_osd_teletext_half = 0;
@@ -181,8 +181,10 @@ no_utf8:
return c;
}
-inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){
- const char *cp=vo_osd_text;
+inline static void vo_update_text_osd(struct osd_state *osd, mp_osd_obj_t* obj,
+ int dxs, int dys)
+{
+ const char *cp = osd->osd_text;
int x=20;
int h=0;
int font;
@@ -203,7 +205,7 @@ inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){
alloc_buf(obj);
- cp=vo_osd_text;
+ cp = osd->osd_text;
x = obj->x;
while (*cp){
uint16_t c=utf8_get_char(&cp);
@@ -1050,7 +1052,8 @@ static mp_osd_obj_t* new_osd_obj(int type){
return osd;
}
-void free_osd_list(void){
+void osd_free(struct osd_state *osd)
+{
mp_osd_obj_t* obj=vo_osd_list;
while(obj){
mp_osd_obj_t* next=obj->next;
@@ -1060,11 +1063,13 @@ void free_osd_list(void){
obj=next;
}
vo_osd_list=NULL;
+ talloc_free(osd);
}
#define FONT_LOAD_DEFER 6
-int vo_update_osd(int dxs,int dys){
+int osd_update(struct osd_state *osd, int dxs, int dys)
+{
mp_osd_obj_t* obj=vo_osd_list;
int chg=0;
#ifdef HAVE_FREETYPE
@@ -1142,8 +1147,8 @@ int vo_update_osd(int dxs,int dys){
obj->flags&=~OSDFLAG_VISIBLE;
break;
case OSDTYPE_OSD:
- if(vo_font && vo_osd_text && vo_osd_text[0]){
- vo_update_text_osd(obj,dxs,dys); // update bbox
+ if(vo_font && osd->osd_text[0]){
+ vo_update_text_osd(osd, obj, dxs, dys); // update bbox
obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
} else
obj->flags&=~OSDFLAG_VISIBLE;
@@ -1183,12 +1188,15 @@ int vo_update_osd(int dxs,int dys){
return chg;
}
-void vo_init_osd(void){
+struct osd_state *osd_create(void)
+{
+ struct osd_state *osd = talloc_ptrtype(NULL, osd);
+ *osd = (struct osd_state){
+ };
if(!draw_alpha_init_flag){
draw_alpha_init_flag=1;
vo_draw_alpha_init();
}
- if(vo_osd_list) free_osd_list();
// temp hack, should be moved to mplayer/mencoder later
new_osd_obj(OSDTYPE_OSD);
new_osd_obj(OSDTYPE_SUBTITLE);
@@ -1203,13 +1211,16 @@ void vo_init_osd(void){
#ifdef HAVE_FREETYPE
force_load_font = 1;
#endif
+ return osd;
}
int vo_osd_changed_flag=0;
-void vo_remove_text(int dxs,int dys,void (*remove)(int x0,int y0, int w,int h)){
+void osd_remove_text(struct osd_state *osd, int dxs, int dys,
+ void (*remove)(int x0, int y0, int w, int h))
+{
mp_osd_obj_t* obj=vo_osd_list;
- vo_update_osd(dxs,dys);
+ osd_update(osd, dxs, dys);
while(obj){
if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) &&
(obj->flags&OSDFLAG_OLD_BBOX)){
@@ -1225,10 +1236,14 @@ void vo_remove_text(int dxs,int dys,void (*remove)(int x0,int y0, int w,int h)){
}
}
-void osd_draw_text(int dxs,int dys,void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx)
+void osd_draw_text(struct osd_state *osd, int dxs, int dys,
+ void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h,
+ unsigned char* src, unsigned char *srca,
+ int stride),
+ void *ctx)
{
mp_osd_obj_t* obj=vo_osd_list;
- vo_update_osd(dxs,dys);
+ osd_update(osd, dxs, dys);
while(obj){
if(obj->flags&OSDFLAG_VISIBLE){
vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack
diff --git a/libvo/sub.h b/libvo/sub.h
index 50b55829ad..328af4d274 100644
--- a/libvo/sub.h
+++ b/libvo/sub.h
@@ -49,14 +49,15 @@ typedef struct mp_osd_obj_s {
unsigned char *bitmap_buffer;
} mp_osd_obj_t;
+struct osd_state {
+ unsigned char osd_text[64];
+};
#include "subreader.h"
extern sub_data* subdata; //currently used subtitles
extern subtitle* vo_sub;
-extern unsigned char* vo_osd_text;
-
extern void* vo_osd_teletext_page;
extern int vo_osd_teletext_half;
extern int vo_osd_teletext_mode;
@@ -108,14 +109,19 @@ extern float spu_gaussvar;
//extern void vo_draw_text_osd(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
//extern void vo_draw_text_progbar(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
//extern void vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
-extern void osd_draw_text(int dxs,int dys,void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx);
-extern void vo_remove_text(int dxs,int dys,void (*remove)(int x0,int y0, int w,int h));
-
-void vo_init_osd(void);
-int vo_update_osd(int dxs,int dys);
+void osd_draw_text(struct osd_state *osd, int dxs, int dys,
+ void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h,
+ unsigned char* src, unsigned char *srca,
+ int stride),
+ void *ctx);
+void osd_remove_text(struct osd_state *osd, int dxs, int dys,
+ void (*remove)(int x0, int y0, int w, int h));
+
+struct osd_state *osd_create(void);
+int osd_update(struct osd_state *osd, int dxs, int dys);
int vo_osd_changed(int new_value);
int vo_osd_check_range_update(int,int,int,int);
-void free_osd_list(void);
+void osd_free(struct osd_state *osd);
extern int vo_osd_changed_flag;
@@ -126,4 +132,9 @@ unsigned utf8_get_char(const char **str);
void osd_set_nav_box (uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey);
#endif
+
+#ifdef IS_OLD_VO
+#define vo_remove_text(...) osd_remove_text(global_osd, __VA_ARGS__)
+#endif
+
#endif /* MPLAYER_SUB_H */
diff --git a/libvo/video_out.c b/libvo/video_out.c
index 67a995c662..ba5051d4c4 100644
--- a/libvo/video_out.c
+++ b/libvo/video_out.c
@@ -256,11 +256,11 @@ int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int
return vo->driver->draw_slice(vo, src, stride, w, h, x, y);
}
-void vo_draw_osd(struct vo *vo)
+void vo_draw_osd(struct vo *vo, struct osd_state *osd)
{
if (!vo->config_ok)
return;
- vo->driver->draw_osd(vo);
+ vo->driver->draw_osd(vo, osd);
}
void vo_flip_page(struct vo *vo)
diff --git a/libvo/video_out.h b/libvo/video_out.h
index 174911c9d2..6a9908e19b 100644
--- a/libvo/video_out.h
+++ b/libvo/video_out.h
@@ -117,6 +117,7 @@ typedef struct vo_info_s
} vo_info_t;
struct vo;
+struct osd_state;
struct vo_driver {
// Driver uses new API
@@ -173,7 +174,7 @@ struct vo_driver {
/*
* Draws OSD to the screen buffer
*/
- void (*draw_osd)(struct vo *vo);
+ void (*draw_osd)(struct vo *vo, struct osd_state *osd);
/*
* Blit/Flip buffer to the screen. Must be called after each frame!
@@ -248,7 +249,7 @@ void list_video_out(void);
int vo_control(struct vo *vo, uint32_t request, void *data);
int vo_draw_frame(struct vo *vo, uint8_t *src[]);
int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int x, int y);
-void vo_draw_osd(struct vo *vo);
+void vo_draw_osd(struct vo *vo, struct osd_state *osd);
void vo_flip_page(struct vo *vo);
void vo_check_events(struct vo *vo);
void vo_destroy(struct vo *vo);
diff --git a/libvo/vo_aa.c b/libvo/vo_aa.c
index f297e01b71..ca547f0e87 100644
--- a/libvo/vo_aa.c
+++ b/libvo/vo_aa.c
@@ -86,6 +86,8 @@ static struct SwsContext *sws=NULL;
int aaopt_osdcolor = AA_SPECIAL;
int aaopt_subcolor = AA_SPECIAL;
+static unsigned char vo_osd_text[64];
+
void
resize(void){
/*
@@ -182,15 +184,10 @@ osdpercent(int duration, int deko, int min, int max, int val, const char * desc,
static void
printosdtext(void)
{
- if(osd_text_length > 0 && !vo_osd_text) {
- memset(c->textbuffer,' ',osd_text_length);
- memset(c->attrbuffer,0,osd_text_length);
- osd_text_length = 0;
- }
/*
* places the mplayer status osd
*/
- if (vo_osd_text && vo_osd_text[0] != 0) {
+ if (vo_osd_text[0] != 0) {
int len;
if(vo_osd_text[0] < 32) {
len = strlen(sub_osd_names_short[vo_osd_text[0]]) + strlen(vo_osd_text+1) + 2;
@@ -534,18 +531,18 @@ static void clear_alpha(int x0,int y0, int w,int h) {
static void
draw_osd(void){
- char * vo_osd_text_save;
+ char vo_osd_text_save;
int vo_osd_progbar_type_save;
printosdprogbar();
/* let vo_draw_text only write subtitle */
- vo_osd_text_save=vo_osd_text; /* we have to save the osd_text */
- vo_osd_text=NULL;
+ vo_osd_text_save = global_osd->osd_text[0];
+ global_osd->osd_text[0] = 0;
vo_osd_progbar_type_save=vo_osd_progbar_type;
vo_osd_progbar_type=-1;
vo_remove_text(aa_scrwidth(c), aa_scrheight(c),clear_alpha);
vo_draw_text(aa_scrwidth(c), aa_scrheight(c), draw_alpha);
- vo_osd_text=vo_osd_text_save;
+ global_osd->osd_text[0] = vo_osd_text_save;
vo_osd_progbar_type=vo_osd_progbar_type_save;
}
diff --git a/libvo/vo_xv.c b/libvo/vo_xv.c
index dca050975e..d63b2f732d 100644
--- a/libvo/vo_xv.c
+++ b/libvo/vo_xv.c
@@ -510,11 +510,11 @@ static void check_events(struct vo *vo)
}
}
-static void draw_osd(struct vo *vo)
+static void draw_osd(struct vo *vo, struct osd_state *osd)
{
struct xvctx *ctx = vo->priv;
- osd_draw_text(ctx->image_width -
+ osd_draw_text(osd, ctx->image_width -
ctx->image_width * vo->panscan_x / (vo->dwidth + vo->panscan_x),
ctx->image_height, ctx->draw_alpha_fnc, vo);
}