Merge branch 'master' into pipe-video
[mesa.git] / src / gallium / state_trackers / vdpau / query.c
1 /**************************************************************************
2 *
3 * Copyright 2010 Younes Manton.
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 #include "vdpau_private.h"
29 #include <vl_winsys.h>
30 #include <assert.h>
31 #include <pipe/p_screen.h>
32 #include <pipe/p_defines.h>
33 #include <math.h>
34 #include <util/u_debug.h>
35
36
37 VdpStatus
38 vlVdpGetApiVersion(uint32_t *api_version)
39 {
40 if (!api_version)
41 return VDP_STATUS_INVALID_POINTER;
42
43 *api_version = 1;
44 return VDP_STATUS_OK;
45 }
46
47 VdpStatus
48 vlVdpGetInformationString(char const **information_string)
49 {
50 if (!information_string)
51 return VDP_STATUS_INVALID_POINTER;
52
53 *information_string = INFORMATION_STRING;
54 return VDP_STATUS_OK;
55 }
56
57 VdpStatus
58 vlVdpVideoSurfaceQueryCapabilities(VdpDevice device, VdpChromaType surface_chroma_type,
59 VdpBool *is_supported, uint32_t *max_width, uint32_t *max_height)
60 {
61 struct vl_screen *vlscreen;
62 uint32_t max_2d_texture_level;
63 VdpStatus ret;
64
65 debug_printf("[VDPAU] Querying video surfaces\n");
66
67 if (!(is_supported && max_width && max_height))
68 return VDP_STATUS_INVALID_POINTER;
69
70 vlVdpDevice *dev = vlGetDataHTAB(device);
71 if (!dev)
72 return VDP_STATUS_INVALID_HANDLE;
73
74 vlscreen = vl_screen_create(dev->display, dev->screen);
75 if (!vlscreen)
76 return VDP_STATUS_RESOURCES;
77
78 /* XXX: Current limits */
79 *is_supported = true;
80 if (surface_chroma_type != VDP_CHROMA_TYPE_420) {
81 *is_supported = false;
82 goto no_sup;
83 }
84
85 max_2d_texture_level = vlscreen->pscreen->get_param( vlscreen->pscreen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS );
86 if (!max_2d_texture_level) {
87 ret = VDP_STATUS_RESOURCES;
88 goto no_sup;
89 }
90
91 /* I am not quite sure if it is max_2d_texture_level-1 or just max_2d_texture_level */
92 *max_width = *max_height = pow(2,max_2d_texture_level-1);
93
94 vl_screen_destroy(vlscreen);
95
96 return VDP_STATUS_OK;
97 no_sup:
98 return ret;
99 }
100
101 VdpStatus
102 vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities(VdpDevice device, VdpChromaType surface_chroma_type,
103 VdpYCbCrFormat bits_ycbcr_format,
104 VdpBool *is_supported)
105 {
106 struct vl_screen *vlscreen;
107
108 debug_printf("[VDPAU] Querying get put video surfaces\n");
109
110 if (!is_supported)
111 return VDP_STATUS_INVALID_POINTER;
112
113 vlVdpDevice *dev = vlGetDataHTAB(device);
114 if (!dev)
115 return VDP_STATUS_INVALID_HANDLE;
116
117 vlscreen = vl_screen_create(dev->display, dev->screen);
118 if (!vlscreen)
119 return VDP_STATUS_RESOURCES;
120
121 if (bits_ycbcr_format != VDP_YCBCR_FORMAT_Y8U8V8A8 && bits_ycbcr_format != VDP_YCBCR_FORMAT_V8U8Y8A8)
122 *is_supported = vlscreen->pscreen->is_format_supported(vlscreen->pscreen,
123 FormatToPipe(bits_ycbcr_format),
124 PIPE_TEXTURE_2D,
125 PIPE_BIND_RENDER_TARGET,
126 PIPE_TEXTURE_GEOM_NON_SQUARE );
127
128 vl_screen_destroy(vlscreen);
129
130 return VDP_STATUS_OK;
131 }
132
133 VdpStatus
134 vlVdpDecoderQueryCapabilities(VdpDevice device, VdpDecoderProfile profile,
135 VdpBool *is_supported, uint32_t *max_level, uint32_t *max_macroblocks,
136 uint32_t *max_width, uint32_t *max_height)
137 {
138 enum pipe_video_profile p_profile;
139 uint32_t max_decode_width;
140 uint32_t max_decode_height;
141 uint32_t max_2d_texture_level;
142 struct vl_screen *vlscreen;
143
144 debug_printf("[VDPAU] Querying decoder\n");
145
146 if (!(is_supported && max_level && max_macroblocks && max_width && max_height))
147 return VDP_STATUS_INVALID_POINTER;
148
149 vlVdpDevice *dev = vlGetDataHTAB(device);
150 if (!dev)
151 return VDP_STATUS_INVALID_HANDLE;
152
153 vlscreen = vl_screen_create(dev->display, dev->screen);
154 if (!vlscreen)
155 return VDP_STATUS_RESOURCES;
156
157 p_profile = ProfileToPipe(profile);
158 if (p_profile == PIPE_VIDEO_PROFILE_UNKNOWN) {
159 *is_supported = false;
160 return VDP_STATUS_OK;
161 }
162
163 if (p_profile != PIPE_VIDEO_PROFILE_MPEG2_SIMPLE && p_profile != PIPE_VIDEO_PROFILE_MPEG2_MAIN) {
164 *is_supported = false;
165 return VDP_STATUS_OK;
166 }
167
168 /* XXX hack, need to implement something more sane when the decoders have been implemented */
169 max_2d_texture_level = vlscreen->pscreen->get_param( vlscreen->pscreen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS );
170 max_decode_width = max_decode_height = pow(2,max_2d_texture_level-2);
171 if (!(max_decode_width && max_decode_height))
172 return VDP_STATUS_RESOURCES;
173
174 *is_supported = true;
175 *max_width = max_decode_width;
176 *max_height = max_decode_height;
177 *max_level = 16;
178 *max_macroblocks = (max_decode_width/16) * (max_decode_height/16);
179
180 vl_screen_destroy(vlscreen);
181
182 return VDP_STATUS_OK;
183 }
184
185 VdpStatus
186 vlVdpOutputSurfaceQueryCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format,
187 VdpBool *is_supported, uint32_t *max_width, uint32_t *max_height)
188 {
189 if (!(is_supported && max_width && max_height))
190 return VDP_STATUS_INVALID_POINTER;
191
192 debug_printf("[VDPAU] Querying ouput surfaces\n");
193
194 return VDP_STATUS_NO_IMPLEMENTATION;
195 }
196
197 VdpStatus
198 vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format,
199 VdpBool *is_supported)
200 {
201 debug_printf("[VDPAU] Querying output surfaces get put native cap\n");
202
203 if (!is_supported)
204 return VDP_STATUS_INVALID_POINTER;
205
206 return VDP_STATUS_NO_IMPLEMENTATION;
207 }
208
209 VdpStatus
210 vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format,
211 VdpYCbCrFormat bits_ycbcr_format,
212 VdpBool *is_supported)
213 {
214 debug_printf("[VDPAU] Querying output surfaces put ycrcb cap\n");
215 if (!is_supported)
216 return VDP_STATUS_INVALID_POINTER;
217
218 return VDP_STATUS_NO_IMPLEMENTATION;
219 }
220
221 VdpStatus
222 vlVdpBitmapSurfaceQueryCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format,
223 VdpBool *is_supported, uint32_t *max_width, uint32_t *max_height)
224 {
225 debug_printf("[VDPAU] Querying bitmap surfaces\n");
226 if (!(is_supported && max_width && max_height))
227 return VDP_STATUS_INVALID_POINTER;
228
229 return VDP_STATUS_NO_IMPLEMENTATION;
230 }
231
232 VdpStatus
233 vlVdpVideoMixerQueryFeatureSupport(VdpDevice device, VdpVideoMixerFeature feature,
234 VdpBool *is_supported)
235 {
236 debug_printf("[VDPAU] Querying mixer feature support\n");
237 if (!is_supported)
238 return VDP_STATUS_INVALID_POINTER;
239
240 return VDP_STATUS_NO_IMPLEMENTATION;
241 }
242
243 VdpStatus
244 vlVdpVideoMixerQueryParameterSupport(VdpDevice device, VdpVideoMixerParameter parameter,
245 VdpBool *is_supported)
246 {
247 if (!is_supported)
248 return VDP_STATUS_INVALID_POINTER;
249
250 return VDP_STATUS_NO_IMPLEMENTATION;
251 }
252
253 VdpStatus
254 vlVdpVideoMixerQueryParameterValueRange(VdpDevice device, VdpVideoMixerParameter parameter,
255 void *min_value, void *max_value)
256 {
257 if (!(min_value && max_value))
258 return VDP_STATUS_INVALID_POINTER;
259
260 return VDP_STATUS_NO_IMPLEMENTATION;
261 }
262
263 VdpStatus
264 vlVdpVideoMixerQueryAttributeSupport(VdpDevice device, VdpVideoMixerAttribute attribute,
265 VdpBool *is_supported)
266 {
267 if (!is_supported)
268 return VDP_STATUS_INVALID_POINTER;
269
270 return VDP_STATUS_NO_IMPLEMENTATION;
271 }
272
273 VdpStatus
274 vlVdpVideoMixerQueryAttributeValueRange(VdpDevice device, VdpVideoMixerAttribute attribute,
275 void *min_value, void *max_value)
276 {
277 if (!(min_value && max_value))
278 return VDP_STATUS_INVALID_POINTER;
279
280 return VDP_STATUS_NO_IMPLEMENTATION;
281 }