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