From 6e749a6b2b9c45829963553cedda64b4a73afe14 Mon Sep 17 00:00:00 2001 From: Jordan Justen Date: Sat, 3 Aug 2019 01:14:01 -0700 Subject: [PATCH] gallium/dri2: Refactor image property queries This refactor will let us more easily use pipe_screen::resource_get_param as an alternative to pipe_screen::resource_get_handle. Signed-off-by: Jordan Justen Reviewed-by: Kenneth Graunke Acked-by: Eric Anholt --- src/gallium/state_trackers/dri/dri2.c | 148 ++++++++++++++------------ 1 file changed, 79 insertions(+), 69 deletions(-) diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c index 98039555892..ac842ddf756 100644 --- a/src/gallium/state_trackers/dri/dri2.c +++ b/src/gallium/state_trackers/dri/dri2.c @@ -1020,70 +1020,24 @@ dri2_create_image_with_modifiers(__DRIscreen *dri_screen, loaderPrivate); } -static GLboolean -dri2_query_image(__DRIimage *image, int attrib, int *value) +static bool +dri2_query_image_common(__DRIimage *image, int attrib, int *value) { - struct winsys_handle whandle; - unsigned usage; - - if (image->use & __DRI_IMAGE_USE_BACKBUFFER) - usage = PIPE_HANDLE_USAGE_EXPLICIT_FLUSH; - else - usage = PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE; - - memset(&whandle, 0, sizeof(whandle)); - switch (attrib) { - case __DRI_IMAGE_ATTRIB_STRIDE: - whandle.type = WINSYS_HANDLE_TYPE_KMS; - if (!image->texture->screen->resource_get_handle(image->texture->screen, - NULL, image->texture, &whandle, usage)) - return GL_FALSE; - *value = whandle.stride; - return GL_TRUE; - case __DRI_IMAGE_ATTRIB_OFFSET: - whandle.type = WINSYS_HANDLE_TYPE_KMS; - if (!image->texture->screen->resource_get_handle(image->texture->screen, - NULL, image->texture, &whandle, usage)) - return GL_FALSE; - *value = whandle.offset; - return GL_TRUE; - case __DRI_IMAGE_ATTRIB_HANDLE: - whandle.type = WINSYS_HANDLE_TYPE_KMS; - if (!image->texture->screen->resource_get_handle(image->texture->screen, - NULL, image->texture, &whandle, usage)) - return GL_FALSE; - *value = whandle.handle; - return GL_TRUE; - case __DRI_IMAGE_ATTRIB_NAME: - whandle.type = WINSYS_HANDLE_TYPE_SHARED; - if (!image->texture->screen->resource_get_handle(image->texture->screen, - NULL, image->texture, &whandle, usage)) - return GL_FALSE; - *value = whandle.handle; - return GL_TRUE; - case __DRI_IMAGE_ATTRIB_FD: - whandle.type= WINSYS_HANDLE_TYPE_FD; - if (!image->texture->screen->resource_get_handle(image->texture->screen, - NULL, image->texture, &whandle, usage)) - return GL_FALSE; - - *value = whandle.handle; - return GL_TRUE; case __DRI_IMAGE_ATTRIB_FORMAT: *value = image->dri_format; - return GL_TRUE; + return true; case __DRI_IMAGE_ATTRIB_WIDTH: *value = image->texture->width0; - return GL_TRUE; + return true; case __DRI_IMAGE_ATTRIB_HEIGHT: *value = image->texture->height0; - return GL_TRUE; + return true; case __DRI_IMAGE_ATTRIB_COMPONENTS: if (image->dri_components == 0) - return GL_FALSE; + return false; *value = image->dri_components; - return GL_TRUE; + return true; case __DRI_IMAGE_ATTRIB_FOURCC: if (image->dri_fourcc) { *value = image->dri_fourcc; @@ -1092,39 +1046,95 @@ dri2_query_image(__DRIimage *image, int attrib, int *value) map = dri2_get_mapping_by_format(image->dri_format); if (!map) - return GL_FALSE; + return false; *value = map->dri_fourcc; } - return GL_TRUE; + return true; + default: + return false; + } +} + +static bool +dri2_query_image_by_resource_handle(__DRIimage *image, int attrib, int *value) +{ + struct pipe_screen *pscreen = image->texture->screen; + struct winsys_handle whandle; + unsigned usage; + memset(&whandle, 0, sizeof(whandle)); + + switch (attrib) { + case __DRI_IMAGE_ATTRIB_STRIDE: + case __DRI_IMAGE_ATTRIB_OFFSET: + case __DRI_IMAGE_ATTRIB_HANDLE: + whandle.type = WINSYS_HANDLE_TYPE_KMS; + break; + case __DRI_IMAGE_ATTRIB_NAME: + whandle.type = WINSYS_HANDLE_TYPE_SHARED; + break; + case __DRI_IMAGE_ATTRIB_FD: + whandle.type = WINSYS_HANDLE_TYPE_FD; + break; case __DRI_IMAGE_ATTRIB_NUM_PLANES: *value = 1; - return GL_TRUE; + return true; case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER: + case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER: whandle.type = WINSYS_HANDLE_TYPE_KMS; whandle.modifier = DRM_FORMAT_MOD_INVALID; - if (!image->texture->screen->resource_get_handle(image->texture->screen, - NULL, image->texture, &whandle, usage)) - return GL_FALSE; + break; + default: + return false; + } + + if (image->use & __DRI_IMAGE_USE_BACKBUFFER) + usage = PIPE_HANDLE_USAGE_EXPLICIT_FLUSH; + else + usage = PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE; + + if (!pscreen->resource_get_handle(pscreen, NULL, image->texture, + &whandle, usage)) + return false; + + switch (attrib) { + case __DRI_IMAGE_ATTRIB_STRIDE: + *value = whandle.stride; + return true; + case __DRI_IMAGE_ATTRIB_OFFSET: + *value = whandle.offset; + return true; + case __DRI_IMAGE_ATTRIB_HANDLE: + case __DRI_IMAGE_ATTRIB_NAME: + case __DRI_IMAGE_ATTRIB_FD: + *value = whandle.handle; + return true; + case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER: if (whandle.modifier == DRM_FORMAT_MOD_INVALID) - return GL_FALSE; + return false; *value = (whandle.modifier >> 32) & 0xffffffff; - return GL_TRUE; + return true; case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER: - whandle.type = WINSYS_HANDLE_TYPE_KMS; - whandle.modifier = DRM_FORMAT_MOD_INVALID; - if (!image->texture->screen->resource_get_handle(image->texture->screen, - NULL, image->texture, &whandle, usage)) - return GL_FALSE; if (whandle.modifier == DRM_FORMAT_MOD_INVALID) - return GL_FALSE; + return false; *value = whandle.modifier & 0xffffffff; - return GL_TRUE; + return true; default: - return GL_FALSE; + return false; } } +static GLboolean +dri2_query_image(__DRIimage *image, int attrib, int *value) +{ + if (dri2_query_image_common(image, attrib, value)) + return GL_TRUE; + else if (dri2_query_image_by_resource_handle(image, attrib, value)) + return GL_TRUE; + else + return GL_FALSE; +} + static __DRIimage * dri2_dup_image(__DRIimage *image, void *loaderPrivate) { -- 2.30.2