Path: blob/21.2-virgl/src/gallium/frontends/vdpau/query.c
4565 views
/**************************************************************************1*2* Copyright 2010 Younes Manton.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include <assert.h>28#include <math.h>2930#include "vdpau_private.h"31#include "pipe/p_screen.h"32#include "pipe/p_defines.h"33#include "util/u_debug.h"3435/**36* Retrieve the VDPAU version implemented by the backend.37*/38VdpStatus39vlVdpGetApiVersion(uint32_t *api_version)40{41if (!api_version)42return VDP_STATUS_INVALID_POINTER;4344*api_version = 1;45return VDP_STATUS_OK;46}4748/**49* Retrieve an implementation-specific string description of the implementation.50* This typically includes detailed version information.51*/52VdpStatus53vlVdpGetInformationString(char const **information_string)54{55if (!information_string)56return VDP_STATUS_INVALID_POINTER;5758*information_string = INFORMATION_STRING;59return VDP_STATUS_OK;60}6162/**63* Query the implementation's VdpVideoSurface capabilities.64*/65VdpStatus66vlVdpVideoSurfaceQueryCapabilities(VdpDevice device, VdpChromaType surface_chroma_type,67VdpBool *is_supported, uint32_t *max_width, uint32_t *max_height)68{69vlVdpDevice *dev;70struct pipe_screen *pscreen;71uint32_t max_2d_texture_size;7273if (!(is_supported && max_width && max_height))74return VDP_STATUS_INVALID_POINTER;7576dev = vlGetDataHTAB(device);77if (!dev)78return VDP_STATUS_INVALID_HANDLE;7980pscreen = dev->vscreen->pscreen;81if (!pscreen)82return VDP_STATUS_RESOURCES;8384mtx_lock(&dev->mutex);8586/* XXX: Current limits */87*is_supported = true;88max_2d_texture_size = pscreen->get_param(pscreen, PIPE_CAP_MAX_TEXTURE_2D_SIZE);89mtx_unlock(&dev->mutex);90if (!max_2d_texture_size)91return VDP_STATUS_RESOURCES;9293*max_width = *max_height = max_2d_texture_size;9495return VDP_STATUS_OK;96}9798/**99* Query the implementation's VdpVideoSurface GetBits/PutBits capabilities.100*/101VdpStatus102vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities(VdpDevice device, VdpChromaType surface_chroma_type,103VdpYCbCrFormat bits_ycbcr_format,104VdpBool *is_supported)105{106vlVdpDevice *dev;107struct pipe_screen *pscreen;108109if (!is_supported)110return VDP_STATUS_INVALID_POINTER;111112dev = vlGetDataHTAB(device);113if (!dev)114return VDP_STATUS_INVALID_HANDLE;115116pscreen = dev->vscreen->pscreen;117if (!pscreen)118return VDP_STATUS_RESOURCES;119120mtx_lock(&dev->mutex);121122switch(bits_ycbcr_format) {123case VDP_YCBCR_FORMAT_NV12:124*is_supported = surface_chroma_type == VDP_CHROMA_TYPE_420;125break;126127case VDP_YCBCR_FORMAT_YV12:128*is_supported = surface_chroma_type == VDP_CHROMA_TYPE_420;129130/* We can convert YV12 to NV12 on the fly! */131if (*is_supported &&132pscreen->is_video_format_supported(pscreen,133PIPE_FORMAT_NV12,134PIPE_VIDEO_PROFILE_UNKNOWN,135PIPE_VIDEO_ENTRYPOINT_BITSTREAM)) {136mtx_unlock(&dev->mutex);137return VDP_STATUS_OK;138}139break;140141case VDP_YCBCR_FORMAT_UYVY:142case VDP_YCBCR_FORMAT_YUYV:143*is_supported = surface_chroma_type == VDP_CHROMA_TYPE_422;144break;145146case VDP_YCBCR_FORMAT_Y8U8V8A8:147case VDP_YCBCR_FORMAT_V8U8Y8A8:148*is_supported = surface_chroma_type == VDP_CHROMA_TYPE_444;149break;150151default:152*is_supported = false;153break;154}155156if (*is_supported &&157!pscreen->is_video_format_supported(pscreen,158FormatYCBCRToPipe(bits_ycbcr_format),159PIPE_VIDEO_PROFILE_UNKNOWN,160PIPE_VIDEO_ENTRYPOINT_BITSTREAM)) {161*is_supported = false;162}163mtx_unlock(&dev->mutex);164165return VDP_STATUS_OK;166}167168/**169* Query the implementation's VdpDecoder capabilities.170*/171VdpStatus172vlVdpDecoderQueryCapabilities(VdpDevice device, VdpDecoderProfile profile,173VdpBool *is_supported, uint32_t *max_level, uint32_t *max_macroblocks,174uint32_t *max_width, uint32_t *max_height)175{176vlVdpDevice *dev;177struct pipe_screen *pscreen;178enum pipe_video_profile p_profile;179180if (!(is_supported && max_level && max_macroblocks && max_width && max_height))181return VDP_STATUS_INVALID_POINTER;182183dev = vlGetDataHTAB(device);184if (!dev)185return VDP_STATUS_INVALID_HANDLE;186187pscreen = dev->vscreen->pscreen;188if (!pscreen)189return VDP_STATUS_RESOURCES;190191p_profile = ProfileToPipe(profile);192if (p_profile == PIPE_VIDEO_PROFILE_UNKNOWN) {193*is_supported = false;194return VDP_STATUS_OK;195}196197mtx_lock(&dev->mutex);198*is_supported = pscreen->get_video_param(pscreen, p_profile, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,199PIPE_VIDEO_CAP_SUPPORTED);200if (*is_supported) {201*max_width = pscreen->get_video_param(pscreen, p_profile, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,202PIPE_VIDEO_CAP_MAX_WIDTH);203*max_height = pscreen->get_video_param(pscreen, p_profile, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,204PIPE_VIDEO_CAP_MAX_HEIGHT);205*max_level = pscreen->get_video_param(pscreen, p_profile, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,206PIPE_VIDEO_CAP_MAX_LEVEL);207*max_macroblocks = pscreen->get_video_param(pscreen, p_profile, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,208PIPE_VIDEO_CAP_MAX_MACROBLOCKS);209if (*max_macroblocks == 0) {210*max_macroblocks = (*max_width/16)*(*max_height/16);211}212} else {213*max_width = 0;214*max_height = 0;215*max_level = 0;216*max_macroblocks = 0;217}218mtx_unlock(&dev->mutex);219220return VDP_STATUS_OK;221}222223/**224* Query the implementation's VdpOutputSurface capabilities.225*/226VdpStatus227vlVdpOutputSurfaceQueryCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format,228VdpBool *is_supported, uint32_t *max_width, uint32_t *max_height)229{230vlVdpDevice *dev;231struct pipe_screen *pscreen;232enum pipe_format format;233234dev = vlGetDataHTAB(device);235if (!dev)236return VDP_STATUS_INVALID_HANDLE;237238pscreen = dev->vscreen->pscreen;239if (!pscreen)240return VDP_STATUS_RESOURCES;241242format = VdpFormatRGBAToPipe(surface_rgba_format);243if (format == PIPE_FORMAT_NONE || format == PIPE_FORMAT_A8_UNORM)244return VDP_STATUS_INVALID_RGBA_FORMAT;245246if (!(is_supported && max_width && max_height))247return VDP_STATUS_INVALID_POINTER;248249mtx_lock(&dev->mutex);250*is_supported = pscreen->is_format_supported251(252pscreen, format, PIPE_TEXTURE_2D, 1, 1,253PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET254);255if (*is_supported) {256uint32_t max_2d_texture_size = pscreen->get_param(257pscreen, PIPE_CAP_MAX_TEXTURE_2D_SIZE);258259if (!max_2d_texture_size) {260mtx_unlock(&dev->mutex);261return VDP_STATUS_ERROR;262}263264*max_width = *max_height = max_2d_texture_size;265} else {266*max_width = 0;267*max_height = 0;268}269mtx_unlock(&dev->mutex);270271return VDP_STATUS_OK;272}273274/**275* Query the implementation's capability to perform a PutBits operation using276* application data matching the surface's format.277*/278VdpStatus279vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format,280VdpBool *is_supported)281{282vlVdpDevice *dev;283struct pipe_screen *pscreen;284enum pipe_format format;285286dev = vlGetDataHTAB(device);287if (!dev)288return VDP_STATUS_INVALID_HANDLE;289290pscreen = dev->vscreen->pscreen;291if (!pscreen)292return VDP_STATUS_ERROR;293294format = VdpFormatRGBAToPipe(surface_rgba_format);295if (format == PIPE_FORMAT_NONE || format == PIPE_FORMAT_A8_UNORM)296return VDP_STATUS_INVALID_RGBA_FORMAT;297298if (!is_supported)299return VDP_STATUS_INVALID_POINTER;300301mtx_lock(&dev->mutex);302*is_supported = pscreen->is_format_supported303(304pscreen, format, PIPE_TEXTURE_2D, 1, 1,305PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET306);307mtx_unlock(&dev->mutex);308309return VDP_STATUS_OK;310}311312/**313* Query the implementation's capability to perform a PutBits operation using314* application data in a specific indexed format.315*/316VdpStatus317vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities(VdpDevice device,318VdpRGBAFormat surface_rgba_format,319VdpIndexedFormat bits_indexed_format,320VdpColorTableFormat color_table_format,321VdpBool *is_supported)322{323vlVdpDevice *dev;324struct pipe_screen *pscreen;325enum pipe_format rgba_format, index_format, colortbl_format;326327dev = vlGetDataHTAB(device);328if (!dev)329return VDP_STATUS_INVALID_HANDLE;330331pscreen = dev->vscreen->pscreen;332if (!pscreen)333return VDP_STATUS_ERROR;334335rgba_format = VdpFormatRGBAToPipe(surface_rgba_format);336if (rgba_format == PIPE_FORMAT_NONE || rgba_format == PIPE_FORMAT_A8_UNORM)337return VDP_STATUS_INVALID_RGBA_FORMAT;338339index_format = FormatIndexedToPipe(bits_indexed_format);340if (index_format == PIPE_FORMAT_NONE)341return VDP_STATUS_INVALID_INDEXED_FORMAT;342343colortbl_format = FormatColorTableToPipe(color_table_format);344if (colortbl_format == PIPE_FORMAT_NONE)345return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT;346347if (!is_supported)348return VDP_STATUS_INVALID_POINTER;349350mtx_lock(&dev->mutex);351*is_supported = pscreen->is_format_supported352(353pscreen, rgba_format, PIPE_TEXTURE_2D, 1, 1,354PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET355);356357*is_supported &= pscreen->is_format_supported358(359pscreen, index_format, PIPE_TEXTURE_2D, 1, 1,360PIPE_BIND_SAMPLER_VIEW361);362363*is_supported &= pscreen->is_format_supported364(365pscreen, colortbl_format, PIPE_TEXTURE_1D, 1, 1,366PIPE_BIND_SAMPLER_VIEW367);368mtx_unlock(&dev->mutex);369370return VDP_STATUS_OK;371}372373/**374* Query the implementation's capability to perform a PutBits operation using375* application data in a specific YCbCr/YUB format.376*/377VdpStatus378vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format,379VdpYCbCrFormat bits_ycbcr_format,380VdpBool *is_supported)381{382vlVdpDevice *dev;383struct pipe_screen *pscreen;384enum pipe_format rgba_format, ycbcr_format;385386dev = vlGetDataHTAB(device);387if (!dev)388return VDP_STATUS_INVALID_HANDLE;389390pscreen = dev->vscreen->pscreen;391if (!pscreen)392return VDP_STATUS_ERROR;393394rgba_format = VdpFormatRGBAToPipe(surface_rgba_format);395if (rgba_format == PIPE_FORMAT_NONE || rgba_format == PIPE_FORMAT_A8_UNORM)396return VDP_STATUS_INVALID_RGBA_FORMAT;397398ycbcr_format = FormatYCBCRToPipe(bits_ycbcr_format);399if (ycbcr_format == PIPE_FORMAT_NONE)400return VDP_STATUS_INVALID_INDEXED_FORMAT;401402if (!is_supported)403return VDP_STATUS_INVALID_POINTER;404405mtx_lock(&dev->mutex);406*is_supported = pscreen->is_format_supported407(408pscreen, rgba_format, PIPE_TEXTURE_2D, 1, 1,409PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET410);411412*is_supported &= pscreen->is_video_format_supported413(414pscreen, ycbcr_format,415PIPE_VIDEO_PROFILE_UNKNOWN,416PIPE_VIDEO_ENTRYPOINT_BITSTREAM417);418mtx_unlock(&dev->mutex);419420return VDP_STATUS_OK;421}422423/**424* Query the implementation's VdpBitmapSurface capabilities.425*/426VdpStatus427vlVdpBitmapSurfaceQueryCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format,428VdpBool *is_supported, uint32_t *max_width, uint32_t *max_height)429{430vlVdpDevice *dev;431struct pipe_screen *pscreen;432enum pipe_format format;433434dev = vlGetDataHTAB(device);435if (!dev)436return VDP_STATUS_INVALID_HANDLE;437438pscreen = dev->vscreen->pscreen;439if (!pscreen)440return VDP_STATUS_RESOURCES;441442format = VdpFormatRGBAToPipe(surface_rgba_format);443if (format == PIPE_FORMAT_NONE)444return VDP_STATUS_INVALID_RGBA_FORMAT;445446if (!(is_supported && max_width && max_height))447return VDP_STATUS_INVALID_POINTER;448449mtx_lock(&dev->mutex);450*is_supported = pscreen->is_format_supported451(452pscreen, format, PIPE_TEXTURE_2D, 1, 1,453PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET454);455if (*is_supported) {456uint32_t max_2d_texture_size = pscreen->get_param(457pscreen, PIPE_CAP_MAX_TEXTURE_2D_SIZE);458459if (!max_2d_texture_size) {460mtx_unlock(&dev->mutex);461return VDP_STATUS_ERROR;462}463464*max_width = *max_height = max_2d_texture_size;465} else {466*max_width = 0;467*max_height = 0;468}469mtx_unlock(&dev->mutex);470471return VDP_STATUS_OK;472}473474/**475* Query the implementation's support for a specific feature.476*/477VdpStatus478vlVdpVideoMixerQueryFeatureSupport(VdpDevice device, VdpVideoMixerFeature feature,479VdpBool *is_supported)480{481if (!is_supported)482return VDP_STATUS_INVALID_POINTER;483484switch (feature) {485case VDP_VIDEO_MIXER_FEATURE_SHARPNESS:486case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION:487case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL:488case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY:489case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1:490*is_supported = VDP_TRUE;491break;492default:493*is_supported = VDP_FALSE;494break;495}496return VDP_STATUS_OK;497}498499/**500* Query the implementation's support for a specific parameter.501*/502VdpStatus503vlVdpVideoMixerQueryParameterSupport(VdpDevice device, VdpVideoMixerParameter parameter,504VdpBool *is_supported)505{506if (!is_supported)507return VDP_STATUS_INVALID_POINTER;508509switch (parameter) {510case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH:511case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT:512case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE:513case VDP_VIDEO_MIXER_PARAMETER_LAYERS:514*is_supported = VDP_TRUE;515break;516default:517*is_supported = VDP_FALSE;518break;519}520return VDP_STATUS_OK;521}522523/**524* Query the implementation's supported for a specific parameter.525*/526VdpStatus527vlVdpVideoMixerQueryParameterValueRange(VdpDevice device, VdpVideoMixerParameter parameter,528void *min_value, void *max_value)529{530vlVdpDevice *dev = vlGetDataHTAB(device);531struct pipe_screen *screen;532533if (!dev)534return VDP_STATUS_INVALID_HANDLE;535if (!(min_value && max_value))536return VDP_STATUS_INVALID_POINTER;537538mtx_lock(&dev->mutex);539screen = dev->vscreen->pscreen;540switch (parameter) {541case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH:542*(uint32_t*)min_value = 48;543*(uint32_t*)max_value = screen->get_video_param(screen, PIPE_VIDEO_PROFILE_UNKNOWN,544PIPE_VIDEO_ENTRYPOINT_BITSTREAM,545PIPE_VIDEO_CAP_MAX_WIDTH);546break;547case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT:548*(uint32_t*)min_value = 48;549*(uint32_t*)max_value = screen->get_video_param(screen, PIPE_VIDEO_PROFILE_UNKNOWN,550PIPE_VIDEO_ENTRYPOINT_BITSTREAM,551PIPE_VIDEO_CAP_MAX_HEIGHT);552break;553554case VDP_VIDEO_MIXER_PARAMETER_LAYERS:555*(uint32_t*)min_value = 0;556*(uint32_t*)max_value = 4;557break;558559case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE:560default:561mtx_unlock(&dev->mutex);562return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER;563}564mtx_unlock(&dev->mutex);565return VDP_STATUS_OK;566}567568/**569* Query the implementation's support for a specific attribute.570*/571VdpStatus572vlVdpVideoMixerQueryAttributeSupport(VdpDevice device, VdpVideoMixerAttribute attribute,573VdpBool *is_supported)574{575if (!is_supported)576return VDP_STATUS_INVALID_POINTER;577578switch (attribute) {579case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR:580case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX:581case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL:582case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL:583case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA:584case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA:585case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE:586*is_supported = VDP_TRUE;587break;588default:589*is_supported = VDP_FALSE;590}591return VDP_STATUS_OK;592}593594/**595* Query the implementation's supported for a specific attribute.596*/597VdpStatus598vlVdpVideoMixerQueryAttributeValueRange(VdpDevice device, VdpVideoMixerAttribute attribute,599void *min_value, void *max_value)600{601if (!(min_value && max_value))602return VDP_STATUS_INVALID_POINTER;603604switch (attribute) {605case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL:606case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA:607case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA:608*(float*)min_value = 0.0f;609*(float*)max_value = 1.0f;610break;611case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL:612*(float*)min_value = -1.0f;613*(float*)max_value = 1.0f;614break;615case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE:616*(uint8_t*)min_value = 0;617*(uint8_t*)max_value = 1;618break;619case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR:620case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX:621default:622return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE;623}624return VDP_STATUS_OK;625}626627628