translate: allow clients to ask for supported output formats

Currently translate asserts on unsupported output formats, making
it impossible to use for some purposes, such as testing whether it
actually works on all formats it supports.

Removing the assert was met with opposition, so this change allows
clients to ask whether an output format is supported, and they are thus
able to avoid attempting to use it.

Since this is just an addition to the API, no adverse effect is
possible, and it makes the testsuite work again.
This commit is contained in:
Luca Barbieri 2010-08-11 21:19:12 +02:00
parent 27fe2347bc
commit 10adb7840c
3 changed files with 88 additions and 0 deletions

View File

@ -48,3 +48,8 @@ struct translate *translate_create( const struct translate_key *key )
return translate_generic_create( key );
}
boolean translate_is_output_format_supported(enum pipe_format format)
{
return translate_generic_is_output_format_supported(format);
}

View File

@ -105,6 +105,8 @@ struct translate *translate_lookup_or_create( struct translate_context *tctx,
struct translate *translate_create( const struct translate_key *key );
boolean translate_is_output_format_supported(enum pipe_format format);
static INLINE int translate_keysize( const struct translate_key *key )
{
return 2 * sizeof(int) + key->nr_elements * sizeof(struct translate_element);
@ -138,5 +140,6 @@ struct translate *translate_sse2_create( const struct translate_key *key );
struct translate *translate_generic_create( const struct translate_key *key );
boolean translate_generic_is_output_format_supported(enum pipe_format format);
#endif

View File

@ -554,3 +554,83 @@ struct translate *translate_generic_create( const struct translate_key *key )
return &tg->translate;
}
boolean translate_generic_is_output_format_supported(enum pipe_format format)
{
switch(format)
{
case PIPE_FORMAT_R64G64B64A64_FLOAT: return TRUE;
case PIPE_FORMAT_R64G64B64_FLOAT: return TRUE;
case PIPE_FORMAT_R64G64_FLOAT: return TRUE;
case PIPE_FORMAT_R64_FLOAT: return TRUE;
case PIPE_FORMAT_R32G32B32A32_FLOAT: return TRUE;
case PIPE_FORMAT_R32G32B32_FLOAT: return TRUE;
case PIPE_FORMAT_R32G32_FLOAT: return TRUE;
case PIPE_FORMAT_R32_FLOAT: return TRUE;
case PIPE_FORMAT_R32G32B32A32_USCALED: return TRUE;
case PIPE_FORMAT_R32G32B32_USCALED: return TRUE;
case PIPE_FORMAT_R32G32_USCALED: return TRUE;
case PIPE_FORMAT_R32_USCALED: return TRUE;
case PIPE_FORMAT_R32G32B32A32_SSCALED: return TRUE;
case PIPE_FORMAT_R32G32B32_SSCALED: return TRUE;
case PIPE_FORMAT_R32G32_SSCALED: return TRUE;
case PIPE_FORMAT_R32_SSCALED: return TRUE;
case PIPE_FORMAT_R32G32B32A32_UNORM: return TRUE;
case PIPE_FORMAT_R32G32B32_UNORM: return TRUE;
case PIPE_FORMAT_R32G32_UNORM: return TRUE;
case PIPE_FORMAT_R32_UNORM: return TRUE;
case PIPE_FORMAT_R32G32B32A32_SNORM: return TRUE;
case PIPE_FORMAT_R32G32B32_SNORM: return TRUE;
case PIPE_FORMAT_R32G32_SNORM: return TRUE;
case PIPE_FORMAT_R32_SNORM: return TRUE;
case PIPE_FORMAT_R16G16B16A16_USCALED: return TRUE;
case PIPE_FORMAT_R16G16B16_USCALED: return TRUE;
case PIPE_FORMAT_R16G16_USCALED: return TRUE;
case PIPE_FORMAT_R16_USCALED: return TRUE;
case PIPE_FORMAT_R16G16B16A16_SSCALED: return TRUE;
case PIPE_FORMAT_R16G16B16_SSCALED: return TRUE;
case PIPE_FORMAT_R16G16_SSCALED: return TRUE;
case PIPE_FORMAT_R16_SSCALED: return TRUE;
case PIPE_FORMAT_R16G16B16A16_UNORM: return TRUE;
case PIPE_FORMAT_R16G16B16_UNORM: return TRUE;
case PIPE_FORMAT_R16G16_UNORM: return TRUE;
case PIPE_FORMAT_R16_UNORM: return TRUE;
case PIPE_FORMAT_R16G16B16A16_SNORM: return TRUE;
case PIPE_FORMAT_R16G16B16_SNORM: return TRUE;
case PIPE_FORMAT_R16G16_SNORM: return TRUE;
case PIPE_FORMAT_R16_SNORM: return TRUE;
case PIPE_FORMAT_R8G8B8A8_USCALED: return TRUE;
case PIPE_FORMAT_R8G8B8_USCALED: return TRUE;
case PIPE_FORMAT_R8G8_USCALED: return TRUE;
case PIPE_FORMAT_R8_USCALED: return TRUE;
case PIPE_FORMAT_R8G8B8A8_SSCALED: return TRUE;
case PIPE_FORMAT_R8G8B8_SSCALED: return TRUE;
case PIPE_FORMAT_R8G8_SSCALED: return TRUE;
case PIPE_FORMAT_R8_SSCALED: return TRUE;
case PIPE_FORMAT_R8G8B8A8_UNORM: return TRUE;
case PIPE_FORMAT_R8G8B8_UNORM: return TRUE;
case PIPE_FORMAT_R8G8_UNORM: return TRUE;
case PIPE_FORMAT_R8_UNORM: return TRUE;
case PIPE_FORMAT_R8G8B8A8_SNORM: return TRUE;
case PIPE_FORMAT_R8G8B8_SNORM: return TRUE;
case PIPE_FORMAT_R8G8_SNORM: return TRUE;
case PIPE_FORMAT_R8_SNORM: return TRUE;
case PIPE_FORMAT_A8R8G8B8_UNORM: return TRUE;
case PIPE_FORMAT_B8G8R8A8_UNORM: return TRUE;
default: return FALSE;
}
}