st/va: implement Context Surface and Buffer
[mesa.git] / src / gallium / state_trackers / va / va_private.h
1 /**************************************************************************
2 *
3 * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4 * Copyright 2014 Advanced Micro Devices, Inc.
5 * All Rights Reserved.
6 *
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:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
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.
26 *
27 **************************************************************************/
28
29 #ifndef VA_PRIVATE_H
30 #define VA_PRIVATE_H
31
32 #include <assert.h>
33
34 #include <va/va.h>
35 #include <va/va_backend.h>
36
37 #include "pipe/p_video_enums.h"
38 #include "pipe/p_video_codec.h"
39
40 #include "vl/vl_compositor.h"
41 #include "vl/vl_csc.h"
42
43 #define VL_VA_DRIVER(ctx) ((vlVaDriver *)ctx->pDriverData)
44 #define VL_VA_PSCREEN(ctx) (VL_VA_DRIVER(ctx)->vscreen->pscreen)
45
46 static inline enum pipe_video_chroma_format
47 ChromaToPipe(int format)
48 {
49 switch (format) {
50 case VA_RT_FORMAT_YUV420:
51 return PIPE_VIDEO_CHROMA_FORMAT_420;
52 case VA_RT_FORMAT_YUV422:
53 return PIPE_VIDEO_CHROMA_FORMAT_422;
54 case VA_RT_FORMAT_YUV444:
55 return PIPE_VIDEO_CHROMA_FORMAT_444;
56 default:
57 assert(0);
58 return PIPE_VIDEO_CHROMA_FORMAT_420;
59 }
60 }
61
62 static inline VAProfile
63 PipeToProfile(enum pipe_video_profile profile)
64 {
65 switch (profile) {
66 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
67 return VAProfileMPEG2Simple;
68 case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
69 return VAProfileMPEG2Main;
70 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE:
71 return VAProfileMPEG4Simple;
72 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE:
73 return VAProfileMPEG4AdvancedSimple;
74 case PIPE_VIDEO_PROFILE_VC1_SIMPLE:
75 return VAProfileVC1Simple;
76 case PIPE_VIDEO_PROFILE_VC1_MAIN:
77 return VAProfileVC1Main;
78 case PIPE_VIDEO_PROFILE_VC1_ADVANCED:
79 return VAProfileVC1Advanced;
80 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
81 return VAProfileH264Baseline;
82 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
83 return VAProfileH264Main;
84 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
85 return VAProfileH264High;
86 case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED:
87 return VAProfileNone;
88 default:
89 assert(0);
90 return -1;
91 }
92 }
93
94 static inline enum pipe_video_profile
95 ProfileToPipe(VAProfile profile)
96 {
97 switch (profile) {
98 case VAProfileMPEG2Simple:
99 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE;
100 case VAProfileMPEG2Main:
101 return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
102 case VAProfileMPEG4Simple:
103 return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE;
104 case VAProfileMPEG4AdvancedSimple:
105 return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE;
106 case VAProfileVC1Simple:
107 return PIPE_VIDEO_PROFILE_VC1_SIMPLE;
108 case VAProfileVC1Main:
109 return PIPE_VIDEO_PROFILE_VC1_MAIN;
110 case VAProfileVC1Advanced:
111 return PIPE_VIDEO_PROFILE_VC1_ADVANCED;
112 case VAProfileH264Baseline:
113 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE;
114 case VAProfileH264Main:
115 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN;
116 case VAProfileH264High:
117 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
118 default:
119 return PIPE_VIDEO_PROFILE_UNKNOWN;
120 }
121 }
122
123 typedef struct {
124 struct vl_screen *vscreen;
125 struct pipe_context *pipe;
126 struct handle_table *htab;
127 struct vl_compositor compositor;
128 struct vl_compositor_state cstate;
129 vl_csc_matrix csc;
130 } vlVaDriver;
131
132 typedef struct {
133 struct pipe_video_codec *decoder;
134 union {
135 struct pipe_picture_desc base;
136 struct pipe_mpeg12_picture_desc mpeg12;
137 struct pipe_mpeg4_picture_desc mpeg4;
138 struct pipe_vc1_picture_desc vc1;
139 struct pipe_h264_picture_desc h264;
140 } desc;
141 } vlVaContext;
142
143 typedef struct {
144 VABufferType type;
145 unsigned int size;
146 unsigned int num_elements;
147 void *data;
148 } vlVaBuffer;
149
150 typedef struct {
151 struct pipe_video_buffer templat, *buffer;
152 struct pipe_fence_handle *fence;
153 } vlVaSurface;
154
155 // Public functions:
156 VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
157
158 // vtable functions:
159 VAStatus vlVaTerminate(VADriverContextP ctx);
160 VAStatus vlVaQueryConfigProfiles(VADriverContextP ctx, VAProfile *profile_list,int *num_profiles);
161 VAStatus vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile,
162 VAEntrypoint *entrypoint_list, int *num_entrypoints);
163 VAStatus vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
164 VAConfigAttrib *attrib_list, int num_attribs);
165 VAStatus vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
166 VAConfigAttrib *attrib_list, int num_attribs, VAConfigID *config_id);
167 VAStatus vlVaDestroyConfig(VADriverContextP ctx, VAConfigID config_id);
168 VAStatus vlVaQueryConfigAttributes(VADriverContextP ctx, VAConfigID config_id, VAProfile *profile,
169 VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, int *num_attribs);
170 VAStatus vlVaCreateSurfaces(VADriverContextP ctx, int width, int height, int format,
171 int num_surfaces, VASurfaceID *surfaces);
172 VAStatus vlVaDestroySurfaces(VADriverContextP ctx, VASurfaceID *surface_list, int num_surfaces);
173 VAStatus vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width, int picture_height,
174 int flag, VASurfaceID *render_targets, int num_render_targets, VAContextID *context);
175 VAStatus vlVaDestroyContext(VADriverContextP ctx, VAContextID context);
176 VAStatus vlVaCreateBuffer(VADriverContextP ctx, VAContextID context, VABufferType type, unsigned int size,
177 unsigned int num_elements, void *data, VABufferID *buf_id);
178 VAStatus vlVaBufferSetNumElements(VADriverContextP ctx, VABufferID buf_id, unsigned int num_elements);
179 VAStatus vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuf);
180 VAStatus vlVaUnmapBuffer(VADriverContextP ctx, VABufferID buf_id);
181 VAStatus vlVaDestroyBuffer(VADriverContextP ctx, VABufferID buffer_id);
182 VAStatus vlVaBeginPicture(VADriverContextP ctx, VAContextID context, VASurfaceID render_target);
183 VAStatus vlVaRenderPicture(VADriverContextP ctx, VAContextID context, VABufferID *buffers, int num_buffers);
184 VAStatus vlVaEndPicture(VADriverContextP ctx, VAContextID context);
185 VAStatus vlVaSyncSurface(VADriverContextP ctx, VASurfaceID render_target);
186 VAStatus vlVaQuerySurfaceStatus(VADriverContextP ctx, VASurfaceID render_target, VASurfaceStatus *status);
187 VAStatus vlVaQuerySurfaceError(VADriverContextP ctx, VASurfaceID render_target,
188 VAStatus error_status, void **error_info);
189 VAStatus vlVaPutSurface(VADriverContextP ctx, VASurfaceID surface, void* draw, short srcx, short srcy,
190 unsigned short srcw, unsigned short srch, short destx, short desty, unsigned short destw,
191 unsigned short desth, VARectangle *cliprects, unsigned int number_cliprects,
192 unsigned int flags);
193 VAStatus vlVaQueryImageFormats(VADriverContextP ctx, VAImageFormat *format_list, int *num_formats);
194 VAStatus vlVaQuerySubpictureFormats(VADriverContextP ctx, VAImageFormat *format_list,
195 unsigned int *flags, unsigned int *num_formats);
196 VAStatus vlVaCreateImage(VADriverContextP ctx, VAImageFormat *format, int width, int height, VAImage *image);
197 VAStatus vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image);
198 VAStatus vlVaDestroyImage(VADriverContextP ctx, VAImageID image);
199 VAStatus vlVaSetImagePalette(VADriverContextP ctx, VAImageID image, unsigned char *palette);
200 VAStatus vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y,
201 unsigned int width, unsigned int height, VAImageID image);
202 VAStatus vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image, int src_x, int src_y,
203 unsigned int src_width, unsigned int src_height, int dest_x, int dest_y,
204 unsigned int dest_width, unsigned int dest_height);
205 VAStatus vlVaQuerySubpictureFormats(VADriverContextP ctx, VAImageFormat *format_list,
206 unsigned int *flags, unsigned int *num_formats);
207 VAStatus vlVaCreateSubpicture(VADriverContextP ctx, VAImageID image, VASubpictureID *subpicture);
208 VAStatus vlVaDestroySubpicture(VADriverContextP ctx, VASubpictureID subpicture);
209 VAStatus vlVaSubpictureImage(VADriverContextP ctx, VASubpictureID subpicture, VAImageID image);
210 VAStatus vlVaSetSubpictureChromakey(VADriverContextP ctx, VASubpictureID subpicture,
211 unsigned int chromakey_min, unsigned int chromakey_max,
212 unsigned int chromakey_mask);
213 VAStatus vlVaSetSubpictureGlobalAlpha(VADriverContextP ctx, VASubpictureID subpicture, float global_alpha);
214 VAStatus vlVaAssociateSubpicture(VADriverContextP ctx, VASubpictureID subpicture, VASurfaceID *target_surfaces,
215 int num_surfaces, short src_x, short src_y,
216 unsigned short src_width, unsigned short src_height,
217 short dest_x, short dest_y, unsigned short dest_width, unsigned short dest_height,
218 unsigned int flags);
219 VAStatus vlVaDeassociateSubpicture(VADriverContextP ctx, VASubpictureID subpicture,
220 VASurfaceID *target_surfaces, int num_surfaces);
221 VAStatus vlVaQueryDisplayAttributes(VADriverContextP ctx, VADisplayAttribute *attr_list, int *num_attributes);
222 VAStatus vlVaGetDisplayAttributes(VADriverContextP ctx, VADisplayAttribute *attr_list, int num_attributes);
223 VAStatus vlVaSetDisplayAttributes(VADriverContextP ctx, VADisplayAttribute *attr_list, int num_attributes);
224 VAStatus vlVaBufferInfo(VADriverContextP ctx, VABufferID buf_id, VABufferType *type,
225 unsigned int *size, unsigned int *num_elements);
226 VAStatus vlVaLockSurface(VADriverContextP ctx, VASurfaceID surface, unsigned int *fourcc,
227 unsigned int *luma_stride, unsigned int *chroma_u_stride, unsigned int *chroma_v_stride,
228 unsigned int *luma_offset, unsigned int *chroma_u_offset, unsigned int *chroma_v_offset,
229 unsigned int *buffer_name, void **buffer);
230 VAStatus vlVaUnlockSurface(VADriverContextP ctx, VASurfaceID surface);
231
232 #endif //VA_PRIVATE_H