1 /**************************************************************************
3 * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4 * Copyright 2014 Advanced Micro Devices, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
29 #include "pipe/p_screen.h"
30 #include "pipe/p_video_codec.h"
32 #include "state_tracker/drm_driver.h"
34 #include "util/u_memory.h"
35 #include "util/u_handle_table.h"
36 #include "util/u_rect.h"
37 #include "util/u_sampler.h"
38 #include "util/u_surface.h"
40 #include "vl/vl_compositor.h"
41 #include "vl/vl_video_buffer.h"
42 #include "vl/vl_winsys.h"
44 #include "va_private.h"
46 #include <va/va_drmcommon.h>
48 static const enum pipe_format vpp_surface_formats
[] = {
49 PIPE_FORMAT_B8G8R8A8_UNORM
, PIPE_FORMAT_R8G8B8A8_UNORM
,
50 PIPE_FORMAT_B8G8R8X8_UNORM
, PIPE_FORMAT_R8G8B8X8_UNORM
54 vlVaCreateSurfaces(VADriverContextP ctx
, int width
, int height
, int format
,
55 int num_surfaces
, VASurfaceID
*surfaces
)
57 return vlVaCreateSurfaces2(ctx
, format
, width
, height
, surfaces
, num_surfaces
,
62 vlVaDestroySurfaces(VADriverContextP ctx
, VASurfaceID
*surface_list
, int num_surfaces
)
68 return VA_STATUS_ERROR_INVALID_CONTEXT
;
70 drv
= VL_VA_DRIVER(ctx
);
71 for (i
= 0; i
< num_surfaces
; ++i
) {
72 vlVaSurface
*surf
= handle_table_get(drv
->htab
, surface_list
[i
]);
74 surf
->buffer
->destroy(surf
->buffer
);
76 drv
->pipe
->screen
->fence_reference(drv
->pipe
->screen
, &surf
->fence
, NULL
);
77 util_dynarray_fini(&surf
->subpics
);
79 handle_table_remove(drv
->htab
, surface_list
[i
]);
82 return VA_STATUS_SUCCESS
;
86 vlVaSyncSurface(VADriverContextP ctx
, VASurfaceID render_target
)
89 return VA_STATUS_ERROR_INVALID_CONTEXT
;
91 return VA_STATUS_SUCCESS
;
95 vlVaQuerySurfaceStatus(VADriverContextP ctx
, VASurfaceID render_target
, VASurfaceStatus
*status
)
98 return VA_STATUS_ERROR_INVALID_CONTEXT
;
100 return VA_STATUS_SUCCESS
;
104 vlVaQuerySurfaceError(VADriverContextP ctx
, VASurfaceID render_target
, VAStatus error_status
, void **error_info
)
107 return VA_STATUS_ERROR_INVALID_CONTEXT
;
109 return VA_STATUS_ERROR_UNIMPLEMENTED
;
113 upload_sampler(struct pipe_context
*pipe
, struct pipe_sampler_view
*dst
,
114 const struct pipe_box
*dst_box
, const void *src
, unsigned src_stride
,
115 unsigned src_x
, unsigned src_y
)
117 struct pipe_transfer
*transfer
;
120 map
= pipe
->transfer_map(pipe
, dst
->texture
, 0, PIPE_TRANSFER_WRITE
,
125 util_copy_rect(map
, dst
->texture
->format
, transfer
->stride
, 0, 0,
126 dst_box
->width
, dst_box
->height
,
127 src
, src_stride
, src_x
, src_y
);
129 pipe
->transfer_unmap(pipe
, transfer
);
133 vlVaPutSubpictures(vlVaSurface
*surf
, vlVaDriver
*drv
,
134 struct pipe_surface
*surf_draw
, struct u_rect
*dirty_area
,
135 struct u_rect
*src_rect
, struct u_rect
*dst_rect
)
140 if (!(surf
->subpics
.data
|| surf
->subpics
.size
))
141 return VA_STATUS_SUCCESS
;
143 for (i
= 0; i
< surf
->subpics
.size
/sizeof(vlVaSubpicture
*); i
++) {
144 struct pipe_blend_state blend
;
148 struct u_rect
*s
, *d
, sr
, dr
, c
;
151 sub
= ((vlVaSubpicture
**)surf
->subpics
.data
)[i
];
155 buf
= handle_table_get(drv
->htab
, sub
->image
->buf
);
157 return VA_STATUS_ERROR_INVALID_IMAGE
;
162 box
.width
= sub
->dst_rect
.x1
- sub
->dst_rect
.x0
;
163 box
.height
= sub
->dst_rect
.y1
- sub
->dst_rect
.y0
;
172 c
.x0
= MAX2(d
->x0
, s
->x0
);
173 c
.y0
= MAX2(d
->y0
, s
->y0
);
174 c
.x1
= MIN2(d
->x0
+ dw
, src_rect
->x1
);
175 c
.y1
= MIN2(d
->y0
+ dh
, src_rect
->y1
);
176 sr
.x0
= s
->x0
+ (c
.x0
- d
->x0
)*(sw
/(float)dw
);
177 sr
.y0
= s
->y0
+ (c
.y0
- d
->y0
)*(sh
/(float)dh
);
178 sr
.x1
= s
->x0
+ (c
.x1
- d
->x0
)*(sw
/(float)dw
);
179 sr
.y1
= s
->y0
+ (c
.y1
- d
->y0
)*(sh
/(float)dh
);
187 dr
.x0
= d
->x0
+ c
.x0
*(dw
/(float)sw
);
188 dr
.y0
= d
->y0
+ c
.y0
*(dh
/(float)sh
);
189 dr
.x1
= d
->x0
+ c
.x1
*(dw
/(float)sw
);
190 dr
.y1
= d
->y0
+ c
.y1
*(dh
/(float)sh
);
192 memset(&blend
, 0, sizeof(blend
));
193 blend
.independent_blend_enable
= 0;
194 blend
.rt
[0].blend_enable
= 1;
195 blend
.rt
[0].rgb_src_factor
= PIPE_BLENDFACTOR_SRC_ALPHA
;
196 blend
.rt
[0].rgb_dst_factor
= PIPE_BLENDFACTOR_INV_SRC_ALPHA
;
197 blend
.rt
[0].alpha_src_factor
= PIPE_BLENDFACTOR_ZERO
;
198 blend
.rt
[0].alpha_dst_factor
= PIPE_BLENDFACTOR_ZERO
;
199 blend
.rt
[0].rgb_func
= PIPE_BLEND_ADD
;
200 blend
.rt
[0].alpha_func
= PIPE_BLEND_ADD
;
201 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
202 blend
.logicop_enable
= 0;
203 blend
.logicop_func
= PIPE_LOGICOP_CLEAR
;
205 blend_state
= drv
->pipe
->create_blend_state(drv
->pipe
, &blend
);
207 vl_compositor_clear_layers(&drv
->cstate
);
208 vl_compositor_set_layer_blend(&drv
->cstate
, 0, blend_state
, false);
209 upload_sampler(drv
->pipe
, sub
->sampler
, &box
, buf
->data
,
210 sub
->image
->pitches
[0], 0, 0);
211 vl_compositor_set_rgba_layer(&drv
->cstate
, &drv
->compositor
, 0, sub
->sampler
,
213 vl_compositor_set_layer_dst_area(&drv
->cstate
, 0, &dr
);
214 vl_compositor_render(&drv
->cstate
, &drv
->compositor
, surf_draw
, dirty_area
, false);
215 drv
->pipe
->delete_blend_state(drv
->pipe
, blend_state
);
218 return VA_STATUS_SUCCESS
;
222 vlVaPutSurface(VADriverContextP ctx
, VASurfaceID surface_id
, void* draw
, short srcx
, short srcy
,
223 unsigned short srcw
, unsigned short srch
, short destx
, short desty
,
224 unsigned short destw
, unsigned short desth
, VARectangle
*cliprects
,
225 unsigned int number_cliprects
, unsigned int flags
)
229 struct pipe_screen
*screen
;
230 struct pipe_resource
*tex
;
231 struct pipe_surface surf_templ
, *surf_draw
;
232 struct vl_screen
*vscreen
;
233 struct u_rect src_rect
, *dirty_area
;
234 struct u_rect dst_rect
= {destx
, destx
+ destw
, desty
, desty
+ desth
};
238 return VA_STATUS_ERROR_INVALID_CONTEXT
;
240 drv
= VL_VA_DRIVER(ctx
);
241 surf
= handle_table_get(drv
->htab
, surface_id
);
243 return VA_STATUS_ERROR_INVALID_SURFACE
;
245 screen
= drv
->pipe
->screen
;
246 vscreen
= drv
->vscreen
;
249 screen
->fence_finish(screen
, surf
->fence
, PIPE_TIMEOUT_INFINITE
);
250 screen
->fence_reference(screen
, &surf
->fence
, NULL
);
253 tex
= vscreen
->texture_from_drawable(vscreen
, draw
);
255 return VA_STATUS_ERROR_INVALID_DISPLAY
;
257 dirty_area
= vscreen
->get_dirty_area(vscreen
);
259 memset(&surf_templ
, 0, sizeof(surf_templ
));
260 surf_templ
.format
= tex
->format
;
261 surf_draw
= drv
->pipe
->create_surface(drv
->pipe
, tex
, &surf_templ
);
263 pipe_resource_reference(&tex
, NULL
);
264 return VA_STATUS_ERROR_INVALID_DISPLAY
;
269 src_rect
.x1
= srcw
+ srcx
;
270 src_rect
.y1
= srch
+ srcy
;
272 vl_compositor_clear_layers(&drv
->cstate
);
273 vl_compositor_set_buffer_layer(&drv
->cstate
, &drv
->compositor
, 0, surf
->buffer
, &src_rect
, NULL
, VL_COMPOSITOR_WEAVE
);
274 vl_compositor_set_layer_dst_area(&drv
->cstate
, 0, &dst_rect
);
275 vl_compositor_render(&drv
->cstate
, &drv
->compositor
, surf_draw
, dirty_area
, true);
277 status
= vlVaPutSubpictures(surf
, drv
, surf_draw
, dirty_area
, &src_rect
, &dst_rect
);
281 screen
->flush_frontbuffer(screen
, tex
, 0, 0,
282 vscreen
->get_private(vscreen
), NULL
);
284 screen
->fence_reference(screen
, &surf
->fence
, NULL
);
285 drv
->pipe
->flush(drv
->pipe
, &surf
->fence
, 0);
287 pipe_resource_reference(&tex
, NULL
);
288 pipe_surface_reference(&surf_draw
, NULL
);
290 return VA_STATUS_SUCCESS
;
294 vlVaLockSurface(VADriverContextP ctx
, VASurfaceID surface
, unsigned int *fourcc
,
295 unsigned int *luma_stride
, unsigned int *chroma_u_stride
, unsigned int *chroma_v_stride
,
296 unsigned int *luma_offset
, unsigned int *chroma_u_offset
, unsigned int *chroma_v_offset
,
297 unsigned int *buffer_name
, void **buffer
)
300 return VA_STATUS_ERROR_INVALID_CONTEXT
;
302 return VA_STATUS_ERROR_UNIMPLEMENTED
;
306 vlVaUnlockSurface(VADriverContextP ctx
, VASurfaceID surface
)
309 return VA_STATUS_ERROR_INVALID_CONTEXT
;
311 return VA_STATUS_ERROR_UNIMPLEMENTED
;
315 vlVaQuerySurfaceAttributes(VADriverContextP ctx
, VAConfigID config
,
316 VASurfaceAttrib
*attrib_list
, unsigned int *num_attribs
)
319 VASurfaceAttrib
*attribs
;
320 struct pipe_screen
*pscreen
;
323 STATIC_ASSERT(ARRAY_SIZE(vpp_surface_formats
) <= VL_VA_MAX_IMAGE_FORMATS
);
325 if (config
== VA_INVALID_ID
)
326 return VA_STATUS_ERROR_INVALID_CONFIG
;
328 if (!attrib_list
&& !num_attribs
)
329 return VA_STATUS_ERROR_INVALID_PARAMETER
;
332 *num_attribs
= VL_VA_MAX_IMAGE_FORMATS
+ VASurfaceAttribCount
;
333 return VA_STATUS_SUCCESS
;
337 return VA_STATUS_ERROR_INVALID_CONTEXT
;
339 drv
= VL_VA_DRIVER(ctx
);
342 return VA_STATUS_ERROR_INVALID_CONTEXT
;
344 pscreen
= VL_VA_PSCREEN(ctx
);
347 return VA_STATUS_ERROR_INVALID_CONTEXT
;
349 attribs
= CALLOC(VL_VA_MAX_IMAGE_FORMATS
+ VASurfaceAttribCount
,
350 sizeof(VASurfaceAttrib
));
353 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
357 /* vlVaCreateConfig returns PIPE_VIDEO_PROFILE_UNKNOWN
358 * only for VAEntrypointVideoProc. */
359 if (config
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
360 for (j
= 0; j
< ARRAY_SIZE(vpp_surface_formats
); ++j
) {
361 attribs
[i
].type
= VASurfaceAttribPixelFormat
;
362 attribs
[i
].value
.type
= VAGenericValueTypeInteger
;
363 attribs
[i
].flags
= VA_SURFACE_ATTRIB_GETTABLE
| VA_SURFACE_ATTRIB_SETTABLE
;
364 attribs
[i
].value
.value
.i
= PipeFormatToVaFourcc(vpp_surface_formats
[j
]);
368 /* Assume VAEntrypointVLD for now. */
369 attribs
[i
].type
= VASurfaceAttribPixelFormat
;
370 attribs
[i
].value
.type
= VAGenericValueTypeInteger
;
371 attribs
[i
].flags
= VA_SURFACE_ATTRIB_GETTABLE
| VA_SURFACE_ATTRIB_SETTABLE
;
372 attribs
[i
].value
.value
.i
= VA_FOURCC_NV12
;
376 attribs
[i
].type
= VASurfaceAttribMemoryType
;
377 attribs
[i
].value
.type
= VAGenericValueTypeInteger
;
378 attribs
[i
].flags
= VA_SURFACE_ATTRIB_GETTABLE
| VA_SURFACE_ATTRIB_SETTABLE
;
379 attribs
[i
].value
.value
.i
= VA_SURFACE_ATTRIB_MEM_TYPE_VA
|
380 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME
;
383 attribs
[i
].type
= VASurfaceAttribExternalBufferDescriptor
;
384 attribs
[i
].value
.type
= VAGenericValueTypePointer
;
385 attribs
[i
].flags
= VA_SURFACE_ATTRIB_SETTABLE
;
386 attribs
[i
].value
.value
.p
= NULL
; /* ignore */
389 attribs
[i
].type
= VASurfaceAttribMaxWidth
;
390 attribs
[i
].value
.type
= VAGenericValueTypeInteger
;
391 attribs
[i
].flags
= VA_SURFACE_ATTRIB_GETTABLE
;
392 attribs
[i
].value
.value
.i
= vl_video_buffer_max_size(pscreen
);
395 attribs
[i
].type
= VASurfaceAttribMaxHeight
;
396 attribs
[i
].value
.type
= VAGenericValueTypeInteger
;
397 attribs
[i
].flags
= VA_SURFACE_ATTRIB_GETTABLE
;
398 attribs
[i
].value
.value
.i
= vl_video_buffer_max_size(pscreen
);
401 if (i
> *num_attribs
) {
404 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED
;
408 memcpy(attrib_list
, attribs
, i
* sizeof(VASurfaceAttrib
));
411 return VA_STATUS_SUCCESS
;
415 suface_from_external_memory(VADriverContextP ctx
, vlVaSurface
*surface
,
416 VASurfaceAttribExternalBuffers
*memory_attibute
,
417 int index
, VASurfaceID
*surfaces
,
418 struct pipe_video_buffer
*templat
)
421 struct pipe_screen
*pscreen
;
422 struct pipe_resource
*resource
;
423 struct pipe_resource res_templ
;
424 struct winsys_handle whandle
;
425 struct pipe_resource
*resources
[VL_NUM_COMPONENTS
];
428 return VA_STATUS_ERROR_INVALID_PARAMETER
;
430 pscreen
= VL_VA_PSCREEN(ctx
);
431 drv
= VL_VA_DRIVER(ctx
);
433 if (!memory_attibute
|| !memory_attibute
->buffers
||
434 index
> memory_attibute
->num_buffers
)
435 return VA_STATUS_ERROR_INVALID_PARAMETER
;
437 if (surface
->templat
.width
!= memory_attibute
->width
||
438 surface
->templat
.height
!= memory_attibute
->height
||
439 memory_attibute
->num_planes
< 1)
440 return VA_STATUS_ERROR_INVALID_PARAMETER
;
442 switch (memory_attibute
->pixel_format
) {
447 if (memory_attibute
->num_planes
!= 1)
448 return VA_STATUS_ERROR_INVALID_PARAMETER
;
451 return VA_STATUS_ERROR_INVALID_PARAMETER
;
454 memset(&res_templ
, 0, sizeof(res_templ
));
455 res_templ
.target
= PIPE_TEXTURE_2D
;
456 res_templ
.last_level
= 0;
457 res_templ
.depth0
= 1;
458 res_templ
.array_size
= 1;
459 res_templ
.width0
= memory_attibute
->width
;
460 res_templ
.height0
= memory_attibute
->height
;
461 res_templ
.format
= surface
->templat
.buffer_format
;
462 res_templ
.bind
= PIPE_BIND_SAMPLER_VIEW
;
463 res_templ
.usage
= PIPE_USAGE_DEFAULT
;
465 memset(&whandle
, 0, sizeof(struct winsys_handle
));
466 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
467 whandle
.handle
= memory_attibute
->buffers
[index
];
468 whandle
.stride
= memory_attibute
->pitches
[index
];
470 resource
= pscreen
->resource_from_handle(pscreen
, &res_templ
, &whandle
);
473 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
475 memset(resources
, 0, sizeof resources
);
476 resources
[0] = resource
;
478 surface
->buffer
= vl_video_buffer_create_ex2(drv
->pipe
, templat
, resources
);
479 if (!surface
->buffer
)
480 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
482 util_dynarray_init(&surface
->subpics
);
483 surfaces
[index
] = handle_table_add(drv
->htab
, surface
);
485 if (!surfaces
[index
]) {
486 surface
->buffer
->destroy(surface
->buffer
);
487 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
490 return VA_STATUS_SUCCESS
;
494 vlVaCreateSurfaces2(VADriverContextP ctx
, unsigned int format
,
495 unsigned int width
, unsigned int height
,
496 VASurfaceID
*surfaces
, unsigned int num_surfaces
,
497 VASurfaceAttrib
*attrib_list
, unsigned int num_attribs
)
500 VASurfaceAttribExternalBuffers
*memory_attibute
;
501 struct pipe_video_buffer templat
;
502 struct pipe_screen
*pscreen
;
509 return VA_STATUS_ERROR_INVALID_CONTEXT
;
511 if (!(width
&& height
))
512 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT
;
514 drv
= VL_VA_DRIVER(ctx
);
517 return VA_STATUS_ERROR_INVALID_CONTEXT
;
519 pscreen
= VL_VA_PSCREEN(ctx
);
522 return VA_STATUS_ERROR_INVALID_CONTEXT
;
525 memory_attibute
= NULL
;
526 memory_type
= VA_SURFACE_ATTRIB_MEM_TYPE_VA
;
529 for (i
= 0; i
< num_attribs
&& attrib_list
; i
++) {
530 if ((attrib_list
[i
].type
== VASurfaceAttribPixelFormat
) &&
531 (attrib_list
[i
].flags
& VA_SURFACE_ATTRIB_SETTABLE
)) {
532 if (attrib_list
[i
].value
.type
!= VAGenericValueTypeInteger
)
533 return VA_STATUS_ERROR_INVALID_PARAMETER
;
534 expected_fourcc
= attrib_list
[i
].value
.value
.i
;
537 if ((attrib_list
[i
].type
== VASurfaceAttribMemoryType
) &&
538 (attrib_list
[i
].flags
& VA_SURFACE_ATTRIB_SETTABLE
)) {
540 if (attrib_list
[i
].value
.type
!= VAGenericValueTypeInteger
)
541 return VA_STATUS_ERROR_INVALID_PARAMETER
;
543 switch (attrib_list
[i
].value
.value
.i
) {
544 case VA_SURFACE_ATTRIB_MEM_TYPE_VA
:
545 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME
:
546 memory_type
= attrib_list
[i
].value
.value
.i
;
549 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE
;
553 if ((attrib_list
[i
].type
== VASurfaceAttribExternalBufferDescriptor
) &&
554 (attrib_list
[i
].flags
== VA_SURFACE_ATTRIB_SETTABLE
)) {
555 if (attrib_list
[i
].value
.type
!= VAGenericValueTypePointer
)
556 return VA_STATUS_ERROR_INVALID_PARAMETER
;
557 memory_attibute
= (VASurfaceAttribExternalBuffers
*)attrib_list
[i
].value
.value
.p
;
561 if (VA_RT_FORMAT_YUV420
!= format
&&
562 VA_RT_FORMAT_YUV422
!= format
&&
563 VA_RT_FORMAT_YUV444
!= format
&&
564 VA_RT_FORMAT_RGB32
!= format
) {
565 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT
;
568 switch (memory_type
) {
569 case VA_SURFACE_ATTRIB_MEM_TYPE_VA
:
571 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME
:
572 if (!memory_attibute
)
573 return VA_STATUS_ERROR_INVALID_PARAMETER
;
575 expected_fourcc
= memory_attibute
->pixel_format
;
581 memset(&templat
, 0, sizeof(templat
));
583 if (expected_fourcc
) {
584 templat
.buffer_format
= VaFourccToPipeFormat(expected_fourcc
);
585 templat
.interlaced
= 0;
587 templat
.buffer_format
= pscreen
->get_video_param
590 PIPE_VIDEO_PROFILE_UNKNOWN
,
591 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
592 PIPE_VIDEO_CAP_PREFERED_FORMAT
594 templat
.interlaced
= pscreen
->get_video_param
597 PIPE_VIDEO_PROFILE_UNKNOWN
,
598 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
599 PIPE_VIDEO_CAP_PREFERS_INTERLACED
603 templat
.chroma_format
= ChromaToPipe(format
);
605 templat
.width
= width
;
606 templat
.height
= height
;
608 memset(surfaces
, VA_INVALID_ID
, num_surfaces
* sizeof(VASurfaceID
));
610 for (i
= 0; i
< num_surfaces
; i
++) {
611 vlVaSurface
*surf
= CALLOC(1, sizeof(vlVaSurface
));
615 surf
->templat
= templat
;
617 switch (memory_type
) {
618 case VA_SURFACE_ATTRIB_MEM_TYPE_VA
:
619 surf
->buffer
= drv
->pipe
->create_video_buffer(drv
->pipe
, &templat
);
624 util_dynarray_init(&surf
->subpics
);
625 surfaces
[i
] = handle_table_add(drv
->htab
, surf
);
627 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME
:
628 vaStatus
= suface_from_external_memory(ctx
, surf
, memory_attibute
, i
, surfaces
, &templat
);
629 if (vaStatus
!= VA_STATUS_SUCCESS
) {
639 return VA_STATUS_SUCCESS
;
643 vlVaDestroySurfaces(ctx
, surfaces
, i
);
645 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
649 vlVaQueryVideoProcFilters(VADriverContextP ctx
, VAContextID context
,
650 VAProcFilterType
*filters
, unsigned int *num_filters
)
652 unsigned int num
= 0;
655 return VA_STATUS_ERROR_INVALID_CONTEXT
;
657 if (!num_filters
|| !filters
)
658 return VA_STATUS_ERROR_INVALID_PARAMETER
;
660 filters
[num
++] = VAProcFilterNone
;
664 return VA_STATUS_SUCCESS
;
668 vlVaQueryVideoProcFilterCaps(VADriverContextP ctx
, VAContextID context
,
669 VAProcFilterType type
, void *filter_caps
,
670 unsigned int *num_filter_caps
)
675 return VA_STATUS_ERROR_INVALID_CONTEXT
;
677 if (!filter_caps
|| !num_filter_caps
)
678 return VA_STATUS_ERROR_INVALID_PARAMETER
;
683 case VAProcFilterNone
:
685 case VAProcFilterNoiseReduction
:
686 case VAProcFilterDeinterlacing
:
687 case VAProcFilterSharpening
:
688 case VAProcFilterColorBalance
:
689 case VAProcFilterSkinToneEnhancement
:
690 return VA_STATUS_ERROR_UNIMPLEMENTED
;
695 *num_filter_caps
= i
;
697 return VA_STATUS_SUCCESS
;
700 static VAProcColorStandardType vpp_input_color_standards
[] = {
701 VAProcColorStandardBT601
704 static VAProcColorStandardType vpp_output_color_standards
[] = {
705 VAProcColorStandardBT601
709 vlVaQueryVideoProcPipelineCaps(VADriverContextP ctx
, VAContextID context
,
710 VABufferID
*filters
, unsigned int num_filters
,
711 VAProcPipelineCaps
*pipeline_cap
)
716 return VA_STATUS_ERROR_INVALID_CONTEXT
;
719 return VA_STATUS_ERROR_INVALID_PARAMETER
;
721 if (num_filters
&& !filters
)
722 return VA_STATUS_ERROR_INVALID_PARAMETER
;
724 pipeline_cap
->pipeline_flags
= 0;
725 pipeline_cap
->filter_flags
= 0;
726 pipeline_cap
->num_forward_references
= 0;
727 pipeline_cap
->num_backward_references
= 0;
728 pipeline_cap
->num_input_color_standards
= Elements(vpp_input_color_standards
);
729 pipeline_cap
->input_color_standards
= vpp_input_color_standards
;
730 pipeline_cap
->num_output_color_standards
= Elements(vpp_output_color_standards
);
731 pipeline_cap
->output_color_standards
= vpp_output_color_standards
;
733 for (i
= 0; i
< num_filters
; i
++) {
734 vlVaBuffer
*buf
= handle_table_get(VL_VA_DRIVER(ctx
)->htab
, filters
[i
]);
736 if (!buf
|| buf
->type
>= VABufferTypeMax
)
737 return VA_STATUS_ERROR_INVALID_BUFFER
;
740 return VA_STATUS_SUCCESS
;