Merge branch 'gallium-polygon-stipple'
[mesa.git] / src / gallium / state_trackers / vdpau / vdpau_private.h
1 /**************************************************************************
2 *
3 * Copyright 2010 Younes Manton & Thomas Balling Sørensen.
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 #ifndef VDPAU_PRIVATE_H
29 #define VDPAU_PRIVATE_H
30
31 #include <assert.h>
32
33 #include <vdpau/vdpau.h>
34 #include <vdpau/vdpau_x11.h>
35
36 #include <pipe/p_compiler.h>
37 #include <pipe/p_video_decoder.h>
38
39 #include <util/u_debug.h>
40 #include <vl/vl_compositor.h>
41
42 #include <vl_winsys.h>
43
44 #define INFORMATION G3DVL VDPAU Driver Shared Library version VER_MAJOR.VER_MINOR
45 #define QUOTEME(x) #x
46 #define TOSTRING(x) QUOTEME(x)
47 #define INFORMATION_STRING TOSTRING(INFORMATION)
48 #define VL_HANDLES
49 #define VL_NUM_DECODE_BUFFERS 4
50
51 static inline enum pipe_video_chroma_format
52 ChromaToPipe(VdpChromaType vdpau_type)
53 {
54 switch (vdpau_type) {
55 case VDP_CHROMA_TYPE_420:
56 return PIPE_VIDEO_CHROMA_FORMAT_420;
57 case VDP_CHROMA_TYPE_422:
58 return PIPE_VIDEO_CHROMA_FORMAT_422;
59 case VDP_CHROMA_TYPE_444:
60 return PIPE_VIDEO_CHROMA_FORMAT_444;
61 default:
62 assert(0);
63 }
64
65 return -1;
66 }
67
68 static inline VdpChromaType
69 PipeToChroma(enum pipe_video_chroma_format pipe_type)
70 {
71 switch (pipe_type) {
72 case PIPE_VIDEO_CHROMA_FORMAT_420:
73 return VDP_CHROMA_TYPE_420;
74 case PIPE_VIDEO_CHROMA_FORMAT_422:
75 return VDP_CHROMA_TYPE_422;
76 case PIPE_VIDEO_CHROMA_FORMAT_444:
77 return VDP_CHROMA_TYPE_444;
78 default:
79 assert(0);
80 }
81
82 return -1;
83 }
84
85
86 static inline enum pipe_format
87 FormatYCBCRToPipe(VdpYCbCrFormat vdpau_format)
88 {
89 switch (vdpau_format) {
90 case VDP_YCBCR_FORMAT_NV12:
91 return PIPE_FORMAT_NV12;
92 case VDP_YCBCR_FORMAT_YV12:
93 return PIPE_FORMAT_YV12;
94 case VDP_YCBCR_FORMAT_UYVY:
95 return PIPE_FORMAT_UYVY;
96 case VDP_YCBCR_FORMAT_YUYV:
97 return PIPE_FORMAT_YUYV;
98 case VDP_YCBCR_FORMAT_Y8U8V8A8: /* Not defined in p_format.h */
99 return 0;
100 case VDP_YCBCR_FORMAT_V8U8Y8A8:
101 return PIPE_FORMAT_VUYA;
102 default:
103 assert(0);
104 }
105
106 return -1;
107 }
108
109 static inline VdpYCbCrFormat
110 PipeToFormatYCBCR(enum pipe_format p_format)
111 {
112 switch (p_format) {
113 case PIPE_FORMAT_NV12:
114 return VDP_YCBCR_FORMAT_NV12;
115 case PIPE_FORMAT_YV12:
116 return VDP_YCBCR_FORMAT_YV12;
117 case PIPE_FORMAT_UYVY:
118 return VDP_YCBCR_FORMAT_UYVY;
119 case PIPE_FORMAT_YUYV:
120 return VDP_YCBCR_FORMAT_YUYV;
121 //case PIPE_FORMAT_YUVA:
122 // return VDP_YCBCR_FORMAT_Y8U8V8A8;
123 case PIPE_FORMAT_VUYA:
124 return VDP_YCBCR_FORMAT_V8U8Y8A8;
125 default:
126 assert(0);
127 }
128
129 return -1;
130 }
131
132 static inline enum pipe_format
133 FormatRGBAToPipe(VdpRGBAFormat vdpau_format)
134 {
135 switch (vdpau_format) {
136 case VDP_RGBA_FORMAT_A8:
137 return PIPE_FORMAT_A8_UNORM;
138 case VDP_RGBA_FORMAT_B10G10R10A2:
139 return PIPE_FORMAT_B10G10R10A2_UNORM;
140 case VDP_RGBA_FORMAT_B8G8R8A8:
141 return PIPE_FORMAT_B8G8R8A8_UNORM;
142 case VDP_RGBA_FORMAT_R10G10B10A2:
143 return PIPE_FORMAT_R10G10B10A2_UNORM;
144 case VDP_RGBA_FORMAT_R8G8B8A8:
145 return PIPE_FORMAT_R8G8B8A8_UNORM;
146 default:
147 assert(0);
148 }
149
150 return -1;
151 }
152
153 static inline VdpRGBAFormat
154 PipeToFormatRGBA(enum pipe_format p_format)
155 {
156 switch (p_format) {
157 case PIPE_FORMAT_A8_UNORM:
158 return VDP_RGBA_FORMAT_A8;
159 case PIPE_FORMAT_B10G10R10A2_UNORM:
160 return VDP_RGBA_FORMAT_B10G10R10A2;
161 case PIPE_FORMAT_B8G8R8A8_UNORM:
162 return VDP_RGBA_FORMAT_B8G8R8A8;
163 case PIPE_FORMAT_R10G10B10A2_UNORM:
164 return VDP_RGBA_FORMAT_R10G10B10A2;
165 case PIPE_FORMAT_R8G8B8A8_UNORM:
166 return VDP_RGBA_FORMAT_R8G8B8A8;
167 default:
168 assert(0);
169 }
170
171 return -1;
172 }
173
174 static inline enum pipe_video_profile
175 ProfileToPipe(VdpDecoderProfile vdpau_profile)
176 {
177 switch (vdpau_profile) {
178 case VDP_DECODER_PROFILE_MPEG1:
179 return PIPE_VIDEO_PROFILE_MPEG1;
180 case VDP_DECODER_PROFILE_MPEG2_SIMPLE:
181 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE;
182 case VDP_DECODER_PROFILE_MPEG2_MAIN:
183 return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
184 case VDP_DECODER_PROFILE_H264_BASELINE:
185 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE;
186 case VDP_DECODER_PROFILE_H264_MAIN: /* Not defined in p_format.h */
187 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN;
188 case VDP_DECODER_PROFILE_H264_HIGH:
189 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
190 default:
191 return PIPE_VIDEO_PROFILE_UNKNOWN;
192 }
193 }
194
195 static inline VdpDecoderProfile
196 PipeToProfile(enum pipe_video_profile p_profile)
197 {
198 switch (p_profile) {
199 case PIPE_VIDEO_PROFILE_MPEG1:
200 return VDP_DECODER_PROFILE_MPEG1;
201 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
202 return VDP_DECODER_PROFILE_MPEG2_SIMPLE;
203 case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
204 return VDP_DECODER_PROFILE_MPEG2_MAIN;
205 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
206 return VDP_DECODER_PROFILE_H264_BASELINE;
207 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN: /* Not defined in p_format.h */
208 return VDP_DECODER_PROFILE_H264_MAIN;
209 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
210 return VDP_DECODER_PROFILE_H264_HIGH;
211 default:
212 assert(0);
213 return -1;
214 }
215 }
216
217 typedef struct
218 {
219 struct vl_screen *vscreen;
220 struct vl_context *context;
221 } vlVdpDevice;
222
223 typedef struct
224 {
225 vlVdpDevice *device;
226 Drawable drawable;
227 } vlVdpPresentationQueueTarget;
228
229 typedef struct
230 {
231 vlVdpDevice *device;
232 Drawable drawable;
233 struct vl_compositor compositor;
234 } vlVdpPresentationQueue;
235
236 typedef struct
237 {
238 vlVdpDevice *device;
239 struct vl_compositor compositor;
240 } vlVdpVideoMixer;
241
242 typedef struct
243 {
244 vlVdpDevice *device;
245 struct pipe_video_buffer *video_buffer;
246 } vlVdpSurface;
247
248 typedef struct
249 {
250 vlVdpDevice *device;
251 struct pipe_surface *surface;
252 struct pipe_sampler_view *sampler_view;
253 } vlVdpOutputSurface;
254
255 typedef struct
256 {
257 vlVdpDevice *device;
258 struct pipe_video_decoder *decoder;
259 struct pipe_video_decode_buffer *buffer[VL_NUM_DECODE_BUFFERS];
260 unsigned cur_buffer;
261 } vlVdpDecoder;
262
263 typedef uint32_t vlHandle;
264
265 boolean vlCreateHTAB(void);
266 void vlDestroyHTAB(void);
267 vlHandle vlAddDataHTAB(void *data);
268 void* vlGetDataHTAB(vlHandle handle);
269 void vlRemoveDataHTAB(vlHandle handle);
270
271 boolean vlGetFuncFTAB(VdpFuncId function_id, void **func);
272
273 /* Public functions */
274 VdpDeviceCreateX11 vdp_imp_device_create_x11;
275 VdpPresentationQueueTargetCreateX11 vlVdpPresentationQueueTargetCreateX11;
276
277 /* Internal function pointers */
278 VdpGetErrorString vlVdpGetErrorString;
279 VdpDeviceDestroy vlVdpDeviceDestroy;
280 VdpGetProcAddress vlVdpGetProcAddress;
281 VdpGetApiVersion vlVdpGetApiVersion;
282 VdpGetInformationString vlVdpGetInformationString;
283 VdpVideoSurfaceQueryCapabilities vlVdpVideoSurfaceQueryCapabilities;
284 VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities;
285 VdpDecoderQueryCapabilities vlVdpDecoderQueryCapabilities;
286 VdpOutputSurfaceQueryCapabilities vlVdpOutputSurfaceQueryCapabilities;
287 VdpOutputSurfaceQueryGetPutBitsNativeCapabilities vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities;
288 VdpOutputSurfaceQueryPutBitsIndexedCapabilities vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities;
289 VdpOutputSurfaceQueryPutBitsYCbCrCapabilities vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities;
290 VdpBitmapSurfaceQueryCapabilities vlVdpBitmapSurfaceQueryCapabilities;
291 VdpVideoMixerQueryFeatureSupport vlVdpVideoMixerQueryFeatureSupport;
292 VdpVideoMixerQueryParameterSupport vlVdpVideoMixerQueryParameterSupport;
293 VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange;
294 VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport;
295 VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange;
296 VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate;
297 VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy;
298 VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters;
299 VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr;
300 VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr;
301 VdpDecoderCreate vlVdpDecoderCreate;
302 VdpDecoderDestroy vlVdpDecoderDestroy;
303 VdpDecoderGetParameters vlVdpDecoderGetParameters;
304 VdpDecoderRender vlVdpDecoderRender;
305 VdpOutputSurfaceCreate vlVdpOutputSurfaceCreate;
306 VdpOutputSurfaceDestroy vlVdpOutputSurfaceDestroy;
307 VdpOutputSurfaceGetParameters vlVdpOutputSurfaceGetParameters;
308 VdpOutputSurfaceGetBitsNative vlVdpOutputSurfaceGetBitsNative;
309 VdpOutputSurfacePutBitsNative vlVdpOutputSurfacePutBitsNative;
310 VdpOutputSurfacePutBitsIndexed vlVdpOutputSurfacePutBitsIndexed;
311 VdpOutputSurfacePutBitsYCbCr vlVdpOutputSurfacePutBitsYCbCr;
312 VdpOutputSurfaceRenderOutputSurface vlVdpOutputSurfaceRenderOutputSurface;
313 VdpOutputSurfaceRenderBitmapSurface vlVdpOutputSurfaceRenderBitmapSurface;
314 VdpBitmapSurfaceCreate vlVdpBitmapSurfaceCreate;
315 VdpBitmapSurfaceDestroy vlVdpBitmapSurfaceDestroy;
316 VdpBitmapSurfaceGetParameters vlVdpBitmapSurfaceGetParameters;
317 VdpBitmapSurfacePutBitsNative vlVdpBitmapSurfacePutBitsNative;
318 VdpPresentationQueueTargetDestroy vlVdpPresentationQueueTargetDestroy;
319 VdpPresentationQueueCreate vlVdpPresentationQueueCreate;
320 VdpPresentationQueueDestroy vlVdpPresentationQueueDestroy;
321 VdpPresentationQueueSetBackgroundColor vlVdpPresentationQueueSetBackgroundColor;
322 VdpPresentationQueueGetBackgroundColor vlVdpPresentationQueueGetBackgroundColor;
323 VdpPresentationQueueGetTime vlVdpPresentationQueueGetTime;
324 VdpPresentationQueueDisplay vlVdpPresentationQueueDisplay;
325 VdpPresentationQueueBlockUntilSurfaceIdle vlVdpPresentationQueueBlockUntilSurfaceIdle;
326 VdpPresentationQueueQuerySurfaceStatus vlVdpPresentationQueueQuerySurfaceStatus;
327 VdpPreemptionCallback vlVdpPreemptionCallback;
328 VdpPreemptionCallbackRegister vlVdpPreemptionCallbackRegister;
329 VdpVideoMixerSetFeatureEnables vlVdpVideoMixerSetFeatureEnables;
330 VdpVideoMixerCreate vlVdpVideoMixerCreate;
331 VdpVideoMixerRender vlVdpVideoMixerRender;
332 VdpVideoMixerSetAttributeValues vlVdpVideoMixerSetAttributeValues;
333 VdpVideoMixerGetFeatureSupport vlVdpVideoMixerGetFeatureSupport;
334 VdpVideoMixerGetFeatureEnables vlVdpVideoMixerGetFeatureEnables;
335 VdpVideoMixerGetParameterValues vlVdpVideoMixerGetParameterValues;
336 VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues;
337 VdpVideoMixerDestroy vlVdpVideoMixerDestroy;
338 VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix;
339
340 #define VDPAU_OUT 0
341 #define VDPAU_ERR 1
342 #define VDPAU_WARN 2
343 #define VDPAU_TRACE 3
344
345 static inline void VDPAU_MSG(unsigned int level, const char *fmt, ...)
346 {
347 static int debug_level = -1;
348
349 if (debug_level == -1) {
350 debug_level = MAX2(debug_get_num_option("VDPAU_DEBUG", 0), 0);
351 }
352
353 if (level <= debug_level) {
354 va_list ap;
355 va_start(ap, fmt);
356 _debug_vprintf(fmt, ap);
357 va_end(ap);
358 }
359 }
360
361 #endif // VDPAU_PRIVATE_H