As discussed with Kristian on #wayland. Pushes the decision of components into the dri driver giving it greater freedom to allow t to implement YUV samplers in hardware, and which mode to use. This interface will also allow drivers like SVGA to implement YUV surfaces without the need to sub-allocate and instead send 3 seperate buffers for each channel, currently not implemented. I have tested these changes on Gallium Svga. Scott tested them on both intel and Gallium Radeon. Kristan and Pekka tested them on intel. v2: Fix typo in dri2_from_planar. v3: Merge in intel changes. Tested-by: Scott Moreau <oreaus@gmail.com> Tested-by: Pekka Paalanen <ppaalanen@gmail.com> Tested-by: Kristian Høgsberg <krh@bitplanet.net> Reviewed-by: Kristian Høgsberg <krh@bitplanet.net> Signed-off-by: Jakob Bornecrantz <jakob@vmware.com>tags/gles3-fmt-v1
| @@ -923,6 +923,10 @@ struct __DRIdri2ExtensionRec { | |||
| * __DRI_IMAGE_FORMAT_NONE is for images that aren't directly usable | |||
| * by the driver (YUV planar formats) but serve as a base image for | |||
| * creating sub-images for the different planes within the image. | |||
| * | |||
| * R8, GR88 and NONE should not be used with createImageFormName or | |||
| * createImage, and are returned by query from sub images created with | |||
| * createImageFromNames (NONE, see above) and fromPlane (R8 & GR88). | |||
| */ | |||
| #define __DRI_IMAGE_FORMAT_RGB565 0x1001 | |||
| #define __DRI_IMAGE_FORMAT_XRGB8888 0x1002 | |||
| @@ -937,6 +941,49 @@ struct __DRIdri2ExtensionRec { | |||
| #define __DRI_IMAGE_USE_SCANOUT 0x0002 | |||
| #define __DRI_IMAGE_USE_CURSOR 0x0004 /* Depricated */ | |||
| /** | |||
| * Four CC formats that matches with WL_DRM_FORMAT_* from wayland_drm.h | |||
| * and GBM_FORMAT_* from gbm.h, used with createImageFromNames. | |||
| * | |||
| * \since 5 | |||
| */ | |||
| #define __DRI_IMAGE_FOURCC_RGB565 0x36314752 | |||
| #define __DRI_IMAGE_FOURCC_ARGB8888 0x34325241 | |||
| #define __DRI_IMAGE_FOURCC_XRGB8888 0x34325258 | |||
| #define __DRI_IMAGE_FOURCC_ABGR8888 0x34324241 | |||
| #define __DRI_IMAGE_FOURCC_XBGR8888 0x34324258 | |||
| #define __DRI_IMAGE_FOURCC_YUV410 0x39565559 | |||
| #define __DRI_IMAGE_FOURCC_YUV411 0x31315559 | |||
| #define __DRI_IMAGE_FOURCC_YUV420 0x32315559 | |||
| #define __DRI_IMAGE_FOURCC_YUV422 0x36315559 | |||
| #define __DRI_IMAGE_FOURCC_YUV444 0x34325559 | |||
| #define __DRI_IMAGE_FOURCC_NV12 0x3231564e | |||
| #define __DRI_IMAGE_FOURCC_NV16 0x3631564e | |||
| #define __DRI_IMAGE_FOURCC_YUYV 0x56595559 | |||
| /** | |||
| * Queryable on images created by createImageFromNames. | |||
| * | |||
| * RGB and RGBA are may be usable directly as images but its still | |||
| * recommended to call fromPlanar with plane == 0. | |||
| * | |||
| * Y_U_V, Y_UV and Y_XUXV all requires call to fromPlanar to create | |||
| * usable sub-images, sampling from images return raw YUV data and | |||
| * color conversion needs to be done in the shader. | |||
| * | |||
| * \since 5 | |||
| */ | |||
| #define __DRI_IMAGE_COMPONENTS_RGB 0x3001 | |||
| #define __DRI_IMAGE_COMPONENTS_RGBA 0x3002 | |||
| #define __DRI_IMAGE_COMPONENTS_Y_U_V 0x3003 | |||
| #define __DRI_IMAGE_COMPONENTS_Y_UV 0x3004 | |||
| #define __DRI_IMAGE_COMPONENTS_Y_XUXV 0x3005 | |||
| /** | |||
| * queryImage attributes | |||
| */ | |||
| @@ -947,6 +994,7 @@ struct __DRIdri2ExtensionRec { | |||
| #define __DRI_IMAGE_ATTRIB_FORMAT 0x2003 /* available in versions 3+ */ | |||
| #define __DRI_IMAGE_ATTRIB_WIDTH 0x2004 /* available in versions 4+ */ | |||
| #define __DRI_IMAGE_ATTRIB_HEIGHT 0x2005 | |||
| #define __DRI_IMAGE_ATTRIB_COMPONENTS 0x2006 /* available in versions 5+ */ | |||
| typedef struct __DRIimageRec __DRIimage; | |||
| typedef struct __DRIimageExtensionRec __DRIimageExtension; | |||
| @@ -983,6 +1031,19 @@ struct __DRIimageExtensionRec { | |||
| */ | |||
| GLboolean (*validateUsage)(__DRIimage *image, unsigned int use); | |||
| /** | |||
| * Unlike createImageFromName __DRI_IMAGE_FORMAT is not but instead | |||
| * __DRI_IMAGE_FOURCC and strides are in bytes not pixels. Stride is | |||
| * also per block and not per pixel (for non-RGB, see gallium blocks). | |||
| * | |||
| * \since 5 | |||
| */ | |||
| __DRIimage *(*createImageFromNames)(__DRIscreen *screen, | |||
| int width, int height, int fourcc, | |||
| int *names, int num_names, | |||
| int *strides, int *offsets, | |||
| void *loaderPrivate); | |||
| /** | |||
| * Create an image out of a sub-region of a parent image. This | |||
| * entry point lets us create individual __DRIimages for different | |||
| @@ -998,10 +1059,8 @@ struct __DRIimageExtensionRec { | |||
| * | |||
| * \since 5 | |||
| */ | |||
| __DRIimage *(*createSubImage)(__DRIimage *image, | |||
| int width, int height, int format, | |||
| int offset, int pitch, | |||
| void *loaderPrivate); | |||
| __DRIimage *(*fromPlanar)(__DRIimage *image, int plane, | |||
| void *loaderPrivate); | |||
| }; | |||
| @@ -1093,68 +1093,16 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, | |||
| * wl_drm format code to a description of the planes in the buffer | |||
| * that lets us create a __DRIimage for each of the planes. */ | |||
| static const struct wl_drm_format_descriptor { | |||
| uint32_t wl_format; | |||
| static const struct wl_drm_components_descriptor { | |||
| uint32_t dri_components; | |||
| EGLint components; | |||
| int nplanes; | |||
| struct { | |||
| int buffer_index; | |||
| int width_shift; | |||
| int height_shift; | |||
| uint32_t dri_format; | |||
| int cpp; | |||
| } planes[3]; | |||
| } wl_drm_formats[] = { | |||
| { WL_DRM_FORMAT_ARGB8888, EGL_TEXTURE_RGBA, 1, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 }, } }, | |||
| { WL_DRM_FORMAT_XRGB8888, EGL_TEXTURE_RGB, 1, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888, 4 }, } }, | |||
| { WL_DRM_FORMAT_YUV410, EGL_TEXTURE_Y_U_V_WL, 3, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } }, | |||
| { WL_DRM_FORMAT_YUV411, EGL_TEXTURE_Y_U_V_WL, 3, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, | |||
| { WL_DRM_FORMAT_YUV420, EGL_TEXTURE_Y_U_V_WL, 3, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } }, | |||
| { WL_DRM_FORMAT_YUV422, EGL_TEXTURE_Y_U_V_WL, 3, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, | |||
| { WL_DRM_FORMAT_YUV444, EGL_TEXTURE_Y_U_V_WL, 3, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, | |||
| { WL_DRM_FORMAT_NV12, EGL_TEXTURE_Y_UV_WL, 2, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } }, | |||
| { WL_DRM_FORMAT_NV16, EGL_TEXTURE_Y_UV_WL, 2, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } }, | |||
| /* For YUYV buffers, we set up two overlapping DRI images and treat | |||
| * them as planar buffers in the compositors. Plane 0 is GR88 and | |||
| * samples YU or YV pairs and places Y into the R component, while | |||
| * plane 1 is ARGB and samples YUYV clusters and places pairs and | |||
| * places U into the G component and V into A. This lets the | |||
| * texture sampler interpolate the Y components correctly when | |||
| * sampling from plane 0, and interpolate U and V correctly when | |||
| * sampling from plane 1. */ | |||
| { WL_DRM_FORMAT_YUYV, EGL_TEXTURE_Y_XUXV_WL, 2, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, | |||
| { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } } | |||
| } wl_drm_components[] = { | |||
| { __DRI_IMAGE_COMPONENTS_RGB, EGL_TEXTURE_RGB, 1 }, | |||
| { __DRI_IMAGE_COMPONENTS_RGBA, EGL_TEXTURE_RGBA, 1 }, | |||
| { __DRI_IMAGE_COMPONENTS_Y_U_V, EGL_TEXTURE_Y_U_V_WL, 3 }, | |||
| { __DRI_IMAGE_COMPONENTS_Y_UV, EGL_TEXTURE_Y_UV_WL, 2 }, | |||
| { __DRI_IMAGE_COMPONENTS_Y_XUXV, EGL_TEXTURE_Y_XUXV_WL, 2 }, | |||
| }; | |||
| static _EGLImage * | |||
| @@ -1164,13 +1112,11 @@ dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, | |||
| { | |||
| struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer; | |||
| struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); | |||
| const struct wl_drm_components_descriptor *f; | |||
| __DRIimage *dri_image; | |||
| _EGLImageAttribs attrs; | |||
| EGLint err; | |||
| uint32_t format; | |||
| int32_t offset, stride, plane, width, height; | |||
| int cpp, index; | |||
| const struct wl_drm_format_descriptor *f; | |||
| int32_t plane; | |||
| if (!wayland_buffer_is_drm(&buffer->buffer)) | |||
| return NULL; | |||
| @@ -1189,17 +1135,12 @@ dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, | |||
| return NULL; | |||
| } | |||
| width = buffer->buffer.width >> f->planes[plane].width_shift; | |||
| height = buffer->buffer.height >> f->planes[plane].height_shift; | |||
| format = f->planes[plane].dri_format; | |||
| cpp = f->planes[plane].cpp; | |||
| index = f->planes[plane].buffer_index; | |||
| offset = buffer->offset[index]; | |||
| stride = buffer->stride[index]; | |||
| dri_image = dri2_dpy->image->fromPlanar(buffer->driver_buffer, plane, NULL); | |||
| dri_image = dri2_dpy->image->createSubImage(buffer->driver_buffer, | |||
| width, height, format, | |||
| offset, stride / cpp, NULL); | |||
| if (dri_image == NULL) { | |||
| _eglError(EGL_BAD_PARAMETER, "dri2_create_image_wayland_wl_buffer"); | |||
| return NULL; | |||
| } | |||
| return dri2_create_image(disp, dri_image); | |||
| } | |||
| @@ -1360,24 +1301,31 @@ dri2_wl_reference_buffer(void *user_data, uint32_t name, | |||
| { | |||
| _EGLDisplay *disp = user_data; | |||
| struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); | |||
| int i; | |||
| __DRIimage *img; | |||
| int i, dri_components = 0; | |||
| img = dri2_dpy->image->createImageFromNames(dri2_dpy->dri_screen, | |||
| buffer->buffer.width, | |||
| buffer->buffer.height, | |||
| buffer->format, (int*)&name, 1, | |||
| buffer->stride, | |||
| buffer->offset, | |||
| NULL); | |||
| if (img == NULL) | |||
| return; | |||
| for (i = 0; i < ARRAY_SIZE(wl_drm_formats); i++) | |||
| if (wl_drm_formats[i].wl_format == buffer->format) { | |||
| buffer->driver_format = &wl_drm_formats[i]; | |||
| break; | |||
| } | |||
| dri2_dpy->image->queryImage(img, __DRI_IMAGE_ATTRIB_COMPONENTS, &dri_components); | |||
| if (buffer->driver_format == NULL) | |||
| return; | |||
| buffer->driver_format = NULL; | |||
| for (i = 0; i < ARRAY_SIZE(wl_drm_components); i++) | |||
| if (wl_drm_components[i].dri_components == dri_components) | |||
| buffer->driver_format = &wl_drm_components[i]; | |||
| buffer->driver_buffer = | |||
| dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, | |||
| buffer->buffer.width, | |||
| buffer->buffer.height, | |||
| __DRI_IMAGE_FORMAT_NONE, name, | |||
| buffer->stride[0] / 4, | |||
| NULL); | |||
| if (buffer->driver_format == NULL) | |||
| dri2_dpy->image->destroyImage(img); | |||
| else | |||
| buffer->driver_buffer = img; | |||
| } | |||
| static void | |||
| @@ -1442,7 +1390,7 @@ dri2_query_wayland_buffer_wl(_EGLDriver *drv, _EGLDisplay *disp, | |||
| EGLint attribute, EGLint *value) | |||
| { | |||
| struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer; | |||
| const struct wl_drm_format_descriptor *format; | |||
| const struct wl_drm_components_descriptor *format; | |||
| if (!wayland_buffer_is_drm(&buffer->buffer)) | |||
| return EGL_FALSE; | |||
| @@ -86,6 +86,7 @@ struct __DRIimageRec { | |||
| unsigned level; | |||
| unsigned layer; | |||
| uint32_t dri_format; | |||
| uint32_t dri_components; | |||
| void *loader_private; | |||
| }; | |||
| @@ -574,6 +574,7 @@ dri2_create_image(__DRIscreen *_screen, | |||
| img->level = 0; | |||
| img->layer = 0; | |||
| img->dri_format = format; | |||
| img->dri_components = 0; | |||
| img->loader_private = loaderPrivate; | |||
| return img; | |||
| @@ -612,6 +613,11 @@ dri2_query_image(__DRIimage *image, int attrib, int *value) | |||
| 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; | |||
| default: | |||
| return GL_FALSE; | |||
| } | |||
| @@ -630,6 +636,8 @@ dri2_dup_image(__DRIimage *image, void *loaderPrivate) | |||
| pipe_resource_reference(&img->texture, image->texture); | |||
| img->level = image->level; | |||
| img->layer = image->layer; | |||
| /* This should be 0 for sub images, but dup is also used for base images. */ | |||
| img->dri_components = image->dri_components; | |||
| img->loader_private = loaderPrivate; | |||
| return img; | |||
| @@ -649,6 +657,76 @@ dri2_validate_usage(__DRIimage *image, unsigned int use) | |||
| return GL_FALSE; | |||
| } | |||
| static __DRIimage * | |||
| dri2_from_names(__DRIscreen *screen, int width, int height, int format, | |||
| int *names, int num_names, int *strides, int *offsets, | |||
| void *loaderPrivate) | |||
| { | |||
| __DRIimage *img; | |||
| int stride, dri_components; | |||
| if (num_names != 1) | |||
| return NULL; | |||
| if (offsets[0] != 0) | |||
| return NULL; | |||
| switch(format) { | |||
| 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_name(screen, width, height, format, | |||
| names[0], stride, loaderPrivate); | |||
| if (img == NULL) | |||
| return NULL; | |||
| img->dri_components = dri_components; | |||
| return img; | |||
| } | |||
| static __DRIimage * | |||
| dri2_from_planar(__DRIimage *image, int plane, void *loaderPrivate) | |||
| { | |||
| __DRIimage *img; | |||
| if (plane != 0) | |||
| return NULL; | |||
| if (image->dri_components == 0) | |||
| return NULL; | |||
| img = dri2_dup_image(image, loaderPrivate); | |||
| if (img == NULL) | |||
| return NULL; | |||
| /* set this to 0 for sub images. */ | |||
| img->dri_components = 0; | |||
| return img; | |||
| } | |||
| static void | |||
| dri2_destroy_image(__DRIimage *img) | |||
| { | |||
| @@ -657,7 +735,7 @@ dri2_destroy_image(__DRIimage *img) | |||
| } | |||
| static struct __DRIimageExtensionRec dri2ImageExtension = { | |||
| { __DRI_IMAGE, 4 }, | |||
| { __DRI_IMAGE, 5 }, | |||
| dri2_create_image_from_name, | |||
| dri2_create_image_from_renderbuffer, | |||
| dri2_destroy_image, | |||
| @@ -665,6 +743,8 @@ static struct __DRIimageExtensionRec dri2ImageExtension = { | |||
| dri2_query_image, | |||
| dri2_dup_image, | |||
| dri2_validate_usage, | |||
| dri2_from_names, | |||
| dri2_from_planar, | |||
| }; | |||
| /* | |||
| @@ -363,7 +363,7 @@ gbm_dri_bo_import(struct gbm_device *gbm, | |||
| struct gbm_dri_bo *bo; | |||
| __DRIimage *image; | |||
| unsigned dri_use = 0; | |||
| int dri_format, width, height, gbm_format, stride, cpp, offset; | |||
| int gbm_format; | |||
| /* Required for query image WIDTH & HEIGHT */ | |||
| if (dri->image->base.version < 4) | |||
| @@ -376,20 +376,15 @@ gbm_dri_bo_import(struct gbm_device *gbm, | |||
| struct wl_drm_buffer *wb = (struct wl_drm_buffer *) buffer; | |||
| image = wb->driver_buffer; | |||
| stride = wb->stride[0]; | |||
| offset = wb->offset[0]; | |||
| cpp = 4; | |||
| switch (wb->format) { | |||
| case WL_DRM_FORMAT_XRGB8888: | |||
| dri_format = __DRI_IMAGE_FORMAT_XRGB8888; | |||
| gbm_format = GBM_FORMAT_XRGB8888; | |||
| break; | |||
| case WL_DRM_FORMAT_ARGB8888: | |||
| dri_format = __DRI_IMAGE_FORMAT_ARGB8888; | |||
| gbm_format = GBM_FORMAT_ARGB8888; | |||
| break; | |||
| case WL_DRM_FORMAT_YUYV: | |||
| dri_format = __DRI_IMAGE_FORMAT_ARGB8888; | |||
| gbm_format = GBM_FORMAT_YUYV; | |||
| break; | |||
| default: | |||
| @@ -401,15 +396,15 @@ gbm_dri_bo_import(struct gbm_device *gbm, | |||
| case GBM_BO_IMPORT_EGL_IMAGE: | |||
| { | |||
| int dri_format; | |||
| if (dri->lookup_image == NULL) | |||
| return NULL; | |||
| image = dri->lookup_image(dri->screen, buffer, dri->lookup_user_data); | |||
| dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format); | |||
| gbm_format = gbm_dri_to_gbm_format(dri_format); | |||
| dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride); | |||
| offset = 0; | |||
| cpp = 4; | |||
| if (gbm_format == 0) | |||
| return NULL; | |||
| break; | |||
| } | |||
| @@ -422,13 +417,7 @@ gbm_dri_bo_import(struct gbm_device *gbm, | |||
| if (bo == NULL) | |||
| return NULL; | |||
| dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_WIDTH, &width); | |||
| dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HEIGHT, &height); | |||
| bo->image = dri->image->createSubImage(image, | |||
| width, height, dri_format, | |||
| offset, stride / cpp, NULL); | |||
| bo->image = dri->image->dupImage(image, NULL); | |||
| if (usage & GBM_BO_USE_SCANOUT) | |||
| dri_use |= __DRI_IMAGE_USE_SCANOUT; | |||
| @@ -441,10 +430,14 @@ gbm_dri_bo_import(struct gbm_device *gbm, | |||
| } | |||
| bo->base.base.gbm = gbm; | |||
| bo->base.base.width = width; | |||
| bo->base.base.height = height; | |||
| bo->base.base.stride = stride; | |||
| bo->base.base.format = gbm_format; | |||
| dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_WIDTH, | |||
| (int*)&bo->base.base.width); | |||
| dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HEIGHT, | |||
| (int*)&bo->base.base.height); | |||
| dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE, | |||
| (int*)&bo->base.base.stride); | |||
| dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE, | |||
| &bo->base.base.handle.s32); | |||
| @@ -141,12 +141,38 @@ uint32_t | |||
| intel_region_get_aligned_offset(struct intel_region *region, uint32_t x, | |||
| uint32_t y); | |||
| /** | |||
| * Used with images created with image_from_names | |||
| * to help support planar images. | |||
| */ | |||
| struct intel_image_format { | |||
| int fourcc; | |||
| int components; | |||
| int nplanes; | |||
| struct { | |||
| int buffer_index; | |||
| int width_shift; | |||
| int height_shift; | |||
| uint32_t dri_format; | |||
| int cpp; | |||
| } planes[3]; | |||
| }; | |||
| struct __DRIimageRec { | |||
| struct intel_region *region; | |||
| GLenum internal_format; | |||
| uint32_t dri_format; | |||
| GLuint format; | |||
| uint32_t offset; | |||
| /* | |||
| * Need to save these here between calls to | |||
| * image_from_names and calls to image_from_planar. | |||
| */ | |||
| uint32_t strides[3]; | |||
| uint32_t offsets[3]; | |||
| struct intel_image_format *planar_format; | |||
| void *data; | |||
| }; | |||
| @@ -190,6 +190,59 @@ static const struct __DRI2flushExtensionRec intelFlushExtension = { | |||
| dri2InvalidateDrawable, | |||
| }; | |||
| struct intel_image_format intel_image_formats[] = { | |||
| { __DRI_IMAGE_FOURCC_ARGB8888, __DRI_IMAGE_COMPONENTS_RGBA, 1, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } }, | |||
| { __DRI_IMAGE_FOURCC_XRGB8888, __DRI_IMAGE_COMPONENTS_RGB, 1, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888, 4 }, } }, | |||
| { __DRI_IMAGE_FOURCC_YUV410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } }, | |||
| { __DRI_IMAGE_FOURCC_YUV411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, | |||
| { __DRI_IMAGE_FOURCC_YUV420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } }, | |||
| { __DRI_IMAGE_FOURCC_YUV422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, | |||
| { __DRI_IMAGE_FOURCC_YUV444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } }, | |||
| { __DRI_IMAGE_FOURCC_NV12, __DRI_IMAGE_COMPONENTS_Y_UV, 2, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } }, | |||
| { __DRI_IMAGE_FOURCC_NV16, __DRI_IMAGE_COMPONENTS_Y_UV, 2, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, | |||
| { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } }, | |||
| /* For YUYV buffers, we set up two overlapping DRI images and treat | |||
| * them as planar buffers in the compositors. Plane 0 is GR88 and | |||
| * samples YU or YV pairs and places Y into the R component, while | |||
| * plane 1 is ARGB and samples YUYV clusters and places pairs and | |||
| * places U into the G component and V into A. This lets the | |||
| * texture sampler interpolate the Y components correctly when | |||
| * sampling from plane 0, and interpolate U and V correctly when | |||
| * sampling from plane 1. */ | |||
| { __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2, | |||
| { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, | |||
| { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } } | |||
| }; | |||
| static __DRIimage * | |||
| intel_allocate_image(int dri_format, void *loaderPrivate) | |||
| { | |||
| @@ -249,7 +302,7 @@ intel_create_image_from_name(__DRIscreen *screen, | |||
| image = intel_allocate_image(format, loaderPrivate); | |||
| if (image->format == MESA_FORMAT_NONE) | |||
| cpp = 0; | |||
| cpp = 1; | |||
| else | |||
| cpp = _mesa_get_format_bytes(image->format); | |||
| image->region = intel_region_alloc_for_handle(intelScreen, | |||
| @@ -372,6 +425,11 @@ intel_query_image(__DRIimage *image, int attrib, int *value) | |||
| case __DRI_IMAGE_ATTRIB_HEIGHT: | |||
| *value = image->region->height; | |||
| return true; | |||
| case __DRI_IMAGE_ATTRIB_COMPONENTS: | |||
| if (image->planar_format == NULL) | |||
| return false; | |||
| *value = image->planar_format->components; | |||
| return true; | |||
| default: | |||
| return false; | |||
| } | |||
| @@ -393,11 +451,15 @@ intel_dup_image(__DRIimage *orig_image, void *loaderPrivate) | |||
| } | |||
| image->internal_format = orig_image->internal_format; | |||
| image->planar_format = orig_image->planar_format; | |||
| image->dri_format = orig_image->dri_format; | |||
| image->format = orig_image->format; | |||
| image->offset = orig_image->offset; | |||
| image->data = loaderPrivate; | |||
| memcpy(image->strides, orig_image->strides, sizeof(image->strides)); | |||
| memcpy(image->offsets, orig_image->offsets, sizeof(image->offsets)); | |||
| return image; | |||
| } | |||
| @@ -413,16 +475,72 @@ intel_validate_usage(__DRIimage *image, unsigned int use) | |||
| } | |||
| static __DRIimage * | |||
| intel_create_sub_image(__DRIimage *parent, | |||
| int width, int height, int dri_format, | |||
| int offset, int pitch, void *loaderPrivate) | |||
| intel_create_image_from_names(__DRIscreen *screen, | |||
| int width, int height, int fourcc, | |||
| int *names, int num_names, | |||
| int *strides, int *offsets, | |||
| void *loaderPrivate) | |||
| { | |||
| struct intel_image_format *f = NULL; | |||
| __DRIimage *image; | |||
| int cpp; | |||
| int i, index; | |||
| if (screen == NULL || names == NULL || num_names != 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_create_image_from_name(screen, width, height, | |||
| __DRI_IMAGE_FORMAT_NONE, | |||
| names[0], strides[0], | |||
| loaderPrivate); | |||
| if (image == NULL) | |||
| 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 * | |||
| intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate) | |||
| { | |||
| int width, height, offset, stride, dri_format, cpp, index, pitch; | |||
| struct intel_image_format *f; | |||
| uint32_t mask_x, mask_y; | |||
| __DRIimage *image; | |||
| if (parent == NULL || parent->planar_format == NULL) | |||
| return NULL; | |||
| f = parent->planar_format; | |||
| if (plane >= f->nplanes) | |||
| return NULL; | |||
| width = parent->region->width >> f->planes[plane].width_shift; | |||
| height = parent->region->height >> f->planes[plane].height_shift; | |||
| dri_format = f->planes[plane].dri_format; | |||
| index = f->planes[plane].buffer_index; | |||
| offset = parent->offsets[index]; | |||
| stride = parent->strides[index]; | |||
| image = intel_allocate_image(dri_format, loaderPrivate); | |||
| cpp = _mesa_get_format_bytes(image->format); | |||
| cpp = _mesa_get_format_bytes(image->format); /* safe since no none format */ | |||
| pitch = stride / cpp; | |||
| if (offset + height * cpp * pitch > parent->region->bo->size) { | |||
| _mesa_warning(NULL, "intel_create_sub_image: subimage out of bounds"); | |||
| FREE(image); | |||
| @@ -463,7 +581,8 @@ static struct __DRIimageExtensionRec intelImageExtension = { | |||
| intel_query_image, | |||
| intel_dup_image, | |||
| intel_validate_usage, | |||
| intel_create_sub_image | |||
| intel_create_image_from_names, | |||
| intel_from_planar | |||
| }; | |||
| static const __DRIextension *intelScreenExtensions[] = { | |||