directfb: inline OpenDisplay, reduce context
[vlc/gmpfix.git] / modules / video_output / directfb.c
blobc618602aafc536a0de54de9038dc4189d2c04113
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);
62 static void Manage (vout_display_t *);
64 /* */
65 struct vout_display_sys_t {
66 IDirectFB *directfb;
67 IDirectFBSurface *primary;
69 picture_pool_t *pool;
72 /* */
73 static int Open(vlc_object_t *object)
75 vout_display_t *vd = (vout_display_t *)object;
76 vout_display_sys_t *sys;
78 /* Allocate structure */
79 vd->sys = sys = calloc(1, sizeof(*sys));
80 if (!sys)
81 return VLC_ENOMEM;
83 /* Init DirectFB */
84 if (DirectFBInit(NULL,NULL) != DFB_OK) {
85 msg_Err(vd, "Cannot init DirectFB");
86 free(sys);
87 return VLC_EGENERIC;
90 DFBSurfaceDescription dsc;
91 /*dsc.flags = DSDESC_CAPS | DSDESC_HEIGHT | DSDESC_WIDTH;*/
92 dsc.flags = DSDESC_CAPS;
93 dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
94 /*dsc.width = 352;*/
95 /*dsc.height = 240;*/
97 IDirectFB *directfb = NULL;
98 if (DirectFBCreate(&directfb) != DFB_OK || !directfb)
99 goto error;
100 sys->directfb = directfb;
102 IDirectFBSurface *primary = NULL;
103 if (directfb->CreateSurface(directfb, &dsc, &primary) || !primary)
104 goto error;
105 sys->primary = primary;
107 /* */
108 int width;
109 int height;
111 primary->GetSize(primary, &width, &height);
112 primary->FillRectangle(primary, 0, 0, width, height);
113 primary->Flip(primary, NULL, 0);
115 vout_display_DeleteWindow(vd, NULL);
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;
144 /* */
145 vout_display_info_t info = vd->info;
146 info.has_hide_mouse = true;
148 /* */
149 vd->fmt = fmt;
150 vd->info = info;
151 vd->pool = Pool;
152 vd->prepare = NULL;
153 vd->display = Display;
154 vd->control = Control;
155 vd->manage = Manage;
157 /* */
158 vout_display_SendEventFullscreen(vd, true);
159 vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height, true);
160 return VLC_SUCCESS;
162 error:
163 msg_Err(vd, "Cannot create primary surface");
164 Close(VLC_OBJECT(vd));
165 return VLC_EGENERIC;
168 static void Close(vlc_object_t *object)
170 vout_display_t *vd = (vout_display_t *)object;
171 vout_display_sys_t *sys = vd->sys;
173 if (sys->pool)
174 picture_pool_Delete(sys->pool);
176 IDirectFBSurface *primary = sys->primary;
177 if (primary)
178 primary->Release(primary);
180 IDirectFB *directfb = sys->directfb;
181 if (directfb)
182 directfb->Release(directfb);
184 free(sys);
187 /* */
188 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
190 vout_display_sys_t *sys = vd->sys;
192 if (!sys->pool)
193 sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
194 return sys->pool;
197 static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
199 vout_display_sys_t *sys = vd->sys;
201 IDirectFBSurface *primary = sys->primary;
203 void *pixels;
204 int pitch;
205 if (primary->Lock(primary, DSLF_WRITE, &pixels, &pitch) == DFB_OK) {
206 picture_resource_t rsc;
208 memset(&rsc, 0, sizeof(rsc));
209 rsc.p[0].p_pixels = pixels;
210 rsc.p[0].i_lines = vd->fmt.i_height;
211 rsc.p[0].i_pitch = pitch;
213 picture_t *direct = picture_NewFromResource(&vd->fmt, &rsc);
214 if (direct) {
215 picture_Copy(direct, picture);
216 picture_Release(direct);
219 if (primary->Unlock(primary) == DFB_OK)
220 primary->Flip(primary, NULL, 0);
222 picture_Release(picture);
223 VLC_UNUSED(subpicture);
226 static int Control(vout_display_t *vd, int query, va_list args)
228 switch (query) {
229 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE: {
230 const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
231 if (cfg->display.width != vd->fmt.i_width ||
232 cfg->display.height != vd->fmt.i_height)
233 return VLC_EGENERIC;
234 return VLC_SUCCESS;
236 default:
237 msg_Err(vd, "Unsupported query in vout display directfb");
238 return VLC_EGENERIC;
242 static void Manage (vout_display_t *vd)
244 VLC_UNUSED(vd);