Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / gpu / command_buffer / service / feature_info.cc
blobd0947bf99eef3316146a15370101c339234a30c7
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
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/feature_info.h"
7 #include <set>
9 #include "base/command_line.h"
10 #include "base/macros.h"
11 #include "base/metrics/histogram.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h"
15 #include "gpu/command_buffer/service/gl_utils.h"
16 #include "gpu/command_buffer/service/gpu_switches.h"
17 #include "gpu/command_buffer/service/texture_definition.h"
18 #include "gpu/config/gpu_switches.h"
19 #include "ui/gl/gl_fence.h"
20 #include "ui/gl/gl_implementation.h"
22 #if !defined(OS_MACOSX)
23 #include "ui/gl/gl_fence_egl.h"
24 #endif
26 namespace gpu {
27 namespace gles2 {
29 namespace {
31 struct FormatInfo {
32 GLenum format;
33 const GLenum* types;
34 size_t count;
37 class StringSet {
38 public:
39 StringSet() {}
41 StringSet(const char* s) {
42 Init(s);
45 StringSet(const std::string& str) {
46 Init(str);
49 StringSet(const std::vector<std::string>& strs) {
50 string_set_.insert(strs.begin(), strs.end());
53 void Init(const char* s) {
54 std::string str(s ? s : "");
55 Init(str);
58 void Init(const std::string& str) {
59 std::vector<std::string> tokens = base::SplitString(
60 str, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
61 string_set_.insert(tokens.begin(), tokens.end());
64 bool Contains(const char* s) {
65 return string_set_.find(s) != string_set_.end();
68 bool Contains(const std::string& s) {
69 return string_set_.find(s) != string_set_.end();
72 const std::set<std::string>& GetImpl() {
73 return string_set_;
76 private:
77 std::set<std::string> string_set_;
80 // Process a string of wordaround type IDs (seperated by ',') and set up
81 // the corresponding Workaround flags.
82 void StringToWorkarounds(
83 const std::string& types, FeatureInfo::Workarounds* workarounds) {
84 DCHECK(workarounds);
85 std::vector<std::string> pieces;
86 base::SplitString(types, ',', &pieces);
87 for (size_t i = 0; i < pieces.size(); ++i) {
88 int number = 0;
89 bool succeed = base::StringToInt(pieces[i], &number);
90 DCHECK(succeed);
91 switch (number) {
92 #define GPU_OP(type, name) \
93 case gpu::type: \
94 workarounds->name = true; \
95 break;
96 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
97 #undef GPU_OP
98 default:
99 NOTIMPLEMENTED();
102 if (workarounds->max_texture_size_limit_4096)
103 workarounds->max_texture_size = 4096;
104 if (workarounds->max_cube_map_texture_size_limit_4096)
105 workarounds->max_cube_map_texture_size = 4096;
106 if (workarounds->max_cube_map_texture_size_limit_1024)
107 workarounds->max_cube_map_texture_size = 1024;
108 if (workarounds->max_cube_map_texture_size_limit_512)
109 workarounds->max_cube_map_texture_size = 512;
111 if (workarounds->max_fragment_uniform_vectors_32)
112 workarounds->max_fragment_uniform_vectors = 32;
113 if (workarounds->max_varying_vectors_16)
114 workarounds->max_varying_vectors = 16;
115 if (workarounds->max_vertex_uniform_vectors_256)
116 workarounds->max_vertex_uniform_vectors = 256;
118 if (workarounds->max_copy_texture_chromium_size_262144)
119 workarounds->max_copy_texture_chromium_size = 262144;
122 } // anonymous namespace.
124 FeatureInfo::FeatureFlags::FeatureFlags()
125 : chromium_color_buffer_float_rgba(false),
126 chromium_color_buffer_float_rgb(false),
127 chromium_framebuffer_multisample(false),
128 chromium_sync_query(false),
129 use_core_framebuffer_multisample(false),
130 multisampled_render_to_texture(false),
131 use_img_for_multisampled_render_to_texture(false),
132 oes_standard_derivatives(false),
133 oes_egl_image_external(false),
134 oes_depth24(false),
135 oes_compressed_etc1_rgb8_texture(false),
136 packed_depth24_stencil8(false),
137 npot_ok(false),
138 enable_texture_float_linear(false),
139 enable_texture_half_float_linear(false),
140 angle_translated_shader_source(false),
141 angle_pack_reverse_row_order(false),
142 arb_texture_rectangle(false),
143 angle_instanced_arrays(false),
144 occlusion_query_boolean(false),
145 use_arb_occlusion_query2_for_occlusion_query_boolean(false),
146 use_arb_occlusion_query_for_occlusion_query_boolean(false),
147 native_vertex_array_object(false),
148 ext_texture_format_atc(false),
149 ext_texture_format_bgra8888(false),
150 ext_texture_format_dxt1(false),
151 ext_texture_format_dxt5(false),
152 enable_shader_name_hashing(false),
153 enable_samplers(false),
154 ext_draw_buffers(false),
155 nv_draw_buffers(false),
156 ext_frag_depth(false),
157 ext_shader_texture_lod(false),
158 use_async_readpixels(false),
159 map_buffer_range(false),
160 ext_discard_framebuffer(false),
161 angle_depth_texture(false),
162 is_swiftshader(false),
163 angle_texture_usage(false),
164 ext_texture_storage(false),
165 chromium_path_rendering(false),
166 blend_equation_advanced(false),
167 blend_equation_advanced_coherent(false),
168 ext_texture_rg(false),
169 enable_subscribe_uniform(false),
170 emulate_primitive_restart_fixed_index(false),
171 ext_render_buffer_format_bgra8888(false) {
174 FeatureInfo::Workarounds::Workarounds() :
175 #define GPU_OP(type, name) name(false),
176 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
177 #undef GPU_OP
178 max_texture_size(0),
179 max_cube_map_texture_size(0),
180 max_fragment_uniform_vectors(0),
181 max_varying_vectors(0),
182 max_vertex_uniform_vectors(0),
183 max_copy_texture_chromium_size(0) {
186 FeatureInfo::FeatureInfo() {
187 InitializeBasicState(*base::CommandLine::ForCurrentProcess());
190 FeatureInfo::FeatureInfo(const base::CommandLine& command_line) {
191 InitializeBasicState(command_line);
194 void FeatureInfo::InitializeBasicState(const base::CommandLine& command_line) {
195 if (command_line.HasSwitch(switches::kGpuDriverBugWorkarounds)) {
196 std::string types = command_line.GetSwitchValueASCII(
197 switches::kGpuDriverBugWorkarounds);
198 StringToWorkarounds(types, &workarounds_);
200 feature_flags_.enable_shader_name_hashing =
201 !command_line.HasSwitch(switches::kDisableShaderNameHashing);
203 feature_flags_.is_swiftshader =
204 (command_line.GetSwitchValueASCII(switches::kUseGL) == "swiftshader");
206 feature_flags_.enable_subscribe_uniform =
207 command_line.HasSwitch(switches::kEnableSubscribeUniformExtension);
209 enable_unsafe_es3_apis_switch_ =
210 command_line.HasSwitch(switches::kEnableUnsafeES3APIs);
212 enable_gl_path_rendering_switch_ =
213 command_line.HasSwitch(switches::kEnableGLPathRendering);
215 unsafe_es3_apis_enabled_ = false;
218 bool FeatureInfo::Initialize() {
219 disallowed_features_ = DisallowedFeatures();
220 InitializeFeatures();
221 return true;
224 bool FeatureInfo::Initialize(const DisallowedFeatures& disallowed_features) {
225 disallowed_features_ = disallowed_features;
226 InitializeFeatures();
227 return true;
230 bool IsGL_REDSupportedOnFBOs() {
231 // Skia uses GL_RED with frame buffers, unfortunately, Mesa claims to support
232 // GL_EXT_texture_rg, but it doesn't support it on frame buffers. To fix
233 // this, we try it, and if it fails, we don't expose GL_EXT_texture_rg.
234 GLint fb_binding = 0;
235 GLint tex_binding = 0;
236 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb_binding);
237 glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex_binding);
239 GLuint textureId = 0;
240 glGenTextures(1, &textureId);
241 glBindTexture(GL_TEXTURE_2D, textureId);
242 GLubyte data[1] = {0};
243 glTexImage2D(GL_TEXTURE_2D, 0, GL_RED_EXT, 1, 1, 0, GL_RED_EXT,
244 GL_UNSIGNED_BYTE, data);
245 GLuint textureFBOID = 0;
246 glGenFramebuffersEXT(1, &textureFBOID);
247 glBindFramebufferEXT(GL_FRAMEBUFFER, textureFBOID);
248 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
249 textureId, 0);
250 bool result =
251 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_UNSUPPORTED;
252 glDeleteFramebuffersEXT(1, &textureFBOID);
253 glDeleteTextures(1, &textureId);
255 glBindFramebufferEXT(GL_FRAMEBUFFER, static_cast<GLuint>(fb_binding));
256 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(tex_binding));
258 DCHECK(glGetError() == GL_NO_ERROR);
260 return result;
263 void FeatureInfo::InitializeFeatures() {
264 // Figure out what extensions to turn on.
265 StringSet extensions;
266 // We need to figure out how to query the extension string before we
267 // have a GLVersionInfo available.
268 const char* version_str =
269 reinterpret_cast<const char*>(glGetString(GL_VERSION));
270 unsigned major_version, minor_version;
271 bool is_es, is_es3;
272 gfx::GLVersionInfo::ParseVersionString(
273 version_str, &major_version, &minor_version, &is_es, &is_es3);
274 if (!is_es && major_version >= 3) {
275 std::vector<std::string> exts;
276 GLint num_extensions = 0;
277 glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
278 for (GLint i = 0; i < num_extensions; ++i) {
279 const char* extension = reinterpret_cast<const char*>(
280 glGetStringi(GL_EXTENSIONS, i));
281 DCHECK(extension != NULL);
282 exts.push_back(extension);
284 extensions = exts;
285 } else {
286 extensions = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
289 const char* renderer_str =
290 reinterpret_cast<const char*>(glGetString(GL_RENDERER));
292 gl_version_info_.reset(new gfx::GLVersionInfo(
293 version_str, renderer_str, extensions.GetImpl()));
295 AddExtensionString("GL_ANGLE_translated_shader_source");
296 AddExtensionString("GL_CHROMIUM_async_pixel_transfers");
297 AddExtensionString("GL_CHROMIUM_bind_uniform_location");
298 AddExtensionString("GL_CHROMIUM_command_buffer_query");
299 AddExtensionString("GL_CHROMIUM_command_buffer_latency_query");
300 AddExtensionString("GL_CHROMIUM_copy_texture");
301 AddExtensionString("GL_CHROMIUM_get_error_query");
302 AddExtensionString("GL_CHROMIUM_lose_context");
303 AddExtensionString("GL_CHROMIUM_pixel_transfer_buffer_object");
304 AddExtensionString("GL_CHROMIUM_rate_limit_offscreen_context");
305 AddExtensionString("GL_CHROMIUM_resize");
306 AddExtensionString("GL_CHROMIUM_resource_safe");
307 AddExtensionString("GL_CHROMIUM_strict_attribs");
308 AddExtensionString("GL_CHROMIUM_texture_mailbox");
309 AddExtensionString("GL_CHROMIUM_trace_marker");
310 AddExtensionString("GL_EXT_debug_marker");
312 if (feature_flags_.enable_subscribe_uniform) {
313 AddExtensionString("GL_CHROMIUM_subscribe_uniform");
316 // OES_vertex_array_object is emulated if not present natively,
317 // so the extension string is always exposed.
318 AddExtensionString("GL_OES_vertex_array_object");
320 if (!disallowed_features_.gpu_memory_manager)
321 AddExtensionString("GL_CHROMIUM_gpu_memory_manager");
323 if (extensions.Contains("GL_ANGLE_translated_shader_source")) {
324 feature_flags_.angle_translated_shader_source = true;
327 // Check if we should allow GL_EXT_texture_compression_dxt1 and
328 // GL_EXT_texture_compression_s3tc.
329 bool enable_dxt1 = false;
330 bool enable_dxt3 = false;
331 bool enable_dxt5 = false;
332 bool have_s3tc = extensions.Contains("GL_EXT_texture_compression_s3tc");
333 bool have_dxt3 =
334 have_s3tc || extensions.Contains("GL_ANGLE_texture_compression_dxt3");
335 bool have_dxt5 =
336 have_s3tc || extensions.Contains("GL_ANGLE_texture_compression_dxt5");
338 if (extensions.Contains("GL_EXT_texture_compression_dxt1") || have_s3tc) {
339 enable_dxt1 = true;
341 if (have_dxt3) {
342 enable_dxt3 = true;
344 if (have_dxt5) {
345 enable_dxt5 = true;
348 if (enable_dxt1) {
349 feature_flags_.ext_texture_format_dxt1 = true;
351 AddExtensionString("GL_EXT_texture_compression_dxt1");
352 validators_.compressed_texture_format.AddValue(
353 GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
354 validators_.compressed_texture_format.AddValue(
355 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
358 if (enable_dxt3) {
359 // The difference between GL_EXT_texture_compression_s3tc and
360 // GL_CHROMIUM_texture_compression_dxt3 is that the former
361 // requires on the fly compression. The latter does not.
362 AddExtensionString("GL_CHROMIUM_texture_compression_dxt3");
363 validators_.compressed_texture_format.AddValue(
364 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT);
367 if (enable_dxt5) {
368 feature_flags_.ext_texture_format_dxt5 = true;
370 // The difference between GL_EXT_texture_compression_s3tc and
371 // GL_CHROMIUM_texture_compression_dxt5 is that the former
372 // requires on the fly compression. The latter does not.
373 AddExtensionString("GL_CHROMIUM_texture_compression_dxt5");
374 validators_.compressed_texture_format.AddValue(
375 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT);
378 bool have_atc = extensions.Contains("GL_AMD_compressed_ATC_texture") ||
379 extensions.Contains("GL_ATI_texture_compression_atitc");
380 if (have_atc) {
381 feature_flags_.ext_texture_format_atc = true;
383 AddExtensionString("GL_AMD_compressed_ATC_texture");
384 validators_.compressed_texture_format.AddValue(GL_ATC_RGB_AMD);
385 validators_.compressed_texture_format.AddValue(
386 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD);
389 // Check if we should enable GL_EXT_texture_filter_anisotropic.
390 if (extensions.Contains("GL_EXT_texture_filter_anisotropic")) {
391 AddExtensionString("GL_EXT_texture_filter_anisotropic");
392 validators_.texture_parameter.AddValue(
393 GL_TEXTURE_MAX_ANISOTROPY_EXT);
394 validators_.g_l_state.AddValue(
395 GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
398 // Check if we should support GL_OES_packed_depth_stencil and/or
399 // GL_GOOGLE_depth_texture / GL_CHROMIUM_depth_texture.
401 // NOTE: GL_OES_depth_texture requires support for depth cubemaps.
402 // GL_ARB_depth_texture requires other features that
403 // GL_OES_packed_depth_stencil does not provide.
405 // Therefore we made up GL_GOOGLE_depth_texture / GL_CHROMIUM_depth_texture.
407 // GL_GOOGLE_depth_texture is legacy. As we exposed it into NaCl we can't
408 // get rid of it.
410 bool enable_depth_texture = false;
411 if (!workarounds_.disable_depth_texture &&
412 (extensions.Contains("GL_ARB_depth_texture") ||
413 extensions.Contains("GL_OES_depth_texture") ||
414 extensions.Contains("GL_ANGLE_depth_texture") ||
415 gl_version_info_->is_es3 ||
416 gl_version_info_->is_desktop_core_profile)) {
417 enable_depth_texture = true;
418 feature_flags_.angle_depth_texture =
419 extensions.Contains("GL_ANGLE_depth_texture");
422 if (enable_depth_texture) {
423 AddExtensionString("GL_CHROMIUM_depth_texture");
424 AddExtensionString("GL_GOOGLE_depth_texture");
425 validators_.texture_internal_format.AddValue(GL_DEPTH_COMPONENT);
426 validators_.texture_format.AddValue(GL_DEPTH_COMPONENT);
427 validators_.pixel_type.AddValue(GL_UNSIGNED_SHORT);
428 validators_.pixel_type.AddValue(GL_UNSIGNED_INT);
431 if (extensions.Contains("GL_EXT_packed_depth_stencil") ||
432 extensions.Contains("GL_OES_packed_depth_stencil") ||
433 gl_version_info_->is_es3 ||
434 gl_version_info_->is_desktop_core_profile) {
435 AddExtensionString("GL_OES_packed_depth_stencil");
436 feature_flags_.packed_depth24_stencil8 = true;
437 if (enable_depth_texture) {
438 validators_.texture_internal_format.AddValue(GL_DEPTH_STENCIL);
439 validators_.texture_format.AddValue(GL_DEPTH_STENCIL);
440 validators_.pixel_type.AddValue(GL_UNSIGNED_INT_24_8);
442 validators_.render_buffer_format.AddValue(GL_DEPTH24_STENCIL8);
445 if (gl_version_info_->is_es3 ||
446 gl_version_info_->is_desktop_core_profile ||
447 extensions.Contains("GL_OES_vertex_array_object") ||
448 extensions.Contains("GL_ARB_vertex_array_object") ||
449 extensions.Contains("GL_APPLE_vertex_array_object")) {
450 feature_flags_.native_vertex_array_object = true;
453 // If we're using client_side_arrays we have to emulate
454 // vertex array objects since vertex array objects do not work
455 // with client side arrays.
456 if (workarounds_.use_client_side_arrays_for_stream_buffers) {
457 feature_flags_.native_vertex_array_object = false;
460 if (gl_version_info_->is_es3 ||
461 extensions.Contains("GL_OES_element_index_uint") ||
462 gfx::HasDesktopGLFeatures()) {
463 AddExtensionString("GL_OES_element_index_uint");
464 validators_.index_type.AddValue(GL_UNSIGNED_INT);
467 // With EXT_sRGB, unsized SRGB_EXT and SRGB_ALPHA_EXT are accepted by the
468 // <format> and <internalformat> parameter of TexImage2D. GLES3 adds support
469 // for SRGB Textures but the accepted internal formats for TexImage2D are only
470 // sized formats GL_SRGB8 and GL_SRGB8_ALPHA8. Also, SRGB_EXT isn't a valid
471 // <format> in this case. So, even with GLES3 explicitly check for
472 // GL_EXT_sRGB.
473 if (((gl_version_info_->is_es3 ||
474 extensions.Contains("GL_OES_rgb8_rgba8")) &&
475 extensions.Contains("GL_EXT_sRGB")) || gfx::HasDesktopGLFeatures()) {
476 AddExtensionString("GL_EXT_sRGB");
477 validators_.texture_internal_format.AddValue(GL_SRGB_EXT);
478 validators_.texture_internal_format.AddValue(GL_SRGB_ALPHA_EXT);
479 validators_.texture_format.AddValue(GL_SRGB_EXT);
480 validators_.texture_format.AddValue(GL_SRGB_ALPHA_EXT);
481 validators_.render_buffer_format.AddValue(GL_SRGB8_ALPHA8_EXT);
482 validators_.frame_buffer_parameter.AddValue(
483 GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT);
486 bool enable_texture_format_bgra8888 = false;
487 bool enable_read_format_bgra = false;
488 bool enable_render_buffer_bgra = false;
489 bool enable_immutable_texture_format_bgra_on_es3 =
490 extensions.Contains("GL_APPLE_texture_format_BGRA8888");
492 // Check if we should allow GL_EXT_texture_format_BGRA8888
493 if (extensions.Contains("GL_EXT_texture_format_BGRA8888") ||
494 enable_immutable_texture_format_bgra_on_es3 ||
495 extensions.Contains("GL_EXT_bgra")) {
496 enable_texture_format_bgra8888 = true;
499 // Only desktop GL extension GL_EXT_bgra or ANGLE guarantee that we can
500 // allocate a renderbuffer with this format.
501 if (extensions.Contains("GL_EXT_bgra") || gl_version_info_->is_angle) {
502 enable_render_buffer_bgra = true;
505 if (extensions.Contains("GL_EXT_read_format_bgra") ||
506 extensions.Contains("GL_EXT_bgra")) {
507 enable_read_format_bgra = true;
510 if (enable_texture_format_bgra8888) {
511 feature_flags_.ext_texture_format_bgra8888 = true;
512 AddExtensionString("GL_EXT_texture_format_BGRA8888");
513 validators_.texture_internal_format.AddValue(GL_BGRA_EXT);
514 validators_.texture_format.AddValue(GL_BGRA_EXT);
517 if (enable_read_format_bgra) {
518 AddExtensionString("GL_EXT_read_format_bgra");
519 validators_.read_pixel_format.AddValue(GL_BGRA_EXT);
522 if (enable_render_buffer_bgra) {
523 feature_flags_.ext_render_buffer_format_bgra8888 = true;
524 AddExtensionString("GL_CHROMIUM_renderbuffer_format_BGRA8888");
525 validators_.render_buffer_format.AddValue(GL_BGRA8_EXT);
528 if (extensions.Contains("GL_OES_rgb8_rgba8") || gfx::HasDesktopGLFeatures()) {
529 AddExtensionString("GL_OES_rgb8_rgba8");
530 validators_.render_buffer_format.AddValue(GL_RGB8_OES);
531 validators_.render_buffer_format.AddValue(GL_RGBA8_OES);
534 // Check if we should allow GL_OES_texture_npot
535 if (!disallowed_features_.npot_support &&
536 (gl_version_info_->is_es3 ||
537 gl_version_info_->is_desktop_core_profile ||
538 extensions.Contains("GL_ARB_texture_non_power_of_two") ||
539 extensions.Contains("GL_OES_texture_npot"))) {
540 AddExtensionString("GL_OES_texture_npot");
541 feature_flags_.npot_ok = true;
544 // Check if we should allow GL_OES_texture_float, GL_OES_texture_half_float,
545 // GL_OES_texture_float_linear, GL_OES_texture_half_float_linear
546 bool enable_texture_float = false;
547 bool enable_texture_float_linear = false;
548 bool enable_texture_half_float = false;
549 bool enable_texture_half_float_linear = false;
551 bool may_enable_chromium_color_buffer_float = false;
553 if (extensions.Contains("GL_ARB_texture_float") ||
554 gl_version_info_->is_desktop_core_profile) {
555 enable_texture_float = true;
556 enable_texture_float_linear = true;
557 enable_texture_half_float = true;
558 enable_texture_half_float_linear = true;
559 may_enable_chromium_color_buffer_float = true;
560 } else {
561 // GLES3 adds support for Float type by default but it doesn't support all
562 // formats as GL_OES_texture_float(i.e.LUMINANCE_ALPHA,LUMINANCE and Alpha)
563 if (extensions.Contains("GL_OES_texture_float")) {
564 enable_texture_float = true;
565 if (extensions.Contains("GL_OES_texture_float_linear")) {
566 enable_texture_float_linear = true;
568 // This extension allows a variety of floating point formats to be
569 // rendered to via framebuffer objects. Enable it's usage only if
570 // support for Floating textures is enabled.
571 if ((gl_version_info_->is_es3 &&
572 extensions.Contains("GL_EXT_color_buffer_float")) ||
573 gl_version_info_->is_angle) {
574 may_enable_chromium_color_buffer_float = true;
578 // TODO(dshwang): GLES3 supports half float by default but GL_HALF_FLOAT_OES
579 // isn't equal to GL_HALF_FLOAT.
580 if (extensions.Contains("GL_OES_texture_half_float")) {
581 enable_texture_half_float = true;
582 if (extensions.Contains("GL_OES_texture_half_float_linear")) {
583 enable_texture_half_float_linear = true;
588 if (enable_texture_float) {
589 validators_.pixel_type.AddValue(GL_FLOAT);
590 validators_.read_pixel_type.AddValue(GL_FLOAT);
591 AddExtensionString("GL_OES_texture_float");
592 if (enable_texture_float_linear) {
593 AddExtensionString("GL_OES_texture_float_linear");
597 if (enable_texture_half_float) {
598 validators_.pixel_type.AddValue(GL_HALF_FLOAT_OES);
599 validators_.read_pixel_type.AddValue(GL_HALF_FLOAT_OES);
600 AddExtensionString("GL_OES_texture_half_float");
601 if (enable_texture_half_float_linear) {
602 AddExtensionString("GL_OES_texture_half_float_linear");
606 if (may_enable_chromium_color_buffer_float) {
607 static_assert(GL_RGBA32F_ARB == GL_RGBA32F &&
608 GL_RGBA32F_EXT == GL_RGBA32F &&
609 GL_RGB32F_ARB == GL_RGB32F &&
610 GL_RGB32F_EXT == GL_RGB32F,
611 "sized float internal format variations must match");
612 // We don't check extension support beyond ARB_texture_float on desktop GL,
613 // and format support varies between GL configurations. For example, spec
614 // prior to OpenGL 3.0 mandates framebuffer support only for one
615 // implementation-chosen format, and ES3.0 EXT_color_buffer_float does not
616 // support rendering to RGB32F. Check for framebuffer completeness with
617 // formats that the extensions expose, and only enable an extension when a
618 // framebuffer created with its texture format is reported as complete.
619 GLint fb_binding = 0;
620 GLint tex_binding = 0;
621 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb_binding);
622 glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex_binding);
624 GLuint tex_id = 0;
625 GLuint fb_id = 0;
626 GLsizei width = 16;
628 glGenTextures(1, &tex_id);
629 glGenFramebuffersEXT(1, &fb_id);
630 glBindTexture(GL_TEXTURE_2D, tex_id);
631 // Nearest filter needed for framebuffer completeness on some drivers.
632 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
633 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, width, 0, GL_RGBA,
634 GL_FLOAT, NULL);
635 glBindFramebufferEXT(GL_FRAMEBUFFER, fb_id);
636 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
637 GL_TEXTURE_2D, tex_id, 0);
638 GLenum statusRGBA = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
639 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, width, 0, GL_RGB,
640 GL_FLOAT, NULL);
641 GLenum statusRGB = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
642 glDeleteFramebuffersEXT(1, &fb_id);
643 glDeleteTextures(1, &tex_id);
645 glBindFramebufferEXT(GL_FRAMEBUFFER, static_cast<GLuint>(fb_binding));
646 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(tex_binding));
648 DCHECK(glGetError() == GL_NO_ERROR);
650 if (statusRGBA == GL_FRAMEBUFFER_COMPLETE) {
651 validators_.texture_internal_format.AddValue(GL_RGBA32F);
652 feature_flags_.chromium_color_buffer_float_rgba = true;
653 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgba");
655 if (statusRGB == GL_FRAMEBUFFER_COMPLETE) {
656 validators_.texture_internal_format.AddValue(GL_RGB32F);
657 feature_flags_.chromium_color_buffer_float_rgb = true;
658 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgb");
662 // Check for multisample support
663 if (!workarounds_.disable_chromium_framebuffer_multisample) {
664 bool ext_has_multisample =
665 extensions.Contains("GL_EXT_framebuffer_multisample") ||
666 gl_version_info_->is_es3 ||
667 gl_version_info_->is_desktop_core_profile;
668 if (gl_version_info_->is_angle) {
669 ext_has_multisample |=
670 extensions.Contains("GL_ANGLE_framebuffer_multisample");
672 feature_flags_.use_core_framebuffer_multisample =
673 gl_version_info_->is_es3 || gl_version_info_->is_desktop_core_profile;
674 if (ext_has_multisample) {
675 feature_flags_.chromium_framebuffer_multisample = true;
676 validators_.frame_buffer_target.AddValue(GL_READ_FRAMEBUFFER_EXT);
677 validators_.frame_buffer_target.AddValue(GL_DRAW_FRAMEBUFFER_EXT);
678 validators_.g_l_state.AddValue(GL_READ_FRAMEBUFFER_BINDING_EXT);
679 validators_.g_l_state.AddValue(GL_MAX_SAMPLES_EXT);
680 validators_.render_buffer_parameter.AddValue(GL_RENDERBUFFER_SAMPLES_EXT);
681 AddExtensionString("GL_CHROMIUM_framebuffer_multisample");
685 if (!workarounds_.disable_multisampled_render_to_texture) {
686 if (extensions.Contains("GL_EXT_multisampled_render_to_texture")) {
687 feature_flags_.multisampled_render_to_texture = true;
688 } else if (extensions.Contains("GL_IMG_multisampled_render_to_texture")) {
689 feature_flags_.multisampled_render_to_texture = true;
690 feature_flags_.use_img_for_multisampled_render_to_texture = true;
692 if (feature_flags_.multisampled_render_to_texture) {
693 validators_.render_buffer_parameter.AddValue(
694 GL_RENDERBUFFER_SAMPLES_EXT);
695 validators_.g_l_state.AddValue(GL_MAX_SAMPLES_EXT);
696 validators_.frame_buffer_parameter.AddValue(
697 GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT);
698 AddExtensionString("GL_EXT_multisampled_render_to_texture");
702 if (extensions.Contains("GL_OES_depth24") || gfx::HasDesktopGLFeatures() ||
703 gl_version_info_->is_es3) {
704 AddExtensionString("GL_OES_depth24");
705 feature_flags_.oes_depth24 = true;
706 validators_.render_buffer_format.AddValue(GL_DEPTH_COMPONENT24);
709 if (gl_version_info_->is_es3 ||
710 extensions.Contains("GL_OES_standard_derivatives") ||
711 gfx::HasDesktopGLFeatures()) {
712 AddExtensionString("GL_OES_standard_derivatives");
713 feature_flags_.oes_standard_derivatives = true;
714 validators_.hint_target.AddValue(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
715 validators_.g_l_state.AddValue(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
718 if (extensions.Contains("GL_OES_EGL_image_external")) {
719 AddExtensionString("GL_OES_EGL_image_external");
720 feature_flags_.oes_egl_image_external = true;
721 validators_.texture_bind_target.AddValue(GL_TEXTURE_EXTERNAL_OES);
722 validators_.get_tex_param_target.AddValue(GL_TEXTURE_EXTERNAL_OES);
723 validators_.texture_parameter.AddValue(GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES);
724 validators_.g_l_state.AddValue(GL_TEXTURE_BINDING_EXTERNAL_OES);
727 if (extensions.Contains("GL_OES_compressed_ETC1_RGB8_texture")) {
728 AddExtensionString("GL_OES_compressed_ETC1_RGB8_texture");
729 feature_flags_.oes_compressed_etc1_rgb8_texture = true;
730 validators_.compressed_texture_format.AddValue(GL_ETC1_RGB8_OES);
733 if (extensions.Contains("GL_AMD_compressed_ATC_texture")) {
734 AddExtensionString("GL_AMD_compressed_ATC_texture");
735 validators_.compressed_texture_format.AddValue(
736 GL_ATC_RGB_AMD);
737 validators_.compressed_texture_format.AddValue(
738 GL_ATC_RGBA_EXPLICIT_ALPHA_AMD);
739 validators_.compressed_texture_format.AddValue(
740 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD);
743 if (extensions.Contains("GL_IMG_texture_compression_pvrtc")) {
744 AddExtensionString("GL_IMG_texture_compression_pvrtc");
745 validators_.compressed_texture_format.AddValue(
746 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG);
747 validators_.compressed_texture_format.AddValue(
748 GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG);
749 validators_.compressed_texture_format.AddValue(
750 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG);
751 validators_.compressed_texture_format.AddValue(
752 GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG);
755 // Ideally we would only expose this extension on Mac OS X, to
756 // support GL_CHROMIUM_iosurface and the compositor. We don't want
757 // applications to start using it; they should use ordinary non-
758 // power-of-two textures. However, for unit testing purposes we
759 // expose it on all supported platforms.
760 if (extensions.Contains("GL_ARB_texture_rectangle") ||
761 gl_version_info_->is_desktop_core_profile) {
762 AddExtensionString("GL_ARB_texture_rectangle");
763 feature_flags_.arb_texture_rectangle = true;
764 // Rectangle textures are used as samplers via glBindTexture, framebuffer
765 // textures via glFramebufferTexture2D, and copy destinations via
766 // glCopyPixels.
767 validators_.texture_bind_target.AddValue(GL_TEXTURE_RECTANGLE_ARB);
768 validators_.texture_target.AddValue(GL_TEXTURE_RECTANGLE_ARB);
769 validators_.get_tex_param_target.AddValue(GL_TEXTURE_RECTANGLE_ARB);
770 validators_.g_l_state.AddValue(GL_TEXTURE_BINDING_RECTANGLE_ARB);
773 #if defined(OS_MACOSX)
774 AddExtensionString("GL_CHROMIUM_iosurface");
775 #endif
777 // TODO(gman): Add support for these extensions.
778 // GL_OES_depth32
780 feature_flags_.enable_texture_float_linear |= enable_texture_float_linear;
781 feature_flags_.enable_texture_half_float_linear |=
782 enable_texture_half_float_linear;
784 if (extensions.Contains("GL_ANGLE_pack_reverse_row_order")) {
785 AddExtensionString("GL_ANGLE_pack_reverse_row_order");
786 feature_flags_.angle_pack_reverse_row_order = true;
787 validators_.pixel_store.AddValue(GL_PACK_REVERSE_ROW_ORDER_ANGLE);
788 validators_.g_l_state.AddValue(GL_PACK_REVERSE_ROW_ORDER_ANGLE);
791 if (extensions.Contains("GL_ANGLE_texture_usage")) {
792 feature_flags_.angle_texture_usage = true;
793 AddExtensionString("GL_ANGLE_texture_usage");
794 validators_.texture_parameter.AddValue(GL_TEXTURE_USAGE_ANGLE);
797 // Note: Only APPLE_texture_format_BGRA8888 extension allows BGRA8_EXT in
798 // ES3's glTexStorage2D. We prefer support BGRA to texture storage.
799 // So we don't expose GL_EXT_texture_storage when ES3 +
800 // GL_EXT_texture_format_BGRA8888 because we fail the GL_BGRA8 requirement.
801 // However we expose GL_EXT_texture_storage when just ES3 because we don't
802 // claim to handle GL_BGRA8.
803 bool support_texture_storage_on_es3 =
804 (gl_version_info_->is_es3 &&
805 enable_immutable_texture_format_bgra_on_es3) ||
806 (gl_version_info_->is_es3 &&
807 !enable_texture_format_bgra8888);
808 if (extensions.Contains("GL_EXT_texture_storage") ||
809 extensions.Contains("GL_ARB_texture_storage") ||
810 support_texture_storage_on_es3 ||
811 gl_version_info_->is_desktop_core_profile) {
812 feature_flags_.ext_texture_storage = true;
813 AddExtensionString("GL_EXT_texture_storage");
814 validators_.texture_parameter.AddValue(GL_TEXTURE_IMMUTABLE_FORMAT_EXT);
815 if (enable_texture_format_bgra8888)
816 validators_.texture_internal_format_storage.AddValue(GL_BGRA8_EXT);
817 if (enable_texture_float) {
818 validators_.texture_internal_format_storage.AddValue(GL_RGBA32F_EXT);
819 validators_.texture_internal_format_storage.AddValue(GL_RGB32F_EXT);
820 validators_.texture_internal_format_storage.AddValue(GL_ALPHA32F_EXT);
821 validators_.texture_internal_format_storage.AddValue(
822 GL_LUMINANCE32F_EXT);
823 validators_.texture_internal_format_storage.AddValue(
824 GL_LUMINANCE_ALPHA32F_EXT);
826 if (enable_texture_half_float) {
827 validators_.texture_internal_format_storage.AddValue(GL_RGBA16F_EXT);
828 validators_.texture_internal_format_storage.AddValue(GL_RGB16F_EXT);
829 validators_.texture_internal_format_storage.AddValue(GL_ALPHA16F_EXT);
830 validators_.texture_internal_format_storage.AddValue(
831 GL_LUMINANCE16F_EXT);
832 validators_.texture_internal_format_storage.AddValue(
833 GL_LUMINANCE_ALPHA16F_EXT);
837 bool have_ext_occlusion_query_boolean =
838 extensions.Contains("GL_EXT_occlusion_query_boolean");
839 bool have_arb_occlusion_query2 =
840 extensions.Contains("GL_ARB_occlusion_query2");
841 bool have_arb_occlusion_query =
842 extensions.Contains("GL_ARB_occlusion_query");
844 if (have_ext_occlusion_query_boolean ||
845 have_arb_occlusion_query2 ||
846 have_arb_occlusion_query) {
847 AddExtensionString("GL_EXT_occlusion_query_boolean");
848 feature_flags_.occlusion_query_boolean = true;
849 feature_flags_.use_arb_occlusion_query2_for_occlusion_query_boolean =
850 !have_ext_occlusion_query_boolean && have_arb_occlusion_query2;
851 feature_flags_.use_arb_occlusion_query_for_occlusion_query_boolean =
852 !have_ext_occlusion_query_boolean && have_arb_occlusion_query &&
853 !have_arb_occlusion_query2;
856 if (!workarounds_.disable_angle_instanced_arrays &&
857 (extensions.Contains("GL_ANGLE_instanced_arrays") ||
858 (extensions.Contains("GL_ARB_instanced_arrays") &&
859 extensions.Contains("GL_ARB_draw_instanced")) ||
860 gl_version_info_->is_es3)) {
861 AddExtensionString("GL_ANGLE_instanced_arrays");
862 feature_flags_.angle_instanced_arrays = true;
863 validators_.vertex_attribute.AddValue(GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
866 bool vendor_agnostic_draw_buffers =
867 extensions.Contains("GL_ARB_draw_buffers") ||
868 extensions.Contains("GL_EXT_draw_buffers");
869 if (!workarounds_.disable_ext_draw_buffers &&
870 (vendor_agnostic_draw_buffers ||
871 (extensions.Contains("GL_NV_draw_buffers") &&
872 gl_version_info_->is_es3) ||
873 gl_version_info_->is_desktop_core_profile)) {
874 AddExtensionString("GL_EXT_draw_buffers");
875 feature_flags_.ext_draw_buffers = true;
877 // This flag is set to enable emulation of EXT_draw_buffers when we're
878 // running on GLES 3.0+, NV_draw_buffers extension is supported and
879 // glDrawBuffers from GLES 3.0 core has been bound. It toggles using the
880 // NV_draw_buffers extension directive instead of EXT_draw_buffers extension
881 // directive in ESSL 100 shaders translated by ANGLE, enabling them to write
882 // into multiple gl_FragData values, which is not by default possible in
883 // ESSL 100 with core GLES 3.0. For more information, see the
884 // NV_draw_buffers specification.
885 feature_flags_.nv_draw_buffers = !vendor_agnostic_draw_buffers;
887 GLint max_color_attachments = 0;
888 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &max_color_attachments);
889 for (GLenum i = GL_COLOR_ATTACHMENT1_EXT;
890 i < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + max_color_attachments);
891 ++i) {
892 validators_.attachment.AddValue(i);
894 static_assert(GL_COLOR_ATTACHMENT0_EXT == GL_COLOR_ATTACHMENT0,
895 "GL_COLOR_ATTACHMENT0_EXT should equal GL_COLOR_ATTACHMENT0");
897 validators_.g_l_state.AddValue(GL_MAX_COLOR_ATTACHMENTS_EXT);
898 validators_.g_l_state.AddValue(GL_MAX_DRAW_BUFFERS_ARB);
899 GLint max_draw_buffers = 0;
900 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &max_draw_buffers);
901 for (GLenum i = GL_DRAW_BUFFER0_ARB;
902 i < static_cast<GLenum>(GL_DRAW_BUFFER0_ARB + max_draw_buffers);
903 ++i) {
904 validators_.g_l_state.AddValue(i);
908 if (gl_version_info_->is_es3 ||
909 extensions.Contains("GL_EXT_blend_minmax") ||
910 gfx::HasDesktopGLFeatures()) {
911 AddExtensionString("GL_EXT_blend_minmax");
912 validators_.equation.AddValue(GL_MIN_EXT);
913 validators_.equation.AddValue(GL_MAX_EXT);
914 static_assert(GL_MIN_EXT == GL_MIN && GL_MAX_EXT == GL_MAX,
915 "min & max variations must match");
918 // TODO(dshwang): GLES3 supports gl_FragDepth, not gl_FragDepthEXT.
919 if (extensions.Contains("GL_EXT_frag_depth") || gfx::HasDesktopGLFeatures()) {
920 AddExtensionString("GL_EXT_frag_depth");
921 feature_flags_.ext_frag_depth = true;
924 if (extensions.Contains("GL_EXT_shader_texture_lod") ||
925 gfx::HasDesktopGLFeatures()) {
926 AddExtensionString("GL_EXT_shader_texture_lod");
927 feature_flags_.ext_shader_texture_lod = true;
930 bool ui_gl_fence_works = gfx::GLFence::IsSupported();
931 UMA_HISTOGRAM_BOOLEAN("GPU.FenceSupport", ui_gl_fence_works);
933 feature_flags_.map_buffer_range =
934 gl_version_info_->is_es3 ||
935 gl_version_info_->is_desktop_core_profile ||
936 extensions.Contains("GL_ARB_map_buffer_range") ||
937 extensions.Contains("GL_EXT_map_buffer_range");
939 // Really it's part of core OpenGL 2.1 and up, but let's assume the
940 // extension is still advertised.
941 bool has_pixel_buffers =
942 gl_version_info_->is_es3 ||
943 gl_version_info_->is_desktop_core_profile ||
944 extensions.Contains("GL_ARB_pixel_buffer_object") ||
945 extensions.Contains("GL_NV_pixel_buffer_object");
947 // We will use either glMapBuffer() or glMapBufferRange() for async readbacks.
948 if (has_pixel_buffers && ui_gl_fence_works &&
949 !workarounds_.disable_async_readpixels) {
950 feature_flags_.use_async_readpixels = true;
953 if (gl_version_info_->is_es3 ||
954 extensions.Contains("GL_ARB_sampler_objects")) {
955 feature_flags_.enable_samplers = true;
956 // TODO(dsinclair): Add AddExtensionString("GL_CHROMIUM_sampler_objects")
957 // when available.
960 if ((gl_version_info_->is_es3 ||
961 extensions.Contains("GL_EXT_discard_framebuffer")) &&
962 !workarounds_.disable_discard_framebuffer) {
963 // DiscardFramebufferEXT is automatically bound to InvalidateFramebuffer.
964 AddExtensionString("GL_EXT_discard_framebuffer");
965 feature_flags_.ext_discard_framebuffer = true;
968 if (ui_gl_fence_works) {
969 AddExtensionString("GL_CHROMIUM_sync_query");
970 feature_flags_.chromium_sync_query = true;
973 if (!workarounds_.disable_blend_equation_advanced) {
974 bool blend_equation_advanced_coherent =
975 extensions.Contains("GL_NV_blend_equation_advanced_coherent") ||
976 extensions.Contains("GL_KHR_blend_equation_advanced_coherent");
978 if (blend_equation_advanced_coherent ||
979 extensions.Contains("GL_NV_blend_equation_advanced") ||
980 extensions.Contains("GL_KHR_blend_equation_advanced")) {
981 const GLenum equations[] = {GL_MULTIPLY_KHR,
982 GL_SCREEN_KHR,
983 GL_OVERLAY_KHR,
984 GL_DARKEN_KHR,
985 GL_LIGHTEN_KHR,
986 GL_COLORDODGE_KHR,
987 GL_COLORBURN_KHR,
988 GL_HARDLIGHT_KHR,
989 GL_SOFTLIGHT_KHR,
990 GL_DIFFERENCE_KHR,
991 GL_EXCLUSION_KHR,
992 GL_HSL_HUE_KHR,
993 GL_HSL_SATURATION_KHR,
994 GL_HSL_COLOR_KHR,
995 GL_HSL_LUMINOSITY_KHR};
997 for (GLenum equation : equations)
998 validators_.equation.AddValue(equation);
999 if (blend_equation_advanced_coherent)
1000 AddExtensionString("GL_KHR_blend_equation_advanced_coherent");
1002 AddExtensionString("GL_KHR_blend_equation_advanced");
1003 feature_flags_.blend_equation_advanced = true;
1004 feature_flags_.blend_equation_advanced_coherent =
1005 blend_equation_advanced_coherent;
1009 if (enable_gl_path_rendering_switch_ &&
1010 !workarounds_.disable_gl_path_rendering &&
1011 extensions.Contains("GL_NV_path_rendering") &&
1012 (extensions.Contains("GL_EXT_direct_state_access") ||
1013 gl_version_info_->is_es3)) {
1014 AddExtensionString("GL_CHROMIUM_path_rendering");
1015 feature_flags_.chromium_path_rendering = true;
1016 validators_.g_l_state.AddValue(GL_PATH_MODELVIEW_MATRIX_CHROMIUM);
1017 validators_.g_l_state.AddValue(GL_PATH_PROJECTION_MATRIX_CHROMIUM);
1018 validators_.g_l_state.AddValue(GL_PATH_STENCIL_FUNC_CHROMIUM);
1019 validators_.g_l_state.AddValue(GL_PATH_STENCIL_REF_CHROMIUM);
1020 validators_.g_l_state.AddValue(GL_PATH_STENCIL_VALUE_MASK_CHROMIUM);
1023 if ((gl_version_info_->is_es3 || gl_version_info_->is_desktop_core_profile ||
1024 extensions.Contains("GL_EXT_texture_rg") ||
1025 extensions.Contains("GL_ARB_texture_rg")) &&
1026 IsGL_REDSupportedOnFBOs()) {
1027 feature_flags_.ext_texture_rg = true;
1028 AddExtensionString("GL_EXT_texture_rg");
1030 validators_.texture_format.AddValue(GL_RED_EXT);
1031 validators_.texture_format.AddValue(GL_RG_EXT);
1032 validators_.texture_internal_format.AddValue(GL_RED_EXT);
1033 validators_.texture_internal_format.AddValue(GL_R8_EXT);
1034 validators_.texture_internal_format.AddValue(GL_RG_EXT);
1035 validators_.texture_internal_format.AddValue(GL_RG8_EXT);
1036 validators_.read_pixel_format.AddValue(GL_RED_EXT);
1037 validators_.read_pixel_format.AddValue(GL_RG_EXT);
1038 validators_.render_buffer_format.AddValue(GL_R8_EXT);
1039 validators_.render_buffer_format.AddValue(GL_RG8_EXT);
1041 UMA_HISTOGRAM_BOOLEAN("GPU.TextureRG", feature_flags_.ext_texture_rg);
1043 #if !defined(OS_MACOSX)
1044 if (workarounds_.ignore_egl_sync_failures) {
1045 gfx::GLFenceEGL::SetIgnoreFailures();
1047 #endif
1049 if (workarounds_.avoid_egl_image_target_texture_reuse) {
1050 TextureDefinition::AvoidEGLTargetTextureReuse();
1053 if (gl_version_info_->IsLowerThanGL(4, 3)) {
1054 // crbug.com/481184.
1055 // GL_PRIMITIVE_RESTART_FIXED_INDEX is only available on Desktop GL 4.3+,
1056 // but we emulate ES 3.0 on top of Desktop GL 4.2+.
1057 feature_flags_.emulate_primitive_restart_fixed_index = true;
1061 bool FeatureInfo::IsES3Capable() const {
1062 if (!enable_unsafe_es3_apis_switch_)
1063 return false;
1064 if (gl_version_info_)
1065 return gl_version_info_->IsES3Capable();
1066 return false;
1069 void FeatureInfo::EnableES3Validators() {
1070 DCHECK(IsES3Capable());
1071 validators_.UpdateValuesES3();
1073 GLint max_color_attachments = 0;
1074 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &max_color_attachments);
1075 const int kTotalColorAttachmentEnums = 16;
1076 const GLenum kColorAttachments[] = {
1077 GL_COLOR_ATTACHMENT0,
1078 GL_COLOR_ATTACHMENT1,
1079 GL_COLOR_ATTACHMENT2,
1080 GL_COLOR_ATTACHMENT3,
1081 GL_COLOR_ATTACHMENT4,
1082 GL_COLOR_ATTACHMENT5,
1083 GL_COLOR_ATTACHMENT6,
1084 GL_COLOR_ATTACHMENT7,
1085 GL_COLOR_ATTACHMENT8,
1086 GL_COLOR_ATTACHMENT9,
1087 GL_COLOR_ATTACHMENT10,
1088 GL_COLOR_ATTACHMENT11,
1089 GL_COLOR_ATTACHMENT12,
1090 GL_COLOR_ATTACHMENT13,
1091 GL_COLOR_ATTACHMENT14,
1092 GL_COLOR_ATTACHMENT15,
1094 if (max_color_attachments < kTotalColorAttachmentEnums) {
1095 validators_.attachment.RemoveValues(
1096 kColorAttachments + max_color_attachments,
1097 kTotalColorAttachmentEnums - max_color_attachments);
1100 GLint max_draw_buffers = 0;
1101 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max_draw_buffers);
1102 const int kTotalDrawBufferEnums = 16;
1103 const GLenum kDrawBuffers[] = {
1104 GL_DRAW_BUFFER0,
1105 GL_DRAW_BUFFER1,
1106 GL_DRAW_BUFFER2,
1107 GL_DRAW_BUFFER3,
1108 GL_DRAW_BUFFER4,
1109 GL_DRAW_BUFFER5,
1110 GL_DRAW_BUFFER6,
1111 GL_DRAW_BUFFER7,
1112 GL_DRAW_BUFFER8,
1113 GL_DRAW_BUFFER9,
1114 GL_DRAW_BUFFER10,
1115 GL_DRAW_BUFFER11,
1116 GL_DRAW_BUFFER12,
1117 GL_DRAW_BUFFER13,
1118 GL_DRAW_BUFFER14,
1119 GL_DRAW_BUFFER15,
1121 if (max_draw_buffers < kTotalDrawBufferEnums) {
1122 validators_.g_l_state.RemoveValues(
1123 kDrawBuffers + max_draw_buffers,
1124 kTotalDrawBufferEnums - max_draw_buffers);
1127 unsafe_es3_apis_enabled_ = true;
1130 void FeatureInfo::AddExtensionString(const char* s) {
1131 std::string str(s);
1132 size_t pos = extensions_.find(str);
1133 while (pos != std::string::npos &&
1134 pos + str.length() < extensions_.length() &&
1135 extensions_.substr(pos + str.length(), 1) != " ") {
1136 // This extension name is a substring of another.
1137 pos = extensions_.find(str, pos + str.length());
1139 if (pos == std::string::npos) {
1140 extensions_ += (extensions_.empty() ? "" : " ") + str;
1144 FeatureInfo::~FeatureInfo() {
1147 } // namespace gles2
1148 } // namespace gpu