1 /**************************************************************************
3 * Copyright 2010 Younes Manton.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
31 #include "vdpau_private.h"
32 #include "pipe/p_screen.h"
33 #include "pipe/p_defines.h"
34 #include "util/u_debug.h"
37 * Retrieve the VDPAU version implemented by the backend.
40 vlVdpGetApiVersion(uint32_t *api_version
)
43 return VDP_STATUS_INVALID_POINTER
;
50 * Retrieve an implementation-specific string description of the implementation.
51 * This typically includes detailed version information.
54 vlVdpGetInformationString(char const **information_string
)
56 if (!information_string
)
57 return VDP_STATUS_INVALID_POINTER
;
59 *information_string
= INFORMATION_STRING
;
64 * Query the implementation's VdpVideoSurface capabilities.
67 vlVdpVideoSurfaceQueryCapabilities(VdpDevice device
, VdpChromaType surface_chroma_type
,
68 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
71 struct pipe_screen
*pscreen
;
72 uint32_t max_2d_texture_level
;
74 if (!(is_supported
&& max_width
&& max_height
))
75 return VDP_STATUS_INVALID_POINTER
;
77 dev
= vlGetDataHTAB(device
);
79 return VDP_STATUS_INVALID_HANDLE
;
81 pscreen
= dev
->vscreen
->pscreen
;
83 return VDP_STATUS_RESOURCES
;
85 pipe_mutex_lock(dev
->mutex
);
87 /* XXX: Current limits */
89 max_2d_texture_level
= pscreen
->get_param(pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
90 pipe_mutex_unlock(dev
->mutex
);
91 if (!max_2d_texture_level
)
92 return VDP_STATUS_RESOURCES
;
94 /* I am not quite sure if it is max_2d_texture_level-1 or just max_2d_texture_level */
95 *max_width
= *max_height
= pow(2,max_2d_texture_level
-1);
101 * Query the implementation's VdpVideoSurface GetBits/PutBits capabilities.
104 vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities(VdpDevice device
, VdpChromaType surface_chroma_type
,
105 VdpYCbCrFormat bits_ycbcr_format
,
106 VdpBool
*is_supported
)
109 struct pipe_screen
*pscreen
;
112 return VDP_STATUS_INVALID_POINTER
;
114 dev
= vlGetDataHTAB(device
);
116 return VDP_STATUS_INVALID_HANDLE
;
118 pscreen
= dev
->vscreen
->pscreen
;
120 return VDP_STATUS_RESOURCES
;
122 pipe_mutex_lock(dev
->mutex
);
124 switch(bits_ycbcr_format
) {
125 case VDP_YCBCR_FORMAT_UYVY
:
126 case VDP_YCBCR_FORMAT_YUYV
:
127 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_422
;
130 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
131 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
132 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_444
;
136 *is_supported
= true;
140 *is_supported
&= pscreen
->is_video_format_supported
143 FormatYCBCRToPipe(bits_ycbcr_format
),
144 PIPE_VIDEO_PROFILE_UNKNOWN
,
145 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
147 pipe_mutex_unlock(dev
->mutex
);
149 return VDP_STATUS_OK
;
153 * Query the implementation's VdpDecoder capabilities.
156 vlVdpDecoderQueryCapabilities(VdpDevice device
, VdpDecoderProfile profile
,
157 VdpBool
*is_supported
, uint32_t *max_level
, uint32_t *max_macroblocks
,
158 uint32_t *max_width
, uint32_t *max_height
)
161 struct pipe_screen
*pscreen
;
162 enum pipe_video_profile p_profile
;
164 if (!(is_supported
&& max_level
&& max_macroblocks
&& max_width
&& max_height
))
165 return VDP_STATUS_INVALID_POINTER
;
167 dev
= vlGetDataHTAB(device
);
169 return VDP_STATUS_INVALID_HANDLE
;
171 pscreen
= dev
->vscreen
->pscreen
;
173 return VDP_STATUS_RESOURCES
;
175 p_profile
= ProfileToPipe(profile
);
176 if (p_profile
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
177 *is_supported
= false;
178 return VDP_STATUS_OK
;
181 pipe_mutex_lock(dev
->mutex
);
182 *is_supported
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
183 PIPE_VIDEO_CAP_SUPPORTED
);
185 *max_width
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
186 PIPE_VIDEO_CAP_MAX_WIDTH
);
187 *max_height
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
188 PIPE_VIDEO_CAP_MAX_HEIGHT
);
189 *max_level
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
190 PIPE_VIDEO_CAP_MAX_LEVEL
);
191 *max_macroblocks
= (*max_width
/16)*(*max_height
/16);
196 *max_macroblocks
= 0;
198 pipe_mutex_unlock(dev
->mutex
);
200 return VDP_STATUS_OK
;
204 * Query the implementation's VdpOutputSurface capabilities.
207 vlVdpOutputSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
208 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
211 struct pipe_screen
*pscreen
;
212 enum pipe_format format
;
214 dev
= vlGetDataHTAB(device
);
216 return VDP_STATUS_INVALID_HANDLE
;
218 pscreen
= dev
->vscreen
->pscreen
;
220 return VDP_STATUS_RESOURCES
;
222 format
= FormatRGBAToPipe(surface_rgba_format
);
223 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
224 return VDP_STATUS_INVALID_RGBA_FORMAT
;
226 if (!(is_supported
&& max_width
&& max_height
))
227 return VDP_STATUS_INVALID_POINTER
;
229 pipe_mutex_lock(dev
->mutex
);
230 *is_supported
= pscreen
->is_format_supported
232 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
233 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
236 uint32_t max_2d_texture_level
= pscreen
->get_param(
237 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
239 if (!max_2d_texture_level
) {
240 pipe_mutex_unlock(dev
->mutex
);
241 return VDP_STATUS_ERROR
;
244 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
249 pipe_mutex_unlock(dev
->mutex
);
251 return VDP_STATUS_OK
;
255 * Query the implementation's capability to perform a PutBits operation using
256 * application data matching the surface's format.
259 vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
260 VdpBool
*is_supported
)
263 struct pipe_screen
*pscreen
;
264 enum pipe_format format
;
266 dev
= vlGetDataHTAB(device
);
268 return VDP_STATUS_INVALID_HANDLE
;
270 pscreen
= dev
->vscreen
->pscreen
;
272 return VDP_STATUS_ERROR
;
274 format
= FormatRGBAToPipe(surface_rgba_format
);
275 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
276 return VDP_STATUS_INVALID_RGBA_FORMAT
;
279 return VDP_STATUS_INVALID_POINTER
;
281 pipe_mutex_lock(dev
->mutex
);
282 *is_supported
= pscreen
->is_format_supported
284 pscreen
, format
, PIPE_TEXTURE_2D
, 1,
285 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
287 pipe_mutex_unlock(dev
->mutex
);
289 return VDP_STATUS_OK
;
293 * Query the implementation's capability to perform a PutBits operation using
294 * application data in a specific indexed format.
297 vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities(VdpDevice device
,
298 VdpRGBAFormat surface_rgba_format
,
299 VdpIndexedFormat bits_indexed_format
,
300 VdpColorTableFormat color_table_format
,
301 VdpBool
*is_supported
)
304 struct pipe_screen
*pscreen
;
305 enum pipe_format rgba_format
, index_format
, colortbl_format
;
307 dev
= vlGetDataHTAB(device
);
309 return VDP_STATUS_INVALID_HANDLE
;
311 pscreen
= dev
->vscreen
->pscreen
;
313 return VDP_STATUS_ERROR
;
315 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
316 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
317 return VDP_STATUS_INVALID_RGBA_FORMAT
;
319 index_format
= FormatIndexedToPipe(bits_indexed_format
);
320 if (index_format
== PIPE_FORMAT_NONE
)
321 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
323 colortbl_format
= FormatColorTableToPipe(color_table_format
);
324 if (colortbl_format
== PIPE_FORMAT_NONE
)
325 return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT
;
328 return VDP_STATUS_INVALID_POINTER
;
330 pipe_mutex_lock(dev
->mutex
);
331 *is_supported
= pscreen
->is_format_supported
333 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
334 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
337 *is_supported
&= pscreen
->is_format_supported
339 pscreen
, index_format
, PIPE_TEXTURE_2D
, 1,
340 PIPE_BIND_SAMPLER_VIEW
343 *is_supported
&= pscreen
->is_format_supported
345 pscreen
, colortbl_format
, PIPE_TEXTURE_1D
, 1,
346 PIPE_BIND_SAMPLER_VIEW
348 pipe_mutex_unlock(dev
->mutex
);
350 return VDP_STATUS_OK
;
354 * Query the implementation's capability to perform a PutBits operation using
355 * application data in a specific YCbCr/YUB format.
358 vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
359 VdpYCbCrFormat bits_ycbcr_format
,
360 VdpBool
*is_supported
)
363 struct pipe_screen
*pscreen
;
364 enum pipe_format rgba_format
, ycbcr_format
;
366 dev
= vlGetDataHTAB(device
);
368 return VDP_STATUS_INVALID_HANDLE
;
370 pscreen
= dev
->vscreen
->pscreen
;
372 return VDP_STATUS_ERROR
;
374 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
375 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
376 return VDP_STATUS_INVALID_RGBA_FORMAT
;
378 ycbcr_format
= FormatYCBCRToPipe(bits_ycbcr_format
);
379 if (ycbcr_format
== PIPE_FORMAT_NONE
)
380 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
383 return VDP_STATUS_INVALID_POINTER
;
385 pipe_mutex_lock(dev
->mutex
);
386 *is_supported
= pscreen
->is_format_supported
388 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
389 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
392 *is_supported
&= pscreen
->is_video_format_supported
394 pscreen
, ycbcr_format
,
395 PIPE_VIDEO_PROFILE_UNKNOWN
,
396 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
398 pipe_mutex_unlock(dev
->mutex
);
400 return VDP_STATUS_OK
;
404 * Query the implementation's VdpBitmapSurface capabilities.
407 vlVdpBitmapSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
408 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
411 struct pipe_screen
*pscreen
;
412 enum pipe_format format
;
414 dev
= vlGetDataHTAB(device
);
416 return VDP_STATUS_INVALID_HANDLE
;
418 pscreen
= dev
->vscreen
->pscreen
;
420 return VDP_STATUS_RESOURCES
;
422 format
= FormatRGBAToPipe(surface_rgba_format
);
423 if (format
== PIPE_FORMAT_NONE
)
424 return VDP_STATUS_INVALID_RGBA_FORMAT
;
426 if (!(is_supported
&& max_width
&& max_height
))
427 return VDP_STATUS_INVALID_POINTER
;
429 pipe_mutex_lock(dev
->mutex
);
430 *is_supported
= pscreen
->is_format_supported
432 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
433 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
436 uint32_t max_2d_texture_level
= pscreen
->get_param(
437 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
439 if (!max_2d_texture_level
) {
440 pipe_mutex_unlock(dev
->mutex
);
441 return VDP_STATUS_ERROR
;
444 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
449 pipe_mutex_unlock(dev
->mutex
);
451 return VDP_STATUS_OK
;
455 * Query the implementation's support for a specific feature.
458 vlVdpVideoMixerQueryFeatureSupport(VdpDevice device
, VdpVideoMixerFeature feature
,
459 VdpBool
*is_supported
)
462 return VDP_STATUS_INVALID_POINTER
;
465 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
466 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
467 *is_supported
= VDP_TRUE
;
470 *is_supported
= VDP_FALSE
;
473 return VDP_STATUS_OK
;
477 * Query the implementation's support for a specific parameter.
480 vlVdpVideoMixerQueryParameterSupport(VdpDevice device
, VdpVideoMixerParameter parameter
,
481 VdpBool
*is_supported
)
484 return VDP_STATUS_INVALID_POINTER
;
487 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
488 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
489 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
490 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
491 *is_supported
= VDP_TRUE
;
494 *is_supported
= VDP_FALSE
;
497 return VDP_STATUS_OK
;
501 * Query the implementation's supported for a specific parameter.
504 vlVdpVideoMixerQueryParameterValueRange(VdpDevice device
, VdpVideoMixerParameter parameter
,
505 void *min_value
, void *max_value
)
507 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
508 struct pipe_screen
*screen
;
509 enum pipe_video_profile prof
= PIPE_VIDEO_PROFILE_UNKNOWN
;
512 return VDP_STATUS_INVALID_HANDLE
;
513 if (!(min_value
&& max_value
))
514 return VDP_STATUS_INVALID_POINTER
;
516 pipe_mutex_lock(dev
->mutex
);
517 screen
= dev
->vscreen
->pscreen
;
519 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
520 *(uint32_t*)min_value
= 48;
521 *(uint32_t*)max_value
= screen
->get_video_param(screen
, prof
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
522 PIPE_VIDEO_CAP_MAX_WIDTH
);
524 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
525 *(uint32_t*)min_value
= 48;
526 *(uint32_t*)max_value
= screen
->get_video_param(screen
, prof
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
527 PIPE_VIDEO_CAP_MAX_HEIGHT
);
530 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
531 *(uint32_t*)min_value
= 0;
532 *(uint32_t*)max_value
= 4;
535 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
537 pipe_mutex_unlock(dev
->mutex
);
538 return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
540 pipe_mutex_unlock(dev
->mutex
);
541 return VDP_STATUS_OK
;
545 * Query the implementation's support for a specific attribute.
548 vlVdpVideoMixerQueryAttributeSupport(VdpDevice device
, VdpVideoMixerAttribute attribute
,
549 VdpBool
*is_supported
)
552 return VDP_STATUS_INVALID_POINTER
;
555 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
556 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
557 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
558 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
559 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
560 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
561 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
562 *is_supported
= VDP_TRUE
;
565 *is_supported
= VDP_FALSE
;
567 return VDP_STATUS_OK
;
571 * Query the implementation's supported for a specific attribute.
574 vlVdpVideoMixerQueryAttributeValueRange(VdpDevice device
, VdpVideoMixerAttribute attribute
,
575 void *min_value
, void *max_value
)
577 if (!(min_value
&& max_value
))
578 return VDP_STATUS_INVALID_POINTER
;
581 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
582 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
583 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
584 *(float*)min_value
= 0.f
;
585 *(float*)max_value
= 1.f
;
587 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
588 *(float*)min_value
= -1.f
;
589 *(float*)max_value
= 1.f
;
591 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
592 *(uint8_t*)min_value
= 0;
593 *(uint8_t*)max_value
= 1;
595 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
596 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
598 return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
600 return VDP_STATUS_OK
;