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