[vlc-commits] directfb: use triple buffering
Rafaël Carré
git at videolan.org
Fri Apr 18 14:56:38 CEST 2014
vlc | branch: master | Rafaël Carré <funman at videolan.org> | Fri Apr 18 13:41:07 2014 +0200| [0a2313a54ca566fada4107533ca45cd844c022a2] | committer: Rafaël Carré
directfb: use triple buffering
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0a2313a54ca566fada4107533ca45cd844c022a2
---
modules/video_output/directfb.c | 100 +++++++++++++++++++++++++++------------
1 file changed, 71 insertions(+), 29 deletions(-)
diff --git a/modules/video_output/directfb.c b/modules/video_output/directfb.c
index b4ae978..6f283a8 100644
--- a/modules/video_output/directfb.c
+++ b/modules/video_output/directfb.c
@@ -62,10 +62,12 @@ static int Control(vout_display_t *, int, va_list);
/* */
struct vout_display_sys_t {
- IDirectFB *directfb;
- IDirectFBSurface *primary;
+ IDirectFB *directfb;
+ IDirectFBSurface *primary;
picture_pool_t *pool;
+ picture_t *pics[3];
+ int idx;
};
/* */
@@ -85,11 +87,13 @@ static int Open(vlc_object_t *object)
}
DFBSurfaceDescription dsc;
- /*dsc.flags = DSDESC_CAPS | DSDESC_HEIGHT | DSDESC_WIDTH;*/
dsc.flags = DSDESC_CAPS;
- dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
- /*dsc.width = 352;*/
- /*dsc.height = 240;*/
+ dsc.caps = DSCAPS_PRIMARY | DSCAPS_TRIPLE;
+#if 0
+ dsc.flags |= DSDESC_HEIGHT | DSDESC_WIDTH;
+ dsc.width = 352;
+ dsc.height = 240;
+#endif
IDirectFB *directfb = NULL;
if (DirectFBCreate(&directfb) != DFB_OK || !directfb)
@@ -106,8 +110,6 @@ static int Open(vlc_object_t *object)
int height;
primary->GetSize(primary, &width, &height);
- primary->FillRectangle(primary, 0, 0, width, height);
- primary->Flip(primary, NULL, 0);
vout_display_DeleteWindow(vd, NULL);
@@ -183,42 +185,82 @@ static void Close(vlc_object_t *object)
free(sys);
}
-/* */
-static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
-{
- vout_display_sys_t *sys = vd->sys;
+struct picture_sys_t {
+ vout_display_sys_t *sys;
+};
- if (!sys->pool)
- sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
- return sys->pool;
+static int Lock(picture_t *pic)
+{
+ vout_display_sys_t *sys = pic->p_sys->sys;
+ return sys->pics[sys->idx] == pic ? VLC_SUCCESS : VLC_EGENERIC;
}
-static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
+/* */
+static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
{
+ VLC_UNUSED(count);
vout_display_sys_t *sys = vd->sys;
-
IDirectFBSurface *primary = sys->primary;
- void *pixels;
- int pitch;
- if (primary->Lock(primary, DSLF_WRITE, &pixels, &pitch) == DFB_OK) {
+ if (!sys->pool) {
picture_resource_t rsc;
-
memset(&rsc, 0, sizeof(rsc));
- rsc.p[0].p_pixels = pixels;
rsc.p[0].i_lines = vd->fmt.i_height;
- rsc.p[0].i_pitch = pitch;
- picture_t *direct = picture_NewFromResource(&vd->fmt, &rsc);
- if (direct) {
- picture_Copy(direct, picture);
- picture_Release(direct);
+ for (int i = 0; i < 3; i++) {
+ rsc.p_sys = malloc(sizeof(*rsc.p_sys));
+ if (!rsc.p_sys)
+ goto cleanup;
+ rsc.p_sys->sys = sys;
+ void *pixels;
+ int pitch;
+ if (primary->Lock(primary, DSLF_WRITE, &pixels, &pitch) != DFB_OK)
+ goto cleanup;
+
+ rsc.p[0].i_pitch = pitch;
+ rsc.p[0].p_pixels = pixels;
+ primary->Unlock(primary);
+ primary->Flip(primary, NULL, 0);
+
+ sys->pics[i] = picture_NewFromResource(&vd->fmt, &rsc);
+ if (!sys->pics[i]) {
+ free(rsc.p_sys);
+ goto cleanup;
+ }
}
- if (primary->Unlock(primary) == DFB_OK)
- primary->Flip(primary, NULL, 0);
+ picture_pool_configuration_t cfg = {
+ .picture_count = 3,
+ .picture = sys->pics,
+ .lock = Lock,
+ .unlock = NULL,
+ };
+
+ sys->pool = picture_pool_NewExtended(&cfg);
+ }
+ return sys->pool;
+
+cleanup:
+ for (int i = 0; i < 2; i++) {
+ if (sys->pics[i]) {
+ free(sys->pics[i]->p_sys);
+ picture_Release(sys->pics[i]);
+ }
}
+
+ return NULL;
+}
+
+static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
+{
+ vout_display_sys_t *sys = vd->sys;
+
+ IDirectFBSurface *primary = sys->primary;
+ primary->Flip(primary, NULL, 0);
+ if (++sys->idx >= 3)
+ sys->idx = 0;
picture_Release(picture);
+
VLC_UNUSED(subpicture);
}
More information about the vlc-commits
mailing list