Performance histograms for extension content verification
[chromium-blink-merge.git] / gpu / command_buffer / service / context_group.h
blob924527f87de9ebc52e8a6b6a4fdf0ccc8b3f90db
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.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_CONTEXT_GROUP_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_CONTEXT_GROUP_H_
8 #include <string>
9 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/containers/hash_tables.h"
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "gpu/command_buffer/common/gles2_cmd_format.h"
17 #include "gpu/command_buffer/service/feature_info.h"
18 #include "gpu/command_buffer/service/gles2_cmd_validation.h"
19 #include "gpu/command_buffer/service/shader_translator_cache.h"
20 #include "gpu/gpu_export.h"
22 namespace gpu {
24 class IdAllocatorInterface;
25 class TransferBufferManagerInterface;
27 namespace gles2 {
29 class ProgramCache;
30 class BufferManager;
31 class GLES2Decoder;
32 class FramebufferManager;
33 class ImageManager;
34 class MailboxManager;
35 class RenderbufferManager;
36 class ProgramManager;
37 class ShaderManager;
38 class TextureManager;
39 class MemoryTracker;
40 struct DisallowedFeatures;
42 // A Context Group helps manage multiple GLES2Decoders that share
43 // resources.
44 class GPU_EXPORT ContextGroup : public base::RefCounted<ContextGroup> {
45 public:
46 ContextGroup(
47 MailboxManager* mailbox_manager,
48 ImageManager* image_manager,
49 MemoryTracker* memory_tracker,
50 ShaderTranslatorCache* shader_translator_cache,
51 FeatureInfo* feature_info,
52 bool bind_generates_resource);
54 // This should only be called by GLES2Decoder. This must be paired with a
55 // call to destroy if it succeeds.
56 bool Initialize(
57 GLES2Decoder* decoder,
58 const DisallowedFeatures& disallowed_features);
60 // Destroys all the resources when called for the last context in the group.
61 // It should only be called by GLES2Decoder.
62 void Destroy(GLES2Decoder* decoder, bool have_context);
64 MailboxManager* mailbox_manager() const {
65 return mailbox_manager_.get();
68 ImageManager* image_manager() const {
69 return image_manager_.get();
72 MemoryTracker* memory_tracker() const {
73 return memory_tracker_.get();
76 ShaderTranslatorCache* shader_translator_cache() const {
77 return shader_translator_cache_.get();
80 bool bind_generates_resource() {
81 return bind_generates_resource_;
84 uint32 max_vertex_attribs() const {
85 return max_vertex_attribs_;
88 uint32 max_texture_units() const {
89 return max_texture_units_;
92 uint32 max_texture_image_units() const {
93 return max_texture_image_units_;
96 uint32 max_vertex_texture_image_units() const {
97 return max_vertex_texture_image_units_;
100 uint32 max_fragment_uniform_vectors() const {
101 return max_fragment_uniform_vectors_;
104 uint32 max_varying_vectors() const {
105 return max_varying_vectors_;
108 uint32 max_vertex_uniform_vectors() const {
109 return max_vertex_uniform_vectors_;
112 uint32 max_color_attachments() const {
113 return max_color_attachments_;
116 uint32 max_draw_buffers() const {
117 return max_draw_buffers_;
120 FeatureInfo* feature_info() {
121 return feature_info_.get();
124 BufferManager* buffer_manager() const {
125 return buffer_manager_.get();
128 FramebufferManager* framebuffer_manager() const {
129 return framebuffer_manager_.get();
132 RenderbufferManager* renderbuffer_manager() const {
133 return renderbuffer_manager_.get();
136 TextureManager* texture_manager() const {
137 return texture_manager_.get();
140 ProgramManager* program_manager() const {
141 return program_manager_.get();
144 bool has_program_cache() const {
145 return program_cache_ != NULL;
148 void set_program_cache(ProgramCache* program_cache) {
149 program_cache_ = program_cache;
152 ShaderManager* shader_manager() const {
153 return shader_manager_.get();
156 TransferBufferManagerInterface* transfer_buffer_manager() const {
157 return transfer_buffer_manager_.get();
160 IdAllocatorInterface* GetIdAllocator(unsigned namespace_id);
162 uint32 GetMemRepresented() const;
164 // Loses all the context associated with this group.
165 void LoseContexts(GLenum reset_status);
167 // EXT_draw_buffer related states for backbuffer.
168 GLenum draw_buffer() const {
169 return draw_buffer_;
171 void set_draw_buffer(GLenum buf) {
172 draw_buffer_ = buf;
175 private:
176 friend class base::RefCounted<ContextGroup>;
177 ~ContextGroup();
179 bool CheckGLFeature(GLint min_required, GLint* v);
180 bool CheckGLFeatureU(GLint min_required, uint32* v);
181 bool QueryGLFeature(GLenum pname, GLint min_required, GLint* v);
182 bool QueryGLFeatureU(GLenum pname, GLint min_required, uint32* v);
183 bool HaveContexts();
185 scoped_refptr<MailboxManager> mailbox_manager_;
186 scoped_refptr<ImageManager> image_manager_;
187 scoped_refptr<MemoryTracker> memory_tracker_;
188 scoped_refptr<ShaderTranslatorCache> shader_translator_cache_;
189 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_;
191 bool enforce_gl_minimums_;
192 bool bind_generates_resource_;
194 uint32 max_vertex_attribs_;
195 uint32 max_texture_units_;
196 uint32 max_texture_image_units_;
197 uint32 max_vertex_texture_image_units_;
198 uint32 max_fragment_uniform_vectors_;
199 uint32 max_varying_vectors_;
200 uint32 max_vertex_uniform_vectors_;
201 uint32 max_color_attachments_;
202 uint32 max_draw_buffers_;
204 ProgramCache* program_cache_;
206 scoped_ptr<BufferManager> buffer_manager_;
208 scoped_ptr<FramebufferManager> framebuffer_manager_;
210 scoped_ptr<RenderbufferManager> renderbuffer_manager_;
212 scoped_ptr<TextureManager> texture_manager_;
214 scoped_ptr<ProgramManager> program_manager_;
216 scoped_ptr<ShaderManager> shader_manager_;
218 linked_ptr<IdAllocatorInterface>
219 id_namespaces_[id_namespaces::kNumIdNamespaces];
221 scoped_refptr<FeatureInfo> feature_info_;
223 std::vector<base::WeakPtr<gles2::GLES2Decoder> > decoders_;
225 GLenum draw_buffer_;
227 DISALLOW_COPY_AND_ASSIGN(ContextGroup);
230 } // namespace gles2
231 } // namespace gpu
233 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_GROUP_H_