[Mesa-dev] [PATCH 03/15] gallium/dri: Support* DRI Image extension version 7
Christopher James Halse Rogers
christopher.halse.rogers at canonical.com
Sat Jul 20 04:40:35 PDT 2013
*ish
---
src/gallium/state_trackers/dri/drm/dri2.c | 118 +++++++++++++++++++++++++++---
1 file changed, 108 insertions(+), 10 deletions(-)
diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index 74e14af..edbf801 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -534,14 +534,14 @@ dri2_lookup_egl_image(struct dri_screen *screen, void *handle)
}
static __DRIimage *
-dri2_create_image_from_name(__DRIscreen *_screen,
- int width, int height, int format,
- int name, int pitch, void *loaderPrivate)
+dri2_create_image_from_winsys(__DRIscreen *_screen,
+ int width, int height, int format,
+ struct winsys_handle *whandle, int pitch,
+ void *loaderPrivate)
{
struct dri_screen *screen = dri_screen(_screen);
__DRIimage *img;
struct pipe_resource templ;
- struct winsys_handle whandle;
unsigned tex_usage;
enum pipe_format pf;
@@ -581,13 +581,10 @@ dri2_create_image_from_name(__DRIscreen *_screen,
templ.depth0 = 1;
templ.array_size = 1;
- memset(&whandle, 0, sizeof(whandle));
- whandle.handle = name;
- whandle.type = DRM_API_HANDLE_TYPE_SHARED;
- whandle.stride = pitch * util_format_get_blocksize(pf);
+ whandle->stride = pitch * util_format_get_blocksize(pf);
img->texture = screen->base.screen->resource_from_handle(screen->base.screen,
- &templ, &whandle);
+ &templ, whandle);
if (!img->texture) {
FREE(img);
return NULL;
@@ -602,6 +599,39 @@ dri2_create_image_from_name(__DRIscreen *_screen,
}
static __DRIimage *
+dri2_create_image_from_name(__DRIscreen *_screen,
+ int width, int height, int format,
+ int name, int pitch, void *loaderPrivate)
+{
+ struct winsys_handle whandle;
+
+ memset(&whandle, 0, sizeof(whandle));
+ whandle.type = DRM_API_HANDLE_TYPE_SHARED;
+ whandle.handle = name;
+
+ return dri2_create_image_from_winsys(_screen, width, height, format,
+ &whandle, pitch, loaderPrivate);
+}
+
+static __DRIimage *
+dri2_create_image_from_fd(__DRIscreen *_screen,
+ int width, int height, int format,
+ int fd, int pitch, void *loaderPrivate)
+{
+ struct winsys_handle whandle;
+
+ if (fd < 0)
+ return NULL;
+
+ memset(&whandle, 0, sizeof(whandle));
+ whandle.type = DRM_API_HANDLE_TYPE_FD;
+ whandle.handle = (unsigned)fd;
+
+ return dri2_create_image_from_winsys(_screen, width, height, format,
+ &whandle, pitch, loaderPrivate);
+}
+
+static __DRIimage *
dri2_create_image_from_renderbuffer(__DRIcontext *context,
int renderbuffer, void *loaderPrivate)
{
@@ -710,6 +740,11 @@ dri2_query_image(__DRIimage *image, int attrib, int *value)
image->texture, &whandle);
*value = whandle.handle;
return GL_TRUE;
+ case __DRI_IMAGE_ATTRIB_FD:
+ whandle.type= DRM_API_HANDLE_TYPE_FD;
+ image->texture->screen->resource_get_handle(image->texture->screen,
+ image->texture, &whandle);
+ *value = whandle.handle;
case __DRI_IMAGE_ATTRIB_FORMAT:
*value = image->dri_format;
return GL_TRUE;
@@ -833,6 +868,67 @@ dri2_from_planar(__DRIimage *image, int plane, void *loaderPrivate)
return img;
}
+static __DRIimage *
+dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture,
+ int depth, int level, unsigned *error,
+ void *loaderPrivate)
+{
+ /* Bad parameter seems like the least-incorrect error */
+ *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
+ return NULL;
+}
+
+static __DRIimage *
+dri2_from_fds(__DRIscreen *screen, int width, int height, int fourcc,
+ int *fds, int num_fds, int *strides, int *offsets,
+ void *loaderPrivate)
+{
+ __DRIimage *img;
+ int format, stride, dri_components;
+
+ if (num_fds != 1)
+ return NULL;
+ if (offsets[0] != 0)
+ return NULL;
+
+ switch(fourcc) {
+ case __DRI_IMAGE_FOURCC_RGB565:
+ format = __DRI_IMAGE_FORMAT_RGB565;
+ dri_components = __DRI_IMAGE_COMPONENTS_RGB;
+ break;
+ case __DRI_IMAGE_FOURCC_ARGB8888:
+ format = __DRI_IMAGE_FORMAT_ARGB8888;
+ dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
+ break;
+ case __DRI_IMAGE_FOURCC_XRGB8888:
+ format = __DRI_IMAGE_FORMAT_XRGB8888;
+ dri_components = __DRI_IMAGE_COMPONENTS_RGB;
+ break;
+ case __DRI_IMAGE_FOURCC_ABGR8888:
+ format = __DRI_IMAGE_FORMAT_ABGR8888;
+ dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
+ break;
+ case __DRI_IMAGE_FOURCC_XBGR8888:
+ format = __DRI_IMAGE_FORMAT_XBGR8888;
+ dri_components = __DRI_IMAGE_COMPONENTS_RGB;
+ break;
+ default:
+ return NULL;
+ }
+
+ /* Strides are in bytes not pixels. */
+ stride = strides[0] /4;
+
+ img = dri2_create_image_from_fd(screen, width, height, format,
+ fds[0], stride, loaderPrivate);
+ if (img == NULL)
+ return NULL;
+
+ img->dri_components = dri_components;
+ return img;
+}
+
+
static void
dri2_destroy_image(__DRIimage *img)
{
@@ -841,7 +937,7 @@ dri2_destroy_image(__DRIimage *img)
}
static struct __DRIimageExtensionRec dri2ImageExtension = {
- { __DRI_IMAGE, 5 },
+ { __DRI_IMAGE, 7 },
dri2_create_image_from_name,
dri2_create_image_from_renderbuffer,
dri2_destroy_image,
@@ -851,6 +947,8 @@ static struct __DRIimageExtensionRec dri2ImageExtension = {
dri2_validate_usage,
dri2_from_names,
dri2_from_planar,
+ dri2_create_from_texture,
+ dri2_from_fds,
};
/*
--
1.8.3.2
More information about the mesa-dev
mailing list