From c172b5355f2a0fa008fd5187ce323fb9676871b3 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Thu, 1 May 2008 11:02:26 +0300 Subject: libvo: Move aspect.c static variables to vo struct This moves non-option variables. aspect.c still defines option globals. --- libvo/aspect.c | 102 ++++++++++++++++++++++++----------------------------- libvo/aspect.h | 34 ++++++++++++------ libvo/video_out.c | 8 ++--- libvo/video_out.h | 14 ++++++++ libvo/vo_dxr2.c | 2 +- libvo/vo_dxr3.c | 1 - libvo/vo_macosx.m | 1 - libvo/vo_quartz.c | 1 - libvo/vo_xv.c | 71 +++++++++++++++++++------------------ libvo/w32_common.c | 2 +- libvo/x11_common.c | 2 +- 11 files changed, 128 insertions(+), 110 deletions(-) diff --git a/libvo/aspect.c b/libvo/aspect.c index e9d414ac87..8079a21e03 100644 --- a/libvo/aspect.c +++ b/libvo/aspect.c @@ -1,6 +1,7 @@ /* Stuff for correct aspect scaling. */ #include "aspect.h" #include "geometry.h" +#include "video_out.h" //#ifndef ASPECT_TEST #include "mp_msg.h" #include "help_mp.h" @@ -12,79 +13,70 @@ #include #endif -int vo_panscan_x = 0; -int vo_panscan_y = 0; -float vo_panscan_amount = 0; float vo_panscanrange = 1.0; #include "video_out.h" float force_monitor_aspect=0; -float monitor_aspect=0; float monitor_pixel_aspect=1; -static struct { - int orgw; // real width - int orgh; // real height - int prew; // prescaled width - int preh; // prescaled height - int scrw; // horizontal resolution - int scrh; // vertical resolution - float asp; -} aspdat; - -void aspect_save_orig(int orgw, int orgh){ +void aspect_save_orig(struct vo *vo, int orgw, int orgh) +{ #ifdef ASPECT_DEBUG printf("aspect_save_orig %dx%d \n",orgw,orgh); #endif - aspdat.orgw = orgw; - aspdat.orgh = orgh; + vo->aspdat.orgw = orgw; + vo->aspdat.orgh = orgh; } -void aspect_save_prescale(int prew, int preh){ +void aspect_save_prescale(struct vo *vo, int prew, int preh) +{ #ifdef ASPECT_DEBUG printf("aspect_save_prescale %dx%d \n",prew,preh); #endif - aspdat.prew = prew; - aspdat.preh = preh; + vo->aspdat.prew = prew; + vo->aspdat.preh = preh; } -void aspect_save_screenres(int scrw, int scrh){ +void aspect_save_screenres(struct vo *vo, int scrw, int scrh) +{ #ifdef ASPECT_DEBUG printf("aspect_save_screenres %dx%d \n",scrw,scrh); #endif - aspdat.scrw = scrw; - aspdat.scrh = scrh; + vo->aspdat.scrw = scrw; + vo->aspdat.scrh = scrh; if (force_monitor_aspect) - monitor_aspect = force_monitor_aspect; + vo->monitor_aspect = force_monitor_aspect; else - monitor_aspect = monitor_pixel_aspect * scrw / scrh; + vo->monitor_aspect = monitor_pixel_aspect * scrw / scrh; } /* aspect is called with the source resolution and the * resolution, that the scaled image should fit into */ -void aspect_fit(int *srcw, int *srch, int fitw, int fith){ +void aspect_fit(struct vo *vo, int *srcw, int *srch, int fitw, int fith) +{ + struct aspect_data *aspdat = &vo->aspdat; int tmpw; #ifdef ASPECT_DEBUG - printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat.scrw,aspdat.scrh, + printf("aspect(0) fitin: %dx%d screenaspect: %.2f\n",aspdat->scrw,aspdat->scrh, monitor_aspect); - printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh); + printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh); #endif *srcw = fitw; - *srch = (int)(((float)fitw / (float)aspdat.prew * (float)aspdat.preh) - * ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect))); + *srch = (int)(((float)fitw / (float)aspdat->prew * (float)aspdat->preh) + * ((float)aspdat->scrh / ((float)aspdat->scrw / vo->monitor_aspect))); *srch+= *srch%2; // round #ifdef ASPECT_DEBUG - printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh); + printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh); #endif - if(*srch>aspdat.scrh || *srchaspdat->scrh || *srchorgh){ + tmpw = (int)(((float)fith / (float)aspdat->preh * (float)aspdat->prew) + * ((float)aspdat->scrw / ((float)aspdat->scrh / (1.0/vo->monitor_aspect)))); tmpw+= tmpw%2; // round - if(tmpw<=aspdat.scrw /*&& tmpw>=aspdat.orgw*/){ + if(tmpw<=aspdat->scrw /*&& tmpw>=aspdat->orgw*/){ *srch = fith; *srcw = tmpw; }else{ @@ -95,47 +87,47 @@ void aspect_fit(int *srcw, int *srch, int fitw, int fith){ #endif } } - aspdat.asp=*srcw / (float)*srch; + aspdat->asp=*srcw / (float)*srch; #ifdef ASPECT_DEBUG - printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh); + printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat->prew,aspdat->preh); #endif } -void aspect(int *srcw, int *srch, int zoom){ - int fitw = zoom ? aspdat.scrw : aspdat.prew; - int fith = zoom ? aspdat.scrh : aspdat.preh; +void aspect(struct vo *vo, int *srcw, int *srch, int zoom){ + int fitw = zoom ? vo->aspdat.scrw : vo->aspdat.prew; + int fith = zoom ? vo->aspdat.scrh : vo->aspdat.preh; if( !zoom && geometry_wh_changed ) { #ifdef ASPECT_DEBUG printf("aspect(0) no aspect forced!\n"); #endif return; // the user doesn't want to fix aspect } - aspect_fit(srcw, srch, fitw, fith); + aspect_fit(vo, srcw, srch, fitw, fith); } -void panscan_init( void ) +void panscan_init(struct vo *vo) { - vo_panscan_x=0; - vo_panscan_y=0; - vo_panscan_amount=0.0f; + vo->panscan_x = 0; + vo->panscan_y = 0; + vo->panscan_amount = 0.0f; } -void panscan_calc( void ) +void panscan_calc(struct vo *vo) { int fwidth,fheight; int vo_panscan_area; if (vo_panscanrange > 0) { - aspect(&fwidth,&fheight,A_ZOOM); - vo_panscan_area = (aspdat.scrh-fheight); - if (!vo_panscan_area) - vo_panscan_area = aspdat.scrw - fwidth; + aspect(vo, &fwidth, &fheight, A_ZOOM); + vo_panscan_area = (vo->aspdat.scrh - fheight); + if (!vo_panscan_area) + vo_panscan_area = vo->aspdat.scrw - fwidth; vo_panscan_area *= vo_panscanrange; - } else - vo_panscan_area = -vo_panscanrange * aspdat.scrh; + } else + vo_panscan_area = -vo_panscanrange * vo->aspdat.scrh; - vo_panscan_amount = vo_fs ? vo_panscan : 0; - vo_panscan_x = vo_panscan_area * vo_panscan_amount * aspdat.asp; - vo_panscan_y = vo_panscan_area * vo_panscan_amount; + vo->panscan_amount = vo_fs ? vo_panscan : 0; + vo->panscan_x = vo_panscan_area * vo->panscan_amount * vo->aspdat.asp; + vo->panscan_y = vo_panscan_area * vo->panscan_amount; } diff --git a/libvo/aspect.h b/libvo/aspect.h index be5e4a12f8..b803b99490 100644 --- a/libvo/aspect.h +++ b/libvo/aspect.h @@ -2,23 +2,35 @@ #define MPLAYER_ASPECT_H /* Stuff for correct aspect scaling. */ -extern int vo_panscan_x; -extern int vo_panscan_y; -extern float vo_panscan_amount; +struct vo; +extern void panscan_init(struct vo *vo); +extern void panscan_calc(struct vo *vo); -extern void panscan_init( void ); -extern void panscan_calc( void ); +void aspect_save_orig(struct vo *vo, int orgw, int orgh); -void aspect_save_orig(int orgw, int orgh); +void aspect_save_prescale(struct vo *vo, int prew, int preh); -void aspect_save_prescale(int prew, int preh); - -void aspect_save_screenres(int scrw, int scrh); +void aspect_save_screenres(struct vo *vo, int scrw, int scrh); #define A_ZOOM 1 #define A_NOZOOM 0 -void aspect(int *srcw, int *srch, int zoom); -void aspect_fit(int *srcw, int *srch, int fitw, int fith); +void aspect(struct vo *vo, int *srcw, int *srch, int zoom); +void aspect_fit(struct vo *vo, int *srcw, int *srch, int fitw, int fith); + + +#ifdef IS_OLD_VO +#define vo_panscan_x global_vo->panscan_x +#define vo_panscan_y global_vo->panscan_y +#define vo_panscan_amount global_vo->panscan_amount +#define monitor_aspect global_vo->monitor_aspect + +#define panscan_init() panscan_init(global_vo) +#define panscan_calc() panscan_calc(global_vo) +#define aspect_save_orig(...) aspect_save_orig(global_vo, __VA_ARGS__) +#define aspect_save_prescale(...) aspect_save_prescale(global_vo, __VA_ARGS__) +#define aspect_save_screenres(...) aspect_save_screenres(global_vo, __VA_ARGS__) +#define aspect(...) aspect(global_vo, __VA_ARGS__) +#endif #endif /* MPLAYER_ASPECT_H */ diff --git a/libvo/video_out.c b/libvo/video_out.c index 42354c5f34..f3be8d174d 100644 --- a/libvo/video_out.c +++ b/libvo/video_out.c @@ -356,12 +356,12 @@ int vo_config(struct vo *vo, uint32_t width, uint32_t height, char *title, uint32_t format) { struct MPOpts *opts = vo->opts; - panscan_init(); - aspect_save_orig(width, height); - aspect_save_prescale(d_width, d_height); + panscan_init(vo); + aspect_save_orig(vo, width, height); + aspect_save_prescale(vo, d_width, d_height); if (vo_control(vo, VOCTRL_UPDATE_SCREENINFO, NULL) == VO_TRUE) { - aspect(&d_width, &d_height, A_NOZOOM); + aspect(vo, &d_width, &d_height, A_NOZOOM); vo->dx = (int)(opts->vo_screenwidth - d_width) / 2; vo->dy = (int)(opts->vo_screenheight - d_height) / 2; geometry(&vo->dx, &vo->dy, &d_width, &d_height, diff --git a/libvo/video_out.h b/libvo/video_out.h index 4e9f3abeae..174911c9d2 100644 --- a/libvo/video_out.h +++ b/libvo/video_out.h @@ -221,6 +221,20 @@ struct vo { int dy; int dwidth; int dheight; + + int panscan_x; + int panscan_y; + float panscan_amount; + float monitor_aspect; + struct aspect_data { + int orgw; // real width + int orgh; // real height + int prew; // prescaled width + int preh; // prescaled height + int scrw; // horizontal resolution + int scrh; // vertical resolution + float asp; + } aspdat; }; struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11, diff --git a/libvo/vo_dxr2.c b/libvo/vo_dxr2.c index f4fd5e9f63..f5dc56bb13 100644 --- a/libvo/vo_dxr2.c +++ b/libvo/vo_dxr2.c @@ -28,7 +28,7 @@ #include -extern float monitor_aspect; +#include "aspect.h" int dxr2_fd = -1; diff --git a/libvo/vo_dxr3.c b/libvo/vo_dxr3.c index 0a5e2b486f..2e8e7cedc5 100644 --- a/libvo/vo_dxr3.c +++ b/libvo/vo_dxr3.c @@ -300,7 +300,6 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_ { int tmp1, tmp2, size; em8300_register_t reg; - extern float monitor_aspect; /* Softzoom turned on, downscale */ /* This activates the subpicture processor, you can safely disable this and still send */ diff --git a/libvo/vo_macosx.m b/libvo/vo_macosx.m index 2fe61dd612..4987bc3bb8 100644 --- a/libvo/vo_macosx.m +++ b/libvo/vo_macosx.m @@ -61,7 +61,6 @@ static uint32_t image_format; static int isFullscreen; static int isOntop; static int isRootwin; -extern float monitor_aspect; static float old_movie_aspect; extern int enable_mouse_movements; diff --git a/libvo/vo_quartz.c b/libvo/vo_quartz.c index be869b78c3..befe158e14 100644 --- a/libvo/vo_quartz.c +++ b/libvo/vo_quartz.c @@ -70,7 +70,6 @@ static int EnterMoviesDone = 0; static int get_image_done = 0; static int vo_quartz_fs; // we are in fullscreen -extern float monitor_aspect; static float old_movie_aspect; static int winLevel = 1; diff --git a/libvo/vo_xv.c b/libvo/vo_xv.c index 01313a30bd..7d11feb510 100644 --- a/libvo/vo_xv.c +++ b/libvo/vo_xv.c @@ -107,7 +107,8 @@ static void draw_alpha_yv12(void *p, int x0, int y0, int w, int h, { struct vo *vo = p; struct xvctx *ctx = vo->priv; - x0 += ctx->image_width * (vo_panscan_x >> 1) / (vo->dwidth + vo_panscan_x); + x0 += ctx->image_width * (vo->panscan_x >> 1) + / (vo->dwidth + vo->panscan_x); vo_draw_alpha_yv12(w, h, src, srca, stride, ctx->xvimage[ctx->current_buf]->data + ctx->xvimage[ctx->current_buf]->offsets[0] + @@ -121,7 +122,8 @@ static void draw_alpha_yuy2(void *p, int x0, int y0, int w, int h, { struct vo *vo = p; struct xvctx *ctx = vo->priv; - x0 += ctx->image_width * (vo_panscan_x >> 1) / (vo->dwidth + vo_panscan_x); + x0 += ctx->image_width * (vo->panscan_x >> 1) + / (vo->dwidth + vo->panscan_x); vo_draw_alpha_yuy2(w, h, src, srca, stride, ctx->xvimage[ctx->current_buf]->data + ctx->xvimage[ctx->current_buf]->offsets[0] + @@ -135,7 +137,8 @@ static void draw_alpha_uyvy(void *p, int x0, int y0, int w, int h, { struct vo *vo = p; struct xvctx *ctx = vo->priv; - x0 += ctx->image_width * (vo_panscan_x >> 1) / (vo->dwidth + vo_panscan_x); + x0 += ctx->image_width * (vo->panscan_x >> 1) + / (vo->dwidth + vo->panscan_x); vo_draw_alpha_yuy2(w, h, src, srca, stride, ctx->xvimage[ctx->current_buf]->data + ctx->xvimage[ctx->current_buf]->offsets[0] + @@ -156,7 +159,7 @@ static void calc_drwXY(struct vo *vo, uint32_t *drwX, uint32_t *drwY) { struct MPOpts *opts = vo->opts; *drwX = *drwY = 0; if (vo_fs) { - aspect(&vo->dwidth, &vo->dheight, A_ZOOM); + aspect(vo, &vo->dwidth, &vo->dheight, A_ZOOM); vo->dwidth = FFMIN(vo->dwidth, opts->vo_screenwidth); vo->dheight = FFMIN(vo->dheight, opts->vo_screenheight); *drwX = (opts->vo_screenwidth - vo->dwidth) / 2; @@ -252,7 +255,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, hint.y = (opts->vo_screenheight - modeline_height) / 2; hint.width = modeline_width; hint.height = modeline_height; - aspect_save_screenres(modeline_width, modeline_height); + aspect_save_screenres(vo, modeline_width, modeline_height); } else #warning This "else" makes no sense #endif @@ -298,7 +301,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, &drwBorderWidth, &drwDepth); if (vo->dwidth <= 0) vo->dwidth = d_width; if (vo->dheight <= 0) vo->dheight = d_height; - aspect_save_prescale(vo->dwidth, vo->dheight); + aspect_save_prescale(vo, vo->dwidth, vo->dheight); } } else { @@ -362,16 +365,16 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, set_gamma_correction(); #endif - aspect(&vo->dwidth, &vo->dheight, A_NOZOOM); + aspect(vo, &vo->dwidth, &vo->dheight, A_NOZOOM); if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0) vo_fs = 1; calc_drwXY(vo, &ctx->drwX, &ctx->drwY); - panscan_calc(); + panscan_calc(vo); - vo_xv_draw_colorkey(vo, ctx->drwX - (vo_panscan_x >> 1), - ctx->drwY - (vo_panscan_y >> 1), - vo->dwidth + vo_panscan_x - 1, - vo->dheight + vo_panscan_y - 1); + vo_xv_draw_colorkey(vo, ctx->drwX - (vo->panscan_x >> 1), + ctx->drwY - (vo->panscan_y >> 1), + vo->dwidth + vo->panscan_x - 1, + vo->dheight + vo->panscan_y - 1); mp_msg(MSGT_VO, MSGL_V, "[xv] dx: %d dy: %d dw: %d dh: %d\n", ctx->drwX, ctx->drwY, vo->dwidth, vo->dheight); @@ -456,18 +459,18 @@ static inline void put_xvimage(struct vo *vo, XvImage *xvi) { XvShmPutImage(x11->display, x11->xv_port, x11->window, x11->vo_gc, xvi, 0, 0, ctx->image_width, - ctx->image_height, ctx->drwX - (vo_panscan_x >> 1), - ctx->drwY - (vo_panscan_y >> 1), vo->dwidth + vo_panscan_x, - vo->dheight + vo_panscan_y, + ctx->image_height, ctx->drwX - (vo->panscan_x >> 1), + ctx->drwY - (vo->panscan_y >> 1), vo->dwidth + vo->panscan_x, + vo->dheight + vo->panscan_y, False); } else #endif { XvPutImage(x11->display, x11->xv_port, x11->window, x11->vo_gc, xvi, 0, 0, ctx->image_width, ctx->image_height, - ctx->drwX - (vo_panscan_x >> 1), ctx->drwY - (vo_panscan_y >> 1), - vo->dwidth + vo_panscan_x, - vo->dheight + vo_panscan_y); + ctx->drwX - (vo->panscan_x >> 1), ctx->drwY - (vo->panscan_y >> 1), + vo->dwidth + vo->panscan_x, + vo->dheight + vo->panscan_y); } } @@ -491,10 +494,10 @@ static void check_events(struct vo *vo) if (e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) { - vo_xv_draw_colorkey(vo, ctx->drwX - (vo_panscan_x >> 1), - ctx->drwY - (vo_panscan_y >> 1), - vo->dwidth + vo_panscan_x - 1, - vo->dheight + vo_panscan_y - 1); + vo_xv_draw_colorkey(vo, ctx->drwX - (vo->panscan_x >> 1), + ctx->drwY - (vo->panscan_y >> 1), + vo->dwidth + vo->panscan_x - 1, + vo->dheight + vo->panscan_y - 1); } if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && ctx->is_paused) @@ -513,7 +516,7 @@ static void draw_osd(struct vo *vo) struct xvctx *ctx = vo->priv; osd_draw_text(ctx->image_width - - ctx->image_width * vo_panscan_x / (vo->dwidth + vo_panscan_x), + ctx->image_width * vo->panscan_x / (vo->dwidth + vo->panscan_x), ctx->image_height, ctx->draw_alpha_fnc, vo); } @@ -880,23 +883,23 @@ static int control(struct vo *vo, uint32_t request, void *data) vo_x11_fullscreen(vo); /* indended, fallthrough to update panscan on fullscreen/windowed switch */ case VOCTRL_SET_PANSCAN: - if ((vo_fs && (vo_panscan != vo_panscan_amount)) - || (!vo_fs && vo_panscan_amount)) + if ((vo_fs && (vo_panscan != vo->panscan_amount)) + || (!vo_fs && vo->panscan_amount)) { - int old_y = vo_panscan_y; + int old_y = vo->panscan_y; - panscan_calc(); + panscan_calc(vo); - if (old_y != vo_panscan_y) + if (old_y != vo->panscan_y) { vo_x11_clearwindow_part(vo, x11->window, - vo->dwidth + vo_panscan_x - 1, - vo->dheight + vo_panscan_y - 1, + vo->dwidth + vo->panscan_x - 1, + vo->dheight + vo->panscan_y - 1, 1); - vo_xv_draw_colorkey(vo, ctx->drwX - (vo_panscan_x >> 1), - ctx->drwY - (vo_panscan_y >> 1), - vo->dwidth + vo_panscan_x - 1, - vo->dheight + vo_panscan_y - 1); + vo_xv_draw_colorkey(vo, ctx->drwX - (vo->panscan_x >> 1), + ctx->drwY - (vo->panscan_y >> 1), + vo->dwidth + vo->panscan_x - 1, + vo->dheight + vo->panscan_y - 1); flip_page(vo); } } diff --git a/libvo/w32_common.c b/libvo/w32_common.c index b45b06cfbc..1346f50a7f 100644 --- a/libvo/w32_common.c +++ b/libvo/w32_common.c @@ -77,7 +77,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l xborder = (r2.right - r2.left) - (r.right - r.left); yborder = (r2.bottom - r2.top) - (r.bottom - r.top); wpos->cx -= xborder; wpos->cy -= yborder; - aspect_fit(&wpos->cx, &wpos->cy, wpos->cx, wpos->cy); + aspect_fit(global_vo, &wpos->cx, &wpos->cy, wpos->cx, wpos->cy); wpos->cx += xborder; wpos->cy += yborder; } return 0; diff --git a/libvo/x11_common.c b/libvo/x11_common.c index ec48f16ff6..6fefae61f3 100644 --- a/libvo/x11_common.c +++ b/libvo/x11_common.c @@ -375,7 +375,7 @@ void update_xinerama_info(struct vo *vo) { XFree(screens); } #endif - aspect_save_screenres(opts->vo_screenwidth, opts->vo_screenheight); + aspect_save_screenres(vo, opts->vo_screenwidth, opts->vo_screenheight); } int vo_init(struct vo *vo) -- cgit v1.2.3