13867933ecbc34ed1f68d735282580ca1e4eedea1Christian König/************************************************************************** 23867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * 33867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian. 43867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * Copyright 2014 Advanced Micro Devices, Inc. 53867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * All Rights Reserved. 63867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * 73867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * Permission is hereby granted, free of charge, to any person obtaining a 83867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * copy of this software and associated documentation files (the 93867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * "Software"), to deal in the Software without restriction, including 103867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * without limitation the rights to use, copy, modify, merge, publish, 113867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * distribute, sub license, and/or sell copies of the Software, and to 123867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * permit persons to whom the Software is furnished to do so, subject to 133867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * the following conditions: 143867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * 153867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * The above copyright notice and this permission notice (including the 163867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * next paragraph) shall be included in all copies or substantial portions 173867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * of the Software. 183867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * 193867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 203867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 213867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 223867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR 233867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 243867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 253867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 263867933ecbc34ed1f68d735282580ca1e4eedea1Christian König * 273867933ecbc34ed1f68d735282580ca1e4eedea1Christian König **************************************************************************/ 283867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 297523db174e0a8aaf12e111b094da404213862bf9Michael Varga#include "util/u_memory.h" 307523db174e0a8aaf12e111b094da404213862bf9Michael Varga#include "util/u_handle_table.h" 317523db174e0a8aaf12e111b094da404213862bf9Michael Varga#include "util/u_sampler.h" 327523db174e0a8aaf12e111b094da404213862bf9Michael Varga 333867933ecbc34ed1f68d735282580ca1e4eedea1Christian König#include "va_private.h" 343867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 357523db174e0a8aaf12e111b094da404213862bf9Michael Vargastatic VAImageFormat subpic_formats[] = { 367523db174e0a8aaf12e111b094da404213862bf9Michael Varga { 377523db174e0a8aaf12e111b094da404213862bf9Michael Varga .fourcc = VA_FOURCC_BGRA, 387523db174e0a8aaf12e111b094da404213862bf9Michael Varga .byte_order = VA_LSB_FIRST, 397523db174e0a8aaf12e111b094da404213862bf9Michael Varga .bits_per_pixel = 32, 407523db174e0a8aaf12e111b094da404213862bf9Michael Varga .depth = 32, 417523db174e0a8aaf12e111b094da404213862bf9Michael Varga .red_mask = 0x00ff0000ul, 427523db174e0a8aaf12e111b094da404213862bf9Michael Varga .green_mask = 0x0000ff00ul, 437523db174e0a8aaf12e111b094da404213862bf9Michael Varga .blue_mask = 0x000000fful, 447523db174e0a8aaf12e111b094da404213862bf9Michael Varga .alpha_mask = 0xff000000ul, 457523db174e0a8aaf12e111b094da404213862bf9Michael Varga }, 467523db174e0a8aaf12e111b094da404213862bf9Michael Varga}; 477523db174e0a8aaf12e111b094da404213862bf9Michael Varga 483867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigVAStatus 493867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigvlVaQuerySubpictureFormats(VADriverContextP ctx, VAImageFormat *format_list, 503867933ecbc34ed1f68d735282580ca1e4eedea1Christian König unsigned int *flags, unsigned int *num_formats) 513867933ecbc34ed1f68d735282580ca1e4eedea1Christian König{ 523867933ecbc34ed1f68d735282580ca1e4eedea1Christian König if (!ctx) 533867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_INVALID_CONTEXT; 543867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 553867933ecbc34ed1f68d735282580ca1e4eedea1Christian König if (!(format_list && flags && num_formats)) 563867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_UNKNOWN; 573867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 587523db174e0a8aaf12e111b094da404213862bf9Michael Varga *num_formats = sizeof(subpic_formats)/sizeof(VAImageFormat); 597523db174e0a8aaf12e111b094da404213862bf9Michael Varga memcpy(format_list, subpic_formats, sizeof(subpic_formats)); 603867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 613867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_SUCCESS; 623867933ecbc34ed1f68d735282580ca1e4eedea1Christian König} 633867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 643867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigVAStatus 657523db174e0a8aaf12e111b094da404213862bf9Michael VargavlVaCreateSubpicture(VADriverContextP ctx, VAImageID image, 667523db174e0a8aaf12e111b094da404213862bf9Michael Varga VASubpictureID *subpicture) 673867933ecbc34ed1f68d735282580ca1e4eedea1Christian König{ 688479782361ab58eeacee7f81b18d9597553859ceChristian König vlVaDriver *drv; 697523db174e0a8aaf12e111b094da404213862bf9Michael Varga vlVaSubpicture *sub; 707523db174e0a8aaf12e111b094da404213862bf9Michael Varga VAImage *img; 717523db174e0a8aaf12e111b094da404213862bf9Michael Varga 723867933ecbc34ed1f68d735282580ca1e4eedea1Christian König if (!ctx) 733867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_INVALID_CONTEXT; 743867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 758479782361ab58eeacee7f81b18d9597553859ceChristian König drv = VL_VA_DRIVER(ctx); 768479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_lock(drv->mutex); 778479782361ab58eeacee7f81b18d9597553859ceChristian König img = handle_table_get(drv->htab, image); 788479782361ab58eeacee7f81b18d9597553859ceChristian König if (!img) { 798479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 807523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_INVALID_IMAGE; 818479782361ab58eeacee7f81b18d9597553859ceChristian König } 827523db174e0a8aaf12e111b094da404213862bf9Michael Varga 837523db174e0a8aaf12e111b094da404213862bf9Michael Varga sub = CALLOC(1, sizeof(*sub)); 848479782361ab58eeacee7f81b18d9597553859ceChristian König if (!sub) { 858479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 867523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_ALLOCATION_FAILED; 878479782361ab58eeacee7f81b18d9597553859ceChristian König } 887523db174e0a8aaf12e111b094da404213862bf9Michael Varga 897523db174e0a8aaf12e111b094da404213862bf9Michael Varga sub->image = img; 907523db174e0a8aaf12e111b094da404213862bf9Michael Varga *subpicture = handle_table_add(VL_VA_DRIVER(ctx)->htab, sub); 918479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 927523db174e0a8aaf12e111b094da404213862bf9Michael Varga 937523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_SUCCESS; 943867933ecbc34ed1f68d735282580ca1e4eedea1Christian König} 953867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 963867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigVAStatus 973867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigvlVaDestroySubpicture(VADriverContextP ctx, VASubpictureID subpicture) 983867933ecbc34ed1f68d735282580ca1e4eedea1Christian König{ 998479782361ab58eeacee7f81b18d9597553859ceChristian König vlVaDriver *drv; 1007523db174e0a8aaf12e111b094da404213862bf9Michael Varga vlVaSubpicture *sub; 1017523db174e0a8aaf12e111b094da404213862bf9Michael Varga 1023867933ecbc34ed1f68d735282580ca1e4eedea1Christian König if (!ctx) 1033867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_INVALID_CONTEXT; 1043867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 1058479782361ab58eeacee7f81b18d9597553859ceChristian König drv = VL_VA_DRIVER(ctx); 1068479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_lock(drv->mutex); 1078479782361ab58eeacee7f81b18d9597553859ceChristian König 1088479782361ab58eeacee7f81b18d9597553859ceChristian König sub = handle_table_get(drv->htab, subpicture); 1098479782361ab58eeacee7f81b18d9597553859ceChristian König if (!sub) { 1108479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 1117523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_INVALID_SUBPICTURE; 1128479782361ab58eeacee7f81b18d9597553859ceChristian König } 1137523db174e0a8aaf12e111b094da404213862bf9Michael Varga 1147523db174e0a8aaf12e111b094da404213862bf9Michael Varga FREE(sub); 1158479782361ab58eeacee7f81b18d9597553859ceChristian König handle_table_remove(drv->htab, subpicture); 1168479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 1177523db174e0a8aaf12e111b094da404213862bf9Michael Varga 1187523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_SUCCESS; 1193867933ecbc34ed1f68d735282580ca1e4eedea1Christian König} 1203867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 1213867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigVAStatus 1223867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigvlVaSubpictureImage(VADriverContextP ctx, VASubpictureID subpicture, VAImageID image) 1233867933ecbc34ed1f68d735282580ca1e4eedea1Christian König{ 1248479782361ab58eeacee7f81b18d9597553859ceChristian König vlVaDriver *drv; 1257523db174e0a8aaf12e111b094da404213862bf9Michael Varga vlVaSubpicture *sub; 1267523db174e0a8aaf12e111b094da404213862bf9Michael Varga VAImage *img; 1277523db174e0a8aaf12e111b094da404213862bf9Michael Varga 1283867933ecbc34ed1f68d735282580ca1e4eedea1Christian König if (!ctx) 1293867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_INVALID_CONTEXT; 1303867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 1318479782361ab58eeacee7f81b18d9597553859ceChristian König drv = VL_VA_DRIVER(ctx); 1328479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_lock(drv->mutex); 1338479782361ab58eeacee7f81b18d9597553859ceChristian König 1348479782361ab58eeacee7f81b18d9597553859ceChristian König img = handle_table_get(drv->htab, image); 1358479782361ab58eeacee7f81b18d9597553859ceChristian König if (!img) { 1368479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 1377523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_INVALID_IMAGE; 1388479782361ab58eeacee7f81b18d9597553859ceChristian König } 1397523db174e0a8aaf12e111b094da404213862bf9Michael Varga 1408479782361ab58eeacee7f81b18d9597553859ceChristian König sub = handle_table_get(drv->htab, subpicture); 1418479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 1427523db174e0a8aaf12e111b094da404213862bf9Michael Varga if (!sub) 1437523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_INVALID_SUBPICTURE; 1447523db174e0a8aaf12e111b094da404213862bf9Michael Varga 1457523db174e0a8aaf12e111b094da404213862bf9Michael Varga sub->image = img; 1467523db174e0a8aaf12e111b094da404213862bf9Michael Varga 1477523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_SUCCESS; 1483867933ecbc34ed1f68d735282580ca1e4eedea1Christian König} 1493867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 1503867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigVAStatus 1513867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigvlVaSetSubpictureChromakey(VADriverContextP ctx, VASubpictureID subpicture, 1523867933ecbc34ed1f68d735282580ca1e4eedea1Christian König unsigned int chromakey_min, unsigned int chromakey_max, unsigned int chromakey_mask) 1533867933ecbc34ed1f68d735282580ca1e4eedea1Christian König{ 1543867933ecbc34ed1f68d735282580ca1e4eedea1Christian König if (!ctx) 1553867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_INVALID_CONTEXT; 1563867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 1573867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_UNIMPLEMENTED; 1583867933ecbc34ed1f68d735282580ca1e4eedea1Christian König} 1593867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 1603867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigVAStatus 1613867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigvlVaSetSubpictureGlobalAlpha(VADriverContextP ctx, VASubpictureID subpicture, float global_alpha) 1623867933ecbc34ed1f68d735282580ca1e4eedea1Christian König{ 1633867933ecbc34ed1f68d735282580ca1e4eedea1Christian König if (!ctx) 1643867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_INVALID_CONTEXT; 1653867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 1663867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_UNIMPLEMENTED; 1673867933ecbc34ed1f68d735282580ca1e4eedea1Christian König} 1683867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 1693867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigVAStatus 1707523db174e0a8aaf12e111b094da404213862bf9Michael VargavlVaAssociateSubpicture(VADriverContextP ctx, VASubpictureID subpicture, 1717523db174e0a8aaf12e111b094da404213862bf9Michael Varga VASurfaceID *target_surfaces, int num_surfaces, 1727523db174e0a8aaf12e111b094da404213862bf9Michael Varga short src_x, short src_y, unsigned short src_width, 1737523db174e0a8aaf12e111b094da404213862bf9Michael Varga unsigned short src_height, short dest_x, short dest_y, 1747523db174e0a8aaf12e111b094da404213862bf9Michael Varga unsigned short dest_width, unsigned short dest_height, 1753867933ecbc34ed1f68d735282580ca1e4eedea1Christian König unsigned int flags) 1763867933ecbc34ed1f68d735282580ca1e4eedea1Christian König{ 1777523db174e0a8aaf12e111b094da404213862bf9Michael Varga vlVaSubpicture *sub; 1787523db174e0a8aaf12e111b094da404213862bf9Michael Varga struct pipe_resource tex_temp, *tex; 1797523db174e0a8aaf12e111b094da404213862bf9Michael Varga struct pipe_sampler_view sampler_templ; 1807523db174e0a8aaf12e111b094da404213862bf9Michael Varga vlVaDriver *drv; 1817523db174e0a8aaf12e111b094da404213862bf9Michael Varga vlVaSurface *surf; 1827523db174e0a8aaf12e111b094da404213862bf9Michael Varga int i; 1837523db174e0a8aaf12e111b094da404213862bf9Michael Varga struct u_rect src_rect = {src_x, src_x + src_width, src_y, src_y + src_height}; 1847523db174e0a8aaf12e111b094da404213862bf9Michael Varga struct u_rect dst_rect = {dest_x, dest_x + dest_width, dest_y, dest_y + dest_height}; 1857523db174e0a8aaf12e111b094da404213862bf9Michael Varga 1863867933ecbc34ed1f68d735282580ca1e4eedea1Christian König if (!ctx) 1873867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_INVALID_CONTEXT; 1887523db174e0a8aaf12e111b094da404213862bf9Michael Varga drv = VL_VA_DRIVER(ctx); 1898479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_lock(drv->mutex); 1907523db174e0a8aaf12e111b094da404213862bf9Michael Varga 1917523db174e0a8aaf12e111b094da404213862bf9Michael Varga sub = handle_table_get(drv->htab, subpicture); 1928479782361ab58eeacee7f81b18d9597553859ceChristian König if (!sub) { 1938479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 1947523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_INVALID_SUBPICTURE; 1958479782361ab58eeacee7f81b18d9597553859ceChristian König } 1967523db174e0a8aaf12e111b094da404213862bf9Michael Varga 1977523db174e0a8aaf12e111b094da404213862bf9Michael Varga for (i = 0; i < num_surfaces; i++) { 1987523db174e0a8aaf12e111b094da404213862bf9Michael Varga surf = handle_table_get(drv->htab, target_surfaces[i]); 1998479782361ab58eeacee7f81b18d9597553859ceChristian König if (!surf) { 2008479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 2017523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_INVALID_SURFACE; 2028479782361ab58eeacee7f81b18d9597553859ceChristian König } 2037523db174e0a8aaf12e111b094da404213862bf9Michael Varga } 2047523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2057523db174e0a8aaf12e111b094da404213862bf9Michael Varga sub->src_rect = src_rect; 2067523db174e0a8aaf12e111b094da404213862bf9Michael Varga sub->dst_rect = dst_rect; 2077523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2087523db174e0a8aaf12e111b094da404213862bf9Michael Varga memset(&tex_temp, 0, sizeof(tex_temp)); 2097523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex_temp.target = PIPE_TEXTURE_2D; 2107523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex_temp.format = PIPE_FORMAT_B8G8R8A8_UNORM; 2117523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex_temp.last_level = 0; 2127523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex_temp.width0 = src_width; 2137523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex_temp.height0 = src_height; 2147523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex_temp.depth0 = 1; 2157523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex_temp.array_size = 1; 2167523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex_temp.usage = PIPE_USAGE_DYNAMIC; 2177523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex_temp.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; 2187523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex_temp.flags = 0; 2197523db174e0a8aaf12e111b094da404213862bf9Michael Varga if (!drv->pipe->screen->is_format_supported( 2207523db174e0a8aaf12e111b094da404213862bf9Michael Varga drv->pipe->screen, tex_temp.format, tex_temp.target, 2218479782361ab58eeacee7f81b18d9597553859ceChristian König tex_temp.nr_samples, tex_temp.bind)) { 2228479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 2237523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_ALLOCATION_FAILED; 2248479782361ab58eeacee7f81b18d9597553859ceChristian König } 2257523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2267523db174e0a8aaf12e111b094da404213862bf9Michael Varga tex = drv->pipe->screen->resource_create(drv->pipe->screen, &tex_temp); 2277523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2287523db174e0a8aaf12e111b094da404213862bf9Michael Varga memset(&sampler_templ, 0, sizeof(sampler_templ)); 2297523db174e0a8aaf12e111b094da404213862bf9Michael Varga u_sampler_view_default_template(&sampler_templ, tex, tex->format); 2307523db174e0a8aaf12e111b094da404213862bf9Michael Varga sub->sampler = drv->pipe->create_sampler_view(drv->pipe, tex, &sampler_templ); 2317523db174e0a8aaf12e111b094da404213862bf9Michael Varga pipe_resource_reference(&tex, NULL); 2328479782361ab58eeacee7f81b18d9597553859ceChristian König if (!sub->sampler) { 2338479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 2347523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_ALLOCATION_FAILED; 2358479782361ab58eeacee7f81b18d9597553859ceChristian König } 2367523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2377523db174e0a8aaf12e111b094da404213862bf9Michael Varga for (i = 0; i < num_surfaces; i++) { 2387523db174e0a8aaf12e111b094da404213862bf9Michael Varga surf = handle_table_get(drv->htab, target_surfaces[i]); 2397523db174e0a8aaf12e111b094da404213862bf9Michael Varga util_dynarray_append(&surf->subpics, vlVaSubpicture *, sub); 2407523db174e0a8aaf12e111b094da404213862bf9Michael Varga } 2418479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 2423867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 2437523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_SUCCESS; 2443867933ecbc34ed1f68d735282580ca1e4eedea1Christian König} 2453867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 2463867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigVAStatus 2473867933ecbc34ed1f68d735282580ca1e4eedea1Christian KönigvlVaDeassociateSubpicture(VADriverContextP ctx, VASubpictureID subpicture, 2483867933ecbc34ed1f68d735282580ca1e4eedea1Christian König VASurfaceID *target_surfaces, int num_surfaces) 2493867933ecbc34ed1f68d735282580ca1e4eedea1Christian König{ 2507523db174e0a8aaf12e111b094da404213862bf9Michael Varga int i; 2517523db174e0a8aaf12e111b094da404213862bf9Michael Varga int j; 2527523db174e0a8aaf12e111b094da404213862bf9Michael Varga vlVaSurface *surf; 2537523db174e0a8aaf12e111b094da404213862bf9Michael Varga vlVaSubpicture *sub, **array; 2547523db174e0a8aaf12e111b094da404213862bf9Michael Varga vlVaDriver *drv; 2557523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2563867933ecbc34ed1f68d735282580ca1e4eedea1Christian König if (!ctx) 2573867933ecbc34ed1f68d735282580ca1e4eedea1Christian König return VA_STATUS_ERROR_INVALID_CONTEXT; 2587523db174e0a8aaf12e111b094da404213862bf9Michael Varga drv = VL_VA_DRIVER(ctx); 2598479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_lock(drv->mutex); 2603867933ecbc34ed1f68d735282580ca1e4eedea1Christian König 2617523db174e0a8aaf12e111b094da404213862bf9Michael Varga sub = handle_table_get(drv->htab, subpicture); 2628479782361ab58eeacee7f81b18d9597553859ceChristian König if (!sub) { 2638479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 2647523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_INVALID_SUBPICTURE; 2658479782361ab58eeacee7f81b18d9597553859ceChristian König } 2667523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2677523db174e0a8aaf12e111b094da404213862bf9Michael Varga for (i = 0; i < num_surfaces; i++) { 2687523db174e0a8aaf12e111b094da404213862bf9Michael Varga surf = handle_table_get(drv->htab, target_surfaces[i]); 2698479782361ab58eeacee7f81b18d9597553859ceChristian König if (!surf) { 2708479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 2717523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_ERROR_INVALID_SURFACE; 2728479782361ab58eeacee7f81b18d9597553859ceChristian König } 2737523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2747523db174e0a8aaf12e111b094da404213862bf9Michael Varga array = surf->subpics.data; 2757523db174e0a8aaf12e111b094da404213862bf9Michael Varga if (!array) 2767523db174e0a8aaf12e111b094da404213862bf9Michael Varga continue; 2777523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2787523db174e0a8aaf12e111b094da404213862bf9Michael Varga for (j = 0; j < surf->subpics.size/sizeof(vlVaSubpicture *); j++) { 2797523db174e0a8aaf12e111b094da404213862bf9Michael Varga if (array[j] == sub) 2807523db174e0a8aaf12e111b094da404213862bf9Michael Varga array[j] = NULL; 2817523db174e0a8aaf12e111b094da404213862bf9Michael Varga } 2827523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2837523db174e0a8aaf12e111b094da404213862bf9Michael Varga while (surf->subpics.size && util_dynarray_top(&surf->subpics, vlVaSubpicture *) == NULL) 2847523db174e0a8aaf12e111b094da404213862bf9Michael Varga (void)util_dynarray_pop(&surf->subpics, vlVaSubpicture *); 2857523db174e0a8aaf12e111b094da404213862bf9Michael Varga } 2868479782361ab58eeacee7f81b18d9597553859ceChristian König pipe_mutex_unlock(drv->mutex); 2877523db174e0a8aaf12e111b094da404213862bf9Michael Varga 2887523db174e0a8aaf12e111b094da404213862bf9Michael Varga return VA_STATUS_SUCCESS; 2893867933ecbc34ed1f68d735282580ca1e4eedea1Christian König} 290