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