freetype: font fallback for Windows
[vlc.git] / modules / video_output / directfb.c
blob26fa0470edf3ac3fc8c65ad2f79b0696b00275f4
1 /*****************************************************************************
2 * directfb.c: DirectFB video output display method
3 *****************************************************************************
4 * Copyright © 2005-2009 VLC authors and VideoLAN
6 * Authors: Iuri Diniz <iuridiniz@gmail.com>
7 * Laurent Aimar <fenrir@videolan.org>
9 * This code is based in sdl.c and fb.c, thanks for VideoLAN team.
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
27 * Preamble
28 *****************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_vout_display.h>
36 #include <vlc_picture_pool.h>
38 #include <directfb.h>
40 /*****************************************************************************
41 * Module descriptor
42 *****************************************************************************/
43 static int Open (vlc_object_t *);
44 static void Close(vlc_object_t *);
46 vlc_module_begin()
47 set_shortname("DirectFB")
48 set_category(CAT_VIDEO)
49 set_subcategory(SUBCAT_VIDEO_VOUT)
50 set_description(N_("DirectFB video output http://www.directfb.org/"))
51 set_capability("vout display", 35)
52 add_shortcut("directfb")
53 set_callbacks(Open, Close)
54 vlc_module_end()
56 /*****************************************************************************
57 * Local prototypes
58 *****************************************************************************/
59 static picture_pool_t *Pool (vout_display_t *, unsigned);
60 static void Display(vout_display_t *, picture_t *, subpicture_t *);
61 static int Control(vout_display_t *, int, va_list);
63 /* */
64 struct vout_display_sys_t {
65 IDirectFB *directfb;
66 IDirectFBSurface *primary;
68 picture_pool_t *pool;
69 picture_t *pics[3];
70 int idx;
73 /* */
74 static int Open(vlc_object_t *object)
76 vout_display_t *vd = (vout_display_t *)object;
77 vout_display_sys_t *sys;
79 if (vout_display_IsWindowed(vd))
80 return VLC_EGENERIC;
82 vd->sys = sys = calloc(1, sizeof(*sys));
83 if (!sys)
84 return VLC_ENOMEM;
86 if (DirectFBInit(NULL,NULL) != DFB_OK) {
87 msg_Err(vd, "Cannot init DirectFB");
88 free(sys);
89 return VLC_EGENERIC;
92 DFBSurfaceDescription dsc;
93 dsc.flags = DSDESC_CAPS;
94 dsc.caps = DSCAPS_PRIMARY | DSCAPS_TRIPLE;
95 #if 0
96 dsc.flags |= DSDESC_HEIGHT | DSDESC_WIDTH;
97 dsc.width = 352;
98 dsc.height = 240;
99 #endif
101 IDirectFB *directfb = NULL;
102 if (DirectFBCreate(&directfb) != DFB_OK || !directfb)
103 goto error;
104 sys->directfb = directfb;
106 IDirectFBSurface *primary = NULL;
107 if (directfb->CreateSurface(directfb, &dsc, &primary) || !primary)
108 goto error;
109 sys->primary = primary;
111 /* */
112 int width;
113 int height;
115 primary->GetSize(primary, &width, &height);
117 /* */
118 video_format_t fmt;
119 video_format_ApplyRotation(&fmt, &vd->fmt);
121 DFBSurfacePixelFormat pixel_format;
122 sys->primary->GetPixelFormat(sys->primary, &pixel_format);
123 switch (pixel_format) {
124 case DSPF_RGB332:
125 fmt.i_chroma = VLC_CODEC_RGB8;
126 fmt.i_rmask = 0x7 << 5;
127 fmt.i_gmask = 0x7 << 2;
128 fmt.i_bmask = 0x3 << 0;
129 break;
130 case DSPF_RGB16: fmt.i_chroma = VLC_CODEC_RGB16; break;
131 case DSPF_RGB24: fmt.i_chroma = VLC_CODEC_RGB24; break;
132 case DSPF_RGB32: fmt.i_chroma = VLC_CODEC_RGB32; break;
133 default:
134 msg_Err(vd, "unknown screen depth %i", pixel_format);
135 Close(VLC_OBJECT(vd));
136 return VLC_EGENERIC;
139 video_format_FixRgb(&fmt);
141 fmt.i_width = width;
142 fmt.i_height = height;
143 fmt.i_visible_width = width;
144 fmt.i_visible_height = height;
146 /* */
147 vout_display_info_t info = vd->info;
148 info.has_hide_mouse = true;
150 /* */
151 vd->fmt = fmt;
152 vd->info = info;
153 vd->pool = Pool;
154 vd->prepare = NULL;
155 vd->display = Display;
156 vd->control = Control;
157 vd->manage = NULL;
159 /* */
160 vout_display_SendEventFullscreen(vd, true);
161 vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height);
162 return VLC_SUCCESS;
164 error:
165 msg_Err(vd, "Cannot create primary surface");
166 Close(VLC_OBJECT(vd));
167 return VLC_EGENERIC;
170 static void Close(vlc_object_t *object)
172 vout_display_t *vd = (vout_display_t *)object;
173 vout_display_sys_t *sys = vd->sys;
175 if (sys->pool)
176 picture_pool_Release(sys->pool);
178 IDirectFBSurface *primary = sys->primary;
179 if (primary)
180 primary->Release(primary);
182 IDirectFB *directfb = sys->directfb;
183 if (directfb)
184 directfb->Release(directfb);
186 free(sys);
189 struct picture_sys_t {
190 vout_display_sys_t *sys;
193 static int Lock(picture_t *pic)
195 vout_display_sys_t *sys = pic->p_sys->sys;
196 return sys->pics[sys->idx] == pic ? VLC_SUCCESS : VLC_EGENERIC;
199 /* */
200 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
202 VLC_UNUSED(count);
203 vout_display_sys_t *sys = vd->sys;
204 IDirectFBSurface *primary = sys->primary;
206 if (!sys->pool) {
207 picture_resource_t rsc;
208 memset(&rsc, 0, sizeof(rsc));
209 rsc.p[0].i_lines = vd->fmt.i_height;
211 for (int i = 0; i < 3; i++) {
212 rsc.p_sys = malloc(sizeof(*rsc.p_sys));
213 if (!rsc.p_sys)
214 goto cleanup;
215 rsc.p_sys->sys = sys;
216 void *pixels;
217 int pitch;
218 if (primary->Lock(primary, DSLF_WRITE, &pixels, &pitch) != DFB_OK)
219 goto cleanup;
221 rsc.p[0].i_pitch = pitch;
222 rsc.p[0].p_pixels = pixels;
223 primary->Unlock(primary);
224 primary->Flip(primary, NULL, 0);
226 sys->pics[i] = picture_NewFromResource(&vd->fmt, &rsc);
227 if (!sys->pics[i]) {
228 free(rsc.p_sys);
229 goto cleanup;
233 picture_pool_configuration_t cfg = {
234 .picture_count = 3,
235 .picture = sys->pics,
236 .lock = Lock,
237 .unlock = NULL,
240 sys->pool = picture_pool_NewExtended(&cfg);
242 return sys->pool;
244 cleanup:
245 for (int i = 0; i < 2; i++) {
246 if (sys->pics[i]) {
247 free(sys->pics[i]->p_sys);
248 picture_Release(sys->pics[i]);
252 return NULL;
255 static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
257 vout_display_sys_t *sys = vd->sys;
259 IDirectFBSurface *primary = sys->primary;
260 primary->Flip(primary, NULL, 0);
261 if (++sys->idx >= 3)
262 sys->idx = 0;
263 picture_Release(picture);
265 VLC_UNUSED(subpicture);
268 static int Control(vout_display_t *vd, int query, va_list args)
270 (void) vd; (void) query; (void) args;
271 return VLC_EGENERIC;