]> git.sesse.net Git - vlc/blob - modules/video_output/drawable.c
Drawable: separate XIDs and HWNDs
[vlc] / modules / video_output / drawable.c
1 /**
2  * @file drawable.c
3  * @brief Legacy monolithic LibVLC video window provider
4  */
5 /*****************************************************************************
6  * Copyright © 2009 Rémi Denis-Courmont
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2.0
11  * of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  ****************************************************************************/
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <stdarg.h>
28 #include <assert.h>
29
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
32 #include <vlc_vout.h>
33 #include <vlc_window.h>
34
35 static int  OpenXID (vlc_object_t *);
36 static int  OpenHWND (vlc_object_t *);
37 static void Close (vlc_object_t *);
38
39 /*
40  * Module descriptor
41  */
42 vlc_module_begin ()
43     set_shortname (N_("Drawable"))
44     set_description (N_("Embedded X window video"))
45     set_category (CAT_VIDEO)
46     set_subcategory (SUBCAT_VIDEO_VOUT)
47     set_capability ("xwindow", 70)
48     set_callbacks (OpenXID, Close)
49
50     add_submodule ()
51         set_description (N_("Embedded Windows video"))
52         set_capability ("hwnd", 70)
53         set_callbacks (OpenHWND, Close)
54
55 vlc_module_end ()
56
57 static int Control (vout_window_t *, int, va_list);
58
59 /**
60  * Find the drawable set by libvlc application.
61  */
62 static int Open (vlc_object_t *obj, const char *varname, bool ptr)
63 {
64     static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
65     vout_window_t *wnd = (vout_window_t *)obj;
66     vlc_value_t val;
67
68     if (var_Create (obj->p_libvlc, "drawable-busy", VLC_VAR_BOOL))
69         return VLC_ENOMEM;
70
71     vlc_mutex_lock (&serializer);
72     /* Note: We cannot simply clear the drawable variable.
73      * It would break libvlc_video_get_parent(). */
74     if (!var_GetBool (obj->p_libvlc, "drawable-busy"))
75     {
76         var_Get (obj->p_libvlc, varname, &val);
77         if (ptr ? (val.p_address != NULL): (val.i_int == 0))
78             var_SetBool (obj->p_libvlc, "drawable-busy", true);
79     }
80     vlc_mutex_unlock (&serializer);
81
82     if (ptr ? (val.p_address == NULL) : (val.i_int == 0))
83     {
84         var_Destroy (obj->p_libvlc, "drawable-busy");
85         return VLC_EGENERIC;
86     }
87
88     if (ptr)
89         wnd->handle.hwnd = val.p_address;
90     else
91         wnd->handle.xid = val.i_int;
92
93     /* FIXME: check that X server matches --x11-display (if specified) */
94     /* FIXME: get window size (in platform-dependent ways) */
95
96     wnd->control = Control;
97     return VLC_SUCCESS;
98 }
99
100 static int  OpenXID (vlc_object_t *obj)
101 {
102     return Open (obj, "drawable-xid", false);
103 }
104
105 static int  OpenHWND (vlc_object_t *obj)
106 {
107     return Open (obj, "drawable-hwnd", true);
108 }
109
110
111 /**
112  * Release the drawable.
113  */
114 static void Close (vlc_object_t *obj)
115 {
116     /* This is atomic with regards to var_GetBool() in Open(): */
117     var_SetBool (obj->p_libvlc, "drawable-busy", false);
118
119     /* Variables are reference-counted... */
120     var_Destroy (obj->p_libvlc, "drawable-busy");
121 }
122
123
124 static int Control (vout_window_t *wnd, int query, va_list ap)
125 {
126     switch (query)
127     {
128         case VOUT_GET_SIZE:
129         {
130             unsigned int *pi_width = va_arg (ap, unsigned int *);
131             unsigned int *pi_height = va_arg (ap, unsigned int *);
132             *pi_width = wnd->width;
133             *pi_height = wnd->height;
134             return VLC_SUCCESS;
135         }
136
137         case VOUT_SET_SIZE: /* not allowed */
138         case VOUT_SET_STAY_ON_TOP: /* not allowed either, would be ugly */
139             return VLC_EGENERIC;
140     }
141
142     msg_Warn (wnd, "unsupported control query %d", query);
143     return VLC_EGENERIC;
144 }
145