1 /**************************************************************************
2  *
3  * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #include <va/va.h>
29 #include <va/va_backend.h>
30 #include "util/u_debug.h"
31 #include "util/u_memory.h"
32 #include "va_private.h"
33 
34 static enum pipe_video_chroma_format
VaRTFormatToPipe(unsigned int va_type)35 VaRTFormatToPipe(unsigned int va_type)
36 {
37    switch (va_type) {
38    case VA_RT_FORMAT_YUV420:
39       return PIPE_VIDEO_CHROMA_FORMAT_420;
40    case VA_RT_FORMAT_YUV422:
41       return PIPE_VIDEO_CHROMA_FORMAT_422;
42    case VA_RT_FORMAT_YUV444:
43       return PIPE_VIDEO_CHROMA_FORMAT_444;
44    default:
45       assert(0);
46    }
47 
48    return -1;
49 }
50 
51 VAStatus
vlVaCreateSurfaces(VADriverContextP ctx,int width,int height,int format,int num_surfaces,VASurfaceID * surfaces)52 vlVaCreateSurfaces(VADriverContextP ctx, int width, int height, int format,
53                    int num_surfaces, VASurfaceID *surfaces)
54 {
55    if (!ctx)
56       return VA_STATUS_ERROR_INVALID_CONTEXT;
57 
58    /* We only support one format */
59    if (VA_RT_FORMAT_YUV420 != format)
60       return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
61 
62    if (!(width && height))
63       return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
64 
65    if (!vlCreateHTAB())
66       return VA_STATUS_ERROR_UNKNOWN;
67 
68    vlVaSurfacePriv *va_surface = (vlVaSurfacePriv *)CALLOC(num_surfaces,sizeof(vlVaSurfacePriv));
69    if (!va_surface)
70       return VA_STATUS_ERROR_ALLOCATION_FAILED;
71 
72    int n = 0;
73    for (n = 0; n < num_surfaces; n++) {
74       va_surface[n].width = width;
75       va_surface[n].height = height;
76       va_surface[n].format = VaRTFormatToPipe(format);
77       va_surface[n].ctx = ctx;
78       surfaces[n] = vlAddDataHTAB((void *)(va_surface + n));
79    }
80 
81    return VA_STATUS_SUCCESS;
82 }
83 
84 VAStatus
vlVaDestroySurfaces(VADriverContextP ctx,VASurfaceID * surface_list,int num_surfaces)85 vlVaDestroySurfaces(VADriverContextP ctx, VASurfaceID *surface_list, int num_surfaces)
86 {
87    if (!ctx)
88       return VA_STATUS_ERROR_INVALID_CONTEXT;
89 
90    return VA_STATUS_ERROR_UNIMPLEMENTED;
91 }
92 
93 VAStatus
vlVaSyncSurface(VADriverContextP ctx,VASurfaceID render_target)94 vlVaSyncSurface(VADriverContextP ctx, VASurfaceID render_target)
95 {
96    if (!ctx)
97       return VA_STATUS_ERROR_INVALID_CONTEXT;
98 
99    return VA_STATUS_ERROR_UNIMPLEMENTED;
100 }
101 
102 VAStatus
vlVaQuerySurfaceStatus(VADriverContextP ctx,VASurfaceID render_target,VASurfaceStatus * status)103 vlVaQuerySurfaceStatus(VADriverContextP ctx, VASurfaceID render_target, VASurfaceStatus *status)
104 {
105    if (!ctx)
106       return VA_STATUS_ERROR_INVALID_CONTEXT;
107 
108    return VA_STATUS_ERROR_UNIMPLEMENTED;
109 }
110 
111 VAStatus
vlVaPutSurface(VADriverContextP ctx,VASurfaceID surface,void * draw,short srcx,short srcy,unsigned short srcw,unsigned short srch,short destx,short desty,unsigned short destw,unsigned short desth,VARectangle * cliprects,unsigned int number_cliprects,unsigned int flags)112 vlVaPutSurface(VADriverContextP ctx, VASurfaceID surface, void* draw, short srcx, short srcy,
113                unsigned short srcw, unsigned short srch, short destx, short desty,
114                unsigned short destw, unsigned short desth, VARectangle *cliprects,
115                unsigned int number_cliprects,  unsigned int flags)
116 {
117    if (!ctx)
118       return VA_STATUS_ERROR_INVALID_CONTEXT;
119 
120    return VA_STATUS_ERROR_UNIMPLEMENTED;
121 }
122 
123 VAStatus
vlVaLockSurface(VADriverContextP ctx,VASurfaceID surface,unsigned int * fourcc,unsigned int * luma_stride,unsigned int * chroma_u_stride,unsigned int * chroma_v_stride,unsigned int * luma_offset,unsigned int * chroma_u_offset,unsigned int * chroma_v_offset,unsigned int * buffer_name,void ** buffer)124 vlVaLockSurface(VADriverContextP ctx, VASurfaceID surface, unsigned int *fourcc,
125                 unsigned int *luma_stride, unsigned int *chroma_u_stride, unsigned int *chroma_v_stride,
126                 unsigned int *luma_offset, unsigned int *chroma_u_offset, unsigned int *chroma_v_offset,
127                 unsigned int *buffer_name, void **buffer)
128 {
129    if (!ctx)
130       return VA_STATUS_ERROR_INVALID_CONTEXT;
131 
132    return VA_STATUS_ERROR_UNIMPLEMENTED;
133 }
134 
135 VAStatus
vlVaUnlockSurface(VADriverContextP ctx,VASurfaceID surface)136 vlVaUnlockSurface(VADriverContextP ctx, VASurfaceID surface)
137 {
138    if (!ctx)
139       return VA_STATUS_ERROR_INVALID_CONTEXT;
140 
141    return VA_STATUS_ERROR_UNIMPLEMENTED;
142 }
143