Home | History | Annotate | Download | only in service
      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.
      4 
      5 #include "gpu/command_buffer/service/feature_info.h"
      6 
      7 #include <set>
      8 
      9 #include "base/command_line.h"
     10 #include "base/macros.h"
     11 #include "base/metrics/histogram.h"
     12 #include "base/strings/string_number_conversions.h"
     13 #include "base/strings/string_split.h"
     14 #include "base/strings/string_util.h"
     15 #include "gpu/command_buffer/service/gl_utils.h"
     16 #include "gpu/command_buffer/service/gpu_switches.h"
     17 #include "ui/gl/gl_fence.h"
     18 #include "ui/gl/gl_implementation.h"
     19 
     20 namespace gpu {
     21 namespace gles2 {
     22 
     23 namespace {
     24 
     25 struct FormatInfo {
     26   GLenum format;
     27   const GLenum* types;
     28   size_t count;
     29 };
     30 
     31 class StringSet {
     32  public:
     33   StringSet() {}
     34 
     35   StringSet(const char* s) {
     36     Init(s);
     37   }
     38 
     39   StringSet(const std::string& str) {
     40     Init(str);
     41   }
     42 
     43   void Init(const char* s) {
     44     std::string str(s ? s : "");
     45     Init(str);
     46   }
     47 
     48   void Init(const std::string& str) {
     49     std::vector<std::string> tokens;
     50     Tokenize(str, " ", &tokens);
     51     string_set_.insert(tokens.begin(), tokens.end());
     52   }
     53 
     54   bool Contains(const char* s) {
     55     return string_set_.find(s) != string_set_.end();
     56   }
     57 
     58   bool Contains(const std::string& s) {
     59     return string_set_.find(s) != string_set_.end();
     60   }
     61 
     62  private:
     63   std::set<std::string> string_set_;
     64 };
     65 
     66 // Process a string of wordaround type IDs (seperated by ',') and set up
     67 // the corresponding Workaround flags.
     68 void StringToWorkarounds(
     69     const std::string& types, FeatureInfo::Workarounds* workarounds) {
     70   DCHECK(workarounds);
     71   std::vector<std::string> pieces;
     72   base::SplitString(types, ',', &pieces);
     73   for (size_t i = 0; i < pieces.size(); ++i) {
     74     int number = 0;
     75     bool succeed = base::StringToInt(pieces[i], &number);
     76     DCHECK(succeed);
     77     switch (number) {
     78 #define GPU_OP(type, name)    \
     79   case gpu::type:             \
     80     workarounds->name = true; \
     81     break;
     82       GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
     83 #undef GPU_OP
     84       default:
     85         NOTIMPLEMENTED();
     86     }
     87   }
     88   if (workarounds->max_texture_size_limit_4096)
     89     workarounds->max_texture_size = 4096;
     90   if (workarounds->max_cube_map_texture_size_limit_4096)
     91     workarounds->max_cube_map_texture_size = 4096;
     92   if (workarounds->max_cube_map_texture_size_limit_1024)
     93     workarounds->max_cube_map_texture_size = 1024;
     94   if (workarounds->max_cube_map_texture_size_limit_512)
     95     workarounds->max_cube_map_texture_size = 512;
     96 
     97   if (workarounds->max_fragment_uniform_vectors_32)
     98     workarounds->max_fragment_uniform_vectors = 32;
     99   if (workarounds->max_varying_vectors_16)
    100     workarounds->max_varying_vectors = 16;
    101   if (workarounds->max_vertex_uniform_vectors_256)
    102     workarounds->max_vertex_uniform_vectors = 256;
    103 }
    104 
    105 }  // anonymous namespace.
    106 
    107 FeatureInfo::FeatureFlags::FeatureFlags()
    108     : chromium_color_buffer_float_rgba(false),
    109       chromium_color_buffer_float_rgb(false),
    110       chromium_framebuffer_multisample(false),
    111       chromium_sync_query(false),
    112       use_core_framebuffer_multisample(false),
    113       multisampled_render_to_texture(false),
    114       use_img_for_multisampled_render_to_texture(false),
    115       oes_standard_derivatives(false),
    116       oes_egl_image_external(false),
    117       oes_depth24(false),
    118       oes_compressed_etc1_rgb8_texture(false),
    119       packed_depth24_stencil8(false),
    120       npot_ok(false),
    121       enable_texture_float_linear(false),
    122       enable_texture_half_float_linear(false),
    123       angle_translated_shader_source(false),
    124       angle_pack_reverse_row_order(false),
    125       arb_texture_rectangle(false),
    126       angle_instanced_arrays(false),
    127       occlusion_query_boolean(false),
    128       use_arb_occlusion_query2_for_occlusion_query_boolean(false),
    129       use_arb_occlusion_query_for_occlusion_query_boolean(false),
    130       native_vertex_array_object(false),
    131       ext_texture_format_bgra8888(false),
    132       enable_shader_name_hashing(false),
    133       enable_samplers(false),
    134       ext_draw_buffers(false),
    135       ext_frag_depth(false),
    136       ext_shader_texture_lod(false),
    137       use_async_readpixels(false),
    138       map_buffer_range(false),
    139       ext_discard_framebuffer(false),
    140       angle_depth_texture(false),
    141       is_angle(false),
    142       is_swiftshader(false),
    143       angle_texture_usage(false),
    144       ext_texture_storage(false) {
    145 }
    146 
    147 FeatureInfo::Workarounds::Workarounds() :
    148 #define GPU_OP(type, name) name(false),
    149     GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
    150 #undef GPU_OP
    151     max_texture_size(0),
    152     max_cube_map_texture_size(0),
    153     max_fragment_uniform_vectors(0),
    154     max_varying_vectors(0),
    155     max_vertex_uniform_vectors(0) {
    156 }
    157 
    158 FeatureInfo::FeatureInfo() {
    159   InitializeBasicState(*CommandLine::ForCurrentProcess());
    160 }
    161 
    162 FeatureInfo::FeatureInfo(const CommandLine& command_line) {
    163   InitializeBasicState(command_line);
    164 }
    165 
    166 void FeatureInfo::InitializeBasicState(const CommandLine& command_line) {
    167   if (command_line.HasSwitch(switches::kGpuDriverBugWorkarounds)) {
    168     std::string types = command_line.GetSwitchValueASCII(
    169         switches::kGpuDriverBugWorkarounds);
    170     StringToWorkarounds(types, &workarounds_);
    171   }
    172   feature_flags_.enable_shader_name_hashing =
    173       !command_line.HasSwitch(switches::kDisableShaderNameHashing);
    174 
    175   feature_flags_.is_swiftshader =
    176       (command_line.GetSwitchValueASCII(switches::kUseGL) == "swiftshader");
    177 
    178   static const GLenum kAlphaTypes[] = {
    179       GL_UNSIGNED_BYTE,
    180   };
    181   static const GLenum kRGBTypes[] = {
    182       GL_UNSIGNED_BYTE,
    183       GL_UNSIGNED_SHORT_5_6_5,
    184   };
    185   static const GLenum kRGBATypes[] = {
    186       GL_UNSIGNED_BYTE,
    187       GL_UNSIGNED_SHORT_4_4_4_4,
    188       GL_UNSIGNED_SHORT_5_5_5_1,
    189   };
    190   static const GLenum kLuminanceTypes[] = {
    191       GL_UNSIGNED_BYTE,
    192   };
    193   static const GLenum kLuminanceAlphaTypes[] = {
    194       GL_UNSIGNED_BYTE,
    195   };
    196   static const FormatInfo kFormatTypes[] = {
    197     { GL_ALPHA, kAlphaTypes, arraysize(kAlphaTypes), },
    198     { GL_RGB, kRGBTypes, arraysize(kRGBTypes), },
    199     { GL_RGBA, kRGBATypes, arraysize(kRGBATypes), },
    200     { GL_LUMINANCE, kLuminanceTypes, arraysize(kLuminanceTypes), },
    201     { GL_LUMINANCE_ALPHA, kLuminanceAlphaTypes,
    202       arraysize(kLuminanceAlphaTypes), } ,
    203   };
    204   for (size_t ii = 0; ii < arraysize(kFormatTypes); ++ii) {
    205     const FormatInfo& info = kFormatTypes[ii];
    206     ValueValidator<GLenum>& validator = texture_format_validators_[info.format];
    207     for (size_t jj = 0; jj < info.count; ++jj) {
    208       validator.AddValue(info.types[jj]);
    209     }
    210   }
    211 }
    212 
    213 bool FeatureInfo::Initialize() {
    214   disallowed_features_ = DisallowedFeatures();
    215   InitializeFeatures();
    216   return true;
    217 }
    218 
    219 bool FeatureInfo::Initialize(const DisallowedFeatures& disallowed_features) {
    220   disallowed_features_ = disallowed_features;
    221   InitializeFeatures();
    222   return true;
    223 }
    224 
    225 void FeatureInfo::InitializeFeatures() {
    226   // Figure out what extensions to turn on.
    227   StringSet extensions(
    228       reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
    229 
    230   bool npot_ok = false;
    231 
    232   const char* renderer_str =
    233       reinterpret_cast<const char*>(glGetString(GL_RENDERER));
    234   if (renderer_str) {
    235     feature_flags_.is_angle = StartsWithASCII(renderer_str, "ANGLE", true);
    236   }
    237 
    238   bool is_es3 = false;
    239   const char* version_str =
    240       reinterpret_cast<const char*>(glGetString(GL_VERSION));
    241   if (version_str) {
    242     std::string lstr(StringToLowerASCII(std::string(version_str)));
    243     is_es3 = (lstr.substr(0, 12) == "opengl es 3.");
    244   }
    245 
    246   AddExtensionString("GL_ANGLE_translated_shader_source");
    247   AddExtensionString("GL_CHROMIUM_async_pixel_transfers");
    248   AddExtensionString("GL_CHROMIUM_bind_uniform_location");
    249   AddExtensionString("GL_CHROMIUM_command_buffer_query");
    250   AddExtensionString("GL_CHROMIUM_command_buffer_latency_query");
    251   AddExtensionString("GL_CHROMIUM_copy_texture");
    252   AddExtensionString("GL_CHROMIUM_get_error_query");
    253   AddExtensionString("GL_CHROMIUM_lose_context");
    254   AddExtensionString("GL_CHROMIUM_pixel_transfer_buffer_object");
    255   AddExtensionString("GL_CHROMIUM_rate_limit_offscreen_context");
    256   AddExtensionString("GL_CHROMIUM_resize");
    257   AddExtensionString("GL_CHROMIUM_resource_safe");
    258   AddExtensionString("GL_CHROMIUM_strict_attribs");
    259   AddExtensionString("GL_CHROMIUM_texture_mailbox");
    260   AddExtensionString("GL_EXT_debug_marker");
    261 
    262   // OES_vertex_array_object is emulated if not present natively,
    263   // so the extension string is always exposed.
    264   AddExtensionString("GL_OES_vertex_array_object");
    265 
    266   if (!disallowed_features_.gpu_memory_manager)
    267     AddExtensionString("GL_CHROMIUM_gpu_memory_manager");
    268 
    269   if (extensions.Contains("GL_ANGLE_translated_shader_source")) {
    270     feature_flags_.angle_translated_shader_source = true;
    271   }
    272 
    273   // Check if we should allow GL_EXT_texture_compression_dxt1 and
    274   // GL_EXT_texture_compression_s3tc.
    275   bool enable_dxt1 = false;
    276   bool enable_dxt3 = false;
    277   bool enable_dxt5 = false;
    278   bool have_s3tc = extensions.Contains("GL_EXT_texture_compression_s3tc");
    279   bool have_dxt3 =
    280       have_s3tc || extensions.Contains("GL_ANGLE_texture_compression_dxt3");
    281   bool have_dxt5 =
    282       have_s3tc || extensions.Contains("GL_ANGLE_texture_compression_dxt5");
    283 
    284   if (extensions.Contains("GL_EXT_texture_compression_dxt1") || have_s3tc) {
    285     enable_dxt1 = true;
    286   }
    287   if (have_dxt3) {
    288     enable_dxt3 = true;
    289   }
    290   if (have_dxt5) {
    291     enable_dxt5 = true;
    292   }
    293 
    294   if (enable_dxt1) {
    295     AddExtensionString("GL_EXT_texture_compression_dxt1");
    296     validators_.compressed_texture_format.AddValue(
    297         GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
    298     validators_.compressed_texture_format.AddValue(
    299         GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
    300   }
    301 
    302   if (enable_dxt3) {
    303     // The difference between GL_EXT_texture_compression_s3tc and
    304     // GL_CHROMIUM_texture_compression_dxt3 is that the former
    305     // requires on the fly compression. The latter does not.
    306     AddExtensionString("GL_CHROMIUM_texture_compression_dxt3");
    307     validators_.compressed_texture_format.AddValue(
    308         GL_COMPRESSED_RGBA_S3TC_DXT3_EXT);
    309   }
    310 
    311   if (enable_dxt5) {
    312     // The difference between GL_EXT_texture_compression_s3tc and
    313     // GL_CHROMIUM_texture_compression_dxt5 is that the former
    314     // requires on the fly compression. The latter does not.
    315     AddExtensionString("GL_CHROMIUM_texture_compression_dxt5");
    316     validators_.compressed_texture_format.AddValue(
    317         GL_COMPRESSED_RGBA_S3TC_DXT5_EXT);
    318   }
    319 
    320   // Check if we should enable GL_EXT_texture_filter_anisotropic.
    321   if (extensions.Contains("GL_EXT_texture_filter_anisotropic")) {
    322     AddExtensionString("GL_EXT_texture_filter_anisotropic");
    323     validators_.texture_parameter.AddValue(
    324         GL_TEXTURE_MAX_ANISOTROPY_EXT);
    325     validators_.g_l_state.AddValue(
    326         GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
    327   }
    328 
    329   // Check if we should support GL_OES_packed_depth_stencil and/or
    330   // GL_GOOGLE_depth_texture / GL_CHROMIUM_depth_texture.
    331   //
    332   // NOTE: GL_OES_depth_texture requires support for depth cubemaps.
    333   // GL_ARB_depth_texture requires other features that
    334   // GL_OES_packed_depth_stencil does not provide.
    335   //
    336   // Therefore we made up GL_GOOGLE_depth_texture / GL_CHROMIUM_depth_texture.
    337   //
    338   // GL_GOOGLE_depth_texture is legacy. As we exposed it into NaCl we can't
    339   // get rid of it.
    340   //
    341   bool enable_depth_texture = false;
    342   if (!workarounds_.disable_depth_texture &&
    343       (extensions.Contains("GL_ARB_depth_texture") ||
    344        extensions.Contains("GL_OES_depth_texture") ||
    345        extensions.Contains("GL_ANGLE_depth_texture") || is_es3)) {
    346     enable_depth_texture = true;
    347     feature_flags_.angle_depth_texture =
    348         extensions.Contains("GL_ANGLE_depth_texture");
    349   }
    350 
    351   if (enable_depth_texture) {
    352     AddExtensionString("GL_CHROMIUM_depth_texture");
    353     AddExtensionString("GL_GOOGLE_depth_texture");
    354     texture_format_validators_[GL_DEPTH_COMPONENT].AddValue(GL_UNSIGNED_SHORT);
    355     texture_format_validators_[GL_DEPTH_COMPONENT].AddValue(GL_UNSIGNED_INT);
    356     validators_.texture_internal_format.AddValue(GL_DEPTH_COMPONENT);
    357     validators_.texture_format.AddValue(GL_DEPTH_COMPONENT);
    358     validators_.pixel_type.AddValue(GL_UNSIGNED_SHORT);
    359     validators_.pixel_type.AddValue(GL_UNSIGNED_INT);
    360   }
    361 
    362   if (extensions.Contains("GL_EXT_packed_depth_stencil") ||
    363       extensions.Contains("GL_OES_packed_depth_stencil") || is_es3) {
    364     AddExtensionString("GL_OES_packed_depth_stencil");
    365     feature_flags_.packed_depth24_stencil8 = true;
    366     if (enable_depth_texture) {
    367       texture_format_validators_[GL_DEPTH_STENCIL]
    368           .AddValue(GL_UNSIGNED_INT_24_8);
    369       validators_.texture_internal_format.AddValue(GL_DEPTH_STENCIL);
    370       validators_.texture_format.AddValue(GL_DEPTH_STENCIL);
    371       validators_.pixel_type.AddValue(GL_UNSIGNED_INT_24_8);
    372     }
    373     validators_.render_buffer_format.AddValue(GL_DEPTH24_STENCIL8);
    374   }
    375 
    376   if (extensions.Contains("GL_OES_vertex_array_object") ||
    377       extensions.Contains("GL_ARB_vertex_array_object") ||
    378       extensions.Contains("GL_APPLE_vertex_array_object")) {
    379     feature_flags_.native_vertex_array_object = true;
    380   }
    381 
    382   // If we're using client_side_arrays we have to emulate
    383   // vertex array objects since vertex array objects do not work
    384   // with client side arrays.
    385   if (workarounds_.use_client_side_arrays_for_stream_buffers) {
    386     feature_flags_.native_vertex_array_object = false;
    387   }
    388 
    389   if (extensions.Contains("GL_OES_element_index_uint") ||
    390       gfx::HasDesktopGLFeatures()) {
    391     AddExtensionString("GL_OES_element_index_uint");
    392     validators_.index_type.AddValue(GL_UNSIGNED_INT);
    393   }
    394 
    395   bool enable_texture_format_bgra8888 = false;
    396   bool enable_read_format_bgra = false;
    397   bool enable_render_buffer_bgra = false;
    398 
    399   // Check if we should allow GL_EXT_texture_format_BGRA8888
    400   if (extensions.Contains("GL_EXT_texture_format_BGRA8888") ||
    401       extensions.Contains("GL_APPLE_texture_format_BGRA8888") ||
    402       extensions.Contains("GL_EXT_bgra")) {
    403     enable_texture_format_bgra8888 = true;
    404   }
    405 
    406   if (extensions.Contains("GL_EXT_bgra")) {
    407     enable_render_buffer_bgra = true;
    408   }
    409 
    410   if (extensions.Contains("GL_EXT_read_format_bgra") ||
    411       extensions.Contains("GL_EXT_bgra")) {
    412     enable_read_format_bgra = true;
    413   }
    414 
    415   if (enable_texture_format_bgra8888) {
    416     feature_flags_.ext_texture_format_bgra8888 = true;
    417     AddExtensionString("GL_EXT_texture_format_BGRA8888");
    418     texture_format_validators_[GL_BGRA_EXT].AddValue(GL_UNSIGNED_BYTE);
    419     validators_.texture_internal_format.AddValue(GL_BGRA_EXT);
    420     validators_.texture_format.AddValue(GL_BGRA_EXT);
    421   }
    422 
    423   if (enable_read_format_bgra) {
    424     AddExtensionString("GL_EXT_read_format_bgra");
    425     validators_.read_pixel_format.AddValue(GL_BGRA_EXT);
    426   }
    427 
    428   if (enable_render_buffer_bgra) {
    429     AddExtensionString("GL_CHROMIUM_renderbuffer_format_BGRA8888");
    430     validators_.render_buffer_format.AddValue(GL_BGRA8_EXT);
    431   }
    432 
    433   if (extensions.Contains("GL_OES_rgb8_rgba8") || gfx::HasDesktopGLFeatures()) {
    434     AddExtensionString("GL_OES_rgb8_rgba8");
    435     validators_.render_buffer_format.AddValue(GL_RGB8_OES);
    436     validators_.render_buffer_format.AddValue(GL_RGBA8_OES);
    437   }
    438 
    439   // Check if we should allow GL_OES_texture_npot
    440   if (extensions.Contains("GL_ARB_texture_non_power_of_two") ||
    441       extensions.Contains("GL_OES_texture_npot")) {
    442     AddExtensionString("GL_OES_texture_npot");
    443     npot_ok = true;
    444   }
    445 
    446   // Check if we should allow GL_OES_texture_float, GL_OES_texture_half_float,
    447   // GL_OES_texture_float_linear, GL_OES_texture_half_float_linear
    448   bool enable_texture_float = false;
    449   bool enable_texture_float_linear = false;
    450   bool enable_texture_half_float = false;
    451   bool enable_texture_half_float_linear = false;
    452 
    453   bool may_enable_chromium_color_buffer_float = false;
    454 
    455   if (extensions.Contains("GL_ARB_texture_float")) {
    456     enable_texture_float = true;
    457     enable_texture_float_linear = true;
    458     enable_texture_half_float = true;
    459     enable_texture_half_float_linear = true;
    460     may_enable_chromium_color_buffer_float = true;
    461   } else {
    462     if (extensions.Contains("GL_OES_texture_float")) {
    463       enable_texture_float = true;
    464       if (extensions.Contains("GL_OES_texture_float_linear")) {
    465         enable_texture_float_linear = true;
    466       }
    467       if ((is_es3 && extensions.Contains("GL_EXT_color_buffer_float")) ||
    468           feature_flags_.is_angle) {
    469         may_enable_chromium_color_buffer_float = true;
    470       }
    471     }
    472     if (extensions.Contains("GL_OES_texture_half_float")) {
    473       enable_texture_half_float = true;
    474       if (extensions.Contains("GL_OES_texture_half_float_linear")) {
    475         enable_texture_half_float_linear = true;
    476       }
    477     }
    478   }
    479 
    480   if (enable_texture_float) {
    481     texture_format_validators_[GL_ALPHA].AddValue(GL_FLOAT);
    482     texture_format_validators_[GL_RGB].AddValue(GL_FLOAT);
    483     texture_format_validators_[GL_RGBA].AddValue(GL_FLOAT);
    484     texture_format_validators_[GL_LUMINANCE].AddValue(GL_FLOAT);
    485     texture_format_validators_[GL_LUMINANCE_ALPHA].AddValue(GL_FLOAT);
    486     validators_.pixel_type.AddValue(GL_FLOAT);
    487     validators_.read_pixel_type.AddValue(GL_FLOAT);
    488     AddExtensionString("GL_OES_texture_float");
    489     if (enable_texture_float_linear) {
    490       AddExtensionString("GL_OES_texture_float_linear");
    491     }
    492   }
    493 
    494   if (enable_texture_half_float) {
    495     texture_format_validators_[GL_ALPHA].AddValue(GL_HALF_FLOAT_OES);
    496     texture_format_validators_[GL_RGB].AddValue(GL_HALF_FLOAT_OES);
    497     texture_format_validators_[GL_RGBA].AddValue(GL_HALF_FLOAT_OES);
    498     texture_format_validators_[GL_LUMINANCE].AddValue(GL_HALF_FLOAT_OES);
    499     texture_format_validators_[GL_LUMINANCE_ALPHA].AddValue(GL_HALF_FLOAT_OES);
    500     validators_.pixel_type.AddValue(GL_HALF_FLOAT_OES);
    501     validators_.read_pixel_type.AddValue(GL_HALF_FLOAT_OES);
    502     AddExtensionString("GL_OES_texture_half_float");
    503     if (enable_texture_half_float_linear) {
    504       AddExtensionString("GL_OES_texture_half_float_linear");
    505     }
    506   }
    507 
    508   if (may_enable_chromium_color_buffer_float) {
    509     COMPILE_ASSERT(GL_RGBA32F_ARB == GL_RGBA32F &&
    510                    GL_RGBA32F_EXT == GL_RGBA32F &&
    511                    GL_RGB32F_ARB == GL_RGB32F &&
    512                    GL_RGB32F_EXT == GL_RGB32F,
    513                    sized_float_internal_format_variations_must_match);
    514     // We don't check extension support beyond ARB_texture_float on desktop GL,
    515     // and format support varies between GL configurations. For example, spec
    516     // prior to OpenGL 3.0 mandates framebuffer support only for one
    517     // implementation-chosen format, and ES3.0 EXT_color_buffer_float does not
    518     // support rendering to RGB32F. Check for framebuffer completeness with
    519     // formats that the extensions expose, and only enable an extension when a
    520     // framebuffer created with its texture format is reported as complete.
    521     GLint fb_binding = 0;
    522     GLint tex_binding = 0;
    523     glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb_binding);
    524     glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex_binding);
    525 
    526     GLuint tex_id = 0;
    527     GLuint fb_id = 0;
    528     GLsizei width = 16;
    529 
    530     glGenTextures(1, &tex_id);
    531     glGenFramebuffersEXT(1, &fb_id);
    532     glBindTexture(GL_TEXTURE_2D, tex_id);
    533     // Nearest filter needed for framebuffer completeness on some drivers.
    534     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    535     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, width, 0, GL_RGBA,
    536                  GL_FLOAT, NULL);
    537     glBindFramebufferEXT(GL_FRAMEBUFFER, fb_id);
    538     glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
    539                               GL_TEXTURE_2D, tex_id, 0);
    540     GLenum statusRGBA = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
    541     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, width, 0, GL_RGB,
    542                  GL_FLOAT, NULL);
    543     GLenum statusRGB = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
    544     glDeleteFramebuffersEXT(1, &fb_id);
    545     glDeleteTextures(1, &tex_id);
    546 
    547     glBindFramebufferEXT(GL_FRAMEBUFFER, static_cast<GLuint>(fb_binding));
    548     glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(tex_binding));
    549 
    550     DCHECK(glGetError() == GL_NO_ERROR);
    551 
    552     if (statusRGBA == GL_FRAMEBUFFER_COMPLETE) {
    553       validators_.texture_internal_format.AddValue(GL_RGBA32F);
    554       feature_flags_.chromium_color_buffer_float_rgba = true;
    555       AddExtensionString("GL_CHROMIUM_color_buffer_float_rgba");
    556     }
    557     if (statusRGB == GL_FRAMEBUFFER_COMPLETE) {
    558       validators_.texture_internal_format.AddValue(GL_RGB32F);
    559       feature_flags_.chromium_color_buffer_float_rgb = true;
    560       AddExtensionString("GL_CHROMIUM_color_buffer_float_rgb");
    561     }
    562   }
    563 
    564   // Check for multisample support
    565   if (!workarounds_.disable_multisampling) {
    566     bool ext_has_multisample =
    567         extensions.Contains("GL_EXT_framebuffer_multisample") || is_es3;
    568     if (feature_flags_.is_angle) {
    569       ext_has_multisample |=
    570           extensions.Contains("GL_ANGLE_framebuffer_multisample");
    571     }
    572     feature_flags_.use_core_framebuffer_multisample = is_es3;
    573     if (ext_has_multisample) {
    574       feature_flags_.chromium_framebuffer_multisample = true;
    575       validators_.frame_buffer_target.AddValue(GL_READ_FRAMEBUFFER_EXT);
    576       validators_.frame_buffer_target.AddValue(GL_DRAW_FRAMEBUFFER_EXT);
    577       validators_.g_l_state.AddValue(GL_READ_FRAMEBUFFER_BINDING_EXT);
    578       validators_.g_l_state.AddValue(GL_MAX_SAMPLES_EXT);
    579       validators_.render_buffer_parameter.AddValue(GL_RENDERBUFFER_SAMPLES_EXT);
    580       AddExtensionString("GL_CHROMIUM_framebuffer_multisample");
    581     }
    582     if (extensions.Contains("GL_EXT_multisampled_render_to_texture")) {
    583       feature_flags_.multisampled_render_to_texture = true;
    584     } else if (extensions.Contains("GL_IMG_multisampled_render_to_texture")) {
    585       feature_flags_.multisampled_render_to_texture = true;
    586       feature_flags_.use_img_for_multisampled_render_to_texture = true;
    587     }
    588     if (feature_flags_.multisampled_render_to_texture) {
    589       validators_.render_buffer_parameter.AddValue(
    590           GL_RENDERBUFFER_SAMPLES_EXT);
    591       validators_.g_l_state.AddValue(GL_MAX_SAMPLES_EXT);
    592       validators_.frame_buffer_parameter.AddValue(
    593           GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT);
    594       AddExtensionString("GL_EXT_multisampled_render_to_texture");
    595     }
    596   }
    597 
    598   if (extensions.Contains("GL_OES_depth24") || gfx::HasDesktopGLFeatures() ||
    599       is_es3) {
    600     AddExtensionString("GL_OES_depth24");
    601     feature_flags_.oes_depth24 = true;
    602     validators_.render_buffer_format.AddValue(GL_DEPTH_COMPONENT24);
    603   }
    604 
    605   if (!workarounds_.disable_oes_standard_derivatives &&
    606       (extensions.Contains("GL_OES_standard_derivatives") ||
    607        gfx::HasDesktopGLFeatures())) {
    608     AddExtensionString("GL_OES_standard_derivatives");
    609     feature_flags_.oes_standard_derivatives = true;
    610     validators_.hint_target.AddValue(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
    611     validators_.g_l_state.AddValue(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES);
    612   }
    613 
    614   if (extensions.Contains("GL_OES_EGL_image_external")) {
    615     AddExtensionString("GL_OES_EGL_image_external");
    616     feature_flags_.oes_egl_image_external = true;
    617     validators_.texture_bind_target.AddValue(GL_TEXTURE_EXTERNAL_OES);
    618     validators_.get_tex_param_target.AddValue(GL_TEXTURE_EXTERNAL_OES);
    619     validators_.texture_parameter.AddValue(GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES);
    620     validators_.g_l_state.AddValue(GL_TEXTURE_BINDING_EXTERNAL_OES);
    621   }
    622 
    623   if (extensions.Contains("GL_OES_compressed_ETC1_RGB8_texture")) {
    624     AddExtensionString("GL_OES_compressed_ETC1_RGB8_texture");
    625     feature_flags_.oes_compressed_etc1_rgb8_texture = true;
    626     validators_.compressed_texture_format.AddValue(GL_ETC1_RGB8_OES);
    627   }
    628 
    629   if (extensions.Contains("GL_AMD_compressed_ATC_texture")) {
    630     AddExtensionString("GL_AMD_compressed_ATC_texture");
    631     validators_.compressed_texture_format.AddValue(
    632         GL_ATC_RGB_AMD);
    633     validators_.compressed_texture_format.AddValue(
    634         GL_ATC_RGBA_EXPLICIT_ALPHA_AMD);
    635     validators_.compressed_texture_format.AddValue(
    636         GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD);
    637   }
    638 
    639   if (extensions.Contains("GL_IMG_texture_compression_pvrtc")) {
    640     AddExtensionString("GL_IMG_texture_compression_pvrtc");
    641     validators_.compressed_texture_format.AddValue(
    642         GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG);
    643     validators_.compressed_texture_format.AddValue(
    644         GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG);
    645     validators_.compressed_texture_format.AddValue(
    646         GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG);
    647     validators_.compressed_texture_format.AddValue(
    648         GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG);
    649   }
    650 
    651   // Ideally we would only expose this extension on Mac OS X, to
    652   // support GL_CHROMIUM_iosurface and the compositor. We don't want
    653   // applications to start using it; they should use ordinary non-
    654   // power-of-two textures. However, for unit testing purposes we
    655   // expose it on all supported platforms.
    656   if (extensions.Contains("GL_ARB_texture_rectangle")) {
    657     AddExtensionString("GL_ARB_texture_rectangle");
    658     feature_flags_.arb_texture_rectangle = true;
    659     validators_.texture_bind_target.AddValue(GL_TEXTURE_RECTANGLE_ARB);
    660     // For the moment we don't add this enum to the texture_target
    661     // validator. This implies that the only way to get image data into a
    662     // rectangular texture is via glTexImageIOSurface2DCHROMIUM, which is
    663     // just fine since again we don't want applications depending on this
    664     // extension.
    665     validators_.get_tex_param_target.AddValue(GL_TEXTURE_RECTANGLE_ARB);
    666     validators_.g_l_state.AddValue(GL_TEXTURE_BINDING_RECTANGLE_ARB);
    667   }
    668 
    669 #if defined(OS_MACOSX)
    670   AddExtensionString("GL_CHROMIUM_iosurface");
    671 #endif
    672 
    673   // TODO(gman): Add support for these extensions.
    674   //     GL_OES_depth32
    675 
    676   feature_flags_.enable_texture_float_linear |= enable_texture_float_linear;
    677   feature_flags_.enable_texture_half_float_linear |=
    678       enable_texture_half_float_linear;
    679   feature_flags_.npot_ok |= npot_ok;
    680 
    681   if (extensions.Contains("GL_ANGLE_pack_reverse_row_order")) {
    682     AddExtensionString("GL_ANGLE_pack_reverse_row_order");
    683     feature_flags_.angle_pack_reverse_row_order = true;
    684     validators_.pixel_store.AddValue(GL_PACK_REVERSE_ROW_ORDER_ANGLE);
    685     validators_.g_l_state.AddValue(GL_PACK_REVERSE_ROW_ORDER_ANGLE);
    686   }
    687 
    688   if (extensions.Contains("GL_ANGLE_texture_usage")) {
    689     feature_flags_.angle_texture_usage = true;
    690     AddExtensionString("GL_ANGLE_texture_usage");
    691     validators_.texture_parameter.AddValue(GL_TEXTURE_USAGE_ANGLE);
    692   }
    693 
    694   if (extensions.Contains("GL_EXT_texture_storage")) {
    695     feature_flags_.ext_texture_storage = true;
    696     AddExtensionString("GL_EXT_texture_storage");
    697     validators_.texture_parameter.AddValue(GL_TEXTURE_IMMUTABLE_FORMAT_EXT);
    698     if (enable_texture_format_bgra8888)
    699         validators_.texture_internal_format_storage.AddValue(GL_BGRA8_EXT);
    700     if (enable_texture_float) {
    701         validators_.texture_internal_format_storage.AddValue(GL_RGBA32F_EXT);
    702         validators_.texture_internal_format_storage.AddValue(GL_RGB32F_EXT);
    703         validators_.texture_internal_format_storage.AddValue(GL_ALPHA32F_EXT);
    704         validators_.texture_internal_format_storage.AddValue(
    705             GL_LUMINANCE32F_EXT);
    706         validators_.texture_internal_format_storage.AddValue(
    707             GL_LUMINANCE_ALPHA32F_EXT);
    708     }
    709     if (enable_texture_half_float) {
    710         validators_.texture_internal_format_storage.AddValue(GL_RGBA16F_EXT);
    711         validators_.texture_internal_format_storage.AddValue(GL_RGB16F_EXT);
    712         validators_.texture_internal_format_storage.AddValue(GL_ALPHA16F_EXT);
    713         validators_.texture_internal_format_storage.AddValue(
    714             GL_LUMINANCE16F_EXT);
    715         validators_.texture_internal_format_storage.AddValue(
    716             GL_LUMINANCE_ALPHA16F_EXT);
    717     }
    718   }
    719 
    720   bool have_ext_occlusion_query_boolean =
    721       extensions.Contains("GL_EXT_occlusion_query_boolean");
    722   bool have_arb_occlusion_query2 =
    723       extensions.Contains("GL_ARB_occlusion_query2");
    724   bool have_arb_occlusion_query =
    725       extensions.Contains("GL_ARB_occlusion_query");
    726 
    727   if (!workarounds_.disable_ext_occlusion_query &&
    728       (have_ext_occlusion_query_boolean ||
    729        have_arb_occlusion_query2 ||
    730        have_arb_occlusion_query)) {
    731     AddExtensionString("GL_EXT_occlusion_query_boolean");
    732     feature_flags_.occlusion_query_boolean = true;
    733     feature_flags_.use_arb_occlusion_query2_for_occlusion_query_boolean =
    734         !have_ext_occlusion_query_boolean && have_arb_occlusion_query2;
    735     feature_flags_.use_arb_occlusion_query_for_occlusion_query_boolean =
    736         !have_ext_occlusion_query_boolean && have_arb_occlusion_query &&
    737         !have_arb_occlusion_query2;
    738   }
    739 
    740   if (!workarounds_.disable_angle_instanced_arrays &&
    741       (extensions.Contains("GL_ANGLE_instanced_arrays") ||
    742        (extensions.Contains("GL_ARB_instanced_arrays") &&
    743         extensions.Contains("GL_ARB_draw_instanced")) ||
    744        is_es3)) {
    745     AddExtensionString("GL_ANGLE_instanced_arrays");
    746     feature_flags_.angle_instanced_arrays = true;
    747     validators_.vertex_attribute.AddValue(GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
    748   }
    749 
    750   if (!workarounds_.disable_ext_draw_buffers &&
    751       (extensions.Contains("GL_ARB_draw_buffers") ||
    752        extensions.Contains("GL_EXT_draw_buffers"))) {
    753     AddExtensionString("GL_EXT_draw_buffers");
    754     feature_flags_.ext_draw_buffers = true;
    755 
    756     GLint max_color_attachments = 0;
    757     glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &max_color_attachments);
    758     for (GLenum i = GL_COLOR_ATTACHMENT1_EXT;
    759          i < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + max_color_attachments);
    760          ++i) {
    761       validators_.attachment.AddValue(i);
    762     }
    763 
    764     validators_.g_l_state.AddValue(GL_MAX_COLOR_ATTACHMENTS_EXT);
    765     validators_.g_l_state.AddValue(GL_MAX_DRAW_BUFFERS_ARB);
    766     GLint max_draw_buffers = 0;
    767     glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &max_draw_buffers);
    768     for (GLenum i = GL_DRAW_BUFFER0_ARB;
    769          i < static_cast<GLenum>(GL_DRAW_BUFFER0_ARB + max_draw_buffers);
    770          ++i) {
    771       validators_.g_l_state.AddValue(i);
    772     }
    773   }
    774 
    775   if (extensions.Contains("GL_EXT_blend_minmax") ||
    776       gfx::HasDesktopGLFeatures()) {
    777     AddExtensionString("GL_EXT_blend_minmax");
    778     validators_.equation.AddValue(GL_MIN_EXT);
    779     validators_.equation.AddValue(GL_MAX_EXT);
    780   }
    781 
    782   if (extensions.Contains("GL_EXT_frag_depth") || gfx::HasDesktopGLFeatures()) {
    783     AddExtensionString("GL_EXT_frag_depth");
    784     feature_flags_.ext_frag_depth = true;
    785   }
    786 
    787   if (extensions.Contains("GL_EXT_shader_texture_lod") ||
    788       gfx::HasDesktopGLFeatures()) {
    789     AddExtensionString("GL_EXT_shader_texture_lod");
    790     feature_flags_.ext_shader_texture_lod = true;
    791   }
    792 
    793 #if !defined(OS_MACOSX)
    794   if (workarounds_.disable_egl_khr_fence_sync) {
    795     gfx::g_driver_egl.ext.b_EGL_KHR_fence_sync = false;
    796   }
    797   if (workarounds_.disable_egl_khr_wait_sync) {
    798     gfx::g_driver_egl.ext.b_EGL_KHR_wait_sync = false;
    799   }
    800 #endif
    801   if (workarounds_.disable_arb_sync)
    802     gfx::g_driver_gl.ext.b_GL_ARB_sync = false;
    803   bool ui_gl_fence_works = gfx::GLFence::IsSupported();
    804   UMA_HISTOGRAM_BOOLEAN("GPU.FenceSupport", ui_gl_fence_works);
    805 
    806   feature_flags_.map_buffer_range =
    807       is_es3 || extensions.Contains("GL_ARB_map_buffer_range");
    808 
    809   // Really it's part of core OpenGL 2.1 and up, but let's assume the
    810   // extension is still advertised.
    811   bool has_pixel_buffers =
    812       is_es3 || extensions.Contains("GL_ARB_pixel_buffer_object");
    813 
    814   // We will use either glMapBuffer() or glMapBufferRange() for async readbacks.
    815   if (has_pixel_buffers && ui_gl_fence_works &&
    816       !workarounds_.disable_async_readpixels) {
    817     feature_flags_.use_async_readpixels = true;
    818   }
    819 
    820   if (is_es3 || extensions.Contains("GL_ARB_sampler_objects")) {
    821     feature_flags_.enable_samplers = true;
    822     // TODO(dsinclair): Add AddExtensionString("GL_CHROMIUM_sampler_objects")
    823     // when available.
    824   }
    825 
    826   if ((is_es3 || extensions.Contains("GL_EXT_discard_framebuffer")) &&
    827       !workarounds_.disable_ext_discard_framebuffer) {
    828     // DiscardFramebufferEXT is automatically bound to InvalidateFramebuffer.
    829     AddExtensionString("GL_EXT_discard_framebuffer");
    830     feature_flags_.ext_discard_framebuffer = true;
    831   }
    832 
    833   if (ui_gl_fence_works) {
    834     AddExtensionString("GL_CHROMIUM_sync_query");
    835     feature_flags_.chromium_sync_query = true;
    836   }
    837 }
    838 
    839 void FeatureInfo::AddExtensionString(const std::string& str) {
    840   size_t pos = extensions_.find(str);
    841   while (pos != std::string::npos &&
    842          pos + str.length() < extensions_.length() &&
    843          extensions_.substr(pos + str.length(), 1) != " ") {
    844     // This extension name is a substring of another.
    845     pos = extensions_.find(str, pos + str.length());
    846   }
    847   if (pos == std::string::npos) {
    848     extensions_ += (extensions_.empty() ? "" : " ") + str;
    849   }
    850 }
    851 
    852 FeatureInfo::~FeatureInfo() {
    853 }
    854 
    855 }  // namespace gles2
    856 }  // namespace gpu
    857