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