From: WuZhen <wuz...@jidemail.com> adds a new type of winsys handle type that allows passing a pointer sized handle to winsys
Change-Id: I3bf1732619206d2bc50f6aca6b27258bb026a212 Reviewed-by: Mauro Rossi <issor.or...@gmail.com> Reviewed-by: Chih-Wei Huang <cwhu...@linux.org.tw> --- include/GL/internal/dri_interface.h | 14 ++++++- src/gallium/include/state_tracker/drm_driver.h | 10 ++++- src/gallium/state_trackers/dri/dri2.c | 12 +++--- src/gallium/state_trackers/dri/drisw.c | 55 ++++++++++++++++++++++++++ src/mesa/drivers/dri/common/dri_util.c | 4 +- src/mesa/drivers/dri/common/dri_util.h | 2 +- 6 files changed, 85 insertions(+), 12 deletions(-) diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h index 8922356990..a84bef90a0 100644 --- a/include/GL/internal/dri_interface.h +++ b/include/GL/internal/dri_interface.h @@ -62,6 +62,7 @@ typedef struct __DRIdrawableRec __DRIdrawable; typedef struct __DRIconfigRec __DRIconfig; typedef struct __DRIframebufferRec __DRIframebuffer; typedef struct __DRIversionRec __DRIversion; +typedef struct __DRIimageRec __DRIimage; typedef struct __DRIcoreExtensionRec __DRIcoreExtension; typedef struct __DRIextensionRec __DRIextension; @@ -861,8 +862,9 @@ struct __DRIlegacyExtensionRec { * conjunction with the core extension. */ #define __DRI_SWRAST "DRI_SWRast" -#define __DRI_SWRAST_VERSION 4 +#define __DRI_SWRAST_VERSION 5 +struct winsys_handle; struct __DRIswrastExtensionRec { __DRIextension base; @@ -909,6 +911,15 @@ struct __DRIswrastExtensionRec { const __DRIconfig ***driver_configs, void *loaderPrivate); + /** + * create a dri image from native window system handle + * + * \since version 5 + */ + __DRIimage *(*createImageFromWinsys)(__DRIscreen *_screen, + int width, int height, int format, + int num_handles, struct winsys_handle *whandle, + void *loaderPrivate); }; /** Common DRI function definitions, shared among DRI2 and Image extensions @@ -1308,7 +1319,6 @@ enum __DRIChromaSiting { #define __BLIT_FLAG_FLUSH 0x0001 #define __BLIT_FLAG_FINISH 0x0002 -typedef struct __DRIimageRec __DRIimage; typedef struct __DRIimageExtensionRec __DRIimageExtension; struct __DRIimageExtensionRec { __DRIextension base; diff --git a/src/gallium/include/state_tracker/drm_driver.h b/src/gallium/include/state_tracker/drm_driver.h index c80fb09dbc..e4d8f17ceb 100644 --- a/src/gallium/include/state_tracker/drm_driver.h +++ b/src/gallium/include/state_tracker/drm_driver.h @@ -11,6 +11,7 @@ struct pipe_resource; #define DRM_API_HANDLE_TYPE_SHARED 0 #define DRM_API_HANDLE_TYPE_KMS 1 #define DRM_API_HANDLE_TYPE_FD 2 +#define DRM_API_HANDLE_TYPE_BUFFER 3 /** @@ -20,7 +21,7 @@ struct winsys_handle { /** * Input for texture_from_handle, valid values are - * DRM_API_HANDLE_TYPE_SHARED or DRM_API_HANDLE_TYPE_FD. + * DRM_API_HANDLE_TYPE_SHARED or DRM_API_HANDLE_TYPE_FD or DRM_API_HANDLE_TYPE_BUFFER. * Input to texture_get_handle, * to select handle for kms, flink, or prime. */ @@ -30,6 +31,13 @@ struct winsys_handle * of a specific layer of an array texture. */ unsigned layer; + + /** + * Input to texture_from_handle. + * Output for texture_get_handle. + */ + void* external_buffer; + /** * Input to texture_from_handle. * Output for texture_get_handle. diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c index 77523e98ff..b9d7bca711 100644 --- a/src/gallium/state_trackers/dri/dri2.c +++ b/src/gallium/state_trackers/dri/dri2.c @@ -111,7 +111,7 @@ static int convert_fourcc(int format, int *dri_components_p) * only needed for exporting dmabuf's, so I think I won't loose much * sleep over it. */ -static int convert_to_fourcc(int format) +int convert_to_fourcc(int format) { switch(format) { case __DRI_IMAGE_FORMAT_RGB565: @@ -765,7 +765,7 @@ dri2_update_tex_buffer(struct dri_drawable *drawable, /* no-op */ } -static __DRIimage * +__DRIimage * dri2_lookup_egl_image(struct dri_screen *screen, void *handle) { const __DRIimageLookupExtension *loader = screen->sPriv->dri2.image; @@ -780,7 +780,7 @@ dri2_lookup_egl_image(struct dri_screen *screen, void *handle) return img; } -static __DRIimage * +__DRIimage * dri2_create_image_from_winsys(__DRIscreen *_screen, int width, int height, int format, int num_handles, struct winsys_handle *whandle, @@ -1173,7 +1173,7 @@ dri2_from_planar(__DRIimage *image, int plane, void *loaderPrivate) return img; } -static __DRIimage * +__DRIimage * dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture, int depth, int level, unsigned *error, void *loaderPrivate) @@ -1374,7 +1374,7 @@ dri2_unmap_image(__DRIcontext *context, __DRIimage *image, void *data) pipe_transfer_unmap(pipe, (struct pipe_transfer *)data); } -static void +void dri2_destroy_image(__DRIimage *img) { pipe_resource_reference(&img->texture, NULL); @@ -1600,7 +1600,7 @@ dri2_server_wait_sync(__DRIcontext *_ctx, void *_fence, unsigned flags) ctx->fence_server_sync(ctx, fence->pipe_fence); } -static __DRI2fenceExtension dri2FenceExtension = { +__DRI2fenceExtension dri2FenceExtension = { .base = { __DRI2_FENCE, 2 }, .create_fence = dri2_create_fence, diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c index b85a73c57d..1360765b99 100644 --- a/src/gallium/state_trackers/dri/drisw.c +++ b/src/gallium/state_trackers/dri/drisw.c @@ -361,14 +361,66 @@ drisw_update_tex_buffer(struct dri_drawable *drawable, pipe_transfer_unmap(pipe, transfer); } +extern __DRIimage *dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture, + int depth, int level, unsigned *error, + void *loaderPrivate); +extern __DRIimage *dri2_lookup_egl_image(struct dri_screen *screen, void *handle); +extern void dri2_destroy_image(__DRIimage *img); +extern int convert_to_fourcc(int format); +extern __DRIimage *dri2_create_image_from_winsys(__DRIscreen *_screen, + int width, int height, int format, + int num_handles, struct winsys_handle *whandle, + void *loaderPrivate); +extern __DRI2fenceExtension dri2FenceExtension; + + +static GLboolean +drisw_query_image(__DRIimage *image, int attrib, int *value) +{ + switch (attrib) { + case __DRI_IMAGE_ATTRIB_FORMAT: + *value = image->dri_format; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_WIDTH: + *value = image->texture->width0; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_HEIGHT: + *value = image->texture->height0; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_COMPONENTS: + if (image->dri_components == 0) + return GL_FALSE; + *value = image->dri_components; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_NUM_PLANES: + *value = 1; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_FOURCC: + *value = convert_to_fourcc(image->dri_format); + return GL_TRUE; + default: + return GL_FALSE; + } +} + /* * Backend function for init_screen. */ +static const __DRIimageExtension driswImageExtension = { + .base = { __DRI_IMAGE, 11 }, + + .createImageFromTexture = dri2_create_from_texture, + .destroyImage = dri2_destroy_image, + .queryImage = drisw_query_image, +}; + static const __DRIextension *drisw_screen_extensions[] = { &driTexBufferExtension.base, &dri2RendererQueryExtension.base, &dri2ConfigQueryExtension.base, + &driswImageExtension.base, + &dri2FenceExtension.base, NULL }; @@ -407,6 +459,9 @@ drisw_init_screen(__DRIscreen * sPriv) if (!configs) goto fail; + screen->lookup_egl_image = dri2_lookup_egl_image; + driSWRastExtension.createImageFromWinsys = dri2_create_image_from_winsys; + return configs; fail: dri_destroy_screen_helper(screen); diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index 209a42ab24..c03744ab9a 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -781,8 +781,8 @@ const __DRIdri2Extension driDRI2Extension = { .createNewScreen2 = driCreateNewScreen2, }; -const __DRIswrastExtension driSWRastExtension = { - .base = { __DRI_SWRAST, 4 }, +__DRIswrastExtension driSWRastExtension = { + .base = { __DRI_SWRAST, 5 }, .createNewScreen = driSWRastCreateNewScreen, .createNewDrawable = driCreateNewDrawable, diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h index 6987f555e6..79148fadb2 100644 --- a/src/mesa/drivers/dri/common/dri_util.h +++ b/src/mesa/drivers/dri/common/dri_util.h @@ -63,7 +63,7 @@ * Extensions. */ extern const __DRIcoreExtension driCoreExtension; -extern const __DRIswrastExtension driSWRastExtension; +extern __DRIswrastExtension driSWRastExtension; extern const __DRIdri2Extension driDRI2Extension; extern const __DRI2configQueryExtension dri2ConfigQueryExtension; extern const __DRIcopySubBufferExtension driCopySubBufferExtension; -- 2.11.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev