mirror of
https://github.com/mpv-player/mpv
synced 2025-02-06 07:01:45 +00:00
video/out: simplify monitor aspect handling
For some reason, this made all VO backends both set the screen resolution in opts->screenwidth/height, and call aspect_save_screenres(). Remove the latter. Move the code to calculate the PAR-corrected window size from aspect.c to vo.c, and make it so that the monitor PAR is recalculated when it makes sense.
This commit is contained in:
parent
3b8e457379
commit
d956bbc065
@ -35,37 +35,16 @@ void aspect_save_videores(struct vo *vo, int w, int h, int d_w, int d_h)
|
||||
vo->aspdat.par = (double)d_w / d_h * h / w;
|
||||
}
|
||||
|
||||
void aspect_save_screenres(struct vo *vo, int scrw, int scrh)
|
||||
{
|
||||
MP_DBG(vo, "aspect_save_screenres %dx%d\n", scrw, scrh);
|
||||
struct mp_vo_opts *opts = vo->opts;
|
||||
if (scrw > 0 && scrh > 0 && opts->force_monitor_aspect)
|
||||
vo->aspdat.monitor_par = opts->force_monitor_aspect * scrh / scrw;
|
||||
else
|
||||
vo->aspdat.monitor_par = 1.0 / opts->monitor_pixel_aspect;
|
||||
}
|
||||
|
||||
void aspect_calc_monitor(struct vo *vo, int *w, int *h)
|
||||
{
|
||||
float pixelaspect = vo->aspdat.monitor_par;
|
||||
|
||||
if (pixelaspect < 1) {
|
||||
*h /= pixelaspect;
|
||||
} else {
|
||||
*w *= pixelaspect;
|
||||
}
|
||||
}
|
||||
|
||||
static void aspect_calc(struct vo *vo, int *srcw, int *srch)
|
||||
{
|
||||
struct aspect_data *aspdat = &vo->aspdat;
|
||||
float pixelaspect = aspdat->monitor_par;
|
||||
float pixelaspect = vo->monitor_par;
|
||||
|
||||
int fitw = FFMAX(1, vo->dwidth);
|
||||
int fith = FFMAX(1, vo->dheight);
|
||||
|
||||
MP_DBG(vo, "aspect(0) fitin: %dx%d monitor_par: %.2f\n",
|
||||
fitw, fith, aspdat->monitor_par);
|
||||
fitw, fith, pixelaspect);
|
||||
*srcw = fitw;
|
||||
*srch = (float)fitw / aspdat->prew * aspdat->preh / pixelaspect;
|
||||
MP_DBG(vo, "aspect(1) wh: %dx%d (org: %dx%d)\n",
|
||||
|
@ -23,9 +23,6 @@
|
||||
struct vo;
|
||||
|
||||
void aspect_save_videores(struct vo *vo, int w, int h, int d_w, int d_h);
|
||||
void aspect_save_screenres(struct vo *vo, int scrw, int scrh);
|
||||
|
||||
void aspect_calc_monitor(struct vo *vo, int *w, int *h);
|
||||
void aspect_calc_panscan(struct vo *vo, int *out_w, int *out_h);
|
||||
|
||||
#endif /* MPLAYER_ASPECT_H */
|
||||
|
@ -219,7 +219,6 @@ static void vo_cocoa_update_screen_info(struct vo *vo)
|
||||
|
||||
NSRect r = [s->current_screen frame];
|
||||
|
||||
aspect_save_screenres(vo, r.size.width, r.size.height);
|
||||
opts->screenwidth = r.size.width;
|
||||
opts->screenheight = r.size.height;
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ static struct vo *vo_create(struct mpv_global *global,
|
||||
.input_ctx = input_ctx,
|
||||
.event_fd = -1,
|
||||
.registered_fd = -1,
|
||||
.aspdat = { .monitor_par = 1 },
|
||||
.monitor_par = 1,
|
||||
.next_pts = MP_NOPTS_VALUE,
|
||||
.next_pts2 = MP_NOPTS_VALUE,
|
||||
};
|
||||
@ -339,6 +339,21 @@ autoprobe:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void calc_monitor_aspect(struct mp_vo_opts *opts, int scr_w, int scr_h,
|
||||
float *pixelaspect, int *w, int *h)
|
||||
{
|
||||
*pixelaspect = 1.0 / opts->monitor_pixel_aspect;
|
||||
|
||||
if (scr_w > 0 && scr_h > 0 && opts->force_monitor_aspect)
|
||||
*pixelaspect = opts->force_monitor_aspect * scr_h / scr_w;
|
||||
|
||||
if (*pixelaspect < 1) {
|
||||
*h /= *pixelaspect;
|
||||
} else {
|
||||
*w *= *pixelaspect;
|
||||
}
|
||||
}
|
||||
|
||||
// Fit *w/*h into the size specified by geo.
|
||||
static void apply_autofit(int *w, int *h, int scr_w, int scr_h,
|
||||
struct m_geometry *geo, bool allow_upscale)
|
||||
@ -378,7 +393,9 @@ static void determine_window_geometry(struct vo *vo, int d_w, int d_h)
|
||||
int scr_w = opts->screenwidth;
|
||||
int scr_h = opts->screenheight;
|
||||
|
||||
aspect_calc_monitor(vo, &d_w, &d_h);
|
||||
MP_DBG(vo, "screen size: %dx%d\n", scr_w, scr_h);
|
||||
|
||||
calc_monitor_aspect(opts, scr_w, scr_h, &vo->monitor_par, &d_w, &d_h);
|
||||
|
||||
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit, true);
|
||||
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit_larger, false);
|
||||
@ -572,7 +589,7 @@ void vo_get_src_dst_rects(struct vo *vo, struct mp_rect *out_src,
|
||||
struct mp_osd_res osd = {
|
||||
.w = vo->dwidth,
|
||||
.h = vo->dheight,
|
||||
.display_par = vo->aspdat.monitor_par,
|
||||
.display_par = vo->monitor_par,
|
||||
};
|
||||
if (opts->keepaspect) {
|
||||
int scaled_width, scaled_height;
|
||||
|
@ -265,12 +265,12 @@ struct vo {
|
||||
|
||||
int xinerama_x;
|
||||
int xinerama_y;
|
||||
float monitor_par;
|
||||
|
||||
struct aspect_data {
|
||||
float monitor_par; // out of screen size or from options
|
||||
int orgw; // real width
|
||||
int orgw; // real width (same as params->w and h)
|
||||
int orgh; // real height
|
||||
int prew; // prescaled width
|
||||
int prew; // prescaled width (same as params->d_w and d_h)
|
||||
int preh; // prescaled height
|
||||
float par; // pixel aspect ratio out of orgw/orgh and prew/preh
|
||||
} aspdat;
|
||||
|
@ -892,7 +892,6 @@ static void update_screeninfo(struct vo *vo)
|
||||
struct mp_vo_opts *opts = vo->opts;
|
||||
opts->screenwidth = mode.w;
|
||||
opts->screenheight = mode.h;
|
||||
aspect_save_screenres(vo, opts->screenwidth, opts->screenheight);
|
||||
}
|
||||
|
||||
static struct mp_image *get_screenshot(struct vo *vo)
|
||||
|
@ -617,8 +617,6 @@ static void w32_update_xinerama_info(struct vo *vo)
|
||||
w32->mon_id = screen;
|
||||
EnumDisplayMonitors(NULL, NULL, mon_enum, (LONG_PTR)vo);
|
||||
}
|
||||
|
||||
aspect_save_screenres(vo, vo->opts->screenwidth, vo->opts->screenheight);
|
||||
}
|
||||
|
||||
static void updateScreenProperties(struct vo *vo)
|
||||
|
@ -1107,8 +1107,6 @@ static void vo_wayland_update_screeninfo (struct vo *vo)
|
||||
|
||||
wl->window.fs_width = opts->screenwidth;
|
||||
wl->window.fs_height = opts->screenheight;
|
||||
|
||||
aspect_save_screenres(vo, opts->screenwidth, opts->screenheight);
|
||||
}
|
||||
|
||||
int vo_wayland_control (struct vo *vo, int *events, int request, void *arg)
|
||||
|
@ -470,7 +470,6 @@ static void vo_x11_update_screeninfo(struct vo *vo)
|
||||
XFree(screens);
|
||||
}
|
||||
#endif
|
||||
aspect_save_screenres(vo, opts->screenwidth, opts->screenheight);
|
||||
}
|
||||
|
||||
int vo_x11_init(struct vo *vo)
|
||||
|
Loading…
Reference in New Issue
Block a user