[PATCH v2 11/11] gbm: add gbm_surface_has_free_buffers and implement it in dri backend

Ander Conselvan de Oliveira ander.conselvan.de.oliveira at intel.com
Wed Jan 25 06:24:23 PST 2012


---
 src/egl/drivers/dri2/platform_drm.c |   13 +++++++++++++
 src/gbm/backends/dri/gbm_dri.c      |   12 ++++++++++++
 src/gbm/backends/dri/gbm_driint.h   |    1 +
 src/gbm/main/gbm.c                  |   12 ++++++++++++
 src/gbm/main/gbm.h                  |    3 +++
 src/gbm/main/gbmint.h               |    1 +
 6 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index b16bc42..ac6f46a 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -65,6 +65,18 @@ release_buffer(struct gbm_dri_surface *surf, __DRIbuffer *buffer, void *data)
 
 }
 
+static int
+has_free_buffers(void *data)
+{
+   struct dri2_egl_surface *dri2_surf = data;
+
+   if (!dri2_surf->drm_buffer_lock[DRM_BUFFER_BACK] ||
+       !dri2_surf->drm_buffer_lock[DRM_BUFFER_THIRD])
+      return 1;
+   else
+      return 0;
+}
+
 static _EGLSurface *
 dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
 		    _EGLConfig *conf, EGLNativeWindowType window,
@@ -103,6 +115,7 @@ dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
 
       surf->get_front_buffer = get_front_buffer;
       surf->release_buffer = release_buffer;
+      surf->has_free_buffers = has_free_buffers;
       surf->dri_private = dri2_surf;
 
       break;
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 8d39861..5dbbbcd 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -475,6 +475,17 @@ gbm_dri_surface_release_buffer(struct gbm_surface *_surf, struct gbm_bo *_bo)
    gbm_dri_bo_destroy(_bo);
 }
 
+static int
+gbm_dri_surface_has_free_buffers(struct gbm_surface *_surf)
+{
+   struct gbm_dri_surface *surf = gbm_dri_surface(_surf);
+
+   if (surf->has_free_buffers && surf->has_free_buffers(surf->dri_private))
+      return 1;
+   else
+      return 0;
+}
+
 static void
 dri_destroy(struct gbm_device *gbm)
 {
@@ -507,6 +518,7 @@ dri_device_create(int fd)
    dri->base.base.surface_lock_front_buffer =
       gbm_dri_surface_lock_front_buffer;
    dri->base.base.surface_release_buffer = gbm_dri_surface_release_buffer;
+   dri->base.base.surface_has_free_buffers = gbm_dri_surface_has_free_buffers;
 
    dri->base.type = GBM_DRM_DRIVER_TYPE_DRI;
    dri->base.base.name = "drm";
diff --git a/src/gbm/backends/dri/gbm_driint.h b/src/gbm/backends/dri/gbm_driint.h
index 3551be3..786f36b 100644
--- a/src/gbm/backends/dri/gbm_driint.h
+++ b/src/gbm/backends/dri/gbm_driint.h
@@ -80,6 +80,7 @@ struct gbm_dri_surface {
 
    __DRIbuffer *(*get_front_buffer)(struct gbm_dri_surface *, void *);
    void (*release_buffer)(struct gbm_dri_surface *, __DRIbuffer *, void *);
+   int (*has_free_buffers)(void *);
    void *dri_private;
 };
 
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 211e931..a49276a 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -366,3 +366,15 @@ gbm_surface_release_buffer(struct gbm_surface *surf, struct gbm_bo *bo)
 {
    surf->gbm->surface_release_buffer(surf, bo);
 }
+
+/**
+ * Return whether or not a surface has free (non-locked) buffers
+ *
+ * \param surf The surface
+ * \return 1 if the surface has free buffers, 0 otherwise
+ */
+GBM_EXPORT int
+gbm_surface_has_free_buffers(struct gbm_surface *surf)
+{
+   return surf->gbm->surface_has_free_buffers(surf);
+}
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 5ffe3dd..3140744 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -155,6 +155,9 @@ gbm_surface_lock_front_buffer(struct gbm_surface *surface);
 void
 gbm_surface_release_buffer(struct gbm_surface *surface, struct gbm_bo *bo);
 
+int
+gbm_surface_has_free_buffers(struct gbm_surface *surface);
+
 void
 gbm_surface_destroy(struct gbm_surface *surface);
 
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index d24ea7a..07edd0b 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -78,6 +78,7 @@ struct gbm_device {
    struct gbm_bo *(*surface_lock_front_buffer)(struct gbm_surface *surface);
    void (*surface_release_buffer)(struct gbm_surface *surface,
                                   struct gbm_bo *bo);
+   int (*surface_has_free_buffers)(struct gbm_surface *surface);
    void (*surface_destroy)(struct gbm_surface *surface);
 };
 
-- 
1.7.4.1



More information about the wayland-devel mailing list