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"
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"
42 StringSet(const char* s
) {
46 StringSet(const std::string
& 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
: "");
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() {
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
) {
86 std::vector
<std::string
> pieces
;
87 base::SplitString(types
, ',', &pieces
);
88 for (size_t i
= 0; i
< pieces
.size(); ++i
) {
90 bool succeed
= base::StringToInt(pieces
[i
], &number
);
93 #define GPU_OP(type, name) \
95 workarounds->name = true; \
97 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP
)
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),
136 oes_compressed_etc1_rgb8_texture(false),
137 packed_depth24_stencil8(false),
139 enable_texture_float_linear(false),
140 enable_texture_half_float_linear(false),
141 angle_translated_shader_source(false),
142 angle_pack_reverse_row_order(false),
143 arb_texture_rectangle(false),
144 angle_instanced_arrays(false),
145 occlusion_query_boolean(false),
146 use_arb_occlusion_query2_for_occlusion_query_boolean(false),
147 use_arb_occlusion_query_for_occlusion_query_boolean(false),
148 native_vertex_array_object(false),
149 ext_texture_format_atc(false),
150 ext_texture_format_bgra8888(false),
151 ext_texture_format_dxt1(false),
152 ext_texture_format_dxt5(false),
153 enable_shader_name_hashing(false),
154 enable_samplers(false),
155 ext_draw_buffers(false),
156 nv_draw_buffers(false),
157 ext_frag_depth(false),
158 ext_shader_texture_lod(false),
159 use_async_readpixels(false),
160 map_buffer_range(false),
161 ext_discard_framebuffer(false),
162 angle_depth_texture(false),
163 is_swiftshader(false),
164 angle_texture_usage(false),
165 ext_texture_storage(false),
166 chromium_path_rendering(false),
167 blend_equation_advanced(false),
168 blend_equation_advanced_coherent(false),
169 ext_texture_rg(false),
170 enable_subscribe_uniform(false),
171 emulate_primitive_restart_fixed_index(false),
172 ext_render_buffer_format_bgra8888(false) {
175 FeatureInfo::Workarounds::Workarounds() :
176 #define GPU_OP(type, name) name(false),
177 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP
)
180 max_cube_map_texture_size(0),
181 max_fragment_uniform_vectors(0),
182 max_varying_vectors(0),
183 max_vertex_uniform_vectors(0),
184 max_copy_texture_chromium_size(0) {
187 FeatureInfo::FeatureInfo() {
188 InitializeBasicState(*base::CommandLine::ForCurrentProcess());
191 FeatureInfo::FeatureInfo(const base::CommandLine
& command_line
) {
192 InitializeBasicState(command_line
);
195 void FeatureInfo::InitializeBasicState(const base::CommandLine
& command_line
) {
196 if (command_line
.HasSwitch(switches::kGpuDriverBugWorkarounds
)) {
197 std::string types
= command_line
.GetSwitchValueASCII(
198 switches::kGpuDriverBugWorkarounds
);
199 StringToWorkarounds(types
, &workarounds_
);
201 feature_flags_
.enable_shader_name_hashing
=
202 !command_line
.HasSwitch(switches::kDisableShaderNameHashing
);
204 feature_flags_
.is_swiftshader
=
205 (command_line
.GetSwitchValueASCII(switches::kUseGL
) == "swiftshader");
207 feature_flags_
.enable_subscribe_uniform
=
208 command_line
.HasSwitch(switches::kEnableSubscribeUniformExtension
);
210 enable_unsafe_es3_apis_switch_
=
211 command_line
.HasSwitch(switches::kEnableUnsafeES3APIs
);
213 enable_gl_path_rendering_switch_
=
214 command_line
.HasSwitch(switches::kEnableGLPathRendering
);
216 unsafe_es3_apis_enabled_
= false;
219 bool FeatureInfo::Initialize() {
220 disallowed_features_
= DisallowedFeatures();
221 InitializeFeatures();
225 bool FeatureInfo::Initialize(const DisallowedFeatures
& disallowed_features
) {
226 disallowed_features_
= disallowed_features
;
227 InitializeFeatures();
231 bool IsGL_REDSupportedOnFBOs() {
232 // Skia uses GL_RED with frame buffers, unfortunately, Mesa claims to support
233 // GL_EXT_texture_rg, but it doesn't support it on frame buffers. To fix
234 // this, we try it, and if it fails, we don't expose GL_EXT_texture_rg.
235 GLint fb_binding
= 0;
236 GLint tex_binding
= 0;
237 glGetIntegerv(GL_FRAMEBUFFER_BINDING
, &fb_binding
);
238 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &tex_binding
);
240 GLuint textureId
= 0;
241 glGenTextures(1, &textureId
);
242 glBindTexture(GL_TEXTURE_2D
, textureId
);
243 GLubyte data
[1] = {0};
244 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RED_EXT
, 1, 1, 0, GL_RED_EXT
,
245 GL_UNSIGNED_BYTE
, data
);
246 GLuint textureFBOID
= 0;
247 glGenFramebuffersEXT(1, &textureFBOID
);
248 glBindFramebufferEXT(GL_FRAMEBUFFER
, textureFBOID
);
249 glFramebufferTexture2DEXT(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
,
252 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER
) != GL_FRAMEBUFFER_UNSUPPORTED
;
253 glDeleteFramebuffersEXT(1, &textureFBOID
);
254 glDeleteTextures(1, &textureId
);
256 glBindFramebufferEXT(GL_FRAMEBUFFER
, static_cast<GLuint
>(fb_binding
));
257 glBindTexture(GL_TEXTURE_2D
, static_cast<GLuint
>(tex_binding
));
259 DCHECK(glGetError() == GL_NO_ERROR
);
264 void FeatureInfo::InitializeFeatures() {
265 // Figure out what extensions to turn on.
266 StringSet
extensions(gfx::GetGLExtensionsFromCurrentContext());
268 const char* version_str
=
269 reinterpret_cast<const char*>(glGetString(GL_VERSION
));
270 const char* renderer_str
=
271 reinterpret_cast<const char*>(glGetString(GL_RENDERER
));
273 gl_version_info_
.reset(new gfx::GLVersionInfo(
274 version_str
, renderer_str
, extensions
.GetImpl()));
276 AddExtensionString("GL_ANGLE_translated_shader_source");
277 AddExtensionString("GL_CHROMIUM_async_pixel_transfers");
278 AddExtensionString("GL_CHROMIUM_bind_uniform_location");
279 AddExtensionString("GL_CHROMIUM_command_buffer_query");
280 AddExtensionString("GL_CHROMIUM_command_buffer_latency_query");
281 AddExtensionString("GL_CHROMIUM_copy_texture");
282 AddExtensionString("GL_CHROMIUM_get_error_query");
283 AddExtensionString("GL_CHROMIUM_lose_context");
284 AddExtensionString("GL_CHROMIUM_pixel_transfer_buffer_object");
285 AddExtensionString("GL_CHROMIUM_rate_limit_offscreen_context");
286 AddExtensionString("GL_CHROMIUM_resize");
287 AddExtensionString("GL_CHROMIUM_resource_safe");
288 AddExtensionString("GL_CHROMIUM_strict_attribs");
289 AddExtensionString("GL_CHROMIUM_texture_mailbox");
290 AddExtensionString("GL_CHROMIUM_trace_marker");
291 AddExtensionString("GL_EXT_debug_marker");
293 if (feature_flags_
.enable_subscribe_uniform
) {
294 AddExtensionString("GL_CHROMIUM_subscribe_uniform");
297 // OES_vertex_array_object is emulated if not present natively,
298 // so the extension string is always exposed.
299 AddExtensionString("GL_OES_vertex_array_object");
301 if (!disallowed_features_
.gpu_memory_manager
)
302 AddExtensionString("GL_CHROMIUM_gpu_memory_manager");
304 if (extensions
.Contains("GL_ANGLE_translated_shader_source")) {
305 feature_flags_
.angle_translated_shader_source
= true;
308 // Check if we should allow GL_EXT_texture_compression_dxt1 and
309 // GL_EXT_texture_compression_s3tc.
310 bool enable_dxt1
= false;
311 bool enable_dxt3
= false;
312 bool enable_dxt5
= false;
313 bool have_s3tc
= extensions
.Contains("GL_EXT_texture_compression_s3tc");
315 have_s3tc
|| extensions
.Contains("GL_ANGLE_texture_compression_dxt3");
317 have_s3tc
|| extensions
.Contains("GL_ANGLE_texture_compression_dxt5");
319 if (extensions
.Contains("GL_EXT_texture_compression_dxt1") || have_s3tc
) {
330 feature_flags_
.ext_texture_format_dxt1
= true;
332 AddExtensionString("GL_EXT_texture_compression_dxt1");
333 validators_
.compressed_texture_format
.AddValue(
334 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
);
335 validators_
.compressed_texture_format
.AddValue(
336 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
);
338 validators_
.texture_internal_format_storage
.AddValue(
339 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
);
340 validators_
.texture_internal_format_storage
.AddValue(
341 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
);
345 // The difference between GL_EXT_texture_compression_s3tc and
346 // GL_CHROMIUM_texture_compression_dxt3 is that the former
347 // requires on the fly compression. The latter does not.
348 AddExtensionString("GL_CHROMIUM_texture_compression_dxt3");
349 validators_
.compressed_texture_format
.AddValue(
350 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
);
351 validators_
.texture_internal_format_storage
.AddValue(
352 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
);
356 feature_flags_
.ext_texture_format_dxt5
= true;
358 // The difference between GL_EXT_texture_compression_s3tc and
359 // GL_CHROMIUM_texture_compression_dxt5 is that the former
360 // requires on the fly compression. The latter does not.
361 AddExtensionString("GL_CHROMIUM_texture_compression_dxt5");
362 validators_
.compressed_texture_format
.AddValue(
363 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
);
364 validators_
.texture_internal_format_storage
.AddValue(
365 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
);
368 bool have_atc
= extensions
.Contains("GL_AMD_compressed_ATC_texture") ||
369 extensions
.Contains("GL_ATI_texture_compression_atitc");
371 feature_flags_
.ext_texture_format_atc
= true;
373 AddExtensionString("GL_AMD_compressed_ATC_texture");
374 validators_
.compressed_texture_format
.AddValue(GL_ATC_RGB_AMD
);
375 validators_
.compressed_texture_format
.AddValue(
376 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
);
378 validators_
.texture_internal_format_storage
.AddValue(GL_ATC_RGB_AMD
);
379 validators_
.texture_internal_format_storage
.AddValue(
380 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
);
383 // Check if we should enable GL_EXT_texture_filter_anisotropic.
384 if (extensions
.Contains("GL_EXT_texture_filter_anisotropic")) {
385 AddExtensionString("GL_EXT_texture_filter_anisotropic");
386 validators_
.texture_parameter
.AddValue(
387 GL_TEXTURE_MAX_ANISOTROPY_EXT
);
388 validators_
.g_l_state
.AddValue(
389 GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
);
392 // Check if we should support GL_OES_packed_depth_stencil and/or
393 // GL_GOOGLE_depth_texture / GL_CHROMIUM_depth_texture.
395 // NOTE: GL_OES_depth_texture requires support for depth cubemaps.
396 // GL_ARB_depth_texture requires other features that
397 // GL_OES_packed_depth_stencil does not provide.
399 // Therefore we made up GL_GOOGLE_depth_texture / GL_CHROMIUM_depth_texture.
401 // GL_GOOGLE_depth_texture is legacy. As we exposed it into NaCl we can't
404 bool enable_depth_texture
= false;
405 if (!workarounds_
.disable_depth_texture
&&
406 (extensions
.Contains("GL_ARB_depth_texture") ||
407 extensions
.Contains("GL_OES_depth_texture") ||
408 extensions
.Contains("GL_ANGLE_depth_texture") ||
409 gl_version_info_
->is_es3
||
410 gl_version_info_
->is_desktop_core_profile
)) {
411 enable_depth_texture
= true;
412 feature_flags_
.angle_depth_texture
=
413 extensions
.Contains("GL_ANGLE_depth_texture");
416 if (enable_depth_texture
) {
417 AddExtensionString("GL_CHROMIUM_depth_texture");
418 AddExtensionString("GL_GOOGLE_depth_texture");
419 validators_
.texture_internal_format
.AddValue(GL_DEPTH_COMPONENT
);
420 validators_
.texture_format
.AddValue(GL_DEPTH_COMPONENT
);
421 validators_
.pixel_type
.AddValue(GL_UNSIGNED_SHORT
);
422 validators_
.pixel_type
.AddValue(GL_UNSIGNED_INT
);
425 if (extensions
.Contains("GL_EXT_packed_depth_stencil") ||
426 extensions
.Contains("GL_OES_packed_depth_stencil") ||
427 gl_version_info_
->is_es3
||
428 gl_version_info_
->is_desktop_core_profile
) {
429 AddExtensionString("GL_OES_packed_depth_stencil");
430 feature_flags_
.packed_depth24_stencil8
= true;
431 if (enable_depth_texture
) {
432 validators_
.texture_internal_format
.AddValue(GL_DEPTH_STENCIL
);
433 validators_
.texture_format
.AddValue(GL_DEPTH_STENCIL
);
434 validators_
.pixel_type
.AddValue(GL_UNSIGNED_INT_24_8
);
436 validators_
.render_buffer_format
.AddValue(GL_DEPTH24_STENCIL8
);
439 if (gl_version_info_
->is_es3
||
440 gl_version_info_
->is_desktop_core_profile
||
441 extensions
.Contains("GL_OES_vertex_array_object") ||
442 extensions
.Contains("GL_ARB_vertex_array_object") ||
443 extensions
.Contains("GL_APPLE_vertex_array_object")) {
444 feature_flags_
.native_vertex_array_object
= true;
447 // If we're using client_side_arrays we have to emulate
448 // vertex array objects since vertex array objects do not work
449 // with client side arrays.
450 if (workarounds_
.use_client_side_arrays_for_stream_buffers
) {
451 feature_flags_
.native_vertex_array_object
= false;
454 if (gl_version_info_
->is_es3
||
455 extensions
.Contains("GL_OES_element_index_uint") ||
456 gfx::HasDesktopGLFeatures()) {
457 AddExtensionString("GL_OES_element_index_uint");
458 validators_
.index_type
.AddValue(GL_UNSIGNED_INT
);
461 // With EXT_sRGB, unsized SRGB_EXT and SRGB_ALPHA_EXT are accepted by the
462 // <format> and <internalformat> parameter of TexImage2D. GLES3 adds support
463 // for SRGB Textures but the accepted internal formats for TexImage2D are only
464 // sized formats GL_SRGB8 and GL_SRGB8_ALPHA8. Also, SRGB_EXT isn't a valid
465 // <format> in this case. So, even with GLES3 explicitly check for
467 if (((gl_version_info_
->is_es3
||
468 extensions
.Contains("GL_OES_rgb8_rgba8")) &&
469 extensions
.Contains("GL_EXT_sRGB")) || gfx::HasDesktopGLFeatures()) {
470 AddExtensionString("GL_EXT_sRGB");
471 validators_
.texture_internal_format
.AddValue(GL_SRGB_EXT
);
472 validators_
.texture_internal_format
.AddValue(GL_SRGB_ALPHA_EXT
);
473 validators_
.texture_format
.AddValue(GL_SRGB_EXT
);
474 validators_
.texture_format
.AddValue(GL_SRGB_ALPHA_EXT
);
475 validators_
.render_buffer_format
.AddValue(GL_SRGB8_ALPHA8_EXT
);
476 validators_
.frame_buffer_parameter
.AddValue(
477 GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT
);
480 bool enable_texture_format_bgra8888
= false;
481 bool enable_read_format_bgra
= false;
482 bool enable_render_buffer_bgra
= false;
483 bool enable_immutable_texture_format_bgra_on_es3
=
484 extensions
.Contains("GL_APPLE_texture_format_BGRA8888");
486 // Check if we should allow GL_EXT_texture_format_BGRA8888
487 if (extensions
.Contains("GL_EXT_texture_format_BGRA8888") ||
488 enable_immutable_texture_format_bgra_on_es3
||
489 !gl_version_info_
->is_es
) {
490 enable_texture_format_bgra8888
= true;
493 // Only desktop GL extension GL_EXT_bgra or ANGLE guarantee that we can
494 // allocate a renderbuffer with this format.
495 if (extensions
.Contains("GL_EXT_bgra") || gl_version_info_
->is_angle
) {
496 enable_render_buffer_bgra
= true;
499 if (extensions
.Contains("GL_EXT_read_format_bgra") ||
500 extensions
.Contains("GL_EXT_bgra")) {
501 enable_read_format_bgra
= true;
504 if (enable_texture_format_bgra8888
) {
505 feature_flags_
.ext_texture_format_bgra8888
= true;
506 AddExtensionString("GL_EXT_texture_format_BGRA8888");
507 validators_
.texture_internal_format
.AddValue(GL_BGRA_EXT
);
508 validators_
.texture_format
.AddValue(GL_BGRA_EXT
);
511 if (enable_read_format_bgra
) {
512 AddExtensionString("GL_EXT_read_format_bgra");
513 validators_
.read_pixel_format
.AddValue(GL_BGRA_EXT
);
516 if (enable_render_buffer_bgra
) {
517 feature_flags_
.ext_render_buffer_format_bgra8888
= true;
518 AddExtensionString("GL_CHROMIUM_renderbuffer_format_BGRA8888");
519 validators_
.render_buffer_format
.AddValue(GL_BGRA8_EXT
);
522 if (extensions
.Contains("GL_OES_rgb8_rgba8") || gfx::HasDesktopGLFeatures()) {
523 AddExtensionString("GL_OES_rgb8_rgba8");
524 validators_
.render_buffer_format
.AddValue(GL_RGB8_OES
);
525 validators_
.render_buffer_format
.AddValue(GL_RGBA8_OES
);
528 // Check if we should allow GL_OES_texture_npot
529 if (!disallowed_features_
.npot_support
&&
530 (gl_version_info_
->is_es3
||
531 gl_version_info_
->is_desktop_core_profile
||
532 extensions
.Contains("GL_ARB_texture_non_power_of_two") ||
533 extensions
.Contains("GL_OES_texture_npot"))) {
534 AddExtensionString("GL_OES_texture_npot");
535 feature_flags_
.npot_ok
= true;
538 // Check if we should allow GL_OES_texture_float, GL_OES_texture_half_float,
539 // GL_OES_texture_float_linear, GL_OES_texture_half_float_linear
540 bool enable_texture_float
= false;
541 bool enable_texture_float_linear
= false;
542 bool enable_texture_half_float
= false;
543 bool enable_texture_half_float_linear
= false;
545 bool may_enable_chromium_color_buffer_float
= false;
547 if (extensions
.Contains("GL_ARB_texture_float") ||
548 gl_version_info_
->is_desktop_core_profile
) {
549 enable_texture_float
= true;
550 enable_texture_float_linear
= true;
551 enable_texture_half_float
= true;
552 enable_texture_half_float_linear
= true;
553 may_enable_chromium_color_buffer_float
= true;
555 // GLES3 adds support for Float type by default but it doesn't support all
556 // formats as GL_OES_texture_float(i.e.LUMINANCE_ALPHA,LUMINANCE and Alpha)
557 if (extensions
.Contains("GL_OES_texture_float")) {
558 enable_texture_float
= true;
559 if (extensions
.Contains("GL_OES_texture_float_linear")) {
560 enable_texture_float_linear
= true;
562 // This extension allows a variety of floating point formats to be
563 // rendered to via framebuffer objects. Enable it's usage only if
564 // support for Floating textures is enabled.
565 if ((gl_version_info_
->is_es3
&&
566 extensions
.Contains("GL_EXT_color_buffer_float")) ||
567 gl_version_info_
->is_angle
) {
568 may_enable_chromium_color_buffer_float
= true;
572 // TODO(dshwang): GLES3 supports half float by default but GL_HALF_FLOAT_OES
573 // isn't equal to GL_HALF_FLOAT.
574 if (extensions
.Contains("GL_OES_texture_half_float")) {
575 enable_texture_half_float
= true;
576 if (extensions
.Contains("GL_OES_texture_half_float_linear")) {
577 enable_texture_half_float_linear
= true;
582 if (enable_texture_float
) {
583 validators_
.pixel_type
.AddValue(GL_FLOAT
);
584 validators_
.read_pixel_type
.AddValue(GL_FLOAT
);
585 AddExtensionString("GL_OES_texture_float");
586 if (enable_texture_float_linear
) {
587 AddExtensionString("GL_OES_texture_float_linear");
591 if (enable_texture_half_float
) {
592 validators_
.pixel_type
.AddValue(GL_HALF_FLOAT_OES
);
593 validators_
.read_pixel_type
.AddValue(GL_HALF_FLOAT_OES
);
594 AddExtensionString("GL_OES_texture_half_float");
595 if (enable_texture_half_float_linear
) {
596 AddExtensionString("GL_OES_texture_half_float_linear");
600 if (may_enable_chromium_color_buffer_float
) {
601 static_assert(GL_RGBA32F_ARB
== GL_RGBA32F
&&
602 GL_RGBA32F_EXT
== GL_RGBA32F
&&
603 GL_RGB32F_ARB
== GL_RGB32F
&&
604 GL_RGB32F_EXT
== GL_RGB32F
,
605 "sized float internal format variations must match");
606 // We don't check extension support beyond ARB_texture_float on desktop GL,
607 // and format support varies between GL configurations. For example, spec
608 // prior to OpenGL 3.0 mandates framebuffer support only for one
609 // implementation-chosen format, and ES3.0 EXT_color_buffer_float does not
610 // support rendering to RGB32F. Check for framebuffer completeness with
611 // formats that the extensions expose, and only enable an extension when a
612 // framebuffer created with its texture format is reported as complete.
613 GLint fb_binding
= 0;
614 GLint tex_binding
= 0;
615 glGetIntegerv(GL_FRAMEBUFFER_BINDING
, &fb_binding
);
616 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &tex_binding
);
622 glGenTextures(1, &tex_id
);
623 glGenFramebuffersEXT(1, &fb_id
);
624 glBindTexture(GL_TEXTURE_2D
, tex_id
);
625 // Nearest filter needed for framebuffer completeness on some drivers.
626 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
627 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA32F
, width
, width
, 0, GL_RGBA
,
629 glBindFramebufferEXT(GL_FRAMEBUFFER
, fb_id
);
630 glFramebufferTexture2DEXT(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
631 GL_TEXTURE_2D
, tex_id
, 0);
632 GLenum statusRGBA
= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER
);
633 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB32F
, width
, width
, 0, GL_RGB
,
635 GLenum statusRGB
= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER
);
636 glDeleteFramebuffersEXT(1, &fb_id
);
637 glDeleteTextures(1, &tex_id
);
639 glBindFramebufferEXT(GL_FRAMEBUFFER
, static_cast<GLuint
>(fb_binding
));
640 glBindTexture(GL_TEXTURE_2D
, static_cast<GLuint
>(tex_binding
));
642 DCHECK(glGetError() == GL_NO_ERROR
);
644 if (statusRGBA
== GL_FRAMEBUFFER_COMPLETE
) {
645 validators_
.texture_internal_format
.AddValue(GL_RGBA32F
);
646 feature_flags_
.chromium_color_buffer_float_rgba
= true;
647 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgba");
649 if (statusRGB
== GL_FRAMEBUFFER_COMPLETE
) {
650 validators_
.texture_internal_format
.AddValue(GL_RGB32F
);
651 feature_flags_
.chromium_color_buffer_float_rgb
= true;
652 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgb");
656 // Check for multisample support
657 if (!workarounds_
.disable_chromium_framebuffer_multisample
) {
658 bool ext_has_multisample
=
659 extensions
.Contains("GL_EXT_framebuffer_multisample") ||
660 gl_version_info_
->is_es3
||
661 gl_version_info_
->is_desktop_core_profile
;
662 if (gl_version_info_
->is_angle
) {
663 ext_has_multisample
|=
664 extensions
.Contains("GL_ANGLE_framebuffer_multisample");
666 feature_flags_
.use_core_framebuffer_multisample
=
667 gl_version_info_
->is_es3
|| gl_version_info_
->is_desktop_core_profile
;
668 if (ext_has_multisample
) {
669 feature_flags_
.chromium_framebuffer_multisample
= true;
670 validators_
.frame_buffer_target
.AddValue(GL_READ_FRAMEBUFFER_EXT
);
671 validators_
.frame_buffer_target
.AddValue(GL_DRAW_FRAMEBUFFER_EXT
);
672 validators_
.g_l_state
.AddValue(GL_READ_FRAMEBUFFER_BINDING_EXT
);
673 validators_
.g_l_state
.AddValue(GL_MAX_SAMPLES_EXT
);
674 validators_
.render_buffer_parameter
.AddValue(GL_RENDERBUFFER_SAMPLES_EXT
);
675 AddExtensionString("GL_CHROMIUM_framebuffer_multisample");
679 if (!workarounds_
.disable_multisampled_render_to_texture
) {
680 if (extensions
.Contains("GL_EXT_multisampled_render_to_texture")) {
681 feature_flags_
.multisampled_render_to_texture
= true;
682 } else if (extensions
.Contains("GL_IMG_multisampled_render_to_texture")) {
683 feature_flags_
.multisampled_render_to_texture
= true;
684 feature_flags_
.use_img_for_multisampled_render_to_texture
= true;
686 if (feature_flags_
.multisampled_render_to_texture
) {
687 validators_
.render_buffer_parameter
.AddValue(
688 GL_RENDERBUFFER_SAMPLES_EXT
);
689 validators_
.g_l_state
.AddValue(GL_MAX_SAMPLES_EXT
);
690 validators_
.frame_buffer_parameter
.AddValue(
691 GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT
);
692 AddExtensionString("GL_EXT_multisampled_render_to_texture");
696 if (extensions
.Contains("GL_OES_depth24") || gfx::HasDesktopGLFeatures() ||
697 gl_version_info_
->is_es3
) {
698 AddExtensionString("GL_OES_depth24");
699 feature_flags_
.oes_depth24
= true;
700 validators_
.render_buffer_format
.AddValue(GL_DEPTH_COMPONENT24
);
703 if (gl_version_info_
->is_es3
||
704 extensions
.Contains("GL_OES_standard_derivatives") ||
705 gfx::HasDesktopGLFeatures()) {
706 AddExtensionString("GL_OES_standard_derivatives");
707 feature_flags_
.oes_standard_derivatives
= true;
708 validators_
.hint_target
.AddValue(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES
);
709 validators_
.g_l_state
.AddValue(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES
);
712 if (extensions
.Contains("GL_OES_EGL_image_external")) {
713 AddExtensionString("GL_OES_EGL_image_external");
714 feature_flags_
.oes_egl_image_external
= true;
715 validators_
.texture_bind_target
.AddValue(GL_TEXTURE_EXTERNAL_OES
);
716 validators_
.get_tex_param_target
.AddValue(GL_TEXTURE_EXTERNAL_OES
);
717 validators_
.texture_parameter
.AddValue(GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES
);
718 validators_
.g_l_state
.AddValue(GL_TEXTURE_BINDING_EXTERNAL_OES
);
721 if (extensions
.Contains("GL_OES_compressed_ETC1_RGB8_texture")) {
722 AddExtensionString("GL_OES_compressed_ETC1_RGB8_texture");
723 feature_flags_
.oes_compressed_etc1_rgb8_texture
= true;
724 validators_
.compressed_texture_format
.AddValue(GL_ETC1_RGB8_OES
);
725 validators_
.texture_internal_format_storage
.AddValue(GL_ETC1_RGB8_OES
);
728 if (extensions
.Contains("GL_AMD_compressed_ATC_texture")) {
729 AddExtensionString("GL_AMD_compressed_ATC_texture");
730 validators_
.compressed_texture_format
.AddValue(
732 validators_
.compressed_texture_format
.AddValue(
733 GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
);
734 validators_
.compressed_texture_format
.AddValue(
735 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
);
737 validators_
.texture_internal_format_storage
.AddValue(
739 validators_
.texture_internal_format_storage
.AddValue(
740 GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
);
741 validators_
.texture_internal_format_storage
.AddValue(
742 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
);
745 if (extensions
.Contains("GL_IMG_texture_compression_pvrtc")) {
746 AddExtensionString("GL_IMG_texture_compression_pvrtc");
747 validators_
.compressed_texture_format
.AddValue(
748 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
);
749 validators_
.compressed_texture_format
.AddValue(
750 GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
);
751 validators_
.compressed_texture_format
.AddValue(
752 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
);
753 validators_
.compressed_texture_format
.AddValue(
754 GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
);
756 validators_
.texture_internal_format_storage
.AddValue(
757 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
);
758 validators_
.texture_internal_format_storage
.AddValue(
759 GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
);
760 validators_
.texture_internal_format_storage
.AddValue(
761 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
);
762 validators_
.texture_internal_format_storage
.AddValue(
763 GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
);
766 // Ideally we would only expose this extension on Mac OS X, to
767 // support GL_CHROMIUM_iosurface and the compositor. We don't want
768 // applications to start using it; they should use ordinary non-
769 // power-of-two textures. However, for unit testing purposes we
770 // expose it on all supported platforms.
771 if (extensions
.Contains("GL_ARB_texture_rectangle") ||
772 gl_version_info_
->is_desktop_core_profile
) {
773 AddExtensionString("GL_ARB_texture_rectangle");
774 feature_flags_
.arb_texture_rectangle
= true;
775 // Rectangle textures are used as samplers via glBindTexture, framebuffer
776 // textures via glFramebufferTexture2D, and copy destinations via
778 validators_
.texture_bind_target
.AddValue(GL_TEXTURE_RECTANGLE_ARB
);
779 validators_
.texture_target
.AddValue(GL_TEXTURE_RECTANGLE_ARB
);
780 validators_
.get_tex_param_target
.AddValue(GL_TEXTURE_RECTANGLE_ARB
);
781 validators_
.g_l_state
.AddValue(GL_TEXTURE_BINDING_RECTANGLE_ARB
);
784 #if defined(OS_MACOSX)
785 AddExtensionString("GL_CHROMIUM_iosurface");
788 // TODO(gman): Add support for these extensions.
791 feature_flags_
.enable_texture_float_linear
|= enable_texture_float_linear
;
792 feature_flags_
.enable_texture_half_float_linear
|=
793 enable_texture_half_float_linear
;
795 if (extensions
.Contains("GL_ANGLE_pack_reverse_row_order")) {
796 AddExtensionString("GL_ANGLE_pack_reverse_row_order");
797 feature_flags_
.angle_pack_reverse_row_order
= true;
798 validators_
.pixel_store
.AddValue(GL_PACK_REVERSE_ROW_ORDER_ANGLE
);
799 validators_
.g_l_state
.AddValue(GL_PACK_REVERSE_ROW_ORDER_ANGLE
);
802 if (extensions
.Contains("GL_ANGLE_texture_usage")) {
803 feature_flags_
.angle_texture_usage
= true;
804 AddExtensionString("GL_ANGLE_texture_usage");
805 validators_
.texture_parameter
.AddValue(GL_TEXTURE_USAGE_ANGLE
);
808 // Note: Only APPLE_texture_format_BGRA8888 extension allows BGRA8_EXT in
809 // ES3's glTexStorage2D. We prefer support BGRA to texture storage.
810 // So we don't expose GL_EXT_texture_storage when ES3 +
811 // GL_EXT_texture_format_BGRA8888 because we fail the GL_BGRA8 requirement.
812 // However we expose GL_EXT_texture_storage when just ES3 because we don't
813 // claim to handle GL_BGRA8.
814 bool support_texture_storage_on_es3
=
815 (gl_version_info_
->is_es3
&&
816 enable_immutable_texture_format_bgra_on_es3
) ||
817 (gl_version_info_
->is_es3
&&
818 !enable_texture_format_bgra8888
);
819 if (extensions
.Contains("GL_EXT_texture_storage") ||
820 extensions
.Contains("GL_ARB_texture_storage") ||
821 support_texture_storage_on_es3
||
822 gl_version_info_
->is_desktop_core_profile
) {
823 feature_flags_
.ext_texture_storage
= true;
824 AddExtensionString("GL_EXT_texture_storage");
825 validators_
.texture_parameter
.AddValue(GL_TEXTURE_IMMUTABLE_FORMAT_EXT
);
826 if (enable_texture_format_bgra8888
)
827 validators_
.texture_internal_format_storage
.AddValue(GL_BGRA8_EXT
);
828 if (enable_texture_float
) {
829 validators_
.texture_internal_format_storage
.AddValue(GL_RGBA32F_EXT
);
830 validators_
.texture_internal_format_storage
.AddValue(GL_RGB32F_EXT
);
831 validators_
.texture_internal_format_storage
.AddValue(GL_ALPHA32F_EXT
);
832 validators_
.texture_internal_format_storage
.AddValue(
833 GL_LUMINANCE32F_EXT
);
834 validators_
.texture_internal_format_storage
.AddValue(
835 GL_LUMINANCE_ALPHA32F_EXT
);
837 if (enable_texture_half_float
) {
838 validators_
.texture_internal_format_storage
.AddValue(GL_RGBA16F_EXT
);
839 validators_
.texture_internal_format_storage
.AddValue(GL_RGB16F_EXT
);
840 validators_
.texture_internal_format_storage
.AddValue(GL_ALPHA16F_EXT
);
841 validators_
.texture_internal_format_storage
.AddValue(
842 GL_LUMINANCE16F_EXT
);
843 validators_
.texture_internal_format_storage
.AddValue(
844 GL_LUMINANCE_ALPHA16F_EXT
);
848 bool have_ext_occlusion_query_boolean
=
849 extensions
.Contains("GL_EXT_occlusion_query_boolean");
850 bool have_arb_occlusion_query2
=
851 extensions
.Contains("GL_ARB_occlusion_query2");
852 bool have_arb_occlusion_query
=
853 extensions
.Contains("GL_ARB_occlusion_query");
855 if (have_ext_occlusion_query_boolean
||
856 have_arb_occlusion_query2
||
857 have_arb_occlusion_query
) {
858 AddExtensionString("GL_EXT_occlusion_query_boolean");
859 feature_flags_
.occlusion_query_boolean
= true;
860 feature_flags_
.use_arb_occlusion_query2_for_occlusion_query_boolean
=
861 !have_ext_occlusion_query_boolean
&& have_arb_occlusion_query2
;
862 feature_flags_
.use_arb_occlusion_query_for_occlusion_query_boolean
=
863 !have_ext_occlusion_query_boolean
&& have_arb_occlusion_query
&&
864 !have_arb_occlusion_query2
;
867 if (!workarounds_
.disable_angle_instanced_arrays
&&
868 (extensions
.Contains("GL_ANGLE_instanced_arrays") ||
869 (extensions
.Contains("GL_ARB_instanced_arrays") &&
870 extensions
.Contains("GL_ARB_draw_instanced")) ||
871 gl_version_info_
->is_es3
)) {
872 AddExtensionString("GL_ANGLE_instanced_arrays");
873 feature_flags_
.angle_instanced_arrays
= true;
874 validators_
.vertex_attribute
.AddValue(GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE
);
877 bool vendor_agnostic_draw_buffers
=
878 extensions
.Contains("GL_ARB_draw_buffers") ||
879 extensions
.Contains("GL_EXT_draw_buffers");
880 if (!workarounds_
.disable_ext_draw_buffers
&&
881 (vendor_agnostic_draw_buffers
||
882 (extensions
.Contains("GL_NV_draw_buffers") &&
883 gl_version_info_
->is_es3
) ||
884 gl_version_info_
->is_desktop_core_profile
)) {
885 AddExtensionString("GL_EXT_draw_buffers");
886 feature_flags_
.ext_draw_buffers
= true;
888 // This flag is set to enable emulation of EXT_draw_buffers when we're
889 // running on GLES 3.0+, NV_draw_buffers extension is supported and
890 // glDrawBuffers from GLES 3.0 core has been bound. It toggles using the
891 // NV_draw_buffers extension directive instead of EXT_draw_buffers extension
892 // directive in ESSL 100 shaders translated by ANGLE, enabling them to write
893 // into multiple gl_FragData values, which is not by default possible in
894 // ESSL 100 with core GLES 3.0. For more information, see the
895 // NV_draw_buffers specification.
896 feature_flags_
.nv_draw_buffers
= !vendor_agnostic_draw_buffers
;
898 GLint max_color_attachments
= 0;
899 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT
, &max_color_attachments
);
900 for (GLenum i
= GL_COLOR_ATTACHMENT1_EXT
;
901 i
< static_cast<GLenum
>(GL_COLOR_ATTACHMENT0
+ max_color_attachments
);
903 validators_
.attachment
.AddValue(i
);
905 static_assert(GL_COLOR_ATTACHMENT0_EXT
== GL_COLOR_ATTACHMENT0
,
906 "GL_COLOR_ATTACHMENT0_EXT should equal GL_COLOR_ATTACHMENT0");
908 validators_
.g_l_state
.AddValue(GL_MAX_COLOR_ATTACHMENTS_EXT
);
909 validators_
.g_l_state
.AddValue(GL_MAX_DRAW_BUFFERS_ARB
);
910 GLint max_draw_buffers
= 0;
911 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB
, &max_draw_buffers
);
912 for (GLenum i
= GL_DRAW_BUFFER0_ARB
;
913 i
< static_cast<GLenum
>(GL_DRAW_BUFFER0_ARB
+ max_draw_buffers
);
915 validators_
.g_l_state
.AddValue(i
);
919 if (gl_version_info_
->is_es3
||
920 extensions
.Contains("GL_EXT_blend_minmax") ||
921 gfx::HasDesktopGLFeatures()) {
922 AddExtensionString("GL_EXT_blend_minmax");
923 validators_
.equation
.AddValue(GL_MIN_EXT
);
924 validators_
.equation
.AddValue(GL_MAX_EXT
);
925 static_assert(GL_MIN_EXT
== GL_MIN
&& GL_MAX_EXT
== GL_MAX
,
926 "min & max variations must match");
929 // TODO(dshwang): GLES3 supports gl_FragDepth, not gl_FragDepthEXT.
930 if (extensions
.Contains("GL_EXT_frag_depth") || gfx::HasDesktopGLFeatures()) {
931 AddExtensionString("GL_EXT_frag_depth");
932 feature_flags_
.ext_frag_depth
= true;
935 if (extensions
.Contains("GL_EXT_shader_texture_lod") ||
936 gfx::HasDesktopGLFeatures()) {
937 AddExtensionString("GL_EXT_shader_texture_lod");
938 feature_flags_
.ext_shader_texture_lod
= true;
941 bool ui_gl_fence_works
= gfx::GLFence::IsSupported();
942 UMA_HISTOGRAM_BOOLEAN("GPU.FenceSupport", ui_gl_fence_works
);
944 feature_flags_
.map_buffer_range
=
945 gl_version_info_
->is_es3
||
946 gl_version_info_
->is_desktop_core_profile
||
947 extensions
.Contains("GL_ARB_map_buffer_range") ||
948 extensions
.Contains("GL_EXT_map_buffer_range");
950 // Really it's part of core OpenGL 2.1 and up, but let's assume the
951 // extension is still advertised.
952 bool has_pixel_buffers
=
953 gl_version_info_
->is_es3
||
954 gl_version_info_
->is_desktop_core_profile
||
955 extensions
.Contains("GL_ARB_pixel_buffer_object") ||
956 extensions
.Contains("GL_NV_pixel_buffer_object");
958 // We will use either glMapBuffer() or glMapBufferRange() for async readbacks.
959 if (has_pixel_buffers
&& ui_gl_fence_works
&&
960 !workarounds_
.disable_async_readpixels
) {
961 feature_flags_
.use_async_readpixels
= true;
964 if (gl_version_info_
->is_es3
||
965 extensions
.Contains("GL_ARB_sampler_objects")) {
966 feature_flags_
.enable_samplers
= true;
967 // TODO(dsinclair): Add AddExtensionString("GL_CHROMIUM_sampler_objects")
971 if ((gl_version_info_
->is_es3
||
972 extensions
.Contains("GL_EXT_discard_framebuffer")) &&
973 !workarounds_
.disable_discard_framebuffer
) {
974 // DiscardFramebufferEXT is automatically bound to InvalidateFramebuffer.
975 AddExtensionString("GL_EXT_discard_framebuffer");
976 feature_flags_
.ext_discard_framebuffer
= true;
979 if (ui_gl_fence_works
) {
980 AddExtensionString("GL_CHROMIUM_sync_query");
981 feature_flags_
.chromium_sync_query
= true;
984 if (!workarounds_
.disable_blend_equation_advanced
) {
985 bool blend_equation_advanced_coherent
=
986 extensions
.Contains("GL_NV_blend_equation_advanced_coherent") ||
987 extensions
.Contains("GL_KHR_blend_equation_advanced_coherent");
989 if (blend_equation_advanced_coherent
||
990 extensions
.Contains("GL_NV_blend_equation_advanced") ||
991 extensions
.Contains("GL_KHR_blend_equation_advanced")) {
992 const GLenum equations
[] = {GL_MULTIPLY_KHR
,
1004 GL_HSL_SATURATION_KHR
,
1006 GL_HSL_LUMINOSITY_KHR
};
1008 for (GLenum equation
: equations
)
1009 validators_
.equation
.AddValue(equation
);
1010 if (blend_equation_advanced_coherent
)
1011 AddExtensionString("GL_KHR_blend_equation_advanced_coherent");
1013 AddExtensionString("GL_KHR_blend_equation_advanced");
1014 feature_flags_
.blend_equation_advanced
= true;
1015 feature_flags_
.blend_equation_advanced_coherent
=
1016 blend_equation_advanced_coherent
;
1020 if (enable_gl_path_rendering_switch_
&&
1021 !workarounds_
.disable_gl_path_rendering
&&
1022 extensions
.Contains("GL_NV_path_rendering") &&
1023 (extensions
.Contains("GL_EXT_direct_state_access") ||
1024 gl_version_info_
->is_es3
)) {
1025 AddExtensionString("GL_CHROMIUM_path_rendering");
1026 feature_flags_
.chromium_path_rendering
= true;
1027 validators_
.g_l_state
.AddValue(GL_PATH_MODELVIEW_MATRIX_CHROMIUM
);
1028 validators_
.g_l_state
.AddValue(GL_PATH_PROJECTION_MATRIX_CHROMIUM
);
1029 validators_
.g_l_state
.AddValue(GL_PATH_STENCIL_FUNC_CHROMIUM
);
1030 validators_
.g_l_state
.AddValue(GL_PATH_STENCIL_REF_CHROMIUM
);
1031 validators_
.g_l_state
.AddValue(GL_PATH_STENCIL_VALUE_MASK_CHROMIUM
);
1034 if ((gl_version_info_
->is_es3
|| gl_version_info_
->is_desktop_core_profile
||
1035 extensions
.Contains("GL_EXT_texture_rg") ||
1036 extensions
.Contains("GL_ARB_texture_rg")) &&
1037 IsGL_REDSupportedOnFBOs()) {
1038 feature_flags_
.ext_texture_rg
= true;
1039 AddExtensionString("GL_EXT_texture_rg");
1041 validators_
.texture_format
.AddValue(GL_RED_EXT
);
1042 validators_
.texture_format
.AddValue(GL_RG_EXT
);
1043 validators_
.texture_internal_format
.AddValue(GL_RED_EXT
);
1044 validators_
.texture_internal_format
.AddValue(GL_R8_EXT
);
1045 validators_
.texture_internal_format
.AddValue(GL_RG_EXT
);
1046 validators_
.texture_internal_format
.AddValue(GL_RG8_EXT
);
1047 validators_
.read_pixel_format
.AddValue(GL_RED_EXT
);
1048 validators_
.read_pixel_format
.AddValue(GL_RG_EXT
);
1049 validators_
.render_buffer_format
.AddValue(GL_R8_EXT
);
1050 validators_
.render_buffer_format
.AddValue(GL_RG8_EXT
);
1052 UMA_HISTOGRAM_BOOLEAN("GPU.TextureRG", feature_flags_
.ext_texture_rg
);
1054 #if !defined(OS_MACOSX)
1055 if (workarounds_
.ignore_egl_sync_failures
) {
1056 gfx::GLFenceEGL::SetIgnoreFailures();
1060 if (workarounds_
.avoid_egl_image_target_texture_reuse
) {
1061 TextureDefinition::AvoidEGLTargetTextureReuse();
1064 if (gl_version_info_
->IsLowerThanGL(4, 3)) {
1065 // crbug.com/481184.
1066 // GL_PRIMITIVE_RESTART_FIXED_INDEX is only available on Desktop GL 4.3+,
1067 // but we emulate ES 3.0 on top of Desktop GL 4.2+.
1068 feature_flags_
.emulate_primitive_restart_fixed_index
= true;
1072 bool FeatureInfo::IsES3Capable() const {
1073 if (!enable_unsafe_es3_apis_switch_
)
1075 if (gl_version_info_
)
1076 return gl_version_info_
->IsES3Capable();
1080 void FeatureInfo::EnableES3Validators() {
1081 DCHECK(IsES3Capable());
1082 validators_
.UpdateValuesES3();
1084 GLint max_color_attachments
= 0;
1085 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS
, &max_color_attachments
);
1086 const int kTotalColorAttachmentEnums
= 16;
1087 const GLenum kColorAttachments
[] = {
1088 GL_COLOR_ATTACHMENT0
,
1089 GL_COLOR_ATTACHMENT1
,
1090 GL_COLOR_ATTACHMENT2
,
1091 GL_COLOR_ATTACHMENT3
,
1092 GL_COLOR_ATTACHMENT4
,
1093 GL_COLOR_ATTACHMENT5
,
1094 GL_COLOR_ATTACHMENT6
,
1095 GL_COLOR_ATTACHMENT7
,
1096 GL_COLOR_ATTACHMENT8
,
1097 GL_COLOR_ATTACHMENT9
,
1098 GL_COLOR_ATTACHMENT10
,
1099 GL_COLOR_ATTACHMENT11
,
1100 GL_COLOR_ATTACHMENT12
,
1101 GL_COLOR_ATTACHMENT13
,
1102 GL_COLOR_ATTACHMENT14
,
1103 GL_COLOR_ATTACHMENT15
,
1105 if (max_color_attachments
< kTotalColorAttachmentEnums
) {
1106 validators_
.attachment
.RemoveValues(
1107 kColorAttachments
+ max_color_attachments
,
1108 kTotalColorAttachmentEnums
- max_color_attachments
);
1111 GLint max_draw_buffers
= 0;
1112 glGetIntegerv(GL_MAX_DRAW_BUFFERS
, &max_draw_buffers
);
1113 const int kTotalDrawBufferEnums
= 16;
1114 const GLenum kDrawBuffers
[] = {
1132 if (max_draw_buffers
< kTotalDrawBufferEnums
) {
1133 validators_
.g_l_state
.RemoveValues(
1134 kDrawBuffers
+ max_draw_buffers
,
1135 kTotalDrawBufferEnums
- max_draw_buffers
);
1138 unsafe_es3_apis_enabled_
= true;
1141 void FeatureInfo::AddExtensionString(const char* s
) {
1143 size_t pos
= extensions_
.find(str
);
1144 while (pos
!= std::string::npos
&&
1145 pos
+ str
.length() < extensions_
.length() &&
1146 extensions_
.substr(pos
+ str
.length(), 1) != " ") {
1147 // This extension name is a substring of another.
1148 pos
= extensions_
.find(str
, pos
+ str
.length());
1150 if (pos
== std::string::npos
) {
1151 extensions_
+= (extensions_
.empty() ? "" : " ") + str
;
1155 FeatureInfo::~FeatureInfo() {
1158 } // namespace gles2