Added VOUT_DISPLAY_EVENT_ON_TOP (vout display).
[vlc.git] / src / video_output / display.c
1 /*****************************************************************************
2  * display.c: "vout display" managment
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 #include <assert.h>
31
32 #include <vlc_common.h>
33 #include <vlc_video_splitter.h>
34 #include <vlc_vout_display.h>
35 #include <vlc_vout.h>
36
37 #include <libvlc.h>
38
39 #include "display.h"
40
41 #include "event.h"
42
43 static void SplitterClose(vout_display_t *vd);
44
45 /*****************************************************************************
46  * FIXME/TODO see how to have direct rendering here (interact with vout.c)
47  *****************************************************************************/
48 static picture_t *VideoBufferNew(filter_t *filter)
49 {
50     vout_display_t *vd = (vout_display_t*)filter->p_owner;
51     const video_format_t *fmt = &filter->fmt_out.video;
52
53     assert(vd->fmt.i_chroma == fmt->i_chroma &&
54            vd->fmt.i_width  == fmt->i_width  &&
55            vd->fmt.i_height == fmt->i_height);
56
57     return vout_display_Get(vd);
58 }
59 static void VideoBufferDelete(filter_t *filter, picture_t *picture)
60 {
61     VLC_UNUSED(filter);
62     picture_Release(picture);
63 }
64
65 static int  FilterAllocationInit(filter_t *filter, void *vd)
66 {
67     filter->pf_vout_buffer_new = VideoBufferNew;
68     filter->pf_vout_buffer_del = VideoBufferDelete;
69     filter->p_owner            = vd;
70
71     return VLC_SUCCESS;
72 }
73 static void FilterAllocationClean(filter_t *filter)
74 {
75     filter->pf_vout_buffer_new = NULL;
76     filter->pf_vout_buffer_del = NULL;
77     filter->p_owner            = NULL;
78 }
79
80 /*****************************************************************************
81  *
82  *****************************************************************************/
83
84 /**
85  * It creates a new vout_display_t using the given configuration.
86  */
87 static vout_display_t *vout_display_New(vlc_object_t *obj,
88                                         const char *module, bool load_module,
89                                         const video_format_t *fmt,
90                                         const vout_display_cfg_t *cfg,
91                                         vout_display_owner_t *owner)
92 {
93     /* */
94     vout_display_t *vd = vlc_object_create(obj, sizeof(*vd));
95
96     /* */
97     video_format_Copy(&vd->source, fmt);
98
99     /* Picture buffer does not have the concept of aspect ratio */
100     video_format_Copy(&vd->fmt, fmt);
101     vd->fmt.i_aspect = 0;
102     vd->fmt.i_sar_num = 0;
103     vd->fmt.i_sar_den = 0;
104
105     vd->info.is_slow = false;
106     vd->info.has_double_click = false;
107     vd->info.has_hide_mouse = false;
108     vd->info.has_pictures_invalid = false;
109
110     vd->cfg = cfg;
111     vd->get = NULL;
112     vd->prepare = NULL;
113     vd->display = NULL;
114     vd->control = NULL;
115     vd->manage = NULL;
116     vd->sys = NULL;
117
118     vd->owner = *owner;
119
120     vlc_object_attach(vd, obj);
121
122     if (load_module) {
123         vd->module = module_need(vd, "vout display", module, module && *module != '\0');
124         if (!vd->module) {
125             vlc_object_detach(vd);
126             vlc_object_release(vd);
127             return NULL;
128         }
129     } else {
130         vd->module = NULL;
131     }
132     return vd;
133 }
134
135 /**
136  * It deletes a vout_display_t
137  */
138 static void vout_display_Delete(vout_display_t *vd)
139 {
140     vlc_object_detach(vd);
141
142     if (vd->module)
143         module_unneed(vd, vd->module);
144
145     vlc_object_release(vd);
146 }
147
148 /**
149  * It controls a vout_display_t
150  */
151 static int vout_display_Control(vout_display_t *vd, int query, ...)
152 {
153     va_list args;
154     int result;
155
156     va_start(args, query);
157     result = vd->control(vd, query, args);
158     va_end(args);
159
160     return result;
161 }
162 static void vout_display_Manage(vout_display_t *vd)
163 {
164     if (vd->manage)
165         vd->manage(vd);
166 }
167
168 /* */
169 void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height,
170                                         const video_format_t *source,
171                                         const vout_display_cfg_t *cfg)
172 {
173     if (cfg->display.width > 0 && cfg->display.height > 0) {
174         *width  = cfg->display.width;
175         *height = cfg->display.height;
176     } else if (cfg->display.width > 0) {
177         *width  = cfg->display.width;
178         *height = (int64_t)source->i_visible_height * source->i_sar_den * cfg->display.width * cfg->display.sar.num /
179             source->i_visible_width / source->i_sar_num / cfg->display.sar.den;
180     } else if (cfg->display.height > 0) {
181         *width  = (int64_t)source->i_visible_width * source->i_sar_num * cfg->display.height * cfg->display.sar.den /
182             source->i_visible_height / source->i_sar_den / cfg->display.sar.num;
183         *height = cfg->display.height;
184     } else if (source->i_sar_num >= source->i_sar_den) {
185         *width  = (int64_t)source->i_visible_width * source->i_sar_num * cfg->display.sar.den / source->i_sar_den / cfg->display.sar.num;
186         *height = source->i_visible_height;
187     } else {
188         *width  = source->i_visible_width;
189         *height = (int64_t)source->i_visible_height * source->i_sar_den * cfg->display.sar.num / source->i_sar_num / cfg->display.sar.den;
190     }
191
192     *width  = *width  * cfg->zoom.num / cfg->zoom.den;
193     *height = *height * cfg->zoom.num / cfg->zoom.den;
194 }
195
196 /* */
197 void vout_display_PlacePicture(vout_display_place_t *place,
198                                const video_format_t *source,
199                                const vout_display_cfg_t *cfg,
200                                bool do_clipping)
201 {
202     /* */
203     memset(place, 0, sizeof(*place));
204     if (cfg->display.width <= 0 || cfg->display.height <= 0)
205         return;
206
207     /* */
208     unsigned width;
209     unsigned height;
210     unsigned display_width;
211     unsigned display_height;
212
213     if (cfg->is_display_filled) {
214         width  = source->i_visible_width;
215         height = source->i_visible_height;
216         display_width  = cfg->display.width;
217         display_height = cfg->display.height;
218     } else {
219         vout_display_cfg_t cfg_tmp = *cfg;
220
221         cfg_tmp.display.width  = 0;
222         cfg_tmp.display.height = 0;
223         vout_display_GetDefaultDisplaySize(&width, &height,
224                                            source, &cfg_tmp);
225
226         display_width  = width;
227         display_height = height;
228         if (do_clipping) {
229             display_width  = __MIN(display_width,  cfg->display.width);
230             display_height = __MIN(display_height, cfg->display.height);
231         }
232     }
233
234     /* Compute the height if we use the width to fill up display_width */
235     const int64_t scaled_height = (int64_t)height * display_width  * cfg->display.sar.num * source->i_sar_den / width  / source->i_sar_num / cfg->display.sar.den;
236     /* And the same but switching width/height */
237     const int64_t scaled_width  = (int64_t)width  * display_height * cfg->display.sar.den * source->i_sar_num / height / source->i_sar_den / cfg->display.sar.num;
238
239     /* We keep the solution that avoid filling outside the display */
240     if (scaled_width <= cfg->display.width) {
241         place->width  = scaled_width;
242         place->height = display_height;
243     } else {
244         place->width  = display_width;
245         place->height = scaled_height;
246     }
247
248     /*  Compute position */
249     switch (cfg->align.horizontal) {
250     case VOUT_DISPLAY_ALIGN_LEFT:
251         place->x = 0;
252         break;
253     case VOUT_DISPLAY_ALIGN_RIGHT:
254         place->x = cfg->display.width - place->width;
255         break;
256     default:
257         place->x = (cfg->display.width - place->width) / 2;
258         break;
259     }
260
261     switch (cfg->align.vertical) {
262     case VOUT_DISPLAY_ALIGN_TOP:
263         place->y = 0;
264         break;
265     case VOUT_DISPLAY_ALIGN_BOTTOM:
266         place->y = cfg->display.height - place->height;
267         break;
268     default:
269         place->y = (cfg->display.height - place->height) / 2;
270         break;
271     }
272 }
273
274 struct vout_display_owner_sys_t {
275     vout_thread_t   *vout;
276     bool            is_wrapper;  /* Is the current display a wrapper */
277     vout_display_t  *wrapper; /* Vout display wrapper */
278
279     /* */
280     vout_display_cfg_t cfg;
281     bool     is_on_top_initial;
282     struct {
283         unsigned num;
284         unsigned den;
285     } sar_initial;
286
287     /* */
288     int  width_saved;
289     int  height_saved;
290
291     struct {
292         unsigned num;
293         unsigned den;
294     } crop_saved;
295
296     /* */
297     bool ch_display_filled;
298     bool is_display_filled;
299
300     bool ch_zoom;
301     struct {
302         int  num;
303         int  den;
304     } zoom;
305
306     bool ch_on_top;
307     bool is_on_top;
308
309     bool ch_sar;
310     struct {
311         unsigned num;
312         unsigned den;
313     } sar;
314
315     bool ch_crop;
316     struct {
317         unsigned x;
318         unsigned y;
319         unsigned width;
320         unsigned height;
321         unsigned num;
322         unsigned den;
323     } crop;
324
325     /* */
326     video_format_t source;
327     filter_chain_t *filters;
328
329     /* Lock protecting the variables used by
330      * VoutDisplayEvent(ie vout_display_SendEvent) */
331     vlc_mutex_t lock;
332
333     /* mouse state */
334     struct {
335         vlc_mouse_t state;
336
337         mtime_t last_pressed;
338         mtime_t last_moved;
339         bool    is_hidden;
340         bool    ch_activity;
341
342         /* */
343         mtime_t double_click_timeout;
344         mtime_t hide_timeout;
345     } mouse;
346
347     bool reset_pictures;
348
349     bool ch_fullscreen;
350     bool is_fullscreen;
351
352     bool ch_display_size;
353     int  display_width;
354     int  display_height;
355     bool display_is_fullscreen;
356     bool display_is_forced;
357 };
358
359 static void VoutDisplayCreateRender(vout_display_t *vd)
360 {
361     vout_display_owner_sys_t *osys = vd->owner.sys;
362
363     osys->filters = NULL;
364
365     video_format_t v_src = vd->source;
366     v_src.i_aspect  = 0;
367     v_src.i_sar_num = 0;
368     v_src.i_sar_den = 0;
369
370     video_format_t v_dst = vd->fmt;
371     v_dst.i_aspect  = 0;
372     v_dst.i_sar_num = 0;
373     v_dst.i_sar_den = 0;
374
375     video_format_t v_dst_cmp = v_dst;
376     if ((v_src.i_chroma == VLC_CODEC_J420 && v_dst.i_chroma == VLC_CODEC_I420) ||
377         (v_src.i_chroma == VLC_CODEC_J422 && v_dst.i_chroma == VLC_CODEC_I422) ||
378         (v_src.i_chroma == VLC_CODEC_J440 && v_dst.i_chroma == VLC_CODEC_I440) ||
379         (v_src.i_chroma == VLC_CODEC_J444 && v_dst.i_chroma == VLC_CODEC_I444))
380         v_dst_cmp.i_chroma = v_src.i_chroma;
381
382     const bool convert = memcmp(&v_src, &v_dst_cmp, sizeof(v_src)) != 0;
383     if (!convert)
384         return;
385
386     msg_Err(vd, "A filter to adapt decoder to display is needed");
387
388     osys->filters = filter_chain_New(vd, "video filter2", false,
389                                      FilterAllocationInit,
390                                      FilterAllocationClean, vd);
391     assert(osys->filters); /* TODO critical */
392
393     /* */
394     es_format_t src;
395     es_format_InitFromVideo(&src, &v_src);
396
397     /* */
398     es_format_t dst;
399
400     filter_t *filter;
401     for (int i = 0; i < 1 + (v_dst_cmp.i_chroma != v_dst.i_chroma); i++) {
402
403         es_format_InitFromVideo(&dst, i == 0 ? &v_dst : &v_dst_cmp);
404
405         filter_chain_Reset(osys->filters, &src, &dst);
406         filter = filter_chain_AppendFilter(osys->filters,
407                                            NULL, NULL, &src, &dst);
408         if (filter)
409             break;
410     }
411     if (!filter)
412     {
413         msg_Err(vd, "VoutDisplayCreateRender FAILED");
414         /* TODO */
415         assert(0);
416     }
417 }
418
419 static void VoutDisplayDestroyRender(vout_display_t *vd)
420 {
421     vout_display_owner_sys_t *osys = vd->owner.sys;
422
423     if (osys->filters)
424         filter_chain_Delete(osys->filters);
425 }
426
427 static void VoutDisplayResetRender(vout_display_t *vd)
428 {
429     VoutDisplayDestroyRender(vd);
430     VoutDisplayCreateRender(vd);
431 }
432 static void VoutDisplayEventMouse(vout_display_t *vd, int event, va_list args)
433 {
434     vout_display_owner_sys_t *osys = vd->owner.sys;
435
436     vlc_mutex_lock(&osys->lock);
437
438     /* */
439     vlc_mouse_t m = osys->mouse.state;
440     bool is_ignored = false;
441
442     switch (event) {
443     case VOUT_DISPLAY_EVENT_MOUSE_STATE: {
444         const int x = (int)va_arg(args, int);
445         const int y = (int)va_arg(args, int);
446         const int button_mask = (int)va_arg(args, int);
447
448         vlc_mouse_Init(&m);
449         m.i_x = x;
450         m.i_y = y;
451         m.i_pressed = button_mask;
452         break;
453     }
454     case VOUT_DISPLAY_EVENT_MOUSE_MOVED: {
455         const int x = (int)va_arg(args, int);
456         const int y = (int)va_arg(args, int);
457         if (x != osys->mouse.state.i_x || y != osys->mouse.state.i_y) {
458             //msg_Dbg(vd, "VoutDisplayEvent 'mouse' @%d,%d", x, y);
459
460             m.i_x = x;
461             m.i_y = y;
462             m.b_double_click = false;
463         } else {
464             is_ignored = true;
465         }
466         break;
467     }
468     case VOUT_DISPLAY_EVENT_MOUSE_PRESSED:
469     case VOUT_DISPLAY_EVENT_MOUSE_RELEASED: {
470         const int button = (int)va_arg(args, int);
471         const int button_mask = 1 << button;
472
473         /* Ignore inconsistent event */
474         if ((event == VOUT_DISPLAY_EVENT_MOUSE_PRESSED  &&  (osys->mouse.state.i_pressed & button_mask)) ||
475             (event == VOUT_DISPLAY_EVENT_MOUSE_RELEASED && !(osys->mouse.state.i_pressed & button_mask))) {
476             is_ignored = true;
477             break;
478         }
479
480         /* */
481         msg_Dbg(vd, "VoutDisplayEvent 'mouse button' %d t=%d", button, event);
482
483         m.b_double_click = false;
484         if (event == VOUT_DISPLAY_EVENT_MOUSE_PRESSED)
485             m.i_pressed |= button_mask;
486         else
487             m.i_pressed &= ~button_mask;
488         break;
489     }
490     case VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK:
491         msg_Dbg(vd, "VoutDisplayEvent 'double click'");
492
493         m.b_double_click = true;
494         break;
495     default:
496         assert(0);
497     }
498
499     if (is_ignored) {
500         vlc_mutex_unlock(&osys->lock);
501         return;
502     }
503
504     /* Emulate double-click if needed */
505     if (!vd->info.has_double_click &&
506         vlc_mouse_HasPressed(&osys->mouse.state, &m, MOUSE_BUTTON_LEFT)) {
507         const mtime_t i_date = mdate();
508
509         if (i_date - osys->mouse.last_pressed < osys->mouse.double_click_timeout ) {
510             m.b_double_click = true;
511             osys->mouse.last_pressed = 0;
512         } else {
513             osys->mouse.last_pressed = mdate();
514         }
515     }
516
517     /* */
518     osys->mouse.state = m;
519
520     /* */
521     osys->mouse.ch_activity = true;
522     if (!vd->info.has_hide_mouse)
523         osys->mouse.last_moved = mdate();
524
525     /* */
526     vlc_mutex_unlock(&osys->lock);
527
528     /* */
529     vout_SendEventMouseVisible(osys->vout);
530     vout_SendDisplayEventMouse(osys->vout, &m);
531 }
532
533 static void VoutDisplayEvent(vout_display_t *vd, int event, va_list args)
534 {
535     vout_display_owner_sys_t *osys = vd->owner.sys;
536
537     switch (event) {
538     case VOUT_DISPLAY_EVENT_CLOSE: {
539         msg_Dbg(vd, "VoutDisplayEvent 'close'");
540         vout_SendEventClose(osys->vout);
541         break;
542     }
543     case VOUT_DISPLAY_EVENT_KEY: {
544         const int key = (int)va_arg(args, int);
545         msg_Dbg(vd, "VoutDisplayEvent 'key' 0x%2.2x", key);
546         vout_SendEventKey(osys->vout, key);
547         break;
548     }
549     case VOUT_DISPLAY_EVENT_MOUSE_STATE:
550     case VOUT_DISPLAY_EVENT_MOUSE_MOVED:
551     case VOUT_DISPLAY_EVENT_MOUSE_PRESSED:
552     case VOUT_DISPLAY_EVENT_MOUSE_RELEASED:
553     case VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK:
554         VoutDisplayEventMouse(vd, event, args);
555         break;
556
557     case VOUT_DISPLAY_EVENT_FULLSCREEN: {
558         const int is_fullscreen = (int)va_arg(args, int);
559
560         msg_Dbg(vd, "VoutDisplayEvent 'fullscreen' %d", is_fullscreen);
561
562         vlc_mutex_lock(&osys->lock);
563         if (!is_fullscreen != !osys->is_fullscreen) {
564             osys->ch_fullscreen = true;
565             osys->is_fullscreen = is_fullscreen;
566         }
567         vlc_mutex_unlock(&osys->lock);
568         break;
569     }
570
571     case VOUT_DISPLAY_EVENT_ON_TOP: {
572         const int is_on_top = (int)va_arg(args, int);
573
574         msg_Dbg(vd, "VoutDisplayEvent 'on top' %d", is_on_top);
575
576         vlc_mutex_lock(&osys->lock);
577         if (!is_on_top != !osys->is_on_top) {
578             osys->ch_on_top = true;
579             osys->is_on_top = is_on_top;
580         }
581         vlc_mutex_unlock(&osys->lock);
582         break;
583     }
584
585     case VOUT_DISPLAY_EVENT_DISPLAY_SIZE: {
586         const int width  = (int)va_arg(args, int);
587         const int height = (int)va_arg(args, int);
588         const bool is_fullscreen = (bool)va_arg(args, int);
589         msg_Dbg(vd, "VoutDisplayEvent 'resize' %dx%d %s",
590                 width, height, is_fullscreen ? "fullscreen" : "window");
591
592         /* */
593         vlc_mutex_lock(&osys->lock);
594
595         osys->ch_display_size       = true;
596         osys->display_width         = width;
597         osys->display_height        = height;
598         osys->display_is_fullscreen = is_fullscreen;
599         osys->display_is_forced     = false;
600
601         vlc_mutex_unlock(&osys->lock);
602         break;
603     }
604
605     case VOUT_DISPLAY_EVENT_PICTURES_INVALID: {
606         msg_Warn(vd, "VoutDisplayEvent 'pictures invalid'");
607
608         /* */
609         assert(vd->info.has_pictures_invalid);
610
611         vlc_mutex_lock(&osys->lock);
612         osys->reset_pictures = true;
613         vlc_mutex_unlock(&osys->lock);
614         break;
615     }
616     default:
617         msg_Err(vd, "VoutDisplayEvent received event %d", event);
618         /* TODO add an assert when all event are handled */
619         break;
620     }
621 }
622
623 static vout_window_t *VoutDisplayNewWindow(vout_display_t *vd, const vout_window_cfg_t *cfg)
624 {
625     vout_display_owner_sys_t *osys = vd->owner.sys;
626
627     return vout_NewDisplayWindow(osys->vout, vd, cfg);
628 }
629 static void VoutDisplayDelWindow(vout_display_t *vd, vout_window_t *window)
630 {
631     vout_display_owner_sys_t *osys = vd->owner.sys;
632
633     vout_DeleteDisplayWindow(osys->vout, vd, window);
634 }
635
636 void vout_ManageDisplay(vout_display_t *vd)
637 {
638     vout_display_owner_sys_t *osys = vd->owner.sys;
639
640     vout_display_Manage(vd);
641
642     /* Handle mouse timeout */
643     const mtime_t date = mdate();
644     bool  hide_mouse = false;
645
646     vlc_mutex_lock(&osys->lock);
647
648     if (!osys->mouse.is_hidden &&
649         osys->mouse.last_moved + osys->mouse.hide_timeout < date) {
650         osys->mouse.is_hidden = hide_mouse = true;
651     } else if (osys->mouse.ch_activity) {
652         osys->mouse.is_hidden = false;
653     }
654     osys->mouse.ch_activity = false;
655     vlc_mutex_unlock(&osys->lock);
656
657     if (hide_mouse) {
658         if (!vd->info.has_hide_mouse) {
659             msg_Dbg(vd, "auto hidding mouse");
660             vout_display_Control(vd, VOUT_DISPLAY_HIDE_MOUSE);
661         }
662         vout_SendEventMouseHidden(osys->vout);
663     }
664
665     bool reset_render = false;
666     for (;;) {
667
668         vlc_mutex_lock(&osys->lock);
669
670         bool ch_fullscreen  = osys->ch_fullscreen;
671         bool is_fullscreen  = osys->is_fullscreen;
672         osys->ch_fullscreen = false;
673
674         bool ch_on_top  = osys->ch_on_top;
675         bool is_on_top  = osys->is_on_top;
676         osys->ch_on_top = false;
677
678         bool ch_display_size       = osys->ch_display_size;
679         int  display_width         = osys->display_width;
680         int  display_height        = osys->display_height;
681         bool display_is_fullscreen = osys->display_is_fullscreen;
682         bool display_is_forced     = osys->display_is_forced;
683         osys->ch_display_size = false;
684
685         bool reset_pictures = osys->reset_pictures;
686         osys->reset_pictures = false;
687
688         vlc_mutex_unlock(&osys->lock);
689
690         if (!ch_fullscreen &&
691             !ch_display_size &&
692             !reset_pictures &&
693             !osys->ch_display_filled &&
694             !osys->ch_zoom &&
695             !ch_on_top &&
696             !osys->ch_sar &&
697             !osys->ch_crop)
698             break;
699
700         /* */
701         if (ch_fullscreen) {
702             vout_display_cfg_t cfg = osys->cfg;
703
704             cfg.is_fullscreen  = is_fullscreen;
705             cfg.display.width  = cfg.is_fullscreen ? 0 : osys->width_saved;
706             cfg.display.height = cfg.is_fullscreen ? 0 : osys->height_saved;
707
708             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_FULLSCREEN, &cfg)) {
709                 msg_Err(vd, "Failed to set fullscreen");
710                 is_fullscreen = osys->cfg.is_fullscreen;
711             }
712             osys->cfg.is_fullscreen = is_fullscreen;
713
714             /* */
715             vout_SendEventFullscreen(osys->vout, osys->cfg.is_fullscreen);
716         }
717
718         /* */
719         if (ch_display_size) {
720             vout_display_cfg_t cfg = osys->cfg;
721             cfg.display.width  = display_width;
722             cfg.display.height = display_height;
723
724             if (!cfg.is_fullscreen != !display_is_fullscreen ||
725                 vout_display_Control(vd, VOUT_DISPLAY_CHANGE_DISPLAY_SIZE, &cfg, display_is_forced)) {
726                 if (!cfg.is_fullscreen == !display_is_fullscreen)
727                     msg_Err(vd, "Failed to resize display");
728
729                 /* We ignore the resized */
730                 display_width  = osys->cfg.display.width;
731                 display_height = osys->cfg.display.height;
732             }
733             osys->cfg.display.width  = display_width;
734             osys->cfg.display.height = display_height;
735
736             if (!display_is_fullscreen) {
737                 osys->width_saved  = display_width;
738                 osys->height_saved = display_height;
739             }
740         }
741         /* */
742         if (osys->ch_display_filled) {
743             vout_display_cfg_t cfg = osys->cfg;
744
745             cfg.is_display_filled = osys->is_display_filled;
746
747             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, &cfg)) {
748                 msg_Err(vd, "Failed to change display filled state");
749                 osys->is_display_filled = osys->cfg.is_display_filled;
750             }
751             osys->cfg.is_display_filled = osys->is_display_filled;
752             osys->ch_display_filled = false;
753
754             vout_SendEventDisplayFilled(osys->vout, osys->cfg.is_display_filled);
755         }
756         /* */
757         if (osys->ch_zoom) {
758             vout_display_cfg_t cfg = osys->cfg;
759
760             cfg.zoom.num = osys->zoom.num;
761             cfg.zoom.den = osys->zoom.den;
762
763             if (10 * cfg.zoom.num <= cfg.zoom.den) {
764                 cfg.zoom.num = 1;
765                 cfg.zoom.den = 10;
766             } else if (cfg.zoom.num >= 10 * cfg.zoom.den) {
767                 cfg.zoom.num = 10;
768                 cfg.zoom.den = 1;
769             }
770
771             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_ZOOM, &cfg)) {
772                 msg_Err(vd, "Failed to change zoom");
773                 osys->zoom.num = osys->cfg.zoom.num;
774                 osys->zoom.den = osys->cfg.zoom.den;
775             } else if (cfg.is_display_filled) {
776                 const int display_width  = (int64_t)vd->source.i_width  * osys->zoom.num / osys->zoom.den;
777                 const int display_height = (int64_t)vd->source.i_height * osys->zoom.num / osys->zoom.den;
778
779                 vlc_mutex_lock(&osys->lock);
780
781                 osys->ch_display_size       = true;
782                 osys->display_width         = display_width;
783                 osys->display_height        = display_height;
784                 osys->display_is_fullscreen = osys->cfg.is_fullscreen;
785                 osys->display_is_forced     = true;
786
787                 vlc_mutex_unlock(&osys->lock);
788             }
789
790             osys->cfg.zoom.num = osys->zoom.num;
791             osys->cfg.zoom.den = osys->zoom.den;
792             osys->ch_zoom = false;
793
794             vout_SendEventZoom(osys->vout, osys->cfg.zoom.num, osys->cfg.zoom.den);
795         }
796         /* */
797         if (ch_on_top) {
798             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_ON_TOP, is_on_top)) {
799                 msg_Err(vd, "Failed to set on top");
800                 is_on_top = osys->is_on_top_initial;
801             }
802             osys->is_on_top_initial = is_on_top;
803
804             /* */
805             vout_SendEventOnTop(osys->vout, osys->is_on_top_initial);
806         }
807         /* */
808         if (osys->ch_sar) {
809             video_format_t source = vd->source;
810
811             if (osys->sar.num > 0 && osys->sar.den > 0) {
812                 source.i_sar_num = osys->sar.num;
813                 source.i_sar_den = osys->sar.den;
814             } else {
815                 source.i_sar_num = osys->source.i_sar_num;
816                 source.i_sar_den = osys->source.i_sar_den;
817             }
818
819             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, &source)) {
820                 /* There nothing much we can do. The only reason a vout display
821                  * does not support it is because it need the core to add black border
822                  * to the video for it.
823                  * TODO add black borders ?
824                  */
825                 msg_Err(vd, "Failed to change source AR");
826                 source = vd->source;
827             }
828             vd->source = source;
829             osys->sar.num = source.i_sar_num;
830             osys->sar.den = source.i_sar_den;
831             osys->ch_sar  = false;
832
833             /* */
834             if (osys->sar.num == osys->source.i_sar_num &&
835                 osys->sar.den == osys->source.i_sar_den)
836             {
837                 vout_SendEventSourceAspect(osys->vout, 0, 0);
838             }
839             else
840             {
841                 unsigned dar_num, dar_den;
842                 vlc_ureduce( &dar_num, &dar_den,
843                              osys->sar.num * vd->source.i_visible_width,
844                              osys->sar.den * vd->source.i_visible_height,
845                              65536);
846                 vout_SendEventSourceAspect(osys->vout, dar_num, dar_den);
847             }
848         }
849         /* */
850         if (osys->ch_crop) {
851             video_format_t source = vd->source;
852             unsigned crop_num = osys->crop.num;
853             unsigned crop_den = osys->crop.den;
854
855             source.i_x_offset       = osys->crop.x;
856             source.i_y_offset       = osys->crop.y;
857             source.i_visible_width  = osys->crop.width;
858             source.i_visible_height = osys->crop.height;
859
860             /* */
861             const bool is_valid = source.i_x_offset < source.i_width &&
862                                   source.i_y_offset < source.i_height &&
863                                   source.i_x_offset + source.i_visible_width  <= source.i_width &&
864                                   source.i_y_offset + source.i_visible_height <= source.i_height &&
865                                   source.i_visible_width > 0 && source.i_visible_height > 0;
866
867             if (!is_valid || vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_CROP, &source)) {
868                 if (is_valid)
869                     msg_Err(vd, "Failed to change source crop TODO implement crop at core");
870                 else
871                     msg_Err(vd, "Invalid crop requested");
872
873                 source = vd->source;
874                 crop_num = osys->crop_saved.num;
875                 crop_den = osys->crop_saved.den;
876                 /* FIXME implement cropping in the core if not supported by the
877                  * vout module (easy)
878                  */
879             }
880             vd->source = source;
881             osys->crop.x      = source.i_x_offset;
882             osys->crop.y      = source.i_y_offset;
883             osys->crop.width  = source.i_visible_width;
884             osys->crop.height = source.i_visible_height;
885             osys->crop.num    = crop_num;
886             osys->crop.den    = crop_den;
887             osys->ch_crop = false;
888
889             /* TODO fix when a ratio is used (complicated). */
890             const unsigned left   = osys->crop.x - osys->source.i_x_offset;
891             const unsigned top    = osys->crop.y - osys->source.i_y_offset;
892             const unsigned right  = osys->source.i_visible_width  - (osys->crop.width  + osys->crop.x);
893             const unsigned bottom = osys->source.i_visible_height - (osys->crop.height + osys->crop.y);
894             vout_SendEventSourceCrop(osys->vout,
895                                      osys->crop.num, osys->crop.den,
896                                      left, top, right, bottom);
897         }
898
899         /* */
900         if (reset_pictures) {
901             if (vout_display_Control(vd, VOUT_DISPLAY_RESET_PICTURES)) {
902                 /* FIXME what to do here ? */
903                 msg_Err(vd, "Failed to reset pictures (probably fatal)");
904             }
905             reset_render = true;
906         }
907     }
908     if (reset_render)
909         VoutDisplayResetRender(vd);
910 }
911
912 bool vout_AreDisplayPicturesInvalid(vout_display_t *vd)
913 {
914     vout_display_owner_sys_t *osys = vd->owner.sys;
915
916     vlc_mutex_lock(&osys->lock);
917     const bool reset_pictures = osys->reset_pictures;
918     vlc_mutex_unlock(&osys->lock);
919
920     return reset_pictures;
921 }
922
923 bool vout_IsDisplayFiltered(vout_display_t *vd)
924 {
925     vout_display_owner_sys_t *osys = vd->owner.sys;
926
927     return osys->filters != NULL;
928 }
929
930 picture_t *vout_FilterDisplay(vout_display_t *vd, picture_t *picture)
931 {
932     vout_display_owner_sys_t *osys = vd->owner.sys;
933
934     assert(osys->filters);
935     return filter_chain_VideoFilter(osys->filters, picture);
936 }
937
938 void vout_SetDisplayFullscreen(vout_display_t *vd, bool is_fullscreen)
939 {
940     vout_display_owner_sys_t *osys = vd->owner.sys;
941
942     vlc_mutex_lock(&osys->lock);
943     if (!osys->is_fullscreen != !is_fullscreen) {
944         osys->ch_fullscreen = true;
945         osys->is_fullscreen = is_fullscreen;
946     }
947     vlc_mutex_unlock(&osys->lock);
948 }
949
950 void vout_SetDisplayFilled(vout_display_t *vd, bool is_filled)
951 {
952     vout_display_owner_sys_t *osys = vd->owner.sys;
953
954     if (!osys->is_display_filled != !is_filled) {
955         osys->ch_display_filled = true;
956         osys->is_display_filled = is_filled;
957     }
958 }
959
960 void vout_SetDisplayZoom(vout_display_t *vd, int num, int den)
961 {
962     vout_display_owner_sys_t *osys = vd->owner.sys;
963
964     if (osys->zoom.num != num || osys->zoom.den != den) {
965         osys->ch_zoom = true;
966         osys->zoom.num = num;
967         osys->zoom.den = den;
968     }
969 }
970 void vout_SetDisplayOnTop(vout_display_t *vd, bool is_on_top)
971 {
972     vout_display_owner_sys_t *osys = vd->owner.sys;
973
974     vlc_mutex_lock(&osys->lock);
975     if (!osys->is_on_top != !is_on_top) {
976         osys->ch_on_top = true;
977         osys->is_on_top = is_on_top;
978     }
979     vlc_mutex_unlock(&osys->lock);
980 }
981 void vout_SetDisplayAspect(vout_display_t *vd, unsigned sar_num, unsigned sar_den)
982 {
983     vout_display_owner_sys_t *osys = vd->owner.sys;
984
985     if (osys->sar.num != sar_num || osys->sar.den != sar_den) {
986         osys->ch_sar = true;
987         osys->sar.num = sar_num;
988         osys->sar.den = sar_den;
989     }
990 }
991 void vout_SetDisplayCrop(vout_display_t *vd,
992                          unsigned crop_num, unsigned crop_den,
993                          unsigned x, unsigned y, unsigned width, unsigned height)
994 {
995     vout_display_owner_sys_t *osys = vd->owner.sys;
996
997     if (osys->crop.x != x || osys->crop.y != y ||
998         osys->crop.width  != width || osys->crop.height != height) {
999
1000         osys->crop.x      = x;
1001         osys->crop.y      = y;
1002         osys->crop.width  = width;
1003         osys->crop.height = height;
1004         osys->crop.num    = crop_num;
1005         osys->crop.den    = crop_den;
1006
1007         osys->ch_crop = true;
1008     }
1009 }
1010
1011
1012 static vout_display_t *DisplayNew(vout_thread_t *vout,
1013                                   const video_format_t *source_org,
1014                                   const vout_display_state_t *state,
1015                                   const char *module,
1016                                   bool is_wrapper, vout_display_t *wrapper,
1017                                   mtime_t double_click_timeout,
1018                                   mtime_t hide_timeout,
1019                                   const vout_display_owner_t *owner_ptr)
1020 {
1021     /* */
1022     vout_display_owner_sys_t *osys = calloc(1, sizeof(*osys));
1023     vout_display_cfg_t *cfg = &osys->cfg;
1024
1025     *cfg = state->cfg;
1026     osys->is_on_top_initial = state->is_on_top;;
1027     osys->sar_initial.num = state->sar.num;
1028     osys->sar_initial.den = state->sar.den;
1029     vout_display_GetDefaultDisplaySize(&cfg->display.width, &cfg->display.height,
1030                                        source_org, cfg);
1031
1032     osys->vout = vout;
1033     osys->is_wrapper = is_wrapper;
1034     osys->wrapper = wrapper;
1035
1036     vlc_mutex_init(&osys->lock);
1037
1038     vlc_mouse_Init(&osys->mouse.state);
1039     osys->mouse.last_moved = mdate();
1040     osys->mouse.double_click_timeout = double_click_timeout;
1041     osys->mouse.hide_timeout = hide_timeout;
1042     osys->is_fullscreen  = cfg->is_fullscreen;
1043     osys->width_saved    =
1044     osys->display_width  = cfg->display.width;
1045     osys->height_saved   =
1046     osys->display_height = cfg->display.height;
1047     osys->is_display_filled = cfg->is_display_filled;
1048     osys->zoom.num = cfg->zoom.num;
1049     osys->zoom.den = cfg->zoom.den;
1050
1051     osys->source = *source_org;
1052
1053     video_format_t source = *source_org;
1054
1055     source.i_x_offset =
1056     osys->crop.x  = 0;
1057     source.i_y_offset =
1058     osys->crop.y  = 0;
1059     source.i_visible_width  =
1060     osys->crop.width    = source.i_width;
1061     source.i_visible_height =
1062     osys->crop.height   = source.i_height;
1063     osys->crop_saved.num = 0;
1064     osys->crop_saved.den = 0;
1065     osys->crop.num = 0;
1066     osys->crop.den = 0;
1067
1068     osys->sar.num = osys->sar_initial.num ? osys->sar_initial.num : source.i_sar_num;
1069     osys->sar.den = osys->sar_initial.den ? osys->sar_initial.den : source.i_sar_den;
1070
1071     vout_display_owner_t owner;
1072     if (owner_ptr) {
1073         owner = *owner_ptr;
1074     } else {
1075         owner.event      = VoutDisplayEvent;
1076         owner.window_new = VoutDisplayNewWindow;
1077         owner.window_del = VoutDisplayDelWindow;
1078     }
1079     owner.sys = osys;
1080
1081     /* */
1082     vout_display_t *p_display = vout_display_New(VLC_OBJECT(vout),
1083                                                  module, !is_wrapper,
1084                                                  &source, cfg, &owner);
1085     if (!p_display) {
1086         free(osys);
1087         return NULL;
1088     }
1089
1090     VoutDisplayCreateRender(p_display);
1091
1092     /* Setup delayed request */
1093     if (osys->sar.num != source_org->i_sar_num ||
1094         osys->sar.den != source_org->i_sar_den)
1095         osys->ch_sar = true;
1096     if (osys->is_on_top)
1097         osys->ch_on_top = true;
1098     if (osys->crop.x      != source_org->i_x_offset ||
1099         osys->crop.y      != source_org->i_y_offset ||
1100         osys->crop.width  != source_org->i_visible_width ||
1101         osys->crop.height != source_org->i_visible_height)
1102         osys->ch_crop = true;
1103
1104     return p_display;
1105 }
1106
1107 void vout_DeleteDisplay(vout_display_t *vd, vout_display_state_t *state)
1108 {
1109     vout_display_owner_sys_t *osys = vd->owner.sys;
1110
1111     if (state) {
1112         if (!osys->is_wrapper )
1113             state->cfg = osys->cfg;
1114         state->is_on_top = osys->is_on_top_initial;
1115         state->sar.num   = osys->sar_initial.num;
1116         state->sar.den   = osys->sar_initial.den;
1117     }
1118
1119     VoutDisplayDestroyRender(vd);
1120     if (osys->is_wrapper)
1121         SplitterClose(vd);
1122     vout_display_Delete(vd);
1123     vlc_mutex_destroy(&osys->lock);
1124     free(osys);
1125 }
1126
1127 /*****************************************************************************
1128  *
1129  *****************************************************************************/
1130 vout_display_t *vout_NewDisplay(vout_thread_t *vout,
1131                                 const video_format_t *source,
1132                                 const vout_display_state_t *state,
1133                                 const char *module,
1134                                 mtime_t double_click_timeout,
1135                                 mtime_t hide_timeout)
1136 {
1137     return DisplayNew(vout, source, state, module, false, NULL,
1138                       double_click_timeout, hide_timeout, NULL);
1139 }
1140
1141 static void SplitterClose(vout_display_t *vd)
1142 {
1143     VLC_UNUSED(vd);
1144     assert(0);
1145 }
1146
1147 #if 0
1148 /*****************************************************************************
1149  *
1150  *****************************************************************************/
1151 struct vout_display_sys_t {
1152     video_splitter_t *splitter;
1153
1154     /* */
1155     int            count;
1156     picture_t      **picture;
1157     vout_display_t **display;
1158 };
1159 struct video_splitter_owner_t {
1160     vout_display_t *wrapper;
1161 };
1162
1163 static vout_window_t *SplitterNewWindow(vout_display_t *vd, const vout_window_cfg_t *cfg_ptr)
1164 {
1165     vout_display_owner_sys_t *osys = vd->owner.sys;
1166
1167     vout_window_cfg_t cfg = *cfg_ptr;
1168     cfg.is_standalone = true;
1169     cfg.x += 0;//output->window.i_x; FIXME
1170     cfg.y += 0;//output->window.i_y;
1171
1172     return vout_NewDisplayWindow(osys->vout, vd, &cfg);
1173 }
1174 static void SplitterDelWindow(vout_display_t *vd, vout_window_t *window)
1175 {
1176     vout_display_owner_sys_t *osys = vd->owner.sys;
1177
1178     vout_DeleteDisplayWindow(osys->vout, vd, window);
1179 }
1180 static void SplitterEvent(vout_display_t *vd, int event, va_list args)
1181 {
1182     vout_display_owner_sys_t *osys = vd->owner.sys;
1183
1184     switch (event) {
1185 #if 0
1186     case VOUT_DISPLAY_EVENT_MOUSE_STATE:
1187     case VOUT_DISPLAY_EVENT_MOUSE_MOVED:
1188     case VOUT_DISPLAY_EVENT_MOUSE_PRESSED:
1189     case VOUT_DISPLAY_EVENT_MOUSE_RELEASED:
1190         /* TODO */
1191         break;
1192 #endif
1193     case VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK:
1194     case VOUT_DISPLAY_EVENT_KEY:
1195     case VOUT_DISPLAY_EVENT_CLOSE:
1196     case VOUT_DISPLAY_EVENT_FULLSCREEN:
1197     case VOUT_DISPLAY_EVENT_DISPLAY_SIZE:
1198     case VOUT_DISPLAY_EVENT_PICTURES_INVALID:
1199         VoutDisplayEvent(vd, event, args);
1200         break;
1201
1202     default:
1203         msg_Err(vd, "SplitterEvent TODO");
1204         break;
1205     }
1206 }
1207
1208 static picture_t *SplitterGet(vout_display_t *vd)
1209 {
1210     /* TODO pool ? */
1211     return picture_NewFromFormat(&vd->fmt);
1212 }
1213 static void SplitterPrepare(vout_display_t *vd, picture_t *picture)
1214 {
1215     vout_display_sys_t *sys = vd->sys;
1216
1217     picture_Hold(picture);
1218
1219     if (video_splitter_Filter(sys->splitter, sys->picture, picture)) {
1220         for (int i = 0; i < sys->count; i++)
1221             sys->picture[i] = NULL;
1222         picture_Release(picture);
1223         return;
1224     }
1225
1226     for (int i = 0; i < sys->count; i++) {
1227         /* */
1228         /* FIXME now vout_FilterDisplay already return a direct buffer FIXME */
1229         sys->picture[i] = vout_FilterDisplay(sys->display[i], sys->picture[i]);
1230         if (!sys->picture[i])
1231             continue;
1232
1233         /* */
1234         picture_t *direct = vout_display_Get(sys->display[i]);
1235         if (!direct) {
1236             msg_Err(vd, "Failed to get a direct buffer");
1237             picture_Release(sys->picture[i]);
1238             sys->picture[i] = NULL;
1239             continue;
1240         }
1241
1242         /* FIXME not always needed (easy when there is a osys->filters) */
1243         picture_Copy(direct, sys->picture[i]);
1244         picture_Release(sys->picture[i]);
1245         sys->picture[i] = direct;
1246
1247         vout_display_Prepare(sys->display[i], sys->picture[i]);
1248     }
1249 }
1250 static void SplitterDisplay(vout_display_t *vd, picture_t *picture)
1251 {
1252     vout_display_sys_t *sys = vd->sys;
1253
1254     for (int i = 0; i < sys->count; i++) {
1255         if (sys->picture[i])
1256             vout_display_Display(sys->display[i], sys->picture[i]);
1257     }
1258     picture_Release(picture);
1259 }
1260 static int SplitterControl(vout_display_t *vd, int query, va_list args)
1261 {
1262     return VLC_EGENERIC;
1263 }
1264 static void SplitterManage(vout_display_t *vd)
1265 {
1266     vout_display_sys_t *sys = vd->sys;
1267
1268     for (int i = 0; i < sys->count; i++)
1269         vout_ManageDisplay(sys->display[i]);
1270 }
1271
1272 static int SplitterPictureNew(video_splitter_t *splitter, picture_t *picture[])
1273 {
1274     vout_display_sys_t *wsys = splitter->p_owner->wrapper->sys;
1275
1276     for (int i = 0; i < wsys->count; i++) {
1277         /* TODO pool ? */
1278         picture[i] = picture_NewFromFormat(&wsys->display[i]->source);
1279         if (!picture[i]) {
1280             for (int j = 0; j < i; j++)
1281                 picture_Release(picture[j]);
1282             return VLC_EGENERIC;
1283         }
1284     }
1285     return VLC_SUCCESS;
1286 }
1287 static void SplitterPictureDel(video_splitter_t *splitter, picture_t *picture[])
1288 {
1289     vout_display_sys_t *wsys = splitter->p_owner->wrapper->sys;
1290
1291     for (int i = 0; i < wsys->count; i++)
1292         picture_Release(picture[i]);
1293 }
1294 static void SplitterClose(vout_display_t *vd)
1295 {
1296     vout_display_sys_t *sys = vd->sys;
1297
1298     /* */
1299     video_splitter_t *splitter = sys->splitter;
1300     free(splitter->p_owner);
1301     video_splitter_Delete(splitter);
1302
1303     /* */
1304     for (int i = 0; i < sys->count; i++)
1305         vout_DeleteDisplay(sys->display[i], NULL);
1306     TAB_CLEAN(sys->count, sys->display);
1307     free(sys->picture);
1308
1309     free(sys);
1310 }
1311
1312 vout_display_t *vout_NewSplitter(vout_thread_t *vout,
1313                                  const video_format_t *source,
1314                                  const vout_display_state_t *state,
1315                                  const char *module,
1316                                  const char *splitter_module,
1317                                  mtime_t double_click_timeout,
1318                                  mtime_t hide_timeout)
1319 {
1320     video_splitter_t *splitter =
1321         video_splitter_New(VLC_OBJECT(vout), splitter_module, source);
1322     if (!splitter)
1323         return NULL;
1324
1325     /* */
1326     vout_display_t *wrapper =
1327         DisplayNew(vout, source, state, module, true, NULL,
1328                     double_click_timeout, hide_timeout, NULL);
1329     if (!wrapper) {
1330         video_splitter_Delete(splitter);
1331         return NULL;
1332     }
1333     vout_display_sys_t *sys = malloc(sizeof(*sys));
1334     if (!sys)
1335         abort();
1336     sys->picture = calloc(splitter->i_output, sizeof(*sys->picture));
1337     if (!sys->picture )
1338         abort();
1339     sys->splitter = splitter;
1340
1341     wrapper->get     = SplitterGet;
1342     wrapper->prepare = SplitterPrepare;
1343     wrapper->display = SplitterDisplay;
1344     wrapper->control = SplitterControl;
1345     wrapper->manage  = SplitterManage;
1346     wrapper->sys     = sys;
1347
1348     /* */
1349     video_splitter_owner_t *owner = malloc(sizeof(*owner));
1350     if (!owner)
1351         abort();
1352     owner->wrapper = wrapper;
1353     splitter->p_owner = owner;
1354     splitter->pf_picture_new = SplitterPictureNew;
1355     splitter->pf_picture_del = SplitterPictureDel;
1356
1357     /* */
1358     TAB_INIT(sys->count, sys->display);
1359     for (int i = 0; i < splitter->i_output; i++) {
1360         vout_display_owner_t owner;
1361
1362         owner.event      = SplitterEvent;
1363         owner.window_new = SplitterNewWindow;
1364         owner.window_del = SplitterDelWindow;
1365
1366         const video_splitter_output_t *output = &splitter->p_output[i];
1367         vout_display_state_t ostate;
1368
1369         memset(&ostate, 0, sizeof(ostate));
1370         ostate.cfg.is_fullscreen = false;
1371         ostate.cfg.display = state->cfg.display;
1372         ostate.cfg.align.horizontal = 0; /* TODO */
1373         ostate.cfg.align.vertical = 0; /* TODO */
1374         ostate.cfg.is_display_filled = true;
1375         ostate.cfg.zoom.num = 1;
1376         ostate.cfg.zoom.den = 1;
1377
1378         vout_display_t *vd = DisplayNew(vout, &output->fmt, &ostate,
1379                                            output->psz_module ? output->psz_module : module,
1380                                            false, wrapper,
1381                                            double_click_timeout, hide_timeout, &owner);
1382         if (!vd) {
1383             vout_DeleteDisplay(wrapper, NULL);
1384             return NULL;
1385         }
1386         TAB_APPEND(sys->count, sys->display, vd);
1387     }
1388
1389     return wrapper;
1390 }
1391 #endif
1392
1393 /*****************************************************************************
1394  * TODO move out
1395  *****************************************************************************/
1396 #include "vout_internal.h"
1397 void vout_SendDisplayEventMouse(vout_thread_t *vout, const vlc_mouse_t *m)
1398 {
1399     if (vlc_mouse_HasMoved(&vout->p->mouse, m)) {
1400         vout_SendEventMouseMoved(vout, m->i_x, m->i_y);
1401     }
1402     if (vlc_mouse_HasButton(&vout->p->mouse, m)) {
1403         static const int buttons[] = {
1404             MOUSE_BUTTON_LEFT,
1405             MOUSE_BUTTON_CENTER,
1406             MOUSE_BUTTON_RIGHT,
1407             MOUSE_BUTTON_WHEEL_UP,
1408             MOUSE_BUTTON_WHEEL_DOWN,
1409             -1
1410         };
1411         for (int i = 0; buttons[i] >= 0; i++) {
1412             const int button = buttons[i];
1413             if (vlc_mouse_HasPressed(&vout->p->mouse, m, button))
1414                 vout_SendEventMousePressed(vout, button);
1415             else if (vlc_mouse_HasReleased(&vout->p->mouse, m, button))
1416                 vout_SendEventMouseReleased(vout, button);
1417         }
1418     }
1419     if (m->b_double_click)
1420         vout_SendEventMouseDoubleClick(vout);
1421     vout->p->mouse = *m;
1422 }
1423 vout_window_t * vout_NewDisplayWindow(vout_thread_t *vout, vout_display_t *vd, const vout_window_cfg_t *cfg)
1424 {
1425     VLC_UNUSED(vd);
1426     vout_window_cfg_t cfg_override = *cfg;
1427
1428     if( !config_GetInt( vout, "embedded-video" ) )
1429         cfg_override.is_standalone = true;
1430
1431     return vout_window_New(VLC_OBJECT(vout), NULL, &cfg_override);
1432 }
1433 void vout_DeleteDisplayWindow(vout_thread_t *vout, vout_display_t *vd, vout_window_t *window)
1434 {
1435     VLC_UNUSED(vout);
1436     VLC_UNUSED(vd);
1437     vout_window_Delete(window);
1438 }
1439