From ebab3109876113f86ed189f26f409529c7abed67 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 8 Apr 2021 14:10:55 +0200 Subject: [PATCH] frontends/va: improve surface attribs processing Instead of checking whether the attribute is settable for each attrib type, check that once at the beginning of the loop. Instead of having an if for each attrib type, use a switch. Return an error if we encounter an unknown attribute. This allows the caller to make sure settable attributes aren't ignored. The intel media driver seems to just assert [1] that it doesn't encounter unknown attributes. [1]: https://github.com/intel/media-driver/blob/95d413e519a980f6a7178880ccbfedace092316c/media_driver/linux/common/ddi/media_libva.cpp#L2530 Signed-off-by: Simon Ser Reviewed-by: Leo Liu Part-of: --- src/gallium/frontends/va/surface.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/gallium/frontends/va/surface.c b/src/gallium/frontends/va/surface.c index 2ceb180884e..d226575dc08 100644 --- a/src/gallium/frontends/va/surface.c +++ b/src/gallium/frontends/va/surface.c @@ -708,16 +708,16 @@ vlVaCreateSurfaces2(VADriverContextP ctx, unsigned int format, expected_fourcc = 0; for (i = 0; i < num_attribs && attrib_list; i++) { - if ((attrib_list[i].type == VASurfaceAttribPixelFormat) && - (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) { + if (!(attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) + continue; + + switch (attrib_list[i].type) { + case VASurfaceAttribPixelFormat: if (attrib_list[i].value.type != VAGenericValueTypeInteger) return VA_STATUS_ERROR_INVALID_PARAMETER; expected_fourcc = attrib_list[i].value.value.i; - } - - if ((attrib_list[i].type == VASurfaceAttribMemoryType) && - (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) { - + break; + case VASurfaceAttribMemoryType: if (attrib_list[i].value.type != VAGenericValueTypeInteger) return VA_STATUS_ERROR_INVALID_PARAMETER; @@ -729,13 +729,14 @@ vlVaCreateSurfaces2(VADriverContextP ctx, unsigned int format, default: return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE; } - } - - if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) && - (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) { + break; + case VASurfaceAttribExternalBufferDescriptor: if (attrib_list[i].value.type != VAGenericValueTypePointer) return VA_STATUS_ERROR_INVALID_PARAMETER; memory_attribute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p; + break; + default: + return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED; } }