Add dri image entry point for creating image from fd
Reviewed-by: Ander Conselvan de Oliveira <conselvan2@gmail.com>
This commit is contained in:
parent
664fe6dc84
commit
2356e28452
|
@ -938,7 +938,7 @@ struct __DRIdri2ExtensionRec {
|
||||||
* extensions.
|
* extensions.
|
||||||
*/
|
*/
|
||||||
#define __DRI_IMAGE "DRI_IMAGE"
|
#define __DRI_IMAGE "DRI_IMAGE"
|
||||||
#define __DRI_IMAGE_VERSION 6
|
#define __DRI_IMAGE_VERSION 7
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These formats correspond to the similarly named MESA_FORMAT_*
|
* These formats correspond to the similarly named MESA_FORMAT_*
|
||||||
|
@ -1021,6 +1021,9 @@ struct __DRIdri2ExtensionRec {
|
||||||
#define __DRI_IMAGE_ATTRIB_WIDTH 0x2004 /* available in versions 4+ */
|
#define __DRI_IMAGE_ATTRIB_WIDTH 0x2004 /* available in versions 4+ */
|
||||||
#define __DRI_IMAGE_ATTRIB_HEIGHT 0x2005
|
#define __DRI_IMAGE_ATTRIB_HEIGHT 0x2005
|
||||||
#define __DRI_IMAGE_ATTRIB_COMPONENTS 0x2006 /* available in versions 5+ */
|
#define __DRI_IMAGE_ATTRIB_COMPONENTS 0x2006 /* available in versions 5+ */
|
||||||
|
#define __DRI_IMAGE_ATTRIB_FD 0x2007 /* available in versions
|
||||||
|
* 7+. Each query will return a
|
||||||
|
* new fd. */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \name Reasons that __DRIimageExtensionRec::createImageFromTexture might fail
|
* \name Reasons that __DRIimageExtensionRec::createImageFromTexture might fail
|
||||||
|
@ -1117,6 +1120,16 @@ struct __DRIimageExtensionRec {
|
||||||
int level,
|
int level,
|
||||||
unsigned *error,
|
unsigned *error,
|
||||||
void *loaderPrivate);
|
void *loaderPrivate);
|
||||||
|
/**
|
||||||
|
* Like createImageFromNames, but takes a prime fd instead.
|
||||||
|
*
|
||||||
|
* \since 7
|
||||||
|
*/
|
||||||
|
__DRIimage *(*createImageFromFds)(__DRIscreen *screen,
|
||||||
|
int width, int height, int fourcc,
|
||||||
|
int *fds, int num_fds,
|
||||||
|
int *strides, int *offsets,
|
||||||
|
void *loaderPrivate);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,39 @@ intel_region_alloc_for_handle(struct intel_screen *screen,
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct intel_region *
|
||||||
|
intel_region_alloc_for_fd(struct intel_screen *screen,
|
||||||
|
GLuint cpp,
|
||||||
|
GLuint width, GLuint height, GLuint pitch,
|
||||||
|
int fd, const char *name)
|
||||||
|
{
|
||||||
|
struct intel_region *region;
|
||||||
|
drm_intel_bo *buffer;
|
||||||
|
int ret;
|
||||||
|
uint32_t bit_6_swizzle, tiling;
|
||||||
|
|
||||||
|
buffer = drm_intel_bo_gem_create_from_prime(screen->bufmgr,
|
||||||
|
fd, height * pitch);
|
||||||
|
if (buffer == NULL)
|
||||||
|
return NULL;
|
||||||
|
ret = drm_intel_bo_get_tiling(buffer, &tiling, &bit_6_swizzle);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "Couldn't get tiling of buffer (%s): %s\n",
|
||||||
|
name, strerror(-ret));
|
||||||
|
drm_intel_bo_unreference(buffer);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
region = intel_region_alloc_internal(screen, cpp,
|
||||||
|
width, height, pitch, tiling, buffer);
|
||||||
|
if (region == NULL) {
|
||||||
|
drm_intel_bo_unreference(buffer);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
intel_region_reference(struct intel_region **dst, struct intel_region *src)
|
intel_region_reference(struct intel_region **dst, struct intel_region *src)
|
||||||
{
|
{
|
||||||
|
|
|
@ -87,6 +87,12 @@ intel_region_alloc_for_handle(struct intel_screen *screen,
|
||||||
GLuint width, GLuint height, GLuint pitch,
|
GLuint width, GLuint height, GLuint pitch,
|
||||||
unsigned int handle, const char *name);
|
unsigned int handle, const char *name);
|
||||||
|
|
||||||
|
struct intel_region *
|
||||||
|
intel_region_alloc_for_fd(struct intel_screen *screen,
|
||||||
|
GLuint cpp,
|
||||||
|
GLuint width, GLuint height, GLuint pitch,
|
||||||
|
int fd, const char *name);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
intel_region_flink(struct intel_region *region, uint32_t *name);
|
intel_region_flink(struct intel_region *region, uint32_t *name);
|
||||||
|
|
||||||
|
|
|
@ -546,6 +546,10 @@ intel_query_image(__DRIimage *image, int attrib, int *value)
|
||||||
return false;
|
return false;
|
||||||
*value = image->planar_format->components;
|
*value = image->planar_format->components;
|
||||||
return true;
|
return true;
|
||||||
|
case __DRI_IMAGE_ATTRIB_FD:
|
||||||
|
if (drm_intel_bo_gem_export_to_prime(image->region->bo, value) == 0)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -623,8 +627,8 @@ intel_create_image_from_names(__DRIscreen *screen,
|
||||||
names[0], strides[0],
|
names[0], strides[0],
|
||||||
loaderPrivate);
|
loaderPrivate);
|
||||||
|
|
||||||
if (image == NULL)
|
if (image == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
image->planar_format = f;
|
image->planar_format = f;
|
||||||
for (i = 0; i < f->nplanes; i++) {
|
for (i = 0; i < f->nplanes; i++) {
|
||||||
|
@ -636,6 +640,52 @@ intel_create_image_from_names(__DRIscreen *screen,
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static __DRIimage *
|
||||||
|
intel_create_image_from_fds(__DRIscreen *screen,
|
||||||
|
int width, int height, int fourcc,
|
||||||
|
int *fds, int num_fds, int *strides, int *offsets,
|
||||||
|
void *loaderPrivate)
|
||||||
|
{
|
||||||
|
struct intel_screen *intelScreen = screen->driverPrivate;
|
||||||
|
struct intel_image_format *f = NULL;
|
||||||
|
__DRIimage *image;
|
||||||
|
int i, index;
|
||||||
|
|
||||||
|
if (fds == NULL || num_fds != 1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(intel_image_formats); i++) {
|
||||||
|
if (intel_image_formats[i].fourcc == fourcc) {
|
||||||
|
f = &intel_image_formats[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
image = intel_allocate_image(__DRI_IMAGE_FORMAT_NONE, loaderPrivate);
|
||||||
|
if (image == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
image->region = intel_region_alloc_for_fd(intelScreen,
|
||||||
|
1, width, height,
|
||||||
|
strides[0], fds[0], "image");
|
||||||
|
if (image->region == NULL) {
|
||||||
|
free(image);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
image->planar_format = f;
|
||||||
|
for (i = 0; i < f->nplanes; i++) {
|
||||||
|
index = f->planes[i].buffer_index;
|
||||||
|
image->offsets[index] = offsets[index];
|
||||||
|
image->strides[index] = strides[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static __DRIimage *
|
static __DRIimage *
|
||||||
intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
|
intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
|
||||||
{
|
{
|
||||||
|
@ -692,7 +742,7 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct __DRIimageExtensionRec intelImageExtension = {
|
static struct __DRIimageExtensionRec intelImageExtension = {
|
||||||
.base = { __DRI_IMAGE, 6 },
|
.base = { __DRI_IMAGE, 7 },
|
||||||
|
|
||||||
.createImageFromName = intel_create_image_from_name,
|
.createImageFromName = intel_create_image_from_name,
|
||||||
.createImageFromRenderbuffer = intel_create_image_from_renderbuffer,
|
.createImageFromRenderbuffer = intel_create_image_from_renderbuffer,
|
||||||
|
@ -703,7 +753,8 @@ static struct __DRIimageExtensionRec intelImageExtension = {
|
||||||
.validateUsage = intel_validate_usage,
|
.validateUsage = intel_validate_usage,
|
||||||
.createImageFromNames = intel_create_image_from_names,
|
.createImageFromNames = intel_create_image_from_names,
|
||||||
.fromPlanar = intel_from_planar,
|
.fromPlanar = intel_from_planar,
|
||||||
.createImageFromTexture = intel_create_image_from_texture
|
.createImageFromTexture = intel_create_image_from_texture,
|
||||||
|
.createImageFromFds = intel_create_image_from_fds
|
||||||
};
|
};
|
||||||
|
|
||||||
static const __DRIextension *intelScreenExtensions[] = {
|
static const __DRIextension *intelScreenExtensions[] = {
|
||||||
|
|
Loading…
Reference in New Issue