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 #ifndef GPU_COMMAND_BUFFER_SERVICE_FEATURE_INFO_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_FEATURE_INFO_H_ 7 8 #include <set> 9 #include <string> 10 #include "base/containers/hash_tables.h" 11 #include "base/memory/ref_counted.h" 12 #include "base/sys_info.h" 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 14 #include "gpu/command_buffer/service/gles2_cmd_validation.h" 15 #include "gpu/config/gpu_driver_bug_workaround_type.h" 16 #include "gpu/gpu_export.h" 17 18 namespace base { 19 class CommandLine; 20 } 21 22 namespace gpu { 23 namespace gles2 { 24 25 // FeatureInfo records the features that are available for a ContextGroup. 26 class GPU_EXPORT FeatureInfo : public base::RefCounted<FeatureInfo> { 27 public: 28 struct FeatureFlags { 29 FeatureFlags(); 30 31 bool chromium_color_buffer_float_rgba; 32 bool chromium_color_buffer_float_rgb; 33 bool chromium_framebuffer_multisample; 34 bool chromium_sync_query; 35 // Use glBlitFramebuffer() and glRenderbufferStorageMultisample() with 36 // GL_EXT_framebuffer_multisample-style semantics, since they are exposed 37 // as core GL functions on this implementation. 38 bool use_core_framebuffer_multisample; 39 bool multisampled_render_to_texture; 40 // Use the IMG GLenum values and functions rather than EXT. 41 bool use_img_for_multisampled_render_to_texture; 42 bool oes_standard_derivatives; 43 bool oes_egl_image_external; 44 bool oes_depth24; 45 bool oes_compressed_etc1_rgb8_texture; 46 bool packed_depth24_stencil8; 47 bool npot_ok; 48 bool enable_texture_float_linear; 49 bool enable_texture_half_float_linear; 50 bool angle_translated_shader_source; 51 bool angle_pack_reverse_row_order; 52 bool arb_texture_rectangle; 53 bool angle_instanced_arrays; 54 bool occlusion_query_boolean; 55 bool use_arb_occlusion_query2_for_occlusion_query_boolean; 56 bool use_arb_occlusion_query_for_occlusion_query_boolean; 57 bool native_vertex_array_object; 58 bool ext_texture_format_bgra8888; 59 bool enable_shader_name_hashing; 60 bool enable_samplers; 61 bool ext_draw_buffers; 62 bool ext_frag_depth; 63 bool ext_shader_texture_lod; 64 bool use_async_readpixels; 65 bool map_buffer_range; 66 bool ext_discard_framebuffer; 67 bool angle_depth_texture; 68 bool is_angle; 69 bool is_swiftshader; 70 bool angle_texture_usage; 71 bool ext_texture_storage; 72 }; 73 74 struct Workarounds { 75 Workarounds(); 76 77 #define GPU_OP(type, name) bool name; 78 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP) 79 #undef GPU_OP 80 81 // Note: 0 here means use driver limit. 82 GLint max_texture_size; 83 GLint max_cube_map_texture_size; 84 GLint max_fragment_uniform_vectors; 85 GLint max_varying_vectors; 86 GLint max_vertex_uniform_vectors; 87 }; 88 89 // Constructor with workarounds taken from the current process's CommandLine 90 FeatureInfo(); 91 92 // Constructor with workarounds taken from |command_line| 93 FeatureInfo(const base::CommandLine& command_line); 94 95 // Initializes the feature information. Needs a current GL context. 96 bool Initialize(); 97 bool Initialize(const DisallowedFeatures& disallowed_features); 98 99 const Validators* validators() const { 100 return &validators_; 101 } 102 103 const ValueValidator<GLenum>& GetTextureFormatValidator(GLenum format) { 104 return texture_format_validators_[format]; 105 } 106 107 const std::string& extensions() const { 108 return extensions_; 109 } 110 111 const FeatureFlags& feature_flags() const { 112 return feature_flags_; 113 } 114 115 const Workarounds& workarounds() const { 116 return workarounds_; 117 } 118 119 private: 120 friend class base::RefCounted<FeatureInfo>; 121 friend class BufferManagerClientSideArraysTest; 122 123 typedef base::hash_map<GLenum, ValueValidator<GLenum> > ValidatorMap; 124 ValidatorMap texture_format_validators_; 125 126 ~FeatureInfo(); 127 128 void AddExtensionString(const std::string& str); 129 void InitializeBasicState(const base::CommandLine& command_line); 130 void InitializeFeatures(); 131 132 Validators validators_; 133 134 DisallowedFeatures disallowed_features_; 135 136 // The extensions string returned by glGetString(GL_EXTENSIONS); 137 std::string extensions_; 138 139 // Flags for some features 140 FeatureFlags feature_flags_; 141 142 // Flags for Workarounds. 143 Workarounds workarounds_; 144 145 DISALLOW_COPY_AND_ASSIGN(FeatureInfo); 146 }; 147 148 } // namespace gles2 149 } // namespace gpu 150 151 #endif // GPU_COMMAND_BUFFER_SERVICE_FEATURE_INFO_H_ 152