Bug 924382 - Allow getting the integer type corresponding to a MOZ_BEGIN_ENUM_CLASS - r=Waldo

This commit is contained in:
Benoit Jacob 2013-11-23 21:20:38 -05:00
parent b27943e7d5
commit d6c2066a07
3 changed files with 34 additions and 26 deletions

View File

@ -37,7 +37,7 @@ class WebGLImageConverter
* texels with typed pointers and this value will tell us by how much we need
* to increment these pointers to advance to the next texel.
*/
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) Format>
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) Format>
static size_t NumElementsPerTexelForFormat() {
switch (Format) {
case WebGLTexelFormat::R8:
@ -73,9 +73,9 @@ class WebGLImageConverter
* to return immediately in these cases to allow the compiler to avoid generating
* useless code.
*/
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) SrcFormat,
MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) DstFormat,
MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelPremultiplicationOp) PremultiplicationOp>
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) SrcFormat,
MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) DstFormat,
MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelPremultiplicationOp) PremultiplicationOp>
void run()
{
// check for never-called cases. We early-return to allow the compiler
@ -146,9 +146,9 @@ class WebGLImageConverter
typename DataTypeForFormat<DstFormat>::Type
DstType;
const MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) IntermediateSrcFormat
const MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) IntermediateSrcFormat
= IntermediateFormat<SrcFormat>::Value;
const MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) IntermediateDstFormat
const MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) IntermediateDstFormat
= IntermediateFormat<DstFormat>::Value;
typedef
typename DataTypeForFormat<IntermediateSrcFormat>::Type
@ -213,8 +213,8 @@ class WebGLImageConverter
return;
}
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) SrcFormat,
MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) DstFormat>
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) SrcFormat,
MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) DstFormat>
void run(WebGLTexelPremultiplicationOp premultiplicationOp)
{
#define WEBGLIMAGECONVERTER_CASE_PREMULTIPLICATIONOP(PremultiplicationOp) \
@ -232,7 +232,7 @@ class WebGLImageConverter
#undef WEBGLIMAGECONVERTER_CASE_PREMULTIPLICATIONOP
}
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) SrcFormat>
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) SrcFormat>
void run(WebGLTexelFormat dstFormat,
WebGLTexelPremultiplicationOp premultiplicationOp)
{

View File

@ -46,14 +46,7 @@ MOZ_END_ENUM_CLASS(WebGLTexelPremultiplicationOp)
namespace WebGLTexelConversions {
// remove this as soon as B2G and Windows use newer compilers
#ifdef MOZ_HAVE_CXX11_STRONG_ENUMS
#define MOZ_ENUM_CLASS_INTEGER_TYPE(X) X
#else
#define MOZ_ENUM_CLASS_INTEGER_TYPE(X) X::Enum
#endif
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) Format>
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) Format>
struct IsFloatFormat
{
static const bool Value =
@ -64,7 +57,7 @@ struct IsFloatFormat
Format == WebGLTexelFormat::A32F;
};
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) Format>
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) Format>
struct Is16bppFormat
{
static const bool Value =
@ -73,7 +66,7 @@ struct Is16bppFormat
Format == WebGLTexelFormat::RGB565;
};
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) Format,
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) Format,
bool IsFloat = IsFloatFormat<Format>::Value,
bool Is16bpp = Is16bppFormat<Format>::Value>
struct DataTypeForFormat
@ -81,22 +74,22 @@ struct DataTypeForFormat
typedef uint8_t Type;
};
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) Format>
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) Format>
struct DataTypeForFormat<Format, true, false>
{
typedef float Type;
};
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) Format>
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) Format>
struct DataTypeForFormat<Format, false, true>
{
typedef uint16_t Type;
};
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) Format>
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) Format>
struct IntermediateFormat
{
static const MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) Value
static const MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) Value
= IsFloatFormat<Format>::Value
? WebGLTexelFormat::RGBA32F
: WebGLTexelFormat::RGBA8;
@ -172,7 +165,7 @@ MOZ_ALWAYS_INLINE bool HasColor(WebGLTexelFormat format) {
//----------------------------------------------------------------------
// Pixel unpacking routines.
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) Format, typename SrcType, typename DstType>
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) Format, typename SrcType, typename DstType>
MOZ_ALWAYS_INLINE void
unpack(const SrcType* __restrict src,
DstType* __restrict dst)
@ -332,8 +325,8 @@ unpack<WebGLTexelFormat::A32F, float, float>(const float* __restrict src, float*
// Pixel packing routines.
//
template<MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelFormat) Format,
MOZ_ENUM_CLASS_INTEGER_TYPE(WebGLTexelPremultiplicationOp) PremultiplicationOp,
template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat) Format,
MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelPremultiplicationOp) PremultiplicationOp,
typename SrcType,
typename DstType>
MOZ_ALWAYS_INLINE void

View File

@ -123,6 +123,14 @@
# define MOZ_END_NESTED_ENUM_CLASS(Name) \
};
# define MOZ_FINISH_NESTED_ENUM_CLASS(Name) /* nothing */
/*
* MOZ_ENUM_CLASS_ENUM_TYPE allows using enum classes
* as template parameter types. For that, we need integer types.
* In the present case where the compiler supports strong enums,
* these are already integer types so there is nothing more to do.
*/
# define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name
#else
/**
* We need Name to both name a type, and scope the provided enumerator
@ -238,6 +246,13 @@
inline int& operator^=(int&, const Name::Enum&) MOZ_DELETE; \
inline int& operator<<=(int&, const Name::Enum&) MOZ_DELETE; \
inline int& operator>>=(int&, const Name::Enum&) MOZ_DELETE;
/*
* MOZ_ENUM_CLASS_ENUM_TYPE allows using enum classes
* as template parameter types. For that, we need integer types.
* In the present case, the integer type is the Enum nested type.
*/
# define MOZ_ENUM_CLASS_ENUM_TYPE(Name) Name::Enum
#endif
/*