2014-05-06 18:22:32 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
2017-06-17 19:10:17 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2014-05-06 18:22:32 +00:00
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-06-17 19:10:17 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2014-05-06 18:22:32 +00:00
|
|
|
*
|
2017-06-17 19:10:17 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2014-05-06 18:22:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "win_state.h"
|
|
|
|
#include "vo.h"
|
|
|
|
|
|
|
|
#include "video/mp_image.h"
|
|
|
|
|
|
|
|
static void calc_monitor_aspect(struct mp_vo_opts *opts, int scr_w, int scr_h,
|
|
|
|
double *pixelaspect, int *w, int *h)
|
|
|
|
{
|
|
|
|
*pixelaspect = 1.0 / opts->monitor_pixel_aspect;
|
|
|
|
|
|
|
|
if (scr_w > 0 && scr_h > 0 && opts->force_monitor_aspect)
|
2015-01-05 16:23:56 +00:00
|
|
|
*pixelaspect = 1.0 / (opts->force_monitor_aspect * scr_h / scr_w);
|
2014-05-06 18:22:32 +00:00
|
|
|
|
|
|
|
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,
|
2015-01-16 21:30:32 +00:00
|
|
|
struct m_geometry *geo, bool allow_up, bool allow_down)
|
2014-05-06 18:22:32 +00:00
|
|
|
{
|
|
|
|
if (!geo->wh_valid)
|
|
|
|
return;
|
|
|
|
|
2019-07-06 21:54:50 +00:00
|
|
|
int dummy = 0;
|
2014-05-06 18:22:32 +00:00
|
|
|
int n_w = *w, n_h = *h;
|
|
|
|
m_geometry_apply(&dummy, &dummy, &n_w, &n_h, scr_w, scr_h, geo);
|
|
|
|
|
2015-01-16 21:30:32 +00:00
|
|
|
if (!allow_up && *w <= n_w && *h <= n_h)
|
|
|
|
return;
|
|
|
|
if (!allow_down && *w >= n_w && *h >= n_h)
|
2014-05-06 18:22:32 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// If aspect mismatches, always make the window smaller than the fit box
|
2015-01-16 21:30:32 +00:00
|
|
|
// (Or larger, if allow_down==false.)
|
2014-05-06 18:22:32 +00:00
|
|
|
double asp = (double)*w / *h;
|
|
|
|
double n_asp = (double)n_w / n_h;
|
2015-01-16 21:30:32 +00:00
|
|
|
if ((n_asp <= asp) == allow_down) {
|
2014-05-06 18:22:32 +00:00
|
|
|
*w = n_w;
|
|
|
|
*h = n_w / asp;
|
|
|
|
} else {
|
|
|
|
*w = n_h * asp;
|
|
|
|
*h = n_h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the "suggested" window size and position and return it in *out_geo.
|
|
|
|
// screen is the bounding box of the current screen within the virtual desktop.
|
|
|
|
// Does not change *vo.
|
2021-08-12 17:45:16 +00:00
|
|
|
// screen: position of the area on virtual desktop on which the video-content
|
|
|
|
// should be placed (maybe after excluding decorations, taskbars, etc)
|
2024-09-28 02:32:33 +00:00
|
|
|
// can be the same as monitor for platforms that don't try to take into
|
|
|
|
// account decorations, taskbars, etc.
|
2021-08-12 17:45:16 +00:00
|
|
|
// monitor: position of the monitor on virtual desktop (used for pixelaspect).
|
2017-01-19 15:30:38 +00:00
|
|
|
// dpi_scale: the DPI multiplier to get from virtual to real coordinates
|
|
|
|
// (>1 for "hidpi")
|
2024-09-27 15:54:01 +00:00
|
|
|
// force_center: force centering x/y in the middle of the given screen even if
|
|
|
|
// opts->force_window_position is not set. ignored if the user
|
|
|
|
// supplies valid x/y coordinates on their own.
|
2014-05-06 18:22:32 +00:00
|
|
|
// Use vo_apply_window_geometry() to copy the result into the vo.
|
|
|
|
// NOTE: currently, all windowing backends do their own handling of window
|
|
|
|
// geometry additional to this code. This is to deal with initial window
|
|
|
|
// placement, fullscreen handling, avoiding resize on reconfig() with no
|
|
|
|
// size change, multi-monitor stuff, and possibly more.
|
2024-09-28 02:32:33 +00:00
|
|
|
void vo_calc_window_geometry(struct vo *vo, const struct mp_rect *screen,
|
2024-09-27 15:54:01 +00:00
|
|
|
const struct mp_rect *monitor, double dpi_scale,
|
|
|
|
bool force_center, struct vo_win_geometry *out_geo)
|
2014-05-06 18:22:32 +00:00
|
|
|
{
|
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
|
|
|
|
|
|
|
*out_geo = (struct vo_win_geometry){0};
|
|
|
|
|
|
|
|
// The case of calling this function even though no video was configured
|
2018-01-20 15:10:42 +00:00
|
|
|
// yet (i.e. vo->params==NULL) happens when vo_gpu creates a hidden window
|
|
|
|
// in order to create a rendering context.
|
2015-12-19 19:04:31 +00:00
|
|
|
struct mp_image_params params = { .w = 320, .h = 200 };
|
2014-05-06 18:22:32 +00:00
|
|
|
if (vo->params)
|
|
|
|
params = *vo->params;
|
|
|
|
|
2017-01-19 15:30:38 +00:00
|
|
|
if (!opts->hidpi_window_scale)
|
|
|
|
dpi_scale = 1;
|
|
|
|
|
2015-12-19 19:04:31 +00:00
|
|
|
int d_w, d_h;
|
|
|
|
mp_image_params_get_dsize(¶ms, &d_w, &d_h);
|
2014-05-06 18:22:32 +00:00
|
|
|
if ((vo->driver->caps & VO_CAP_ROTATE90) && params.rotate % 180 == 90)
|
|
|
|
MPSWAP(int, d_w, d_h);
|
2017-01-19 15:30:38 +00:00
|
|
|
d_w = MPCLAMP(d_w * opts->window_scale * dpi_scale, 1, 16000);
|
|
|
|
d_h = MPCLAMP(d_h * opts->window_scale * dpi_scale, 1, 16000);
|
2014-05-06 18:22:32 +00:00
|
|
|
|
|
|
|
int scr_w = screen->x1 - screen->x0;
|
|
|
|
int scr_h = screen->y1 - screen->y0;
|
|
|
|
|
2021-08-12 17:45:16 +00:00
|
|
|
int mon_w = monitor->x1 - monitor->x0;
|
|
|
|
int mon_h = monitor->y1 - monitor->y0;
|
|
|
|
|
|
|
|
MP_DBG(vo, "max content size: %dx%d\n", scr_w, scr_h);
|
|
|
|
MP_DBG(vo, "monitor size: %dx%d\n", mon_w, mon_h);
|
2014-05-06 18:22:32 +00:00
|
|
|
|
2021-08-12 17:45:16 +00:00
|
|
|
calc_monitor_aspect(opts, mon_w, mon_h, &out_geo->monitor_par, &d_w, &d_h);
|
2014-05-06 18:22:32 +00:00
|
|
|
|
2015-01-16 21:30:32 +00:00
|
|
|
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit, true, true);
|
|
|
|
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit_smaller, true, false);
|
2016-10-30 13:38:26 +00:00
|
|
|
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit_larger, false, true);
|
2014-05-06 18:22:32 +00:00
|
|
|
|
|
|
|
out_geo->win.x0 = (int)(scr_w - d_w) / 2;
|
|
|
|
out_geo->win.y0 = (int)(scr_h - d_h) / 2;
|
2024-09-27 15:54:01 +00:00
|
|
|
|
|
|
|
int old_w = d_w;
|
|
|
|
int old_h = d_h;
|
|
|
|
|
2014-05-06 18:22:32 +00:00
|
|
|
m_geometry_apply(&out_geo->win.x0, &out_geo->win.y0, &d_w, &d_h,
|
|
|
|
scr_w, scr_h, &opts->geometry);
|
|
|
|
|
2024-09-27 15:54:01 +00:00
|
|
|
if ((opts->force_window_position || force_center) && !opts->geometry.xy_valid) {
|
|
|
|
out_geo->win.x0 += old_w / 2 - d_w / 2;
|
|
|
|
out_geo->win.y0 += old_h / 2 - d_h / 2;
|
|
|
|
}
|
|
|
|
|
2014-05-06 18:22:32 +00:00
|
|
|
out_geo->win.x0 += screen->x0;
|
|
|
|
out_geo->win.y0 += screen->y0;
|
|
|
|
out_geo->win.x1 = out_geo->win.x0 + d_w;
|
|
|
|
out_geo->win.y1 = out_geo->win.y0 + d_h;
|
|
|
|
|
2024-09-27 15:54:01 +00:00
|
|
|
if (opts->geometry.xy_valid || opts->force_window_position || force_center)
|
2014-05-06 18:22:32 +00:00
|
|
|
out_geo->flags |= VO_WIN_FORCE_POS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the parameters in *geo to the vo fields.
|
|
|
|
// (Doesn't do anything else - windowing backends should trigger VO_EVENT_RESIZE
|
|
|
|
// to ensure that the VO reinitializes rendering properly.)
|
|
|
|
void vo_apply_window_geometry(struct vo *vo, const struct vo_win_geometry *geo)
|
|
|
|
{
|
|
|
|
vo->dwidth = geo->win.x1 - geo->win.x0;
|
|
|
|
vo->dheight = geo->win.y1 - geo->win.y0;
|
|
|
|
vo->monitor_par = geo->monitor_par;
|
|
|
|
}
|