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