- add sources.
[platform/framework/web/crosswalk.git] / src / gpu / command_buffer / service / feature_info.h
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 class CommandLine;
19
20 namespace gpu {
21 namespace gles2 {
22
23 // FeatureInfo records the features that are available for a ContextGroup.
24 class 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 oes_depth24;
36     bool npot_ok;
37     bool enable_texture_float_linear;
38     bool enable_texture_half_float_linear;
39     bool chromium_stream_texture;
40     bool angle_translated_shader_source;
41     bool angle_pack_reverse_row_order;
42     bool arb_texture_rectangle;
43     bool angle_instanced_arrays;
44     bool occlusion_query_boolean;
45     bool use_arb_occlusion_query2_for_occlusion_query_boolean;
46     bool use_arb_occlusion_query_for_occlusion_query_boolean;
47     bool native_vertex_array_object;
48     bool enable_shader_name_hashing;
49     bool enable_samplers;
50     bool ext_draw_buffers;
51     bool ext_frag_depth;
52     bool use_async_readpixels;
53     bool map_buffer_range;
54     bool ext_discard_framebuffer;
55   };
56
57   struct Workarounds {
58     Workarounds();
59
60 #define GPU_OP(type, name) bool name;
61     GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
62 #undef GPU_OP
63
64     // Note: 0 here means use driver limit.
65     GLint max_texture_size;
66     GLint max_cube_map_texture_size;
67   };
68
69   // Constructor with workarounds taken from the current process's CommandLine
70   FeatureInfo();
71
72   // Constructor with workarounds taken from |command_line|
73   FeatureInfo(const CommandLine& command_line);
74
75   // Initializes the feature information. Needs a current GL context.
76   bool Initialize();
77   bool Initialize(const DisallowedFeatures& disallowed_features);
78
79   const Validators* validators() const {
80     return &validators_;
81   }
82
83   const ValueValidator<GLenum>& GetTextureFormatValidator(GLenum format) {
84     return texture_format_validators_[format];
85   }
86
87   const std::string& extensions() const {
88     return extensions_;
89   }
90
91   const FeatureFlags& feature_flags() const {
92     return feature_flags_;
93   }
94
95   const Workarounds& workarounds() const {
96     return workarounds_;
97   }
98
99  private:
100   friend class base::RefCounted<FeatureInfo>;
101   friend class BufferManagerClientSideArraysTest;
102   friend class GLES2DecoderTestBase;
103
104   typedef base::hash_map<GLenum, ValueValidator<GLenum> > ValidatorMap;
105   ValidatorMap texture_format_validators_;
106
107   ~FeatureInfo();
108
109   void AddExtensionString(const std::string& str);
110   void InitializeBasicState(const CommandLine& command_line);
111   void InitializeFeatures();
112
113   Validators validators_;
114
115   DisallowedFeatures disallowed_features_;
116
117   // The extensions string returned by glGetString(GL_EXTENSIONS);
118   std::string extensions_;
119
120   // Flags for some features
121   FeatureFlags feature_flags_;
122
123   // Flags for Workarounds.
124   Workarounds workarounds_;
125
126   DISALLOW_COPY_AND_ASSIGN(FeatureInfo);
127 };
128
129 }  // namespace gles2
130 }  // namespace gpu
131
132 #endif  // GPU_COMMAND_BUFFER_SERVICE_FEATURE_INFO_H_