Bug 958369 - 1/5 - Make GLFeature a typed enum - r=jgilbert

This commit is contained in:
Benoit Jacob 2014-01-10 13:55:23 -05:00
Родитель bba51d87ca
Коммит b05e26dc69
3 изменённых файлов: 49 добавлений и 55 удалений

Просмотреть файл

@ -72,7 +72,7 @@ WebGLContext::InitWebGL2()
WEBGL_depth_texture, WEBGL_depth_texture,
WEBGL_draw_buffers WEBGL_draw_buffers
}; };
const GLFeature::Enum sFeatureRequiredArr[] = { const GLFeature sFeatureRequiredArr[] = {
GLFeature::blend_minmax, GLFeature::blend_minmax,
GLFeature::instanced_non_arrays, GLFeature::instanced_non_arrays,
GLFeature::transform_feedback GLFeature::transform_feedback

Просмотреть файл

@ -81,42 +81,36 @@ namespace mozilla {
namespace mozilla { namespace mozilla {
namespace gl { namespace gl {
/** GLFeature::Enum MOZ_BEGIN_ENUM_CLASS(GLFeature)
* We don't use typed enum to keep the implicit integer conversion. bind_buffer_offset,
* This enum should be sorted by name. blend_minmax,
*/ depth_texture,
namespace GLFeature { draw_buffers,
enum Enum { draw_instanced,
bind_buffer_offset, element_index_uint,
blend_minmax, ES2_compatibility,
depth_texture, ES3_compatibility,
draw_buffers, framebuffer_blit,
draw_instanced, framebuffer_multisample,
element_index_uint, framebuffer_object,
ES2_compatibility, get_query_object_iv,
ES3_compatibility, instanced_arrays,
framebuffer_blit, instanced_non_arrays,
framebuffer_multisample, occlusion_query,
framebuffer_object, occlusion_query_boolean,
get_query_object_iv, occlusion_query2,
instanced_arrays, packed_depth_stencil,
instanced_non_arrays, query_objects,
occlusion_query, robustness,
occlusion_query_boolean, sRGB,
occlusion_query2, standard_derivatives,
packed_depth_stencil, texture_float,
query_objects, texture_float_linear,
robustness, texture_non_power_of_two,
sRGB, transform_feedback,
standard_derivatives, vertex_array_object,
texture_float, EnumMax
texture_float_linear, MOZ_END_ENUM_CLASS(GLFeature)
texture_non_power_of_two,
transform_feedback,
vertex_array_object,
EnumMax
};
}
MOZ_BEGIN_ENUM_CLASS(ContextProfile, uint8_t) MOZ_BEGIN_ENUM_CLASS(ContextProfile, uint8_t)
Unknown = 0, Unknown = 0,
@ -473,15 +467,15 @@ protected:
* by the context version/profile * by the context version/profile
*/ */
public: public:
bool IsSupported(GLFeature::Enum feature) const { bool IsSupported(GLFeature feature) const {
return mAvailableFeatures[feature]; return mAvailableFeatures[size_t(feature)];
} }
static const char* GetFeatureName(GLFeature::Enum feature); static const char* GetFeatureName(GLFeature feature);
private: private:
std::bitset<GLFeature::EnumMax> mAvailableFeatures; std::bitset<size_t(GLFeature::EnumMax)> mAvailableFeatures;
/** /**
* Init features regarding OpenGL extension and context version and profile * Init features regarding OpenGL extension and context version and profile
@ -491,7 +485,7 @@ private:
/** /**
* Mark the feature and associated extensions as unsupported * Mark the feature and associated extensions as unsupported
*/ */
void MarkUnsupported(GLFeature::Enum feature); void MarkUnsupported(GLFeature feature);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Robustness handling // Robustness handling

Просмотреть файл

@ -325,7 +325,7 @@ static const FeatureInfo sFeatureInfoArr[] = {
}; };
static inline const FeatureInfo& static inline const FeatureInfo&
GetFeatureInfo(GLFeature::Enum feature) GetFeatureInfo(GLFeature feature)
{ {
static_assert(MOZ_ARRAY_LENGTH(sFeatureInfoArr) == size_t(GLFeature::EnumMax), static_assert(MOZ_ARRAY_LENGTH(sFeatureInfoArr) == size_t(GLFeature::EnumMax),
"Mismatched lengths for sFeatureInfoInfos and GLFeature enums"); "Mismatched lengths for sFeatureInfoInfos and GLFeature enums");
@ -333,11 +333,11 @@ GetFeatureInfo(GLFeature::Enum feature)
MOZ_ASSERT(feature < GLFeature::EnumMax, MOZ_ASSERT(feature < GLFeature::EnumMax,
"GLContext::GetFeatureInfoInfo : unknown <feature>"); "GLContext::GetFeatureInfoInfo : unknown <feature>");
return sFeatureInfoArr[feature]; return sFeatureInfoArr[size_t(feature)];
} }
static inline uint32_t static inline uint32_t
ProfileVersionForFeature(GLFeature::Enum feature, ContextProfile profile) ProfileVersionForFeature(GLFeature feature, ContextProfile profile)
{ {
MOZ_ASSERT(profile != ContextProfile::Unknown, MOZ_ASSERT(profile != ContextProfile::Unknown,
"GLContext::ProfileVersionForFeature : unknown <profile>"); "GLContext::ProfileVersionForFeature : unknown <profile>");
@ -352,7 +352,7 @@ ProfileVersionForFeature(GLFeature::Enum feature, ContextProfile profile)
} }
static inline bool static inline bool
IsFeatureIsPartOfProfileVersion(GLFeature::Enum feature, IsFeatureIsPartOfProfileVersion(GLFeature feature,
ContextProfile profile, unsigned int version) ContextProfile profile, unsigned int version)
{ {
unsigned int profileVersion = ProfileVersionForFeature(feature, profile); unsigned int profileVersion = ProfileVersionForFeature(feature, profile);
@ -365,7 +365,7 @@ IsFeatureIsPartOfProfileVersion(GLFeature::Enum feature,
} }
const char* const char*
GLContext::GetFeatureName(GLFeature::Enum feature) GLContext::GetFeatureName(GLFeature feature)
{ {
return GetFeatureInfo(feature).mName; return GetFeatureInfo(feature).mName;
} }
@ -391,16 +391,16 @@ CanReadSRGBFromFBOTexture(GLContext* gl)
void void
GLContext::InitFeatures() GLContext::InitFeatures()
{ {
for (size_t i = 0; i < GLFeature::EnumMax; i++) for (size_t feature_index = 0; feature_index < size_t(GLFeature::EnumMax); feature_index++)
{ {
GLFeature::Enum feature = GLFeature::Enum(i); GLFeature feature = GLFeature(feature_index);
if (IsFeatureIsPartOfProfileVersion(feature, mProfile, mVersion)) { if (IsFeatureIsPartOfProfileVersion(feature, mProfile, mVersion)) {
mAvailableFeatures[feature] = true; mAvailableFeatures[feature_index] = true;
continue; continue;
} }
mAvailableFeatures[feature] = false; mAvailableFeatures[feature_index] = false;
const FeatureInfo& featureInfo = GetFeatureInfo(feature); const FeatureInfo& featureInfo = GetFeatureInfo(feature);
@ -413,7 +413,7 @@ GLContext::InitFeatures()
} }
if (IsExtensionSupported(featureInfo.mExtensions[j])) { if (IsExtensionSupported(featureInfo.mExtensions[j])) {
mAvailableFeatures[feature] = true; mAvailableFeatures[feature_index] = true;
break; break;
} }
} }
@ -427,15 +427,15 @@ GLContext::InitFeatures()
(IsExtensionSupported(ARB_framebuffer_sRGB) || (IsExtensionSupported(ARB_framebuffer_sRGB) ||
IsExtensionSupported(EXT_framebuffer_sRGB)); IsExtensionSupported(EXT_framebuffer_sRGB));
mAvailableFeatures[GLFeature::sRGB] = mAvailableFeatures[size_t(GLFeature::sRGB)] =
aresRGBExtensionsAvailable && aresRGBExtensionsAvailable &&
CanReadSRGBFromFBOTexture(this); CanReadSRGBFromFBOTexture(this);
} }
void void
GLContext::MarkUnsupported(GLFeature::Enum feature) GLContext::MarkUnsupported(GLFeature feature)
{ {
mAvailableFeatures[feature] = false; mAvailableFeatures[size_t(feature)] = false;
const FeatureInfo& featureInfo = GetFeatureInfo(feature); const FeatureInfo& featureInfo = GetFeatureInfo(feature);