feature_info.h revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
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
18class CommandLine;
19
20namespace gpu {
21namespace gles2 {
22
23// FeatureInfo records the features that are available for a ContextGroup.
24class GPU_EXPORT FeatureInfo : public base::RefCounted<FeatureInfo> {
25 public:
26  struct FeatureFlags {
27    FeatureFlags();
28
29    bool chromium_framebuffer_multisample;
30    bool multisampled_render_to_texture;
31    // Use the IMG GLenum values and functions rather than EXT.
32    bool use_img_for_multisampled_render_to_texture;
33    bool oes_standard_derivatives;
34    bool oes_egl_image_external;
35    bool npot_ok;
36    bool enable_texture_float_linear;
37    bool enable_texture_half_float_linear;
38    bool chromium_stream_texture;
39    bool angle_translated_shader_source;
40    bool angle_pack_reverse_row_order;
41    bool arb_texture_rectangle;
42    bool angle_instanced_arrays;
43    bool occlusion_query_boolean;
44    bool use_arb_occlusion_query2_for_occlusion_query_boolean;
45    bool use_arb_occlusion_query_for_occlusion_query_boolean;
46    bool native_vertex_array_object;
47    bool enable_shader_name_hashing;
48    bool enable_samplers;
49    bool ext_draw_buffers;
50    bool ext_frag_depth;
51    bool use_async_readpixels;
52    bool map_buffer_range;
53  };
54
55  struct Workarounds {
56    Workarounds();
57
58#define GPU_OP(type, name) bool name;
59    GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
60#undef GPU_OP
61
62    // Note: 0 here means use driver limit.
63    GLint max_texture_size;
64    GLint max_cube_map_texture_size;
65  };
66
67  FeatureInfo();
68
69  // If allowed features = NULL or "*", all features are allowed. Otherwise
70  // only features that match the strings in allowed_features are allowed.
71  bool Initialize(const char* allowed_features);
72  bool Initialize(const DisallowedFeatures& disallowed_features,
73                  const char* allowed_features);
74
75  // Turns on certain features if they can be turned on.
76  void AddFeatures(const CommandLine& command_line);
77
78  const Validators* validators() const {
79    return &validators_;
80  }
81
82  const ValueValidator<GLenum>& GetTextureFormatValidator(GLenum format) {
83    return texture_format_validators_[format];
84  }
85
86  const std::string& extensions() const {
87    return extensions_;
88  }
89
90  const FeatureFlags& feature_flags() const {
91    return feature_flags_;
92  }
93
94  const Workarounds& workarounds() const {
95    return workarounds_;
96  }
97
98 private:
99  friend class base::RefCounted<FeatureInfo>;
100  friend class BufferManagerClientSideArraysTest;
101  friend class GLES2DecoderTestBase;
102
103  typedef base::hash_map<GLenum, ValueValidator<GLenum> > ValidatorMap;
104  ValidatorMap texture_format_validators_;
105
106  ~FeatureInfo();
107
108  void AddExtensionString(const std::string& str);
109
110  Validators validators_;
111
112  DisallowedFeatures disallowed_features_;
113
114  // The extensions string returned by glGetString(GL_EXTENSIONS);
115  std::string extensions_;
116
117  // Flags for some features
118  FeatureFlags feature_flags_;
119
120  // Flags for Workarounds.
121  Workarounds workarounds_;
122
123  DISALLOW_COPY_AND_ASSIGN(FeatureInfo);
124};
125
126}  // namespace gles2
127}  // namespace gpu
128
129#endif  // GPU_COMMAND_BUFFER_SERVICE_FEATURE_INFO_H_
130