Added a way to retreive an opengl context from a 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, bool allow_reset_pictures)
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;
686         if (allow_reset_pictures) {
687             reset_pictures = osys->reset_pictures;
688             osys->reset_pictures = false;
689         } else {
690             reset_pictures = false;
691         }
692
693         vlc_mutex_unlock(&osys->lock);
694
695         if (!ch_fullscreen &&
696             !ch_display_size &&
697             !reset_pictures &&
698             !osys->ch_display_filled &&
699             !osys->ch_zoom &&
700             !ch_on_top &&
701             !osys->ch_sar &&
702             !osys->ch_crop)
703             break;
704
705         /* */
706         if (ch_fullscreen) {
707             vout_display_cfg_t cfg = osys->cfg;
708
709             cfg.is_fullscreen  = is_fullscreen;
710             cfg.display.width  = cfg.is_fullscreen ? 0 : osys->width_saved;
711             cfg.display.height = cfg.is_fullscreen ? 0 : osys->height_saved;
712
713             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_FULLSCREEN, &cfg)) {
714                 msg_Err(vd, "Failed to set fullscreen");
715                 is_fullscreen = osys->cfg.is_fullscreen;
716             }
717             osys->cfg.is_fullscreen = is_fullscreen;
718
719             /* */
720             vout_SendEventFullscreen(osys->vout, osys->cfg.is_fullscreen);
721         }
722
723         /* */
724         if (ch_display_size) {
725             vout_display_cfg_t cfg = osys->cfg;
726             cfg.display.width  = display_width;
727             cfg.display.height = display_height;
728
729             if (!cfg.is_fullscreen != !display_is_fullscreen ||
730                 vout_display_Control(vd, VOUT_DISPLAY_CHANGE_DISPLAY_SIZE, &cfg, display_is_forced)) {
731                 if (!cfg.is_fullscreen == !display_is_fullscreen)
732                     msg_Err(vd, "Failed to resize display");
733
734                 /* We ignore the resized */
735                 display_width  = osys->cfg.display.width;
736                 display_height = osys->cfg.display.height;
737             }
738             osys->cfg.display.width  = display_width;
739             osys->cfg.display.height = display_height;
740
741             if (!display_is_fullscreen) {
742                 osys->width_saved  = display_width;
743                 osys->height_saved = display_height;
744             }
745         }
746         /* */
747         if (osys->ch_display_filled) {
748             vout_display_cfg_t cfg = osys->cfg;
749
750             cfg.is_display_filled = osys->is_display_filled;
751
752             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, &cfg)) {
753                 msg_Err(vd, "Failed to change display filled state");
754                 osys->is_display_filled = osys->cfg.is_display_filled;
755             }
756             osys->cfg.is_display_filled = osys->is_display_filled;
757             osys->ch_display_filled = false;
758
759             vout_SendEventDisplayFilled(osys->vout, osys->cfg.is_display_filled);
760         }
761         /* */
762         if (osys->ch_zoom) {
763             vout_display_cfg_t cfg = osys->cfg;
764
765             cfg.zoom.num = osys->zoom.num;
766             cfg.zoom.den = osys->zoom.den;
767
768             if (10 * cfg.zoom.num <= cfg.zoom.den) {
769                 cfg.zoom.num = 1;
770                 cfg.zoom.den = 10;
771             } else if (cfg.zoom.num >= 10 * cfg.zoom.den) {
772                 cfg.zoom.num = 10;
773                 cfg.zoom.den = 1;
774             }
775
776             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_ZOOM, &cfg)) {
777                 msg_Err(vd, "Failed to change zoom");
778                 osys->zoom.num = osys->cfg.zoom.num;
779                 osys->zoom.den = osys->cfg.zoom.den;
780             } else if (cfg.is_display_filled) {
781                 const int display_width  = (int64_t)vd->source.i_width  * osys->zoom.num / osys->zoom.den;
782                 const int display_height = (int64_t)vd->source.i_height * osys->zoom.num / osys->zoom.den;
783
784                 vlc_mutex_lock(&osys->lock);
785
786                 osys->ch_display_size       = true;
787                 osys->display_width         = display_width;
788                 osys->display_height        = display_height;
789                 osys->display_is_fullscreen = osys->cfg.is_fullscreen;
790                 osys->display_is_forced     = true;
791
792                 vlc_mutex_unlock(&osys->lock);
793             }
794
795             osys->cfg.zoom.num = osys->zoom.num;
796             osys->cfg.zoom.den = osys->zoom.den;
797             osys->ch_zoom = false;
798
799             vout_SendEventZoom(osys->vout, osys->cfg.zoom.num, osys->cfg.zoom.den);
800         }
801         /* */
802         if (ch_on_top) {
803             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_ON_TOP, is_on_top)) {
804                 msg_Err(vd, "Failed to set on top");
805                 is_on_top = osys->is_on_top_initial;
806             }
807             osys->is_on_top_initial = is_on_top;
808
809             /* */
810             vout_SendEventOnTop(osys->vout, osys->is_on_top_initial);
811         }
812         /* */
813         if (osys->ch_sar) {
814             video_format_t source = vd->source;
815
816             if (osys->sar.num > 0 && osys->sar.den > 0) {
817                 source.i_sar_num = osys->sar.num;
818                 source.i_sar_den = osys->sar.den;
819             } else {
820                 source.i_sar_num = osys->source.i_sar_num;
821                 source.i_sar_den = osys->source.i_sar_den;
822             }
823
824             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, &source)) {
825                 /* There nothing much we can do. The only reason a vout display
826                  * does not support it is because it need the core to add black border
827                  * to the video for it.
828                  * TODO add black borders ?
829                  */
830                 msg_Err(vd, "Failed to change source AR");
831                 source = vd->source;
832             }
833             vd->source = source;
834             osys->sar.num = source.i_sar_num;
835             osys->sar.den = source.i_sar_den;
836             osys->ch_sar  = false;
837
838             /* */
839             if (osys->sar.num == osys->source.i_sar_num &&
840                 osys->sar.den == osys->source.i_sar_den)
841             {
842                 vout_SendEventSourceAspect(osys->vout, 0, 0);
843             }
844             else
845             {
846                 unsigned dar_num, dar_den;
847                 vlc_ureduce( &dar_num, &dar_den,
848                              osys->sar.num * vd->source.i_visible_width,
849                              osys->sar.den * vd->source.i_visible_height,
850                              65536);
851                 vout_SendEventSourceAspect(osys->vout, dar_num, dar_den);
852             }
853         }
854         /* */
855         if (osys->ch_crop) {
856             video_format_t source = vd->source;
857             unsigned crop_num = osys->crop.num;
858             unsigned crop_den = osys->crop.den;
859
860             source.i_x_offset       = osys->crop.x;
861             source.i_y_offset       = osys->crop.y;
862             source.i_visible_width  = osys->crop.width;
863             source.i_visible_height = osys->crop.height;
864
865             /* */
866             const bool is_valid = source.i_x_offset < source.i_width &&
867                                   source.i_y_offset < source.i_height &&
868                                   source.i_x_offset + source.i_visible_width  <= source.i_width &&
869                                   source.i_y_offset + source.i_visible_height <= source.i_height &&
870                                   source.i_visible_width > 0 && source.i_visible_height > 0;
871
872             if (!is_valid || vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_CROP, &source)) {
873                 if (is_valid)
874                     msg_Err(vd, "Failed to change source crop TODO implement crop at core");
875                 else
876                     msg_Err(vd, "Invalid crop requested");
877
878                 source = vd->source;
879                 crop_num = osys->crop_saved.num;
880                 crop_den = osys->crop_saved.den;
881                 /* FIXME implement cropping in the core if not supported by the
882                  * vout module (easy)
883                  */
884             }
885             vd->source = source;
886             osys->crop.x      = source.i_x_offset;
887             osys->crop.y      = source.i_y_offset;
888             osys->crop.width  = source.i_visible_width;
889             osys->crop.height = source.i_visible_height;
890             osys->crop.num    = crop_num;
891             osys->crop.den    = crop_den;
892             osys->ch_crop = false;
893
894             /* TODO fix when a ratio is used (complicated). */
895             const unsigned left   = osys->crop.x - osys->source.i_x_offset;
896             const unsigned top    = osys->crop.y - osys->source.i_y_offset;
897             const unsigned right  = osys->source.i_visible_width  - (osys->crop.width  + osys->crop.x);
898             const unsigned bottom = osys->source.i_visible_height - (osys->crop.height + osys->crop.y);
899             vout_SendEventSourceCrop(osys->vout,
900                                      osys->crop.num, osys->crop.den,
901                                      left, top, right, bottom);
902         }
903
904         /* */
905         if (reset_pictures) {
906             if (vout_display_Control(vd, VOUT_DISPLAY_RESET_PICTURES)) {
907                 /* FIXME what to do here ? */
908                 msg_Err(vd, "Failed to reset pictures (probably fatal)");
909             }
910             reset_render = true;
911         }
912     }
913     if (reset_render)
914         VoutDisplayResetRender(vd);
915 }
916
917 bool vout_AreDisplayPicturesInvalid(vout_display_t *vd)
918 {
919     vout_display_owner_sys_t *osys = vd->owner.sys;
920
921     vlc_mutex_lock(&osys->lock);
922     const bool reset_pictures = osys->reset_pictures;
923     vlc_mutex_unlock(&osys->lock);
924
925     return reset_pictures;
926 }
927
928 bool vout_IsDisplayFiltered(vout_display_t *vd)
929 {
930     vout_display_owner_sys_t *osys = vd->owner.sys;
931
932     return osys->filters != NULL;
933 }
934
935 picture_t *vout_FilterDisplay(vout_display_t *vd, picture_t *picture)
936 {
937     vout_display_owner_sys_t *osys = vd->owner.sys;
938
939     assert(osys->filters);
940     return filter_chain_VideoFilter(osys->filters, picture);
941 }
942
943 void vout_SetDisplayFullscreen(vout_display_t *vd, bool is_fullscreen)
944 {
945     vout_display_owner_sys_t *osys = vd->owner.sys;
946
947     vlc_mutex_lock(&osys->lock);
948     if (!osys->is_fullscreen != !is_fullscreen) {
949         osys->ch_fullscreen = true;
950         osys->is_fullscreen = is_fullscreen;
951     }
952     vlc_mutex_unlock(&osys->lock);
953 }
954
955 void vout_SetDisplayFilled(vout_display_t *vd, bool is_filled)
956 {
957     vout_display_owner_sys_t *osys = vd->owner.sys;
958
959     if (!osys->is_display_filled != !is_filled) {
960         osys->ch_display_filled = true;
961         osys->is_display_filled = is_filled;
962     }
963 }
964
965 void vout_SetDisplayZoom(vout_display_t *vd, int num, int den)
966 {
967     vout_display_owner_sys_t *osys = vd->owner.sys;
968
969     if (osys->zoom.num != num || osys->zoom.den != den) {
970         osys->ch_zoom = true;
971         osys->zoom.num = num;
972         osys->zoom.den = den;
973     }
974 }
975 void vout_SetDisplayOnTop(vout_display_t *vd, bool is_on_top)
976 {
977     vout_display_owner_sys_t *osys = vd->owner.sys;
978
979     vlc_mutex_lock(&osys->lock);
980     if (!osys->is_on_top != !is_on_top) {
981         osys->ch_on_top = true;
982         osys->is_on_top = is_on_top;
983     }
984     vlc_mutex_unlock(&osys->lock);
985 }
986 void vout_SetDisplayAspect(vout_display_t *vd, unsigned sar_num, unsigned sar_den)
987 {
988     vout_display_owner_sys_t *osys = vd->owner.sys;
989
990     if (osys->sar.num != sar_num || osys->sar.den != sar_den) {
991         osys->ch_sar = true;
992         osys->sar.num = sar_num;
993         osys->sar.den = sar_den;
994     }
995 }
996 void vout_SetDisplayCrop(vout_display_t *vd,
997                          unsigned crop_num, unsigned crop_den,
998                          unsigned x, unsigned y, unsigned width, unsigned height)
999 {
1000     vout_display_owner_sys_t *osys = vd->owner.sys;
1001
1002     if (osys->crop.x != x || osys->crop.y != y ||
1003         osys->crop.width  != width || osys->crop.height != height) {
1004
1005         osys->crop.x      = x;
1006         osys->crop.y      = y;
1007         osys->crop.width  = width;
1008         osys->crop.height = height;
1009         osys->crop.num    = crop_num;
1010         osys->crop.den    = crop_den;
1011
1012         osys->ch_crop = true;
1013     }
1014 }
1015 vout_opengl_t *vout_GetDisplayOpengl(vout_display_t *vd)
1016 {
1017     vout_opengl_t *gl;
1018     if (vout_display_Control(vd, VOUT_DISPLAY_GET_OPENGL, &gl))
1019         return NULL;
1020     return gl;
1021 }
1022
1023 static vout_display_t *DisplayNew(vout_thread_t *vout,
1024                                   const video_format_t *source_org,
1025                                   const vout_display_state_t *state,
1026                                   const char *module,
1027                                   bool is_wrapper, vout_display_t *wrapper,
1028                                   mtime_t double_click_timeout,
1029                                   mtime_t hide_timeout,
1030                                   const vout_display_owner_t *owner_ptr)
1031 {
1032     /* */
1033     vout_display_owner_sys_t *osys = calloc(1, sizeof(*osys));
1034     vout_display_cfg_t *cfg = &osys->cfg;
1035
1036     *cfg = state->cfg;
1037     osys->is_on_top_initial = state->is_on_top;;
1038     osys->sar_initial.num = state->sar.num;
1039     osys->sar_initial.den = state->sar.den;
1040     vout_display_GetDefaultDisplaySize(&cfg->display.width, &cfg->display.height,
1041                                        source_org, cfg);
1042
1043     osys->vout = vout;
1044     osys->is_wrapper = is_wrapper;
1045     osys->wrapper = wrapper;
1046
1047     vlc_mutex_init(&osys->lock);
1048
1049     vlc_mouse_Init(&osys->mouse.state);
1050     osys->mouse.last_moved = mdate();
1051     osys->mouse.double_click_timeout = double_click_timeout;
1052     osys->mouse.hide_timeout = hide_timeout;
1053     osys->is_fullscreen  = cfg->is_fullscreen;
1054     osys->width_saved    =
1055     osys->display_width  = cfg->display.width;
1056     osys->height_saved   =
1057     osys->display_height = cfg->display.height;
1058     osys->is_display_filled = cfg->is_display_filled;
1059     osys->zoom.num = cfg->zoom.num;
1060     osys->zoom.den = cfg->zoom.den;
1061
1062     osys->source = *source_org;
1063
1064     video_format_t source = *source_org;
1065
1066     source.i_x_offset =
1067     osys->crop.x  = 0;
1068     source.i_y_offset =
1069     osys->crop.y  = 0;
1070     source.i_visible_width  =
1071     osys->crop.width    = source.i_width;
1072     source.i_visible_height =
1073     osys->crop.height   = source.i_height;
1074     osys->crop_saved.num = 0;
1075     osys->crop_saved.den = 0;
1076     osys->crop.num = 0;
1077     osys->crop.den = 0;
1078
1079     osys->sar.num = osys->sar_initial.num ? osys->sar_initial.num : source.i_sar_num;
1080     osys->sar.den = osys->sar_initial.den ? osys->sar_initial.den : source.i_sar_den;
1081
1082     vout_display_owner_t owner;
1083     if (owner_ptr) {
1084         owner = *owner_ptr;
1085     } else {
1086         owner.event      = VoutDisplayEvent;
1087         owner.window_new = VoutDisplayNewWindow;
1088         owner.window_del = VoutDisplayDelWindow;
1089     }
1090     owner.sys = osys;
1091
1092     /* */
1093     vout_display_t *p_display = vout_display_New(VLC_OBJECT(vout),
1094                                                  module, !is_wrapper,
1095                                                  &source, cfg, &owner);
1096     if (!p_display) {
1097         free(osys);
1098         return NULL;
1099     }
1100
1101     VoutDisplayCreateRender(p_display);
1102
1103     /* Setup delayed request */
1104     if (osys->sar.num != source_org->i_sar_num ||
1105         osys->sar.den != source_org->i_sar_den)
1106         osys->ch_sar = true;
1107     if (osys->is_on_top)
1108         osys->ch_on_top = true;
1109     if (osys->crop.x      != source_org->i_x_offset ||
1110         osys->crop.y      != source_org->i_y_offset ||
1111         osys->crop.width  != source_org->i_visible_width ||
1112         osys->crop.height != source_org->i_visible_height)
1113         osys->ch_crop = true;
1114
1115     return p_display;
1116 }
1117
1118 void vout_DeleteDisplay(vout_display_t *vd, vout_display_state_t *state)
1119 {
1120     vout_display_owner_sys_t *osys = vd->owner.sys;
1121
1122     if (state) {
1123         if (!osys->is_wrapper )
1124             state->cfg = osys->cfg;
1125         state->is_on_top = osys->is_on_top_initial;
1126         state->sar.num   = osys->sar_initial.num;
1127         state->sar.den   = osys->sar_initial.den;
1128     }
1129
1130     VoutDisplayDestroyRender(vd);
1131     if (osys->is_wrapper)
1132         SplitterClose(vd);
1133     vout_display_Delete(vd);
1134     vlc_mutex_destroy(&osys->lock);
1135     free(osys);
1136 }
1137
1138 /*****************************************************************************
1139  *
1140  *****************************************************************************/
1141 vout_display_t *vout_NewDisplay(vout_thread_t *vout,
1142                                 const video_format_t *source,
1143                                 const vout_display_state_t *state,
1144                                 const char *module,
1145                                 mtime_t double_click_timeout,
1146                                 mtime_t hide_timeout)
1147 {
1148     return DisplayNew(vout, source, state, module, false, NULL,
1149                       double_click_timeout, hide_timeout, NULL);
1150 }
1151
1152 static void SplitterClose(vout_display_t *vd)
1153 {
1154     VLC_UNUSED(vd);
1155     assert(0);
1156 }
1157
1158 #if 0
1159 /*****************************************************************************
1160  *
1161  *****************************************************************************/
1162 struct vout_display_sys_t {
1163     video_splitter_t *splitter;
1164
1165     /* */
1166     int            count;
1167     picture_t      **picture;
1168     vout_display_t **display;
1169 };
1170 struct video_splitter_owner_t {
1171     vout_display_t *wrapper;
1172 };
1173
1174 static vout_window_t *SplitterNewWindow(vout_display_t *vd, const vout_window_cfg_t *cfg_ptr)
1175 {
1176     vout_display_owner_sys_t *osys = vd->owner.sys;
1177
1178     vout_window_cfg_t cfg = *cfg_ptr;
1179     cfg.is_standalone = true;
1180     cfg.x += 0;//output->window.i_x; FIXME
1181     cfg.y += 0;//output->window.i_y;
1182
1183     return vout_NewDisplayWindow(osys->vout, vd, &cfg);
1184 }
1185 static void SplitterDelWindow(vout_display_t *vd, vout_window_t *window)
1186 {
1187     vout_display_owner_sys_t *osys = vd->owner.sys;
1188
1189     vout_DeleteDisplayWindow(osys->vout, vd, window);
1190 }
1191 static void SplitterEvent(vout_display_t *vd, int event, va_list args)
1192 {
1193     vout_display_owner_sys_t *osys = vd->owner.sys;
1194
1195     switch (event) {
1196 #if 0
1197     case VOUT_DISPLAY_EVENT_MOUSE_STATE:
1198     case VOUT_DISPLAY_EVENT_MOUSE_MOVED:
1199     case VOUT_DISPLAY_EVENT_MOUSE_PRESSED:
1200     case VOUT_DISPLAY_EVENT_MOUSE_RELEASED:
1201         /* TODO */
1202         break;
1203 #endif
1204     case VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK:
1205     case VOUT_DISPLAY_EVENT_KEY:
1206     case VOUT_DISPLAY_EVENT_CLOSE:
1207     case VOUT_DISPLAY_EVENT_FULLSCREEN:
1208     case VOUT_DISPLAY_EVENT_DISPLAY_SIZE:
1209     case VOUT_DISPLAY_EVENT_PICTURES_INVALID:
1210         VoutDisplayEvent(vd, event, args);
1211         break;
1212
1213     default:
1214         msg_Err(vd, "SplitterEvent TODO");
1215         break;
1216     }
1217 }
1218
1219 static picture_t *SplitterGet(vout_display_t *vd)
1220 {
1221     /* TODO pool ? */
1222     return picture_NewFromFormat(&vd->fmt);
1223 }
1224 static void SplitterPrepare(vout_display_t *vd, picture_t *picture)
1225 {
1226     vout_display_sys_t *sys = vd->sys;
1227
1228     picture_Hold(picture);
1229
1230     if (video_splitter_Filter(sys->splitter, sys->picture, picture)) {
1231         for (int i = 0; i < sys->count; i++)
1232             sys->picture[i] = NULL;
1233         picture_Release(picture);
1234         return;
1235     }
1236
1237     for (int i = 0; i < sys->count; i++) {
1238         /* */
1239         /* FIXME now vout_FilterDisplay already return a direct buffer FIXME */
1240         sys->picture[i] = vout_FilterDisplay(sys->display[i], sys->picture[i]);
1241         if (!sys->picture[i])
1242             continue;
1243
1244         /* */
1245         picture_t *direct = vout_display_Get(sys->display[i]);
1246         if (!direct) {
1247             msg_Err(vd, "Failed to get a direct buffer");
1248             picture_Release(sys->picture[i]);
1249             sys->picture[i] = NULL;
1250             continue;
1251         }
1252
1253         /* FIXME not always needed (easy when there is a osys->filters) */
1254         picture_Copy(direct, sys->picture[i]);
1255         picture_Release(sys->picture[i]);
1256         sys->picture[i] = direct;
1257
1258         vout_display_Prepare(sys->display[i], sys->picture[i]);
1259     }
1260 }
1261 static void SplitterDisplay(vout_display_t *vd, picture_t *picture)
1262 {
1263     vout_display_sys_t *sys = vd->sys;
1264
1265     for (int i = 0; i < sys->count; i++) {
1266         if (sys->picture[i])
1267             vout_display_Display(sys->display[i], sys->picture[i]);
1268     }
1269     picture_Release(picture);
1270 }
1271 static int SplitterControl(vout_display_t *vd, int query, va_list args)
1272 {
1273     return VLC_EGENERIC;
1274 }
1275 static void SplitterManage(vout_display_t *vd)
1276 {
1277     vout_display_sys_t *sys = vd->sys;
1278
1279     for (int i = 0; i < sys->count; i++)
1280         vout_ManageDisplay(sys->display[i]);
1281 }
1282
1283 static int SplitterPictureNew(video_splitter_t *splitter, picture_t *picture[])
1284 {
1285     vout_display_sys_t *wsys = splitter->p_owner->wrapper->sys;
1286
1287     for (int i = 0; i < wsys->count; i++) {
1288         /* TODO pool ? */
1289         picture[i] = picture_NewFromFormat(&wsys->display[i]->source);
1290         if (!picture[i]) {
1291             for (int j = 0; j < i; j++)
1292                 picture_Release(picture[j]);
1293             return VLC_EGENERIC;
1294         }
1295     }
1296     return VLC_SUCCESS;
1297 }
1298 static void SplitterPictureDel(video_splitter_t *splitter, picture_t *picture[])
1299 {
1300     vout_display_sys_t *wsys = splitter->p_owner->wrapper->sys;
1301
1302     for (int i = 0; i < wsys->count; i++)
1303         picture_Release(picture[i]);
1304 }
1305 static void SplitterClose(vout_display_t *vd)
1306 {
1307     vout_display_sys_t *sys = vd->sys;
1308
1309     /* */
1310     video_splitter_t *splitter = sys->splitter;
1311     free(splitter->p_owner);
1312     video_splitter_Delete(splitter);
1313
1314     /* */
1315     for (int i = 0; i < sys->count; i++)
1316         vout_DeleteDisplay(sys->display[i], NULL);
1317     TAB_CLEAN(sys->count, sys->display);
1318     free(sys->picture);
1319
1320     free(sys);
1321 }
1322
1323 vout_display_t *vout_NewSplitter(vout_thread_t *vout,
1324                                  const video_format_t *source,
1325                                  const vout_display_state_t *state,
1326                                  const char *module,
1327                                  const char *splitter_module,
1328                                  mtime_t double_click_timeout,
1329                                  mtime_t hide_timeout)
1330 {
1331     video_splitter_t *splitter =
1332         video_splitter_New(VLC_OBJECT(vout), splitter_module, source);
1333     if (!splitter)
1334         return NULL;
1335
1336     /* */
1337     vout_display_t *wrapper =
1338         DisplayNew(vout, source, state, module, true, NULL,
1339                     double_click_timeout, hide_timeout, NULL);
1340     if (!wrapper) {
1341         video_splitter_Delete(splitter);
1342         return NULL;
1343     }
1344     vout_display_sys_t *sys = malloc(sizeof(*sys));
1345     if (!sys)
1346         abort();
1347     sys->picture = calloc(splitter->i_output, sizeof(*sys->picture));
1348     if (!sys->picture )
1349         abort();
1350     sys->splitter = splitter;
1351
1352     wrapper->get     = SplitterGet;
1353     wrapper->prepare = SplitterPrepare;
1354     wrapper->display = SplitterDisplay;
1355     wrapper->control = SplitterControl;
1356     wrapper->manage  = SplitterManage;
1357     wrapper->sys     = sys;
1358
1359     /* */
1360     video_splitter_owner_t *owner = malloc(sizeof(*owner));
1361     if (!owner)
1362         abort();
1363     owner->wrapper = wrapper;
1364     splitter->p_owner = owner;
1365     splitter->pf_picture_new = SplitterPictureNew;
1366     splitter->pf_picture_del = SplitterPictureDel;
1367
1368     /* */
1369     TAB_INIT(sys->count, sys->display);
1370     for (int i = 0; i < splitter->i_output; i++) {
1371         vout_display_owner_t owner;
1372
1373         owner.event      = SplitterEvent;
1374         owner.window_new = SplitterNewWindow;
1375         owner.window_del = SplitterDelWindow;
1376
1377         const video_splitter_output_t *output = &splitter->p_output[i];
1378         vout_display_state_t ostate;
1379
1380         memset(&ostate, 0, sizeof(ostate));
1381         ostate.cfg.is_fullscreen = false;
1382         ostate.cfg.display = state->cfg.display;
1383         ostate.cfg.align.horizontal = 0; /* TODO */
1384         ostate.cfg.align.vertical = 0; /* TODO */
1385         ostate.cfg.is_display_filled = true;
1386         ostate.cfg.zoom.num = 1;
1387         ostate.cfg.zoom.den = 1;
1388
1389         vout_display_t *vd = DisplayNew(vout, &output->fmt, &ostate,
1390                                            output->psz_module ? output->psz_module : module,
1391                                            false, wrapper,
1392                                            double_click_timeout, hide_timeout, &owner);
1393         if (!vd) {
1394             vout_DeleteDisplay(wrapper, NULL);
1395             return NULL;
1396         }
1397         TAB_APPEND(sys->count, sys->display, vd);
1398     }
1399
1400     return wrapper;
1401 }
1402 #endif
1403
1404 /*****************************************************************************
1405  * TODO move out
1406  *****************************************************************************/
1407 #include "vout_internal.h"
1408 void vout_SendDisplayEventMouse(vout_thread_t *vout, const vlc_mouse_t *m)
1409 {
1410     if (vlc_mouse_HasMoved(&vout->p->mouse, m)) {
1411         vout_SendEventMouseMoved(vout, m->i_x, m->i_y);
1412     }
1413     if (vlc_mouse_HasButton(&vout->p->mouse, m)) {
1414         static const int buttons[] = {
1415             MOUSE_BUTTON_LEFT,
1416             MOUSE_BUTTON_CENTER,
1417             MOUSE_BUTTON_RIGHT,
1418             MOUSE_BUTTON_WHEEL_UP,
1419             MOUSE_BUTTON_WHEEL_DOWN,
1420             -1
1421         };
1422         for (int i = 0; buttons[i] >= 0; i++) {
1423             const int button = buttons[i];
1424             if (vlc_mouse_HasPressed(&vout->p->mouse, m, button))
1425                 vout_SendEventMousePressed(vout, button);
1426             else if (vlc_mouse_HasReleased(&vout->p->mouse, m, button))
1427                 vout_SendEventMouseReleased(vout, button);
1428         }
1429     }
1430     if (m->b_double_click)
1431         vout_SendEventMouseDoubleClick(vout);
1432     vout->p->mouse = *m;
1433 }
1434 vout_window_t * vout_NewDisplayWindow(vout_thread_t *vout, vout_display_t *vd, const vout_window_cfg_t *cfg)
1435 {
1436     VLC_UNUSED(vd);
1437     vout_window_cfg_t cfg_override = *cfg;
1438
1439     if( !config_GetInt( vout, "embedded-video" ) )
1440         cfg_override.is_standalone = true;
1441
1442     return vout_window_New(VLC_OBJECT(vout), NULL, &cfg_override);
1443 }
1444 void vout_DeleteDisplayWindow(vout_thread_t *vout, vout_display_t *vd, vout_window_t *window)
1445 {
1446     VLC_UNUSED(vout);
1447     VLC_UNUSED(vd);
1448     vout_window_Delete(window);
1449 }
1450