Vout: add a new vout_window type for android native windows
[vlc/gmpfix.git] / src / video_output / window.c
blobbc45bc28ea0c934547236576e3e31cac01242bfc
1 /*****************************************************************************
2 * window.c: "vout window" managment
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
5 * $Id$
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 #include <assert.h>
32 #include <vlc_common.h>
33 #include <vlc_vout_window.h>
34 #include <vlc_modules.h>
35 #include "inhibit.h"
36 #include <libvlc.h>
38 typedef struct
40 vout_window_t wnd;
41 module_t *module;
42 vlc_inhibit_t *inhibit;
43 } window_t;
45 static int vout_window_start(void *func, va_list ap)
47 int (*activate)(vout_window_t *, const vout_window_cfg_t *) = func;
48 vout_window_t *wnd = va_arg(ap, vout_window_t *);
49 const vout_window_cfg_t *cfg = va_arg(ap, const vout_window_cfg_t *);
51 return activate(wnd, cfg);
54 vout_window_t *vout_window_New(vlc_object_t *obj,
55 const char *module,
56 const vout_window_cfg_t *cfg)
58 window_t *w = vlc_custom_create(obj, sizeof(*w), "window");
59 vout_window_t *window = &w->wnd;
61 memset(&window->handle, 0, sizeof(window->handle));
62 window->control = NULL;
63 window->sys = NULL;
64 window->type = cfg->type;
66 const char *type;
67 switch (cfg->type) {
68 #if defined(_WIN32) || defined(__OS2__)
69 case VOUT_WINDOW_TYPE_HWND:
70 type = "vout window hwnd";
71 window->handle.hwnd = NULL;
72 break;
73 #endif
74 #ifdef __APPLE__
75 case VOUT_WINDOW_TYPE_NSOBJECT:
76 type = "vout window nsobject";
77 window->handle.nsobject = NULL;
78 break;
79 #endif
80 case VOUT_WINDOW_TYPE_XID:
81 type = "vout window xid";
82 window->handle.xid = 0;
83 window->display.x11 = NULL;
84 break;
85 case VOUT_WINDOW_TYPE_ANDROID_NATIVE:
86 type = "vout window anative";
87 window->handle.anativewindow = NULL;
88 break;
89 default:
90 assert(0);
93 w->module = vlc_module_load(window, type, module, module && *module,
94 vout_window_start, window, cfg);
95 if (!w->module) {
96 vlc_object_release(window);
97 return NULL;
100 /* Hook for screensaver inhibition */
101 if (var_InheritBool(obj, "disable-screensaver") &&
102 cfg->type == VOUT_WINDOW_TYPE_XID) {
103 w->inhibit = vlc_inhibit_Create(VLC_OBJECT (window));
104 if (w->inhibit != NULL)
105 vlc_inhibit_Set(w->inhibit, VLC_INHIBIT_VIDEO);
106 /* FIXME: ^ wait for vout activation, pause */
108 else
109 w->inhibit = NULL;
110 return window;
113 static void vout_window_stop(void *func, va_list ap)
115 int (*deactivate)(vout_window_t *) = func;
116 vout_window_t *wnd = va_arg(ap, vout_window_t *);
118 deactivate(wnd);
121 void vout_window_Delete(vout_window_t *window)
123 if (!window)
124 return;
126 window_t *w = (window_t *)window;
127 if (w->inhibit)
129 vlc_inhibit_Set (w->inhibit, VLC_INHIBIT_NONE);
130 vlc_inhibit_Destroy (w->inhibit);
133 vlc_module_unload(w->module, vout_window_stop, window);
134 vlc_object_release(window);
137 int vout_window_Control(vout_window_t *window, int query, ...)
139 va_list args;
140 va_start(args, query);
141 int ret = window->control(window, query, args);
142 va_end(args);
144 return ret;