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