+static void VoutDisplayFitWindow(vout_display_t *vd, bool default_size)
+{
+ vout_display_owner_sys_t *osys = vd->owner.sys;
+ vout_display_cfg_t cfg = osys->cfg;
+
+ if (!cfg.is_display_filled)
+ return;
+
+ cfg.display.width = 0;
+ if (default_size) {
+ cfg.display.height = 0;
+ } else {
+ cfg.display.height = osys->height_saved;
+ cfg.zoom.num = 1;
+ cfg.zoom.den = 1;
+ }
+
+ unsigned display_width;
+ unsigned display_height;
+ vout_display_GetDefaultDisplaySize(&display_width, &display_height,
+ &vd->source, &cfg);
+
+ vlc_mutex_lock(&osys->lock);
+
+ osys->ch_display_size = true;
+ osys->display_width = display_width;
+ osys->display_height = display_height;
+ osys->display_is_fullscreen = osys->cfg.is_fullscreen;
+ osys->display_is_forced = true;
+
+ vlc_mutex_unlock(&osys->lock);
+}
+
+static void VoutDisplayCropRatio(unsigned *x, unsigned *y,
+ unsigned *width, unsigned *height,
+ const video_format_t *source,
+ unsigned num, unsigned den)
+{
+ unsigned scaled_width = (uint64_t)source->i_visible_height * num * source->i_sar_den / den / source->i_sar_num;
+ unsigned scaled_height = (uint64_t)source->i_visible_width * den * source->i_sar_num / num / source->i_sar_den;
+
+ if (scaled_width < source->i_visible_width) {
+ *x = (source->i_visible_width - scaled_width) / 2;
+ *y = 0;
+ *width = scaled_width;
+ *height = source->i_visible_height;
+ } else {
+ *x = 0;
+ *y = (source->i_visible_height - scaled_height) / 2;
+ *width = source->i_visible_width;
+ *height = scaled_height;
+ }
+ *x += source->i_x_offset;
+ *y += source->i_y_offset;
+}
+