OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/feature_info.h" | 5 #include "gpu/command_buffer/service/feature_info.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 command_line->HasSwitch(switches::kDisableVirtualContexts); | 224 command_line->HasSwitch(switches::kDisableVirtualContexts); |
225 | 225 |
226 // The shader translator is needed to translate from WebGL-conformant GLES SL | 226 // The shader translator is needed to translate from WebGL-conformant GLES SL |
227 // to normal GLES SL, enforce WebGL conformance, translate from GLES SL 1.0 to | 227 // to normal GLES SL, enforce WebGL conformance, translate from GLES SL 1.0 to |
228 // target context GLSL, etc. | 228 // target context GLSL, etc. |
229 // The flag here is for testing only. | 229 // The flag here is for testing only. |
230 disable_shader_translator_ = | 230 disable_shader_translator_ = |
231 command_line->HasSwitch(switches::kDisableGLSLTranslator); | 231 command_line->HasSwitch(switches::kDisableGLSLTranslator); |
232 | 232 |
233 unsafe_es3_apis_enabled_ = false; | 233 unsafe_es3_apis_enabled_ = false; |
| 234 |
| 235 // Default context_type_ to a GLES2 Context. |
| 236 context_type_ = CONTEXT_TYPE_OPENGLES2; |
234 } | 237 } |
235 | 238 |
236 bool FeatureInfo::Initialize() { | 239 bool FeatureInfo::Initialize(ContextType context_type, |
237 disallowed_features_ = DisallowedFeatures(); | 240 const DisallowedFeatures& disallowed_features) { |
| 241 disallowed_features_ = disallowed_features; |
| 242 context_type_ = context_type; |
238 InitializeFeatures(); | 243 InitializeFeatures(); |
239 return true; | 244 return true; |
240 } | 245 } |
241 | 246 |
242 bool FeatureInfo::Initialize(const DisallowedFeatures& disallowed_features) { | 247 bool FeatureInfo::InitializeForTesting() { |
243 disallowed_features_ = disallowed_features; | 248 return Initialize(CONTEXT_TYPE_OPENGLES2, DisallowedFeatures()); |
244 InitializeFeatures(); | |
245 return true; | |
246 } | 249 } |
247 | 250 |
248 bool IsGL_REDSupportedOnFBOs() { | 251 bool IsGL_REDSupportedOnFBOs() { |
249 // Skia uses GL_RED with frame buffers, unfortunately, Mesa claims to support | 252 // Skia uses GL_RED with frame buffers, unfortunately, Mesa claims to support |
250 // GL_EXT_texture_rg, but it doesn't support it on frame buffers. To fix | 253 // GL_EXT_texture_rg, but it doesn't support it on frame buffers. To fix |
251 // this, we try it, and if it fails, we don't expose GL_EXT_texture_rg. | 254 // this, we try it, and if it fails, we don't expose GL_EXT_texture_rg. |
252 GLint fb_binding = 0; | 255 GLint fb_binding = 0; |
253 GLint tex_binding = 0; | 256 GLint tex_binding = 0; |
254 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb_binding); | 257 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb_binding); |
255 glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex_binding); | 258 glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex_binding); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgba"); | 694 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgba"); |
692 } | 695 } |
693 if (statusRGB == GL_FRAMEBUFFER_COMPLETE) { | 696 if (statusRGB == GL_FRAMEBUFFER_COMPLETE) { |
694 validators_.texture_internal_format.AddValue(GL_RGB32F); | 697 validators_.texture_internal_format.AddValue(GL_RGB32F); |
695 feature_flags_.chromium_color_buffer_float_rgb = true; | 698 feature_flags_.chromium_color_buffer_float_rgb = true; |
696 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgb"); | 699 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgb"); |
697 } | 700 } |
698 } | 701 } |
699 | 702 |
700 // Check for multisample support | 703 // Check for multisample support |
701 if (!workarounds_.disable_chromium_framebuffer_multisample) { | 704 |
| 705 // crbug.com/527565 - On some GPUs, MSAA does not perform acceptably for |
| 706 // rasterization. We disable it on non-WebGL contexts. For WebGL contexts |
| 707 // we leave it up to the site to decide whether to enable MSAA. |
| 708 bool disable_all_multisample = |
| 709 workarounds_.disable_msaa_on_non_webgl_contexts && !IsWebGLContext(); |
| 710 |
| 711 if (!disable_all_multisample && |
| 712 !workarounds_.disable_chromium_framebuffer_multisample) { |
702 bool ext_has_multisample = | 713 bool ext_has_multisample = |
703 extensions.Contains("GL_EXT_framebuffer_multisample") || | 714 extensions.Contains("GL_EXT_framebuffer_multisample") || |
704 gl_version_info_->is_es3 || | 715 gl_version_info_->is_es3 || |
705 gl_version_info_->is_desktop_core_profile; | 716 gl_version_info_->is_desktop_core_profile; |
706 if (gl_version_info_->is_angle) { | 717 if (gl_version_info_->is_angle) { |
707 ext_has_multisample |= | 718 ext_has_multisample |= |
708 extensions.Contains("GL_ANGLE_framebuffer_multisample"); | 719 extensions.Contains("GL_ANGLE_framebuffer_multisample"); |
709 } | 720 } |
710 feature_flags_.use_core_framebuffer_multisample = | 721 feature_flags_.use_core_framebuffer_multisample = |
711 gl_version_info_->is_es3 || gl_version_info_->is_desktop_core_profile; | 722 gl_version_info_->is_es3 || gl_version_info_->is_desktop_core_profile; |
712 if (ext_has_multisample) { | 723 if (ext_has_multisample) { |
713 feature_flags_.chromium_framebuffer_multisample = true; | 724 feature_flags_.chromium_framebuffer_multisample = true; |
714 validators_.frame_buffer_target.AddValue(GL_READ_FRAMEBUFFER_EXT); | 725 validators_.frame_buffer_target.AddValue(GL_READ_FRAMEBUFFER_EXT); |
715 validators_.frame_buffer_target.AddValue(GL_DRAW_FRAMEBUFFER_EXT); | 726 validators_.frame_buffer_target.AddValue(GL_DRAW_FRAMEBUFFER_EXT); |
716 validators_.g_l_state.AddValue(GL_READ_FRAMEBUFFER_BINDING_EXT); | 727 validators_.g_l_state.AddValue(GL_READ_FRAMEBUFFER_BINDING_EXT); |
717 validators_.g_l_state.AddValue(GL_MAX_SAMPLES_EXT); | 728 validators_.g_l_state.AddValue(GL_MAX_SAMPLES_EXT); |
718 validators_.render_buffer_parameter.AddValue(GL_RENDERBUFFER_SAMPLES_EXT); | 729 validators_.render_buffer_parameter.AddValue(GL_RENDERBUFFER_SAMPLES_EXT); |
719 AddExtensionString("GL_CHROMIUM_framebuffer_multisample"); | 730 AddExtensionString("GL_CHROMIUM_framebuffer_multisample"); |
720 } | 731 } |
721 } | 732 } |
722 | 733 |
723 if (!workarounds_.disable_multisampled_render_to_texture) { | 734 if (!disable_all_multisample && |
| 735 !workarounds_.disable_multisampled_render_to_texture) { |
724 if (extensions.Contains("GL_EXT_multisampled_render_to_texture")) { | 736 if (extensions.Contains("GL_EXT_multisampled_render_to_texture")) { |
725 feature_flags_.multisampled_render_to_texture = true; | 737 feature_flags_.multisampled_render_to_texture = true; |
726 } else if (extensions.Contains("GL_IMG_multisampled_render_to_texture")) { | 738 } else if (extensions.Contains("GL_IMG_multisampled_render_to_texture")) { |
727 feature_flags_.multisampled_render_to_texture = true; | 739 feature_flags_.multisampled_render_to_texture = true; |
728 feature_flags_.use_img_for_multisampled_render_to_texture = true; | 740 feature_flags_.use_img_for_multisampled_render_to_texture = true; |
729 } | 741 } |
730 if (feature_flags_.multisampled_render_to_texture) { | 742 if (feature_flags_.multisampled_render_to_texture) { |
731 validators_.render_buffer_parameter.AddValue( | 743 validators_.render_buffer_parameter.AddValue( |
732 GL_RENDERBUFFER_SAMPLES_EXT); | 744 GL_RENDERBUFFER_SAMPLES_EXT); |
733 validators_.g_l_state.AddValue(GL_MAX_SAMPLES_EXT); | 745 validators_.g_l_state.AddValue(GL_MAX_SAMPLES_EXT); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 }; | 1198 }; |
1187 if (max_draw_buffers < kTotalDrawBufferEnums) { | 1199 if (max_draw_buffers < kTotalDrawBufferEnums) { |
1188 validators_.g_l_state.RemoveValues( | 1200 validators_.g_l_state.RemoveValues( |
1189 kDrawBuffers + max_draw_buffers, | 1201 kDrawBuffers + max_draw_buffers, |
1190 kTotalDrawBufferEnums - max_draw_buffers); | 1202 kTotalDrawBufferEnums - max_draw_buffers); |
1191 } | 1203 } |
1192 | 1204 |
1193 unsafe_es3_apis_enabled_ = true; | 1205 unsafe_es3_apis_enabled_ = true; |
1194 } | 1206 } |
1195 | 1207 |
| 1208 bool FeatureInfo::IsWebGLContext() const { |
| 1209 // Switch statement to cause a compile-time error if we miss a case. |
| 1210 switch (context_type_) { |
| 1211 case CONTEXT_TYPE_WEBGL1: |
| 1212 case CONTEXT_TYPE_WEBGL2: |
| 1213 return true; |
| 1214 case CONTEXT_TYPE_OPENGLES2: |
| 1215 case CONTEXT_TYPE_OPENGLES3: |
| 1216 return false; |
| 1217 } |
| 1218 |
| 1219 NOTREACHED(); |
| 1220 return false; |
| 1221 } |
| 1222 |
1196 void FeatureInfo::AddExtensionString(const char* s) { | 1223 void FeatureInfo::AddExtensionString(const char* s) { |
1197 std::string str(s); | 1224 std::string str(s); |
1198 size_t pos = extensions_.find(str); | 1225 size_t pos = extensions_.find(str); |
1199 while (pos != std::string::npos && | 1226 while (pos != std::string::npos && |
1200 pos + str.length() < extensions_.length() && | 1227 pos + str.length() < extensions_.length() && |
1201 extensions_.substr(pos + str.length(), 1) != " ") { | 1228 extensions_.substr(pos + str.length(), 1) != " ") { |
1202 // This extension name is a substring of another. | 1229 // This extension name is a substring of another. |
1203 pos = extensions_.find(str, pos + str.length()); | 1230 pos = extensions_.find(str, pos + str.length()); |
1204 } | 1231 } |
1205 if (pos == std::string::npos) { | 1232 if (pos == std::string::npos) { |
1206 extensions_ += (extensions_.empty() ? "" : " ") + str; | 1233 extensions_ += (extensions_.empty() ? "" : " ") + str; |
1207 } | 1234 } |
1208 } | 1235 } |
1209 | 1236 |
1210 FeatureInfo::~FeatureInfo() { | 1237 FeatureInfo::~FeatureInfo() { |
1211 } | 1238 } |
1212 | 1239 |
1213 } // namespace gles2 | 1240 } // namespace gles2 |
1214 } // namespace gpu | 1241 } // namespace gpu |
OLD | NEW |