Chromium Code Reviews| Index: gpu/command_buffer/service/feature_info.cc |
| =================================================================== |
| --- gpu/command_buffer/service/feature_info.cc (revision 68245) |
| +++ gpu/command_buffer/service/feature_info.cc (working copy) |
| @@ -12,7 +12,7 @@ |
| namespace gpu { |
| namespace gles2 { |
| -FeatureInfo::FeatureInfo() { |
| +FeatureInfo::FeatureInfo() : requestable_extensions_dirty_(false) { |
| } |
| // Helps query for extensions. |
| @@ -89,8 +89,6 @@ |
| reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)), |
| desired_features); |
| - bool npot_ok = false; |
| - |
| AddExtensionString("GL_CHROMIUM_map_sub"); |
| AddExtensionString("GL_CHROMIUM_copy_texture_to_parent_texture"); |
| AddExtensionString("GL_CHROMIUM_resource_safe"); |
| @@ -101,6 +99,8 @@ |
| if (desired_features && ext.Desire("GL_CHROMIUM_webglsl")) { |
| AddExtensionString("GL_CHROMIUM_webglsl"); |
| feature_flags_.chromium_webglsl = true; |
| + } else { |
| + AddRequestableExtensionString("GL_CHROMIUM_webglsl"); |
| } |
| // Check if we should allow GL_EXT_texture_compression_dxt1 and |
| @@ -108,13 +108,12 @@ |
| bool enable_dxt1 = false; |
| bool enable_s3tc = false; |
| - if (ext.HaveAndDesire("GL_EXT_texture_compression_dxt1")) { |
| + DoSimpleTestForEnablingExtension( |
| + &ext, "GL_EXT_texture_compression_dxt1", &enable_dxt1); |
| + DoSimpleTestForEnablingExtension( |
| + &ext, "GL_EXT_texture_compression_s3tc", &enable_s3tc); |
| + if (enable_s3tc) |
| enable_dxt1 = true; |
| - } |
| - if (ext.HaveAndDesire("GL_EXT_texture_compression_s3tc")) { |
| - enable_dxt1 = true; |
| - enable_s3tc = true; |
| - } |
| if (enable_dxt1) { |
| AddExtensionString("GL_EXT_texture_compression_dxt1"); |
| @@ -133,7 +132,10 @@ |
| } |
| // Check if we should enable GL_EXT_texture_filter_anisotropic. |
| - if (ext.HaveAndDesire("GL_EXT_texture_filter_anisotropic")) { |
| + bool enable_anisotropic = false; |
| + DoSimpleTestForEnablingExtension( |
| + &ext, "GL_EXT_texture_filter_anisotropic", &enable_anisotropic); |
| + if (enable_anisotropic) { |
| AddExtensionString("GL_EXT_texture_filter_anisotropic"); |
| validators_.texture_parameter.AddValue( |
| GL_TEXTURE_MAX_ANISOTROPY_EXT); |
| @@ -148,21 +150,26 @@ |
| // GL_OES_packed_depth_stencil does not provide. Therefore we made up |
| // GL_GOOGLE_depth_texture. |
| bool enable_depth_texture = false; |
| - if (ext.Desire("GL_GOOGLE_depth_texture") && |
| - (ext.Have("GL_ARB_depth_texture") || |
| - ext.Have("GL_OES_depth_texture"))) { |
| - enable_depth_texture = true; |
| - AddExtensionString("GL_GOOGLE_depth_texture"); |
| - validators_.texture_internal_format.AddValue(GL_DEPTH_COMPONENT); |
| - validators_.texture_format.AddValue(GL_DEPTH_COMPONENT); |
| - validators_.pixel_type.AddValue(GL_UNSIGNED_SHORT); |
| - validators_.pixel_type.AddValue(GL_UNSIGNED_INT); |
| + if (ext.Have("GL_ARB_depth_texture") || |
| + ext.Have("GL_OES_depth_texture")) { |
| + if (ext.Desire("GL_GOOGLE_depth_texture")) { |
| + enable_depth_texture = true; |
| + AddExtensionString("GL_GOOGLE_depth_texture"); |
| + validators_.texture_internal_format.AddValue(GL_DEPTH_COMPONENT); |
| + validators_.texture_format.AddValue(GL_DEPTH_COMPONENT); |
| + validators_.pixel_type.AddValue(GL_UNSIGNED_SHORT); |
| + validators_.pixel_type.AddValue(GL_UNSIGNED_INT); |
| + } else { |
| + AddRequestableExtensionString("GL_GOOGLE_depth_texture"); |
| + } |
| } |
| + |
| // TODO(gman): Add depth types fo ElementsPerGroup and BytesPerElement |
| - |
| - if (ext.Desire("GL_OES_packed_depth_stencil") && |
| - (ext.Have("GL_EXT_packed_depth_stencil") || |
| - ext.Have("GL_OES_packed_depth_stencil"))) { |
| + bool enable_packed_depth_stencil = false; |
| + DoSimpleTestForEnablingExtension( |
| + &ext, "GL_OES_packed_depth_stencil", "GL_EXT_packed_depth_stencil", |
| + &enable_packed_depth_stencil); |
| + if (enable_packed_depth_stencil) { |
| AddExtensionString("GL_OES_packed_depth_stencil"); |
| if (enable_depth_texture) { |
| validators_.texture_internal_format.AddValue(GL_DEPTH_STENCIL); |
| @@ -175,18 +182,22 @@ |
| bool enable_texture_format_bgra8888 = false; |
| bool enable_read_format_bgra = false; |
| // Check if we should allow GL_EXT_texture_format_BGRA8888 |
| - if (ext.Desire("GL_EXT_texture_format_BGRA8888") && |
| - (ext.Have("GL_EXT_texture_format_BGRA8888") || |
| - ext.Have("GL_APPLE_texture_format_BGRA8888"))) { |
| - enable_texture_format_bgra8888 = true; |
| - } |
| + DoSimpleTestForEnablingExtension( |
| + &ext, |
| + "GL_EXT_texture_format_BGRA8888", |
| + "GL_APPLE_texture_format_BGRA8888", |
| + &enable_texture_format_bgra8888); |
| - if (ext.HaveAndDesire("GL_EXT_bgra")) { |
| + bool temp_bgra_variable = false; |
| + DoSimpleTestForEnablingExtension(&ext, "GL_EXT_bgra", &temp_bgra_variable); |
| + if (temp_bgra_variable) { |
| enable_texture_format_bgra8888 = true; |
| enable_read_format_bgra = true; |
| } |
| - if (ext.HaveAndDesire("GL_EXT_read_format_bgra")) { |
| + DoSimpleTestForEnablingExtension( |
| + &ext, "GL_EXT_read_format_bgra", &temp_bgra_variable); |
| + if (temp_bgra_variable) { |
| enable_read_format_bgra = true; |
| } |
| @@ -202,11 +213,13 @@ |
| } |
| // Check if we should allow GL_OES_texture_npot |
| - if (ext.Desire("GL_OES_texture_npot") && |
| - (ext.Have("GL_ARB_texture_non_power_of_two") || |
| - ext.Have("GL_OES_texture_npot"))) { |
| + bool npot_ok = false; |
| + |
| + DoSimpleTestForEnablingExtension( |
| + &ext, "GL_OES_texture_npot", "GL_ARB_texture_non_power_of_two", |
| + &npot_ok); |
| + if (npot_ok) { |
| AddExtensionString("GL_OES_texture_npot"); |
| - npot_ok = true; |
| } |
| // Check if we should allow GL_OES_texture_float, GL_OES_texture_half_float, |
| @@ -215,26 +228,23 @@ |
| bool enable_texture_float_linear = false; |
| bool enable_texture_half_float = false; |
| bool enable_texture_half_float_linear = false; |
| - if (ext.HaveAndDesire("GL_ARB_texture_float")) { |
| - enable_texture_float = true; |
| - enable_texture_float_linear = true; |
| - enable_texture_half_float = true; |
| - enable_texture_half_float_linear = true; |
| - } else { |
| - if (ext.HaveAndDesire("GL_OES_texture_float")) { |
| - enable_texture_float = true; |
| - if (ext.HaveAndDesire("GL_OES_texture_float_linear")) { |
| - enable_texture_float_linear = true; |
| - } |
| - } |
| - if (ext.HaveAndDesire("GL_OES_texture_half_float")) { |
| - enable_texture_half_float = true; |
| - if (ext.HaveAndDesire("GL_OES_texture_half_float_linear")) { |
| - enable_texture_half_float_linear = true; |
| - } |
| - } |
| - } |
| + // Note that we do not allow requests for the GL_ARB_texture_float |
| + // extension directly, since it implies the existence of internal |
| + // formats that don't exist in GL_OES_texture_float. |
| + DoSimpleTestForEnablingExtension( |
| + &ext, "GL_OES_texture_float", "GL_ARB_texture_float", |
| + &enable_texture_float); |
| + DoSimpleTestForEnablingExtension( |
| + &ext, "GL_OES_texture_float_linear", "GL_ARB_texture_float", |
| + &enable_texture_float_linear); |
| + DoSimpleTestForEnablingExtension( |
| + &ext, "GL_OES_texture_half_float", "GL_ARB_texture_float", |
| + &enable_texture_half_float); |
| + DoSimpleTestForEnablingExtension( |
| + &ext, "GL_OES_texture_half_float_linear", "GL_ARB_texture_float", |
| + &enable_texture_half_float_linear); |
| + |
| if (enable_texture_float) { |
| validators_.pixel_type.AddValue(GL_FLOAT); |
| AddExtensionString("GL_OES_texture_float"); |
| @@ -289,12 +299,76 @@ |
| feature_flags_.npot_ok = npot_ok; |
| } |
| +const std::string& FeatureInfo::RequestableExtensions() { |
| + if (requestable_extensions_dirty_) { |
| + requestable_extensions_ = ""; |
| + for (size_t i = 0; i < requestable_extensions_list_.size(); ++i) { |
| + if (i > 0) |
| + requestable_extensions_ += " "; |
| + requestable_extensions_ += requestable_extensions_list_[i]; |
| + } |
| + } |
| + return requestable_extensions_; |
| +} |
| + |
| +void FeatureInfo::DoSimpleTestForEnablingExtension( |
| + void* extensions_helper, const char* extension, bool* should_enable) { |
| + *should_enable = false; |
| + ExtensionHelper* helper = static_cast<ExtensionHelper*>(extensions_helper); |
| + if (helper->Have(extension)) { |
| + if (helper->Desire(extension)) { |
| + *should_enable = true; |
| + } else { |
| + AddRequestableExtensionString(extension); |
| + } |
| + } |
| +} |
| + |
| +void FeatureInfo::DoSimpleTestForEnablingExtension( |
| + void* extensions_helper, const char* extension, |
| + const char* alternate_extension, bool* should_enable) { |
| + *should_enable = false; |
| + ExtensionHelper* helper = static_cast<ExtensionHelper*>(extensions_helper); |
| + if (helper->Have(extension) || |
| + helper->Have(alternate_extension)) { |
| + if (helper->Desire(extension)) { |
| + *should_enable = true; |
| + } else { |
| + AddRequestableExtensionString(extension); |
| + } |
| + } |
| +} |
| + |
| void FeatureInfo::AddExtensionString(const std::string& str) { |
| if (extensions_.find(str) == std::string::npos) { |
| extensions_ += (extensions_.empty() ? "" : " ") + str; |
| + RemoveRequestableExtensionString(str); |
|
greggman
2010/12/04 01:28:44
Why remove added extensions? Shouldn't the list of
|
| } |
| } |
| +void FeatureInfo::AddRequestableExtensionString(const std::string& str) { |
| + if (extensions_.find(str) == std::string::npos) { |
| + for (size_t i = 0; i < requestable_extensions_list_.size(); ++i) { |
| + if (requestable_extensions_list_[i] == str) { |
| + break; |
| + } |
| + } |
| + requestable_extensions_list_.push_back(str); |
| + requestable_extensions_dirty_ = true; |
| + } |
| +} |
| + |
| +void FeatureInfo::RemoveRequestableExtensionString(const std::string& str) { |
| + for (size_t i = 0; i < requestable_extensions_list_.size(); ++i) { |
| + if (requestable_extensions_list_[i] == str) { |
| + requestable_extensions_list_.erase( |
| + requestable_extensions_list_.begin() + i); |
| + requestable_extensions_dirty_ = true; |
| + break; |
| + } |
| + } |
| +} |
| + |
| } // namespace gles2 |
| } // namespace gpu |