OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/feature_info.h" | 5 #include "gpu/command_buffer/service/feature_info.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 validators_.texture_internal_format.AddValue(GL_SRGB_ALPHA_EXT); | 554 validators_.texture_internal_format.AddValue(GL_SRGB_ALPHA_EXT); |
555 validators_.texture_format.AddValue(GL_SRGB_EXT); | 555 validators_.texture_format.AddValue(GL_SRGB_EXT); |
556 validators_.texture_format.AddValue(GL_SRGB_ALPHA_EXT); | 556 validators_.texture_format.AddValue(GL_SRGB_ALPHA_EXT); |
557 validators_.render_buffer_format.AddValue(GL_SRGB8_ALPHA8_EXT); | 557 validators_.render_buffer_format.AddValue(GL_SRGB8_ALPHA8_EXT); |
558 validators_.frame_buffer_parameter.AddValue( | 558 validators_.frame_buffer_parameter.AddValue( |
559 GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT); | 559 GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT); |
560 validators_.texture_unsized_internal_format.AddValue(GL_SRGB_EXT); | 560 validators_.texture_unsized_internal_format.AddValue(GL_SRGB_EXT); |
561 validators_.texture_unsized_internal_format.AddValue(GL_SRGB_ALPHA_EXT); | 561 validators_.texture_unsized_internal_format.AddValue(GL_SRGB_ALPHA_EXT); |
562 } | 562 } |
563 | 563 |
564 bool enable_texture_format_bgra8888 = false; | 564 // Note: Only APPLE_texture_format_BGRA8888 extension allows BGRA8_EXT in |
565 bool enable_read_format_bgra = false; | 565 // ES3's glTexStorage2D, whereas EXT_texture_format_BGRA8888 doesn't provide |
566 bool enable_render_buffer_bgra = false; | 566 // that compatibility. So if EXT_texture_format_BGRA8888 (but not |
567 bool enable_immutable_texture_format_bgra_on_es3 = | 567 // APPLE_texture_format_BGRA8888) is present on an underlying ES3 context, we |
568 extensions.Contains("GL_APPLE_texture_format_BGRA8888"); | 568 // have to choose which one of BGRA vs texture storage we expose. |
| 569 // When creating ES2 contexts, we prefer support BGRA to texture storage, so |
| 570 // we disable texture storage if only EXT_texture_format_BGRA8888 is present. |
| 571 // If neither is present, we expose texture storage. |
| 572 // When creating ES3 contexts, we do need to expose texture storage, so we |
| 573 // disable BGRA if we have to. |
| 574 bool has_apple_bgra = extensions.Contains("GL_APPLE_texture_format_BGRA8888"); |
| 575 bool has_ext_bgra = extensions.Contains("GL_EXT_texture_format_BGRA8888"); |
| 576 bool has_bgra = has_ext_bgra || has_apple_bgra || !gl_version_info_->is_es; |
569 | 577 |
570 // Check if we should allow GL_EXT_texture_format_BGRA8888. | 578 bool has_ext_texture_storage = extensions.Contains("GL_EXT_texture_storage"); |
571 if (extensions.Contains("GL_EXT_texture_format_BGRA8888") || | 579 bool has_arb_texture_storage = extensions.Contains("GL_ARB_texture_storage"); |
572 enable_immutable_texture_format_bgra_on_es3 || | 580 bool has_texture_storage = |
573 !gl_version_info_->is_es) { | 581 !workarounds_.disable_texture_storage && |
574 enable_texture_format_bgra8888 = true; | 582 (has_ext_texture_storage || has_arb_texture_storage || |
575 } | 583 gl_version_info_->is_es3 || gl_version_info_->IsAtLeastGL(4, 2)); |
576 | 584 |
577 // On desktop, all devices support BGRA render buffers (note that on desktop | 585 bool enable_texture_format_bgra8888 = has_bgra; |
578 // BGRA internal formats are converted to RGBA in the API implementation). | 586 bool enable_texture_storage = has_texture_storage; |
579 // For ES, there is no extension that exposes BGRA renderbuffers, however | |
580 // Angle does support these. | |
581 if (gl_version_info_->is_angle || !gl_version_info_->is_es) { | |
582 enable_render_buffer_bgra = true; | |
583 } | |
584 | 587 |
585 // On desktop, all devices support BGRA readback since OpenGL 2.0, which we | 588 bool texture_storage_incompatible_with_bgra = |
586 // require. On ES, support is indicated by the GL_EXT_read_format_bgra | 589 gl_version_info_->is_es3 && !has_ext_texture_storage && !has_apple_bgra; |
587 // extension. | 590 if (texture_storage_incompatible_with_bgra && |
588 if (extensions.Contains("GL_EXT_read_format_bgra") || | 591 enable_texture_format_bgra8888 && enable_texture_storage) { |
589 !gl_version_info_->is_es) { | 592 switch (context_type_) { |
590 enable_read_format_bgra = true; | 593 case CONTEXT_TYPE_OPENGLES2: |
| 594 case CONTEXT_TYPE_WEBGL1: |
| 595 enable_texture_storage = false; |
| 596 break; |
| 597 case CONTEXT_TYPE_OPENGLES3: |
| 598 case CONTEXT_TYPE_WEBGL2: |
| 599 enable_texture_format_bgra8888 = false; |
| 600 break; |
| 601 } |
591 } | 602 } |
592 | 603 |
593 if (enable_texture_format_bgra8888) { | 604 if (enable_texture_format_bgra8888) { |
594 feature_flags_.ext_texture_format_bgra8888 = true; | 605 feature_flags_.ext_texture_format_bgra8888 = true; |
595 AddExtensionString("GL_EXT_texture_format_BGRA8888"); | 606 AddExtensionString("GL_EXT_texture_format_BGRA8888"); |
596 validators_.texture_internal_format.AddValue(GL_BGRA_EXT); | 607 validators_.texture_internal_format.AddValue(GL_BGRA_EXT); |
597 validators_.texture_format.AddValue(GL_BGRA_EXT); | 608 validators_.texture_format.AddValue(GL_BGRA_EXT); |
598 validators_.texture_unsized_internal_format.AddValue(GL_BGRA_EXT); | 609 validators_.texture_unsized_internal_format.AddValue(GL_BGRA_EXT); |
599 } | 610 } |
600 | 611 |
| 612 // On desktop, all devices support BGRA render buffers (note that on desktop |
| 613 // BGRA internal formats are converted to RGBA in the API implementation). |
| 614 // For ES, there is no extension that exposes BGRA renderbuffers, however |
| 615 // Angle does support these. |
| 616 bool enable_render_buffer_bgra = |
| 617 gl_version_info_->is_angle || !gl_version_info_->is_es; |
| 618 |
| 619 if (enable_render_buffer_bgra) { |
| 620 feature_flags_.ext_render_buffer_format_bgra8888 = true; |
| 621 AddExtensionString("GL_CHROMIUM_renderbuffer_format_BGRA8888"); |
| 622 validators_.render_buffer_format.AddValue(GL_BGRA8_EXT); |
| 623 } |
| 624 |
| 625 // On desktop, all devices support BGRA readback since OpenGL 2.0, which we |
| 626 // require. On ES, support is indicated by the GL_EXT_read_format_bgra |
| 627 // extension. |
| 628 bool enable_read_format_bgra = |
| 629 extensions.Contains("GL_EXT_read_format_bgra") || |
| 630 !gl_version_info_->is_es; |
| 631 |
601 if (enable_read_format_bgra) { | 632 if (enable_read_format_bgra) { |
602 feature_flags_.ext_read_format_bgra = true; | 633 feature_flags_.ext_read_format_bgra = true; |
603 AddExtensionString("GL_EXT_read_format_bgra"); | 634 AddExtensionString("GL_EXT_read_format_bgra"); |
604 validators_.read_pixel_format.AddValue(GL_BGRA_EXT); | 635 validators_.read_pixel_format.AddValue(GL_BGRA_EXT); |
605 } | 636 } |
606 | 637 |
607 // glGetInteger64v for timestamps is implemented on the client side in a way | 638 // glGetInteger64v for timestamps is implemented on the client side in a way |
608 // that it does not depend on a driver-level implementation of | 639 // that it does not depend on a driver-level implementation of |
609 // glGetInteger64v. The GPUTimer class which implements timer queries can also | 640 // glGetInteger64v. The GPUTimer class which implements timer queries can also |
610 // fallback to an implementation that does not depend on glGetInteger64v on | 641 // fallback to an implementation that does not depend on glGetInteger64v on |
611 // ES2. Thus we can enable GL_EXT_disjoint_timer_query on ES2 contexts even | 642 // ES2. Thus we can enable GL_EXT_disjoint_timer_query on ES2 contexts even |
612 // though it does not support glGetInteger64v due to a specification bug. | 643 // though it does not support glGetInteger64v due to a specification bug. |
613 if (extensions.Contains("GL_EXT_disjoint_timer_query") || | 644 if (extensions.Contains("GL_EXT_disjoint_timer_query") || |
614 extensions.Contains("GL_ARB_timer_query") || | 645 extensions.Contains("GL_ARB_timer_query") || |
615 extensions.Contains("GL_EXT_timer_query")) { | 646 extensions.Contains("GL_EXT_timer_query")) { |
616 AddExtensionString("GL_EXT_disjoint_timer_query"); | 647 AddExtensionString("GL_EXT_disjoint_timer_query"); |
617 } | 648 } |
618 | 649 |
619 if (enable_render_buffer_bgra) { | |
620 feature_flags_.ext_render_buffer_format_bgra8888 = true; | |
621 AddExtensionString("GL_CHROMIUM_renderbuffer_format_BGRA8888"); | |
622 validators_.render_buffer_format.AddValue(GL_BGRA8_EXT); | |
623 } | |
624 | |
625 if (extensions.Contains("GL_OES_rgb8_rgba8") || gfx::HasDesktopGLFeatures()) { | 650 if (extensions.Contains("GL_OES_rgb8_rgba8") || gfx::HasDesktopGLFeatures()) { |
626 AddExtensionString("GL_OES_rgb8_rgba8"); | 651 AddExtensionString("GL_OES_rgb8_rgba8"); |
627 validators_.render_buffer_format.AddValue(GL_RGB8_OES); | 652 validators_.render_buffer_format.AddValue(GL_RGB8_OES); |
628 validators_.render_buffer_format.AddValue(GL_RGBA8_OES); | 653 validators_.render_buffer_format.AddValue(GL_RGBA8_OES); |
629 } | 654 } |
630 | 655 |
631 // Check if we should allow GL_OES_texture_npot | 656 // Check if we should allow GL_OES_texture_npot |
632 if (!disallowed_features_.npot_support && | 657 if (!disallowed_features_.npot_support && |
633 (gl_version_info_->is_es3 || | 658 (gl_version_info_->is_es3 || |
634 gl_version_info_->is_desktop_core_profile || | 659 gl_version_info_->is_desktop_core_profile || |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 | 993 |
969 // TODO(gman): Add support for these extensions. | 994 // TODO(gman): Add support for these extensions. |
970 // GL_OES_depth32 | 995 // GL_OES_depth32 |
971 | 996 |
972 if (extensions.Contains("GL_ANGLE_texture_usage")) { | 997 if (extensions.Contains("GL_ANGLE_texture_usage")) { |
973 feature_flags_.angle_texture_usage = true; | 998 feature_flags_.angle_texture_usage = true; |
974 AddExtensionString("GL_ANGLE_texture_usage"); | 999 AddExtensionString("GL_ANGLE_texture_usage"); |
975 validators_.texture_parameter.AddValue(GL_TEXTURE_USAGE_ANGLE); | 1000 validators_.texture_parameter.AddValue(GL_TEXTURE_USAGE_ANGLE); |
976 } | 1001 } |
977 | 1002 |
978 // Note: Only APPLE_texture_format_BGRA8888 extension allows BGRA8_EXT in | 1003 if (enable_texture_storage) { |
979 // ES3's glTexStorage2D. We prefer support BGRA to texture storage. | |
980 // So we don't expose GL_EXT_texture_storage when ES3 + | |
981 // GL_EXT_texture_format_BGRA8888 because we fail the GL_BGRA8 requirement. | |
982 // However we expose GL_EXT_texture_storage when just ES3 because we don't | |
983 // claim to handle GL_BGRA8. | |
984 bool support_texture_storage_on_es3 = | |
985 (gl_version_info_->is_es3 && | |
986 enable_immutable_texture_format_bgra_on_es3) || | |
987 (gl_version_info_->is_es3 && | |
988 !enable_texture_format_bgra8888); | |
989 if (!workarounds_.disable_texture_storage && | |
990 (extensions.Contains("GL_EXT_texture_storage") || | |
991 extensions.Contains("GL_ARB_texture_storage") || | |
992 support_texture_storage_on_es3 || | |
993 gl_version_info_->IsAtLeastGL(4, 2))) { | |
994 feature_flags_.ext_texture_storage = true; | 1004 feature_flags_.ext_texture_storage = true; |
995 AddExtensionString("GL_EXT_texture_storage"); | 1005 AddExtensionString("GL_EXT_texture_storage"); |
996 validators_.texture_parameter.AddValue(GL_TEXTURE_IMMUTABLE_FORMAT_EXT); | 1006 validators_.texture_parameter.AddValue(GL_TEXTURE_IMMUTABLE_FORMAT_EXT); |
997 if (enable_texture_format_bgra8888) | 1007 if (enable_texture_format_bgra8888) |
998 validators_.texture_internal_format_storage.AddValue(GL_BGRA8_EXT); | 1008 validators_.texture_internal_format_storage.AddValue(GL_BGRA8_EXT); |
999 if (enable_texture_float) { | 1009 if (enable_texture_float) { |
1000 validators_.texture_internal_format_storage.AddValue(GL_RGBA32F_EXT); | 1010 validators_.texture_internal_format_storage.AddValue(GL_RGBA32F_EXT); |
1001 validators_.texture_internal_format_storage.AddValue(GL_RGB32F_EXT); | 1011 validators_.texture_internal_format_storage.AddValue(GL_RGB32F_EXT); |
1002 validators_.texture_internal_format_storage.AddValue(GL_ALPHA32F_EXT); | 1012 validators_.texture_internal_format_storage.AddValue(GL_ALPHA32F_EXT); |
1003 validators_.texture_internal_format_storage.AddValue( | 1013 validators_.texture_internal_format_storage.AddValue( |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 // crbug.com/481184. | 1290 // crbug.com/481184. |
1281 // GL_PRIMITIVE_RESTART_FIXED_INDEX is only available on Desktop GL 4.3+, | 1291 // GL_PRIMITIVE_RESTART_FIXED_INDEX is only available on Desktop GL 4.3+, |
1282 // but we emulate ES 3.0 on top of Desktop GL 4.2+. | 1292 // but we emulate ES 3.0 on top of Desktop GL 4.2+. |
1283 feature_flags_.emulate_primitive_restart_fixed_index = true; | 1293 feature_flags_.emulate_primitive_restart_fixed_index = true; |
1284 } | 1294 } |
1285 } | 1295 } |
1286 | 1296 |
1287 bool FeatureInfo::IsES3Capable() const { | 1297 bool FeatureInfo::IsES3Capable() const { |
1288 if (!enable_unsafe_es3_apis_switch_) | 1298 if (!enable_unsafe_es3_apis_switch_) |
1289 return false; | 1299 return false; |
| 1300 if (workarounds_.disable_texture_storage) |
| 1301 return false; |
1290 if (gl_version_info_) | 1302 if (gl_version_info_) |
1291 return gl_version_info_->IsES3Capable(); | 1303 return gl_version_info_->IsES3Capable(); |
1292 return false; | 1304 return false; |
1293 } | 1305 } |
1294 | 1306 |
1295 void FeatureInfo::EnableES3Validators() { | 1307 void FeatureInfo::EnableES3Validators() { |
1296 DCHECK(IsES3Capable()); | 1308 DCHECK(IsES3Capable()); |
1297 validators_.UpdateValuesES3(); | 1309 validators_.UpdateValuesES3(); |
1298 | 1310 |
1299 GLint max_color_attachments = 0; | 1311 GLint max_color_attachments = 0; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 if (pos == std::string::npos) { | 1395 if (pos == std::string::npos) { |
1384 extensions_ += (extensions_.empty() ? "" : " ") + str; | 1396 extensions_ += (extensions_.empty() ? "" : " ") + str; |
1385 } | 1397 } |
1386 } | 1398 } |
1387 | 1399 |
1388 FeatureInfo::~FeatureInfo() { | 1400 FeatureInfo::~FeatureInfo() { |
1389 } | 1401 } |
1390 | 1402 |
1391 } // namespace gles2 | 1403 } // namespace gles2 |
1392 } // namespace gpu | 1404 } // namespace gpu |
OLD | NEW |