[MacViews] Show comboboxes with a native NSMenu
[chromium-blink-merge.git] / gpu / command_buffer / service / feature_info.cc
blobb3c5be635f8d86666d862165c9912a4e70f08ff6
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_astc(false),
150 ext_texture_format_atc(false),
151 ext_texture_format_bgra8888(false),
152 ext_texture_format_dxt1(false),
153 ext_texture_format_dxt5(false),
154 enable_shader_name_hashing(false),
155 enable_samplers(false),
156 ext_draw_buffers(false),
157 nv_draw_buffers(false),
158 ext_frag_depth(false),
159 ext_shader_texture_lod(false),
160 use_async_readpixels(false),
161 map_buffer_range(false),
162 ext_discard_framebuffer(false),
163 angle_depth_texture(false),
164 is_swiftshader(false),
165 angle_texture_usage(false),
166 ext_texture_storage(false),
167 chromium_path_rendering(false),
168 blend_equation_advanced(false),
169 blend_equation_advanced_coherent(false),
170 ext_texture_rg(false),
171 chromium_image_ycbcr_422(false),
172 enable_subscribe_uniform(false),
173 emulate_primitive_restart_fixed_index(false),
174 ext_render_buffer_format_bgra8888(false) {}
176 FeatureInfo::Workarounds::Workarounds() :
177 #define GPU_OP(type, name) name(false),
178 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
179 #undef GPU_OP
180 max_texture_size(0),
181 max_cube_map_texture_size(0),
182 max_fragment_uniform_vectors(0),
183 max_varying_vectors(0),
184 max_vertex_uniform_vectors(0),
185 max_copy_texture_chromium_size(0) {
188 FeatureInfo::FeatureInfo() {
189 InitializeBasicState(base::CommandLine::InitializedForCurrentProcess()
190 ? base::CommandLine::ForCurrentProcess()
191 : nullptr);
194 FeatureInfo::FeatureInfo(const base::CommandLine& command_line) {
195 InitializeBasicState(&command_line);
198 void FeatureInfo::InitializeBasicState(const base::CommandLine* command_line) {
199 if (!command_line)
200 return;
202 if (command_line->HasSwitch(switches::kGpuDriverBugWorkarounds)) {
203 std::string types = command_line->GetSwitchValueASCII(
204 switches::kGpuDriverBugWorkarounds);
205 StringToWorkarounds(types, &workarounds_);
207 feature_flags_.enable_shader_name_hashing =
208 !command_line->HasSwitch(switches::kDisableShaderNameHashing);
210 feature_flags_.is_swiftshader =
211 (command_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader");
213 feature_flags_.enable_subscribe_uniform =
214 command_line->HasSwitch(switches::kEnableSubscribeUniformExtension);
216 enable_unsafe_es3_apis_switch_ =
217 command_line->HasSwitch(switches::kEnableUnsafeES3APIs);
219 enable_gl_path_rendering_switch_ =
220 command_line->HasSwitch(switches::kEnableGLPathRendering);
222 // The shader translator is needed to translate from WebGL-conformant GLES SL
223 // to normal GLES SL, enforce WebGL conformance, translate from GLES SL 1.0 to
224 // target context GLSL, etc.
225 // The flag here is for testing only.
226 disable_shader_translator_ =
227 command_line->HasSwitch(switches::kDisableGLSLTranslator);
229 unsafe_es3_apis_enabled_ = false;
232 bool FeatureInfo::Initialize() {
233 disallowed_features_ = DisallowedFeatures();
234 InitializeFeatures();
235 return true;
238 bool FeatureInfo::Initialize(const DisallowedFeatures& disallowed_features) {
239 disallowed_features_ = disallowed_features;
240 InitializeFeatures();
241 return true;
244 bool IsGL_REDSupportedOnFBOs() {
245 // Skia uses GL_RED with frame buffers, unfortunately, Mesa claims to support
246 // GL_EXT_texture_rg, but it doesn't support it on frame buffers. To fix
247 // this, we try it, and if it fails, we don't expose GL_EXT_texture_rg.
248 GLint fb_binding = 0;
249 GLint tex_binding = 0;
250 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb_binding);
251 glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex_binding);
253 GLuint textureId = 0;
254 glGenTextures(1, &textureId);
255 glBindTexture(GL_TEXTURE_2D, textureId);
256 GLubyte data[1] = {0};
257 glTexImage2D(GL_TEXTURE_2D, 0, GL_RED_EXT, 1, 1, 0, GL_RED_EXT,
258 GL_UNSIGNED_BYTE, data);
259 GLuint textureFBOID = 0;
260 glGenFramebuffersEXT(1, &textureFBOID);
261 glBindFramebufferEXT(GL_FRAMEBUFFER, textureFBOID);
262 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
263 textureId, 0);
264 bool result =
265 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_UNSUPPORTED;
266 glDeleteFramebuffersEXT(1, &textureFBOID);
267 glDeleteTextures(1, &textureId);
269 glBindFramebufferEXT(GL_FRAMEBUFFER, static_cast<GLuint>(fb_binding));
270 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(tex_binding));
272 DCHECK(glGetError() == GL_NO_ERROR);
274 return result;
277 void FeatureInfo::InitializeFeatures() {
278 // Figure out what extensions to turn on.
279 StringSet extensions(gfx::GetGLExtensionsFromCurrentContext());
281 const char* version_str =
282 reinterpret_cast<const char*>(glGetString(GL_VERSION));
283 const char* renderer_str =
284 reinterpret_cast<const char*>(glGetString(GL_RENDERER));
286 gl_version_info_.reset(new gfx::GLVersionInfo(
287 version_str, renderer_str, extensions.GetImpl()));
289 AddExtensionString("GL_ANGLE_translated_shader_source");
290 AddExtensionString("GL_CHROMIUM_async_pixel_transfers");
291 AddExtensionString("GL_CHROMIUM_bind_uniform_location");
292 AddExtensionString("GL_CHROMIUM_command_buffer_query");
293 AddExtensionString("GL_CHROMIUM_command_buffer_latency_query");
294 AddExtensionString("GL_CHROMIUM_copy_texture");
295 AddExtensionString("GL_CHROMIUM_get_error_query");
296 AddExtensionString("GL_CHROMIUM_lose_context");
297 AddExtensionString("GL_CHROMIUM_pixel_transfer_buffer_object");
298 AddExtensionString("GL_CHROMIUM_rate_limit_offscreen_context");
299 AddExtensionString("GL_CHROMIUM_resize");
300 AddExtensionString("GL_CHROMIUM_resource_safe");
301 AddExtensionString("GL_CHROMIUM_strict_attribs");
302 AddExtensionString("GL_CHROMIUM_texture_mailbox");
303 AddExtensionString("GL_CHROMIUM_trace_marker");
304 AddExtensionString("GL_EXT_debug_marker");
306 if (feature_flags_.enable_subscribe_uniform) {
307 AddExtensionString("GL_CHROMIUM_subscribe_uniform");
310 // OES_vertex_array_object is emulated if not present natively,
311 // so the extension string is always exposed.
312 AddExtensionString("GL_OES_vertex_array_object");
314 if (!disallowed_features_.gpu_memory_manager)
315 AddExtensionString("GL_CHROMIUM_gpu_memory_manager");
317 if (extensions.Contains("GL_ANGLE_translated_shader_source")) {
318 feature_flags_.angle_translated_shader_source = true;
321 // Check if we should allow GL_EXT_texture_compression_dxt1 and
322 // GL_EXT_texture_compression_s3tc.
323 bool enable_dxt1 = false;
324 bool enable_dxt3 = false;
325 bool enable_dxt5 = false;
326 bool have_s3tc = extensions.Contains("GL_EXT_texture_compression_s3tc");
327 bool have_dxt3 =
328 have_s3tc || extensions.Contains("GL_ANGLE_texture_compression_dxt3");
329 bool have_dxt5 =
330 have_s3tc || extensions.Contains("GL_ANGLE_texture_compression_dxt5");
332 if (extensions.Contains("GL_EXT_texture_compression_dxt1") || have_s3tc) {
333 enable_dxt1 = true;
335 if (have_dxt3) {
336 enable_dxt3 = true;
338 if (have_dxt5) {
339 enable_dxt5 = true;
342 if (enable_dxt1) {
343 feature_flags_.ext_texture_format_dxt1 = true;
345 AddExtensionString("GL_EXT_texture_compression_dxt1");
346 validators_.compressed_texture_format.AddValue(
347 GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
348 validators_.compressed_texture_format.AddValue(
349 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
351 validators_.texture_internal_format_storage.AddValue(
352 GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
353 validators_.texture_internal_format_storage.AddValue(
354 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
357 if (enable_dxt3) {
358 // The difference between GL_EXT_texture_compression_s3tc and
359 // GL_CHROMIUM_texture_compression_dxt3 is that the former
360 // requires on the fly compression. The latter does not.
361 AddExtensionString("GL_CHROMIUM_texture_compression_dxt3");
362 validators_.compressed_texture_format.AddValue(
363 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT);
364 validators_.texture_internal_format_storage.AddValue(
365 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT);
368 if (enable_dxt5) {
369 feature_flags_.ext_texture_format_dxt5 = true;
371 // The difference between GL_EXT_texture_compression_s3tc and
372 // GL_CHROMIUM_texture_compression_dxt5 is that the former
373 // requires on the fly compression. The latter does not.
374 AddExtensionString("GL_CHROMIUM_texture_compression_dxt5");
375 validators_.compressed_texture_format.AddValue(
376 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT);
377 validators_.texture_internal_format_storage.AddValue(
378 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT);
381 bool have_astc = extensions.Contains("GL_KHR_texture_compression_astc_ldr");
382 if (have_astc) {
383 feature_flags_.ext_texture_format_astc = true;
384 AddExtensionString("GL_KHR_texture_compression_astc_ldr");
386 // GL_COMPRESSED_RGBA_ASTC(0x93B0 ~ 0x93BD)
387 GLint astc_format_it = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
388 GLint astc_format_max = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
389 for (; astc_format_it <= astc_format_max; astc_format_it++)
390 validators_.compressed_texture_format.AddValue(astc_format_it);
392 // GL_COMPRESSED_SRGB8_ALPHA8_ASTC(0x93D0 ~ 0x93DD)
393 astc_format_it = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
394 astc_format_max = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
395 for (; astc_format_it <= astc_format_max; astc_format_it++)
396 validators_.compressed_texture_format.AddValue(astc_format_it);
399 bool have_atc = extensions.Contains("GL_AMD_compressed_ATC_texture") ||
400 extensions.Contains("GL_ATI_texture_compression_atitc");
401 if (have_atc) {
402 feature_flags_.ext_texture_format_atc = true;
404 AddExtensionString("GL_AMD_compressed_ATC_texture");
405 validators_.compressed_texture_format.AddValue(GL_ATC_RGB_AMD);
406 validators_.compressed_texture_format.AddValue(
407 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD);
409 validators_.texture_internal_format_storage.AddValue(GL_ATC_RGB_AMD);
410 validators_.texture_internal_format_storage.AddValue(
411 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD);
414 // Check if we should enable GL_EXT_texture_filter_anisotropic.
415 if (extensions.Contains("GL_EXT_texture_filter_anisotropic")) {
416 AddExtensionString("GL_EXT_texture_filter_anisotropic");
417 validators_.texture_parameter.AddValue(
418 GL_TEXTURE_MAX_ANISOTROPY_EXT);
419 validators_.g_l_state.AddValue(
420 GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
423 // Check if we should support GL_OES_packed_depth_stencil and/or
424 // GL_GOOGLE_depth_texture / GL_CHROMIUM_depth_texture.
426 // NOTE: GL_OES_depth_texture requires support for depth cubemaps.
427 // GL_ARB_depth_texture requires other features that
428 // GL_OES_packed_depth_stencil does not provide.
430 // Therefore we made up GL_GOOGLE_depth_texture / GL_CHROMIUM_depth_texture.
432 // GL_GOOGLE_depth_texture is legacy. As we exposed it into NaCl we can't
433 // get rid of it.
435 bool enable_depth_texture = false;
436 if (!workarounds_.disable_depth_texture &&
437 (extensions.Contains("GL_ARB_depth_texture") ||
438 extensions.Contains("GL_OES_depth_texture") ||
439 extensions.Contains("GL_ANGLE_depth_texture") ||
440 gl_version_info_->is_es3 ||
441 gl_version_info_->is_desktop_core_profile)) {
442 enable_depth_texture = true;
443 feature_flags_.angle_depth_texture =
444 extensions.Contains("GL_ANGLE_depth_texture");
447 if (enable_depth_texture) {
448 AddExtensionString("GL_CHROMIUM_depth_texture");
449 AddExtensionString("GL_GOOGLE_depth_texture");
450 validators_.texture_internal_format.AddValue(GL_DEPTH_COMPONENT);
451 validators_.texture_format.AddValue(GL_DEPTH_COMPONENT);
452 validators_.pixel_type.AddValue(GL_UNSIGNED_SHORT);
453 validators_.pixel_type.AddValue(GL_UNSIGNED_INT);
456 if (extensions.Contains("GL_EXT_packed_depth_stencil") ||
457 extensions.Contains("GL_OES_packed_depth_stencil") ||
458 gl_version_info_->is_es3 ||
459 gl_version_info_->is_desktop_core_profile) {
460 AddExtensionString("GL_OES_packed_depth_stencil");
461 feature_flags_.packed_depth24_stencil8 = true;
462 if (enable_depth_texture) {
463 validators_.texture_internal_format.AddValue(GL_DEPTH_STENCIL);
464 validators_.texture_format.AddValue(GL_DEPTH_STENCIL);
465 validators_.pixel_type.AddValue(GL_UNSIGNED_INT_24_8);
467 validators_.render_buffer_format.AddValue(GL_DEPTH24_STENCIL8);
470 if (gl_version_info_->is_es3 ||
471 gl_version_info_->is_desktop_core_profile ||
472 extensions.Contains("GL_OES_vertex_array_object") ||
473 extensions.Contains("GL_ARB_vertex_array_object") ||
474 extensions.Contains("GL_APPLE_vertex_array_object")) {
475 feature_flags_.native_vertex_array_object = true;
478 // If we're using client_side_arrays we have to emulate
479 // vertex array objects since vertex array objects do not work
480 // with client side arrays.
481 if (workarounds_.use_client_side_arrays_for_stream_buffers) {
482 feature_flags_.native_vertex_array_object = false;
485 if (gl_version_info_->is_es3 ||
486 extensions.Contains("GL_OES_element_index_uint") ||
487 gfx::HasDesktopGLFeatures()) {
488 AddExtensionString("GL_OES_element_index_uint");
489 validators_.index_type.AddValue(GL_UNSIGNED_INT);
492 // With EXT_sRGB, unsized SRGB_EXT and SRGB_ALPHA_EXT are accepted by the
493 // <format> and <internalformat> parameter of TexImage2D. GLES3 adds support
494 // for SRGB Textures but the accepted internal formats for TexImage2D are only
495 // sized formats GL_SRGB8 and GL_SRGB8_ALPHA8. Also, SRGB_EXT isn't a valid
496 // <format> in this case. So, even with GLES3 explicitly check for
497 // GL_EXT_sRGB.
498 if (((gl_version_info_->is_es3 ||
499 extensions.Contains("GL_OES_rgb8_rgba8")) &&
500 extensions.Contains("GL_EXT_sRGB")) || gfx::HasDesktopGLFeatures()) {
501 AddExtensionString("GL_EXT_sRGB");
502 validators_.texture_internal_format.AddValue(GL_SRGB_EXT);
503 validators_.texture_internal_format.AddValue(GL_SRGB_ALPHA_EXT);
504 validators_.texture_format.AddValue(GL_SRGB_EXT);
505 validators_.texture_format.AddValue(GL_SRGB_ALPHA_EXT);
506 validators_.render_buffer_format.AddValue(GL_SRGB8_ALPHA8_EXT);
507 validators_.frame_buffer_parameter.AddValue(
508 GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT);
511 bool enable_texture_format_bgra8888 = false;
512 bool enable_read_format_bgra = false;
513 bool enable_render_buffer_bgra = false;
514 bool enable_immutable_texture_format_bgra_on_es3 =
515 extensions.Contains("GL_APPLE_texture_format_BGRA8888");
517 // Check if we should allow GL_EXT_texture_format_BGRA8888
518 if (extensions.Contains("GL_EXT_texture_format_BGRA8888") ||
519 enable_immutable_texture_format_bgra_on_es3 ||
520 !gl_version_info_->is_es) {
521 enable_texture_format_bgra8888 = true;
524 // Only desktop GL extension GL_EXT_bgra or ANGLE guarantee that we can
525 // allocate a renderbuffer with this format.
526 if (extensions.Contains("GL_EXT_bgra") || gl_version_info_->is_angle) {
527 enable_render_buffer_bgra = true;
530 if (extensions.Contains("GL_EXT_read_format_bgra") ||
531 extensions.Contains("GL_EXT_bgra")) {
532 enable_read_format_bgra = true;
535 if (enable_texture_format_bgra8888) {
536 feature_flags_.ext_texture_format_bgra8888 = true;
537 AddExtensionString("GL_EXT_texture_format_BGRA8888");
538 validators_.texture_internal_format.AddValue(GL_BGRA_EXT);
539 validators_.texture_format.AddValue(GL_BGRA_EXT);
542 if (enable_read_format_bgra) {
543 AddExtensionString("GL_EXT_read_format_bgra");
544 validators_.read_pixel_format.AddValue(GL_BGRA_EXT);
547 // We only support timer queries if we also support glGetInteger64v.
548 // For GL_EXT_disjoint_timer_query, glGetInteger64v is only support under ES3.
549 if ((gl_version_info_->is_es3 &&
550 extensions.Contains("GL_EXT_disjoint_timer_query")) ||
551 extensions.Contains("GL_ARB_timer_query") ||
552 extensions.Contains("GL_EXT_timer_query")) {
553 AddExtensionString("GL_EXT_disjoint_timer_query");
556 if (enable_render_buffer_bgra) {
557 feature_flags_.ext_render_buffer_format_bgra8888 = true;
558 AddExtensionString("GL_CHROMIUM_renderbuffer_format_BGRA8888");
559 validators_.render_buffer_format.AddValue(GL_BGRA8_EXT);
562 if (extensions.Contains("GL_OES_rgb8_rgba8") || gfx::HasDesktopGLFeatures()) {
563 AddExtensionString("GL_OES_rgb8_rgba8");
564 validators_.render_buffer_format.AddValue(GL_RGB8_OES);
565 validators_.render_buffer_format.AddValue(GL_RGBA8_OES);
568 // Check if we should allow GL_OES_texture_npot
569 if (!disallowed_features_.npot_support &&
570 (gl_version_info_->is_es3 ||
571 gl_version_info_->is_desktop_core_profile ||
572 extensions.Contains("GL_ARB_texture_non_power_of_two") ||
573 extensions.Contains("GL_OES_texture_npot"))) {
574 AddExtensionString("GL_OES_texture_npot");
575 feature_flags_.npot_ok = true;
578 // Check if we should allow GL_OES_texture_float, GL_OES_texture_half_float,
579 // GL_OES_texture_float_linear, GL_OES_texture_half_float_linear
580 bool enable_texture_float = false;
581 bool enable_texture_float_linear = false;
582 bool enable_texture_half_float = false;
583 bool enable_texture_half_float_linear = false;
585 bool may_enable_chromium_color_buffer_float = false;
587 if (extensions.Contains("GL_ARB_texture_float") ||
588 gl_version_info_->is_desktop_core_profile) {
589 enable_texture_float = true;
590 enable_texture_float_linear = true;
591 enable_texture_half_float = true;
592 enable_texture_half_float_linear = true;
593 may_enable_chromium_color_buffer_float = true;
594 } else {
595 // GLES3 adds support for Float type by default but it doesn't support all
596 // formats as GL_OES_texture_float(i.e.LUMINANCE_ALPHA,LUMINANCE and Alpha)
597 if (extensions.Contains("GL_OES_texture_float")) {
598 enable_texture_float = true;
599 if (extensions.Contains("GL_OES_texture_float_linear")) {
600 enable_texture_float_linear = true;
602 // This extension allows a variety of floating point formats to be
603 // rendered to via framebuffer objects. Enable it's usage only if
604 // support for Floating textures is enabled.
605 if ((gl_version_info_->is_es3 &&
606 extensions.Contains("GL_EXT_color_buffer_float")) ||
607 gl_version_info_->is_angle) {
608 may_enable_chromium_color_buffer_float = true;
612 // TODO(dshwang): GLES3 supports half float by default but GL_HALF_FLOAT_OES
613 // isn't equal to GL_HALF_FLOAT.
614 if (extensions.Contains("GL_OES_texture_half_float")) {
615 enable_texture_half_float = true;
616 if (extensions.Contains("GL_OES_texture_half_float_linear")) {
617 enable_texture_half_float_linear = true;
622 if (enable_texture_float) {
623 validators_.pixel_type.AddValue(GL_FLOAT);
624 validators_.read_pixel_type.AddValue(GL_FLOAT);
625 AddExtensionString("GL_OES_texture_float");
626 if (enable_texture_float_linear) {
627 AddExtensionString("GL_OES_texture_float_linear");
631 if (enable_texture_half_float) {
632 validators_.pixel_type.AddValue(GL_HALF_FLOAT_OES);
633 validators_.read_pixel_type.AddValue(GL_HALF_FLOAT_OES);
634 AddExtensionString("GL_OES_texture_half_float");
635 if (enable_texture_half_float_linear) {
636 AddExtensionString("GL_OES_texture_half_float_linear");
640 if (may_enable_chromium_color_buffer_float) {
641 static_assert(GL_RGBA32F_ARB == GL_RGBA32F &&
642 GL_RGBA32F_EXT == GL_RGBA32F &&
643 GL_RGB32F_ARB == GL_RGB32F &&
644 GL_RGB32F_EXT == GL_RGB32F,
645 "sized float internal format variations must match");
646 // We don't check extension support beyond ARB_texture_float on desktop GL,
647 // and format support varies between GL configurations. For example, spec
648 // prior to OpenGL 3.0 mandates framebuffer support only for one
649 // implementation-chosen format, and ES3.0 EXT_color_buffer_float does not
650 // support rendering to RGB32F. Check for framebuffer completeness with
651 // formats that the extensions expose, and only enable an extension when a
652 // framebuffer created with its texture format is reported as complete.
653 GLint fb_binding = 0;
654 GLint tex_binding = 0;
655 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb_binding);
656 glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex_binding);
658 GLuint tex_id = 0;
659 GLuint fb_id = 0;
660 GLsizei width = 16;
662 glGenTextures(1, &tex_id);
663 glGenFramebuffersEXT(1, &fb_id);
664 glBindTexture(GL_TEXTURE_2D, tex_id);
665 // Nearest filter needed for framebuffer completeness on some drivers.
666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
667 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, width, 0, GL_RGBA,
668 GL_FLOAT, NULL);
669 glBindFramebufferEXT(GL_FRAMEBUFFER, fb_id);
670 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
671 GL_TEXTURE_2D, tex_id, 0);
672 GLenum statusRGBA = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
673 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, width, 0, GL_RGB,
674 GL_FLOAT, NULL);
675 GLenum statusRGB = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
676 glDeleteFramebuffersEXT(1, &fb_id);
677 glDeleteTextures(1, &tex_id);
679 glBindFramebufferEXT(GL_FRAMEBUFFER, static_cast<GLuint>(fb_binding));
680 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(tex_binding));
682 DCHECK(glGetError() == GL_NO_ERROR);
684 if (statusRGBA == GL_FRAMEBUFFER_COMPLETE) {
685 validators_.texture_internal_format.AddValue(GL_RGBA32F);
686 feature_flags_.chromium_color_buffer_float_rgba = true;
687 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgba");
689 if (statusRGB == GL_FRAMEBUFFER_COMPLETE) {
690 validators_.texture_internal_format.AddValue(GL_RGB32F);
691 feature_flags_.chromium_color_buffer_float_rgb = true;
692 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgb");
696 // Check for multisample support
697 if (!workarounds_.disable_chromium_framebuffer_multisample) {
698 bool ext_has_multisample =
699 extensions.Contains("GL_EXT_framebuffer_multisample") ||
700 gl_version_info_->is_es3 ||
701 gl_version_info_->is_desktop_core_profile;
702 if (gl_version_info_->is_angle) {
703 ext_has_multisample |=
704 extensions.Contains("GL_ANGLE_framebuffer_multisample");
706 feature_flags_.use_core_framebuffer_multisample =
707 gl_version_info_->is_es3 || gl_version_info_->is_desktop_core_profile;
708 if (ext_has_multisample) {
709 feature_flags_.chromium_framebuffer_multisample = true;
710 validators_.frame_buffer_target.AddValue(GL_READ_FRAMEBUFFER_EXT);
711 validators_.frame_buffer_target.AddValue(GL_DRAW_FRAMEBUFFER_EXT);
712 validators_.g_l_state.AddValue(GL_READ_FRAMEBUFFER_BINDING_EXT);
713 validators_.g_l_state.AddValue(GL_MAX_SAMPLES_EXT);
714 validators_.render_buffer_parameter.AddValue(GL_RENDERBUFFER_SAMPLES_EXT);
715 AddExtensionString("GL_CHROMIUM_framebuffer_multisample");
719 if (!workarounds_.disable_multisampled_render_to_texture) {
720 if (extensions.Contains("GL_EXT_multisampled_render_to_texture")) {
721 feature_flags_.multisampled_render_to_texture = true;
722 } else if (extensions.Contains("GL_IMG_multisampled_render_to_texture")) {
723 feature_flags_.multisampled_render_to_texture = true;
724 feature_flags_.use_img_for_multisampled_render_to_texture = true;
726 if (feature_flags_.multisampled_render_to_texture) {
727 validators_.render_buffer_parameter.AddValue(
728 GL_RENDERBUFFER_SAMPLES_EXT);
729 validators_.g_l_state.AddValue(GL_MAX_SAMPLES_EXT);
730 validators_.frame_buffer_parameter.AddValue(
731 GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT);
732 AddExtensionString("GL_EXT_multisampled_render_to_texture");
736 if (extensions.Contains("GL_OES_depth24") || gfx::HasDesktopGLFeatures() ||
737 gl_version_info_->is_es3) {
738 AddExtensionString("GL_OES_depth24");
739 feature_flags_.oes_depth24 = true;
740 validators_.render_buffer_format.AddValue(GL_DEPTH_COMPONENT24);
743 if (gl_version_info_->is_es3 ||
744 extensions.Contains("GL_OES_standard_derivatives") ||
745 gfx::HasDesktopGLFeatures()) {
746 AddExtensionString("GL_OES_standard_derivatives");
747 feature_flags_.oes_standard_derivatives = true;
748 validators_.hint_target.AddValue(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
749 validators_.g_l_state.AddValue(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
752 if (extensions.Contains("GL_OES_EGL_image_external")) {
753 AddExtensionString("GL_OES_EGL_image_external");
754 feature_flags_.oes_egl_image_external = true;
755 validators_.texture_bind_target.AddValue(GL_TEXTURE_EXTERNAL_OES);
756 validators_.get_tex_param_target.AddValue(GL_TEXTURE_EXTERNAL_OES);
757 validators_.texture_parameter.AddValue(GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES);
758 validators_.g_l_state.AddValue(GL_TEXTURE_BINDING_EXTERNAL_OES);
761 if (extensions.Contains("GL_OES_compressed_ETC1_RGB8_texture")) {
762 AddExtensionString("GL_OES_compressed_ETC1_RGB8_texture");
763 feature_flags_.oes_compressed_etc1_rgb8_texture = true;
764 validators_.compressed_texture_format.AddValue(GL_ETC1_RGB8_OES);
765 validators_.texture_internal_format_storage.AddValue(GL_ETC1_RGB8_OES);
768 if (extensions.Contains("GL_AMD_compressed_ATC_texture")) {
769 AddExtensionString("GL_AMD_compressed_ATC_texture");
770 validators_.compressed_texture_format.AddValue(
771 GL_ATC_RGB_AMD);
772 validators_.compressed_texture_format.AddValue(
773 GL_ATC_RGBA_EXPLICIT_ALPHA_AMD);
774 validators_.compressed_texture_format.AddValue(
775 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD);
777 validators_.texture_internal_format_storage.AddValue(
778 GL_ATC_RGB_AMD);
779 validators_.texture_internal_format_storage.AddValue(
780 GL_ATC_RGBA_EXPLICIT_ALPHA_AMD);
781 validators_.texture_internal_format_storage.AddValue(
782 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD);
785 if (extensions.Contains("GL_IMG_texture_compression_pvrtc")) {
786 AddExtensionString("GL_IMG_texture_compression_pvrtc");
787 validators_.compressed_texture_format.AddValue(
788 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG);
789 validators_.compressed_texture_format.AddValue(
790 GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG);
791 validators_.compressed_texture_format.AddValue(
792 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG);
793 validators_.compressed_texture_format.AddValue(
794 GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG);
796 validators_.texture_internal_format_storage.AddValue(
797 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG);
798 validators_.texture_internal_format_storage.AddValue(
799 GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG);
800 validators_.texture_internal_format_storage.AddValue(
801 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG);
802 validators_.texture_internal_format_storage.AddValue(
803 GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG);
806 // Ideally we would only expose this extension on Mac OS X, to
807 // support GL_CHROMIUM_iosurface and the compositor. We don't want
808 // applications to start using it; they should use ordinary non-
809 // power-of-two textures. However, for unit testing purposes we
810 // expose it on all supported platforms.
811 if (extensions.Contains("GL_ARB_texture_rectangle") ||
812 gl_version_info_->is_desktop_core_profile) {
813 AddExtensionString("GL_ARB_texture_rectangle");
814 feature_flags_.arb_texture_rectangle = true;
815 // Rectangle textures are used as samplers via glBindTexture, framebuffer
816 // textures via glFramebufferTexture2D, and copy destinations via
817 // glCopyPixels.
818 validators_.texture_bind_target.AddValue(GL_TEXTURE_RECTANGLE_ARB);
819 validators_.texture_target.AddValue(GL_TEXTURE_RECTANGLE_ARB);
820 validators_.get_tex_param_target.AddValue(GL_TEXTURE_RECTANGLE_ARB);
821 validators_.g_l_state.AddValue(GL_TEXTURE_BINDING_RECTANGLE_ARB);
824 #if defined(OS_MACOSX)
825 AddExtensionString("GL_CHROMIUM_iosurface");
826 #endif
828 if (extensions.Contains("GL_APPLE_ycbcr_422")) {
829 AddExtensionString("GL_CHROMIUM_ycbcr_422_image");
830 feature_flags_.chromium_image_ycbcr_422 = true;
833 // TODO(gman): Add support for these extensions.
834 // GL_OES_depth32
836 feature_flags_.enable_texture_float_linear |= enable_texture_float_linear;
837 feature_flags_.enable_texture_half_float_linear |=
838 enable_texture_half_float_linear;
840 if (extensions.Contains("GL_ANGLE_pack_reverse_row_order")) {
841 AddExtensionString("GL_ANGLE_pack_reverse_row_order");
842 feature_flags_.angle_pack_reverse_row_order = true;
843 validators_.pixel_store.AddValue(GL_PACK_REVERSE_ROW_ORDER_ANGLE);
844 validators_.g_l_state.AddValue(GL_PACK_REVERSE_ROW_ORDER_ANGLE);
847 if (extensions.Contains("GL_ANGLE_texture_usage")) {
848 feature_flags_.angle_texture_usage = true;
849 AddExtensionString("GL_ANGLE_texture_usage");
850 validators_.texture_parameter.AddValue(GL_TEXTURE_USAGE_ANGLE);
853 // Note: Only APPLE_texture_format_BGRA8888 extension allows BGRA8_EXT in
854 // ES3's glTexStorage2D. We prefer support BGRA to texture storage.
855 // So we don't expose GL_EXT_texture_storage when ES3 +
856 // GL_EXT_texture_format_BGRA8888 because we fail the GL_BGRA8 requirement.
857 // However we expose GL_EXT_texture_storage when just ES3 because we don't
858 // claim to handle GL_BGRA8.
859 bool support_texture_storage_on_es3 =
860 (gl_version_info_->is_es3 &&
861 enable_immutable_texture_format_bgra_on_es3) ||
862 (gl_version_info_->is_es3 &&
863 !enable_texture_format_bgra8888);
864 if (!workarounds_.disable_texture_storage &&
865 (extensions.Contains("GL_EXT_texture_storage") ||
866 extensions.Contains("GL_ARB_texture_storage") ||
867 support_texture_storage_on_es3 ||
868 gl_version_info_->is_desktop_core_profile)) {
869 feature_flags_.ext_texture_storage = true;
870 AddExtensionString("GL_EXT_texture_storage");
871 validators_.texture_parameter.AddValue(GL_TEXTURE_IMMUTABLE_FORMAT_EXT);
872 if (enable_texture_format_bgra8888)
873 validators_.texture_internal_format_storage.AddValue(GL_BGRA8_EXT);
874 if (enable_texture_float) {
875 validators_.texture_internal_format_storage.AddValue(GL_RGBA32F_EXT);
876 validators_.texture_internal_format_storage.AddValue(GL_RGB32F_EXT);
877 validators_.texture_internal_format_storage.AddValue(GL_ALPHA32F_EXT);
878 validators_.texture_internal_format_storage.AddValue(
879 GL_LUMINANCE32F_EXT);
880 validators_.texture_internal_format_storage.AddValue(
881 GL_LUMINANCE_ALPHA32F_EXT);
883 if (enable_texture_half_float) {
884 validators_.texture_internal_format_storage.AddValue(GL_RGBA16F_EXT);
885 validators_.texture_internal_format_storage.AddValue(GL_RGB16F_EXT);
886 validators_.texture_internal_format_storage.AddValue(GL_ALPHA16F_EXT);
887 validators_.texture_internal_format_storage.AddValue(
888 GL_LUMINANCE16F_EXT);
889 validators_.texture_internal_format_storage.AddValue(
890 GL_LUMINANCE_ALPHA16F_EXT);
894 bool have_ext_occlusion_query_boolean =
895 extensions.Contains("GL_EXT_occlusion_query_boolean");
896 bool have_arb_occlusion_query2 =
897 extensions.Contains("GL_ARB_occlusion_query2");
898 bool have_arb_occlusion_query =
899 extensions.Contains("GL_ARB_occlusion_query");
901 if (have_ext_occlusion_query_boolean ||
902 have_arb_occlusion_query2 ||
903 have_arb_occlusion_query) {
904 AddExtensionString("GL_EXT_occlusion_query_boolean");
905 feature_flags_.occlusion_query_boolean = true;
906 feature_flags_.use_arb_occlusion_query2_for_occlusion_query_boolean =
907 !have_ext_occlusion_query_boolean && have_arb_occlusion_query2;
908 feature_flags_.use_arb_occlusion_query_for_occlusion_query_boolean =
909 !have_ext_occlusion_query_boolean && have_arb_occlusion_query &&
910 !have_arb_occlusion_query2;
913 if (!workarounds_.disable_angle_instanced_arrays &&
914 (extensions.Contains("GL_ANGLE_instanced_arrays") ||
915 (extensions.Contains("GL_ARB_instanced_arrays") &&
916 extensions.Contains("GL_ARB_draw_instanced")) ||
917 gl_version_info_->is_es3)) {
918 AddExtensionString("GL_ANGLE_instanced_arrays");
919 feature_flags_.angle_instanced_arrays = true;
920 validators_.vertex_attribute.AddValue(GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
923 bool vendor_agnostic_draw_buffers =
924 extensions.Contains("GL_ARB_draw_buffers") ||
925 extensions.Contains("GL_EXT_draw_buffers");
926 if (!workarounds_.disable_ext_draw_buffers &&
927 (vendor_agnostic_draw_buffers ||
928 (extensions.Contains("GL_NV_draw_buffers") &&
929 gl_version_info_->is_es3) ||
930 gl_version_info_->is_desktop_core_profile)) {
931 AddExtensionString("GL_EXT_draw_buffers");
932 feature_flags_.ext_draw_buffers = true;
934 // This flag is set to enable emulation of EXT_draw_buffers when we're
935 // running on GLES 3.0+, NV_draw_buffers extension is supported and
936 // glDrawBuffers from GLES 3.0 core has been bound. It toggles using the
937 // NV_draw_buffers extension directive instead of EXT_draw_buffers extension
938 // directive in ESSL 100 shaders translated by ANGLE, enabling them to write
939 // into multiple gl_FragData values, which is not by default possible in
940 // ESSL 100 with core GLES 3.0. For more information, see the
941 // NV_draw_buffers specification.
942 feature_flags_.nv_draw_buffers = !vendor_agnostic_draw_buffers;
944 GLint max_color_attachments = 0;
945 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &max_color_attachments);
946 for (GLenum i = GL_COLOR_ATTACHMENT1_EXT;
947 i < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + max_color_attachments);
948 ++i) {
949 validators_.attachment.AddValue(i);
951 static_assert(GL_COLOR_ATTACHMENT0_EXT == GL_COLOR_ATTACHMENT0,
952 "GL_COLOR_ATTACHMENT0_EXT should equal GL_COLOR_ATTACHMENT0");
954 validators_.g_l_state.AddValue(GL_MAX_COLOR_ATTACHMENTS_EXT);
955 validators_.g_l_state.AddValue(GL_MAX_DRAW_BUFFERS_ARB);
956 GLint max_draw_buffers = 0;
957 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &max_draw_buffers);
958 for (GLenum i = GL_DRAW_BUFFER0_ARB;
959 i < static_cast<GLenum>(GL_DRAW_BUFFER0_ARB + max_draw_buffers);
960 ++i) {
961 validators_.g_l_state.AddValue(i);
965 if (gl_version_info_->is_es3 ||
966 extensions.Contains("GL_EXT_blend_minmax") ||
967 gfx::HasDesktopGLFeatures()) {
968 AddExtensionString("GL_EXT_blend_minmax");
969 validators_.equation.AddValue(GL_MIN_EXT);
970 validators_.equation.AddValue(GL_MAX_EXT);
971 static_assert(GL_MIN_EXT == GL_MIN && GL_MAX_EXT == GL_MAX,
972 "min & max variations must match");
975 // TODO(dshwang): GLES3 supports gl_FragDepth, not gl_FragDepthEXT.
976 if (extensions.Contains("GL_EXT_frag_depth") || gfx::HasDesktopGLFeatures()) {
977 AddExtensionString("GL_EXT_frag_depth");
978 feature_flags_.ext_frag_depth = true;
981 if (extensions.Contains("GL_EXT_shader_texture_lod") ||
982 gfx::HasDesktopGLFeatures()) {
983 AddExtensionString("GL_EXT_shader_texture_lod");
984 feature_flags_.ext_shader_texture_lod = true;
987 bool ui_gl_fence_works = gfx::GLFence::IsSupported();
988 UMA_HISTOGRAM_BOOLEAN("GPU.FenceSupport", ui_gl_fence_works);
990 feature_flags_.map_buffer_range =
991 gl_version_info_->is_es3 ||
992 gl_version_info_->is_desktop_core_profile ||
993 extensions.Contains("GL_ARB_map_buffer_range") ||
994 extensions.Contains("GL_EXT_map_buffer_range");
996 // Really it's part of core OpenGL 2.1 and up, but let's assume the
997 // extension is still advertised.
998 bool has_pixel_buffers =
999 gl_version_info_->is_es3 ||
1000 gl_version_info_->is_desktop_core_profile ||
1001 extensions.Contains("GL_ARB_pixel_buffer_object") ||
1002 extensions.Contains("GL_NV_pixel_buffer_object");
1004 // We will use either glMapBuffer() or glMapBufferRange() for async readbacks.
1005 if (has_pixel_buffers && ui_gl_fence_works &&
1006 !workarounds_.disable_async_readpixels) {
1007 feature_flags_.use_async_readpixels = true;
1010 if (gl_version_info_->is_es3 ||
1011 extensions.Contains("GL_ARB_sampler_objects")) {
1012 feature_flags_.enable_samplers = true;
1013 // TODO(dsinclair): Add AddExtensionString("GL_CHROMIUM_sampler_objects")
1014 // when available.
1017 if ((gl_version_info_->is_es3 ||
1018 extensions.Contains("GL_EXT_discard_framebuffer")) &&
1019 !workarounds_.disable_discard_framebuffer) {
1020 // DiscardFramebufferEXT is automatically bound to InvalidateFramebuffer.
1021 AddExtensionString("GL_EXT_discard_framebuffer");
1022 feature_flags_.ext_discard_framebuffer = true;
1025 if (ui_gl_fence_works) {
1026 AddExtensionString("GL_CHROMIUM_sync_query");
1027 feature_flags_.chromium_sync_query = true;
1030 if (!workarounds_.disable_blend_equation_advanced) {
1031 bool blend_equation_advanced_coherent =
1032 extensions.Contains("GL_NV_blend_equation_advanced_coherent") ||
1033 extensions.Contains("GL_KHR_blend_equation_advanced_coherent");
1035 if (blend_equation_advanced_coherent ||
1036 extensions.Contains("GL_NV_blend_equation_advanced") ||
1037 extensions.Contains("GL_KHR_blend_equation_advanced")) {
1038 const GLenum equations[] = {GL_MULTIPLY_KHR,
1039 GL_SCREEN_KHR,
1040 GL_OVERLAY_KHR,
1041 GL_DARKEN_KHR,
1042 GL_LIGHTEN_KHR,
1043 GL_COLORDODGE_KHR,
1044 GL_COLORBURN_KHR,
1045 GL_HARDLIGHT_KHR,
1046 GL_SOFTLIGHT_KHR,
1047 GL_DIFFERENCE_KHR,
1048 GL_EXCLUSION_KHR,
1049 GL_HSL_HUE_KHR,
1050 GL_HSL_SATURATION_KHR,
1051 GL_HSL_COLOR_KHR,
1052 GL_HSL_LUMINOSITY_KHR};
1054 for (GLenum equation : equations)
1055 validators_.equation.AddValue(equation);
1056 if (blend_equation_advanced_coherent)
1057 AddExtensionString("GL_KHR_blend_equation_advanced_coherent");
1059 AddExtensionString("GL_KHR_blend_equation_advanced");
1060 feature_flags_.blend_equation_advanced = true;
1061 feature_flags_.blend_equation_advanced_coherent =
1062 blend_equation_advanced_coherent;
1066 if (enable_gl_path_rendering_switch_ &&
1067 !workarounds_.disable_gl_path_rendering &&
1068 extensions.Contains("GL_NV_path_rendering") &&
1069 (extensions.Contains("GL_EXT_direct_state_access") ||
1070 gl_version_info_->is_es3)) {
1071 AddExtensionString("GL_CHROMIUM_path_rendering");
1072 feature_flags_.chromium_path_rendering = true;
1073 validators_.g_l_state.AddValue(GL_PATH_MODELVIEW_MATRIX_CHROMIUM);
1074 validators_.g_l_state.AddValue(GL_PATH_PROJECTION_MATRIX_CHROMIUM);
1075 validators_.g_l_state.AddValue(GL_PATH_STENCIL_FUNC_CHROMIUM);
1076 validators_.g_l_state.AddValue(GL_PATH_STENCIL_REF_CHROMIUM);
1077 validators_.g_l_state.AddValue(GL_PATH_STENCIL_VALUE_MASK_CHROMIUM);
1080 if ((gl_version_info_->is_es3 || gl_version_info_->is_desktop_core_profile ||
1081 extensions.Contains("GL_EXT_texture_rg") ||
1082 extensions.Contains("GL_ARB_texture_rg")) &&
1083 IsGL_REDSupportedOnFBOs()) {
1084 feature_flags_.ext_texture_rg = true;
1085 AddExtensionString("GL_EXT_texture_rg");
1087 validators_.texture_format.AddValue(GL_RED_EXT);
1088 validators_.texture_format.AddValue(GL_RG_EXT);
1089 validators_.texture_internal_format.AddValue(GL_RED_EXT);
1090 validators_.texture_internal_format.AddValue(GL_R8_EXT);
1091 validators_.texture_internal_format.AddValue(GL_RG_EXT);
1092 validators_.texture_internal_format.AddValue(GL_RG8_EXT);
1093 validators_.read_pixel_format.AddValue(GL_RED_EXT);
1094 validators_.read_pixel_format.AddValue(GL_RG_EXT);
1095 validators_.render_buffer_format.AddValue(GL_R8_EXT);
1096 validators_.render_buffer_format.AddValue(GL_RG8_EXT);
1098 UMA_HISTOGRAM_BOOLEAN("GPU.TextureRG", feature_flags_.ext_texture_rg);
1100 #if !defined(OS_MACOSX)
1101 if (workarounds_.ignore_egl_sync_failures) {
1102 gfx::GLFenceEGL::SetIgnoreFailures();
1104 #endif
1106 if (workarounds_.avoid_egl_image_target_texture_reuse) {
1107 TextureDefinition::AvoidEGLTargetTextureReuse();
1110 if (gl_version_info_->IsLowerThanGL(4, 3)) {
1111 // crbug.com/481184.
1112 // GL_PRIMITIVE_RESTART_FIXED_INDEX is only available on Desktop GL 4.3+,
1113 // but we emulate ES 3.0 on top of Desktop GL 4.2+.
1114 feature_flags_.emulate_primitive_restart_fixed_index = true;
1118 bool FeatureInfo::IsES3Capable() const {
1119 if (!enable_unsafe_es3_apis_switch_)
1120 return false;
1121 if (gl_version_info_)
1122 return gl_version_info_->IsES3Capable();
1123 return false;
1126 void FeatureInfo::EnableES3Validators() {
1127 DCHECK(IsES3Capable());
1128 validators_.UpdateValuesES3();
1130 GLint max_color_attachments = 0;
1131 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &max_color_attachments);
1132 const int kTotalColorAttachmentEnums = 16;
1133 const GLenum kColorAttachments[] = {
1134 GL_COLOR_ATTACHMENT0,
1135 GL_COLOR_ATTACHMENT1,
1136 GL_COLOR_ATTACHMENT2,
1137 GL_COLOR_ATTACHMENT3,
1138 GL_COLOR_ATTACHMENT4,
1139 GL_COLOR_ATTACHMENT5,
1140 GL_COLOR_ATTACHMENT6,
1141 GL_COLOR_ATTACHMENT7,
1142 GL_COLOR_ATTACHMENT8,
1143 GL_COLOR_ATTACHMENT9,
1144 GL_COLOR_ATTACHMENT10,
1145 GL_COLOR_ATTACHMENT11,
1146 GL_COLOR_ATTACHMENT12,
1147 GL_COLOR_ATTACHMENT13,
1148 GL_COLOR_ATTACHMENT14,
1149 GL_COLOR_ATTACHMENT15,
1151 if (max_color_attachments < kTotalColorAttachmentEnums) {
1152 validators_.attachment.RemoveValues(
1153 kColorAttachments + max_color_attachments,
1154 kTotalColorAttachmentEnums - max_color_attachments);
1157 GLint max_draw_buffers = 0;
1158 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max_draw_buffers);
1159 const int kTotalDrawBufferEnums = 16;
1160 const GLenum kDrawBuffers[] = {
1161 GL_DRAW_BUFFER0,
1162 GL_DRAW_BUFFER1,
1163 GL_DRAW_BUFFER2,
1164 GL_DRAW_BUFFER3,
1165 GL_DRAW_BUFFER4,
1166 GL_DRAW_BUFFER5,
1167 GL_DRAW_BUFFER6,
1168 GL_DRAW_BUFFER7,
1169 GL_DRAW_BUFFER8,
1170 GL_DRAW_BUFFER9,
1171 GL_DRAW_BUFFER10,
1172 GL_DRAW_BUFFER11,
1173 GL_DRAW_BUFFER12,
1174 GL_DRAW_BUFFER13,
1175 GL_DRAW_BUFFER14,
1176 GL_DRAW_BUFFER15,
1178 if (max_draw_buffers < kTotalDrawBufferEnums) {
1179 validators_.g_l_state.RemoveValues(
1180 kDrawBuffers + max_draw_buffers,
1181 kTotalDrawBufferEnums - max_draw_buffers);
1184 unsafe_es3_apis_enabled_ = true;
1187 void FeatureInfo::AddExtensionString(const char* s) {
1188 std::string str(s);
1189 size_t pos = extensions_.find(str);
1190 while (pos != std::string::npos &&
1191 pos + str.length() < extensions_.length() &&
1192 extensions_.substr(pos + str.length(), 1) != " ") {
1193 // This extension name is a substring of another.
1194 pos = extensions_.find(str, pos + str.length());
1196 if (pos == std::string::npos) {
1197 extensions_ += (extensions_.empty() ? "" : " ") + str;
1201 FeatureInfo::~FeatureInfo() {
1204 } // namespace gles2
1205 } // namespace gpu