Commit c47f7383 authored by David Fuhrmann's avatar David Fuhrmann

macosx vout: replace custom picture placement code by placePicture call, and other simplifications

Now, the vout should have the same functionality as all the other. At least in
fullscreen, zoom should work now like in other vouts.
Furthermore, this commit tells the core our current size on every resize,
so we get a sharp osd screen every time. For zoom / ar / crop / size handling,
the code was simplified in order to remove duplicated lines and to make the
code more readable.

Should also close #307.
parent 8c8fce6f
...@@ -317,28 +317,6 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -317,28 +317,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
if (vout_window_SetFullScreen (sys->embed, cfg->is_fullscreen)) if (vout_window_SetFullScreen (sys->embed, cfg->is_fullscreen))
return VLC_EGENERIC; return VLC_EGENERIC;
NSRect frame;
/* when entering fullscreen, set the OSD / display size to the visible screen size.
* this way, the text rendering will be as sharp as possible.
* when returning from fullscreen, pick the dimensions from cfg, which can be different
* from the native video size because of crop and zoom */
if (cfg->is_fullscreen)
frame = [[[sys->glView window] screen] visibleFrame];
else
frame = NSMakeRect( 0., 0., cfg->display.width, cfg->display.height );
vout_display_SendEventDisplaySize( vd, frame.size.width, frame.size.height, cfg->is_fullscreen );
const video_format_t * source;
source = &vd->source;
vout_display_cfg_t place_cfg = *cfg;
place_cfg.display.width = frame.size.width;
place_cfg.display.height = frame.size.height;
vout_display_place_t place;
vout_display_PlacePicture(&place, source, &place_cfg, false);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
case VOUT_DISPLAY_CHANGE_WINDOW_STATE: case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
...@@ -362,9 +340,6 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -362,9 +340,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
NSPoint topleftbase; NSPoint topleftbase;
NSPoint topleftscreen; NSPoint topleftscreen;
NSRect new_frame; NSRect new_frame;
const vout_display_cfg_t *cfg;
int i_width = 0;
int i_height = 0;
id o_window = [sys->glView window]; id o_window = [sys->glView window];
if (!o_window) if (!o_window)
...@@ -374,20 +349,52 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -374,20 +349,52 @@ static int Control (vout_display_t *vd, int query, va_list ap)
NSRect screenFrame = [[o_window screen] visibleFrame]; NSRect screenFrame = [[o_window screen] visibleFrame];
NSSize windowMinSize = [o_window minSize]; NSSize windowMinSize = [o_window minSize];
int i_width = 0;
int i_height = 0;
const vout_display_cfg_t *cfg;
const video_format_t *source;
bool is_forced = false;
vout_display_place_t place;
topleftbase.x = 0; topleftbase.x = 0;
topleftbase.y = windowFrame.size.height; topleftbase.y = windowFrame.size.height;
topleftscreen = [o_window convertBaseToScreen: topleftbase]; topleftscreen = [o_window convertBaseToScreen: topleftbase];
if (query == VOUT_DISPLAY_CHANGE_SOURCE_CROP || query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT) if (query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT || query == VOUT_DISPLAY_CHANGE_SOURCE_CROP)
{ {
const video_format_t *source;
source = (const video_format_t *)va_arg (ap, const video_format_t *); source = (const video_format_t *)va_arg (ap, const video_format_t *);
cfg = vd->cfg; cfg = vd->cfg;
}
else
{
source = &vd->source;
cfg = (const vout_display_cfg_t*)va_arg (ap, const vout_display_cfg_t *);
if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
is_forced = (bool)va_arg (ap, int);
}
vout_display_place_t place; if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE && is_forced
vout_display_PlacePicture (&place, source, cfg, false); && (cfg->display.width != vd->cfg->display.width
|| cfg->display.height != vd->cfg->display.height)
&& vout_window_SetSize (sys->embed, cfg->display.width, cfg->display.height))
return VLC_EGENERIC;
/* for the case that the core wants to resize below minimum window size we correct the size here
to ensure a centered picture */
vout_display_cfg_t cfg_tmp = *cfg;
if (cfg_tmp.display.width < windowMinSize.width)
cfg_tmp.display.width = windowMinSize.width;
if (cfg_tmp.display.height < windowMinSize.height)
cfg_tmp.display.height = windowMinSize.height;
vout_display_PlacePicture (&place, source, &cfg_tmp, false);
i_width = place.width;
i_height = place.height;
if (query == VOUT_DISPLAY_CHANGE_SOURCE_CROP || query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT)
{
vd->fmt.i_width = vd->source.i_width * place.width / vd->source.i_visible_width; vd->fmt.i_width = vd->source.i_width * place.width / vd->source.i_visible_width;
vd->fmt.i_height = vd->source.i_height * place.height / vd->source.i_visible_height; vd->fmt.i_height = vd->source.i_height * place.height / vd->source.i_visible_height;
vd->fmt.i_visible_width = vd->source.i_visible_width; vd->fmt.i_visible_width = vd->source.i_visible_width;
...@@ -395,9 +402,6 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -395,9 +402,6 @@ static int Control (vout_display_t *vd, int query, va_list ap)
vd->fmt.i_x_offset = vd->source.i_x_offset * place.width / vd->source.i_visible_width; vd->fmt.i_x_offset = vd->source.i_x_offset * place.width / vd->source.i_visible_width;
vd->fmt.i_y_offset = vd->source.i_y_offset * place.height / vd->source.i_visible_height; vd->fmt.i_y_offset = vd->source.i_y_offset * place.height / vd->source.i_visible_height;
i_width = place.width;
i_height = place.height;
if (vd->fmt.i_x_offset > 0) if (vd->fmt.i_x_offset > 0)
{ {
if (vd->source.i_width / vd->fmt.i_x_offset <= 4) if (vd->source.i_width / vd->fmt.i_x_offset <= 4)
...@@ -413,49 +417,28 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -413,49 +417,28 @@ static int Control (vout_display_t *vd, int query, va_list ap)
vd->fmt.i_visible_height = vd->source.i_height; vd->fmt.i_visible_height = vd->source.i_height;
vd->fmt.i_x_offset = 0; vd->fmt.i_x_offset = 0;
vd->fmt.i_y_offset = 0; vd->fmt.i_y_offset = 0;
i_width = vd->source.i_width;
i_height = vd->source.i_height;
} }
} }
glViewport (0, 0, i_width, i_height);
} }
else
{
// VOUT_DISPLAY_CHANGE_ZOOM, VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, VOUT_DISPLAY_CHANGE_DISPLAY_SIZE
const vout_display_cfg_t *cfg;
const video_format_t *source;
bool is_forced = false;
source = &vd->source; /* For resize, we call glViewport in reshape and not here.
cfg = (const vout_display_cfg_t*)va_arg (ap, const vout_display_cfg_t *); This has the positive side effect that we avoid erratic sizing as we animate every resize. */
is_forced = (bool)va_arg (ap, int); if (query != VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
{
if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE glViewport (place.x, place.y, i_width, i_height);
&& is_forced
&& (cfg->display.width != vd->cfg->display.width
||cfg->display.height != vd->cfg->display.height)
&& vout_window_SetSize (sys->embed,
cfg->display.width,
cfg->display.height))
return VLC_EGENERIC;
vout_display_place_t place;
vout_display_PlacePicture (&place, source, cfg, false);
i_width = place.width;
i_height = place.height;
} }
// this should not be needed, but currently it improves crop somehow, when we are in fullscreen
if (query == VOUT_DISPLAY_CHANGE_SOURCE_CROP)
[sys->glView performSelectorOnMainThread:@selector(reshapeView:) withObject:nil waitUntilDone:NO];
/* Calculate the window's new size, if it is larger than our minimal size */ /* Calculate the window's new size, if it is larger than our minimal size */
if (i_width < windowMinSize.width) if (i_width < windowMinSize.width)
i_width = windowMinSize.width; i_width = windowMinSize.width;
if (i_height < windowMinSize.height) if (i_height < windowMinSize.height)
i_height = windowMinSize.height; i_height = windowMinSize.height;
// is needed in the case we do not an actual resize if (config_GetInt (vd, "macosx-video-autoresize") && query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE && is_forced &&
[sys->glView performSelectorOnMainThread:@selector(reshapeView:) withObject:nil waitUntilDone:NO];
if (config_GetInt (vd, "macosx-video-autoresize") && query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE &&
(i_height != glViewFrame.size.height || i_width != glViewFrame.size.width)) (i_height != glViewFrame.size.height || i_width != glViewFrame.size.width))
{ {
new_frame.size.width = windowFrame.size.width - glViewFrame.size.width + i_width; new_frame.size.width = windowFrame.size.width - glViewFrame.size.width + i_width;
...@@ -540,6 +523,7 @@ static void OpenglSwap(vlc_gl_t *gl) ...@@ -540,6 +523,7 @@ static void OpenglSwap(vlc_gl_t *gl)
#define VLCAssertMainThread() assert([[NSThread currentThread] isMainThread]) #define VLCAssertMainThread() assert([[NSThread currentThread] isMainThread])
+ (void)getNewView:(NSValue *)value + (void)getNewView:(NSValue *)value
{ {
id *ret = [value pointerValue]; id *ret = [value pointerValue];
...@@ -717,44 +701,21 @@ static void OpenglSwap(vlc_gl_t *gl) ...@@ -717,44 +701,21 @@ static void OpenglSwap(vlc_gl_t *gl)
VLCAssertMainThread(); VLCAssertMainThread();
NSRect bounds = [self bounds]; NSRect bounds = [self bounds];
vout_display_place_t place;
CGFloat height, width;
if( !vd || ( vd && vd->cfg->is_display_filled ))
{
height = bounds.size.height;
width = bounds.size.width;
}
else
{
height = vd->source.i_visible_height;
width = vd->source.i_visible_width;
}
GLint x = width, y = height;
@synchronized(self) { @synchronized(self) {
if (vd) { if (vd) {
CGFloat videoHeight = vd->source.i_visible_height; vout_display_cfg_t cfg_tmp = *(vd->cfg);
CGFloat videoWidth = vd->source.i_visible_width; cfg_tmp.display.width = bounds.size.width;
cfg_tmp.display.height = bounds.size.height;
GLint sarNum = vd->source.i_sar_num; vout_display_PlacePicture (&place, &vd->source, &cfg_tmp, false);
GLint sarDen = vd->source.i_sar_den; vout_display_SendEventDisplaySize (vd, bounds.size.width, bounds.size.height, vd->cfg->is_fullscreen);
if (height * videoWidth * sarNum < width * videoHeight * sarDen)
{
x = (height * videoWidth * sarNum) / (videoHeight * sarDen);
y = height;
}
else
{
x = width;
y = (width * videoHeight * sarDen) / (videoWidth * sarNum);
}
} }
} }
if ([self lockgl]) { if ([self lockgl]) {
glViewport((bounds.size.width - x) / 2, (bounds.size.height - y) / 2, x, y); glViewport (place.x, place.y, place.width, place.height);
@synchronized(self) { @synchronized(self) {
// This may be cleared before -drawRect is being called, // This may be cleared before -drawRect is being called,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment