[RFC 7/9] gbm: implement gbm_surface_get_bo in dri backend
Ander Conselvan de Oliveira
conselvan2 at gmail.com
Wed Dec 14 02:00:06 PST 2011
From: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
---
src/egl/drivers/dri2/platform_drm.c | 11 ++++++++
src/gbm/backends/dri/gbm_dri.c | 45 ++++++++++++++++++++++++++++++++++-
src/gbm/backends/dri/gbm_driint.h | 1 +
3 files changed, 56 insertions(+), 1 deletions(-)
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index bafaa22..06fdd85 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -37,6 +37,16 @@
#include "egl_dri2.h"
+static __DRIbuffer *
+get_front_buffer(struct gbm_dri_surface *surf, void *data)
+{
+ struct dri2_egl_surface *dri2_surf = data;
+
+ (void) surf;
+
+ return &dri2_surf->buffers[__DRI_BUFFER_FRONT_LEFT];
+}
+
static _EGLSurface *
dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
_EGLConfig *conf, EGLNativeWindowType window,
@@ -71,6 +81,7 @@ dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
dri2_surf->base.Width = surf->base.width;
dri2_surf->base.Height = surf->base.height;
+ surf->get_front_buffer = get_front_buffer;
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 60ee4de..d6ac956 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -416,7 +416,50 @@ gbm_dri_surface_destroy(struct gbm_surface *_surf)
static struct gbm_bo *
gbm_dri_surface_get_bo(struct gbm_surface *_surf)
{
- return NULL;
+ struct gbm_dri_device *dri = gbm_dri_device(_surf->gbm);
+ struct gbm_dri_surface *surf = gbm_dri_surface(_surf);
+ struct gbm_dri_bo *bo;
+ __DRIbuffer *dri_buffer;
+ int dri_format = 0;
+
+ if (surf->get_front_buffer == NULL)
+ return NULL;
+
+ switch (_surf->format) {
+ case GBM_BO_FORMAT_XRGB8888:
+ dri_format = __DRI_IMAGE_FORMAT_XRGB8888;
+ break;
+ case GBM_BO_FORMAT_ARGB8888:
+ dri_format = __DRI_IMAGE_FORMAT_ARGB8888;
+ break;
+ default:
+ return NULL;
+ }
+
+ dri_buffer = surf->get_front_buffer(surf, surf->dri_private);
+ if (!dri_buffer)
+ return NULL;
+
+ bo = calloc(1, sizeof *bo);
+ if (bo == NULL)
+ return NULL;
+
+ bo->base.base.gbm = _surf->gbm;
+ bo->base.base.width = _surf->width;
+ bo->base.base.height = _surf->height;
+
+ bo->image =
+ dri->image->createImageFromName(dri->screen,
+ _surf->width, _surf->height, dri_format,
+ dri_buffer->name, dri_buffer->pitch / 4,
+ bo);
+
+ dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
+ &bo->base.base.handle.s32);
+ dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE,
+ (int *) &bo->base.base.pitch);
+
+ return &bo->base.base;
}
static void
diff --git a/src/gbm/backends/dri/gbm_driint.h b/src/gbm/backends/dri/gbm_driint.h
index f404368..8853251 100644
--- a/src/gbm/backends/dri/gbm_driint.h
+++ b/src/gbm/backends/dri/gbm_driint.h
@@ -77,6 +77,7 @@ struct gbm_dri_bo {
struct gbm_dri_surface {
struct gbm_surface base;
+ __DRIbuffer *(*get_front_buffer)(struct gbm_dri_surface *, void *);
void *dri_private;
};
--
1.7.4.1
More information about the wayland-devel
mailing list