diff options
author | Drew Davenport <[email protected]> | 2018-04-27 09:34:58 -0600 |
---|---|---|
committer | Kristian H. Kristensen <[email protected]> | 2018-05-03 15:48:35 -0700 |
commit | 4373dd32154a232efde65859568eb0259c5f885c (patch) | |
tree | 1bf05fc7c1629667f728e6496be6cdd89c2da5c9 | |
parent | 7cf284f18e6774c810ed6db17b98e597bf96f8a5 (diff) |
st/va: Support YUV formats in vaCreateSurfaces
Reviewed-by: Kristian H. Kristensen <[email protected]>
-rw-r--r-- | src/gallium/state_trackers/va/surface.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/src/gallium/state_trackers/va/surface.c b/src/gallium/state_trackers/va/surface.c index 0824f1b74a9..003f88f1f9e 100644 --- a/src/gallium/state_trackers/va/surface.c +++ b/src/gallium/state_trackers/va/surface.c @@ -531,10 +531,12 @@ surface_from_external_memory(VADriverContextP ctx, vlVaSurface *surface, { vlVaDriver *drv; struct pipe_screen *pscreen; - struct pipe_resource *resource; struct pipe_resource res_templ; struct winsys_handle whandle; struct pipe_resource *resources[VL_NUM_COMPONENTS]; + const enum pipe_format *resource_formats = NULL; + VAStatus result; + int i; pscreen = VL_VA_PSCREEN(ctx); drv = VL_VA_DRIVER(ctx); @@ -548,17 +550,12 @@ surface_from_external_memory(VADriverContextP ctx, vlVaSurface *surface, memory_attribute->num_planes < 1) return VA_STATUS_ERROR_INVALID_PARAMETER; - switch (memory_attribute->pixel_format) { - case VA_FOURCC_RGBA: - case VA_FOURCC_RGBX: - case VA_FOURCC_BGRA: - case VA_FOURCC_BGRX: - if (memory_attribute->num_planes != 1) - return VA_STATUS_ERROR_INVALID_PARAMETER; - break; - default: + if (memory_attribute->num_planes > VL_NUM_COMPONENTS) + return VA_STATUS_ERROR_INVALID_PARAMETER; + + resource_formats = vl_video_buffer_formats(pscreen, templat->buffer_format); + if (!resource_formats) return VA_STATUS_ERROR_INVALID_PARAMETER; - } memset(&res_templ, 0, sizeof(res_templ)); res_templ.target = PIPE_TEXTURE_2D; @@ -567,29 +564,45 @@ surface_from_external_memory(VADriverContextP ctx, vlVaSurface *surface, res_templ.array_size = 1; res_templ.width0 = memory_attribute->width; res_templ.height0 = memory_attribute->height; - res_templ.format = surface->templat.buffer_format; res_templ.bind = PIPE_BIND_SAMPLER_VIEW; res_templ.usage = PIPE_USAGE_DEFAULT; memset(&whandle, 0, sizeof(struct winsys_handle)); whandle.type = DRM_API_HANDLE_TYPE_FD; whandle.handle = memory_attribute->buffers[index]; - whandle.stride = memory_attribute->pitches[0]; - - resource = pscreen->resource_from_handle(pscreen, &res_templ, &whandle, - PIPE_HANDLE_USAGE_READ_WRITE); - - if (!resource) - return VA_STATUS_ERROR_ALLOCATION_FAILED; + // Create a resource for each plane. memset(resources, 0, sizeof resources); - resources[0] = resource; + for (i = 0; i < memory_attribute->num_planes; i++) { + res_templ.format = resource_formats[i]; + if (res_templ.format == PIPE_FORMAT_NONE) { + result = VA_STATUS_ERROR_INVALID_PARAMETER; + goto fail; + } - surface->buffer = vl_video_buffer_create_ex2(drv->pipe, templat, resources); - if (!surface->buffer) - return VA_STATUS_ERROR_ALLOCATION_FAILED; + whandle.stride = memory_attribute->pitches[i]; + whandle.offset = memory_attribute->offsets[i]; + resources[i] = pscreen->resource_from_handle(pscreen, &res_templ, &whandle, + PIPE_HANDLE_USAGE_READ_WRITE); + if (!resources[i]) { + result = VA_STATUS_ERROR_ALLOCATION_FAILED; + goto fail; + } + } + surface->buffer = vl_video_buffer_create_ex2(drv->pipe, templat, resources); + if (!surface->buffer) { + result = VA_STATUS_ERROR_ALLOCATION_FAILED; + goto fail; + } return VA_STATUS_SUCCESS; + +fail: + for (i = 0; i < VL_NUM_COMPONENTS; i++) { + if (resources[i]) + pscreen->resource_destroy(pscreen, resources[i]); + } + return result; } VAStatus |