Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / context_group.h
blob179f298dbb843001bac5d95868149963fc213f83
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 MailboxManager;
34 class RenderbufferManager;
35 class ProgramManager;
36 class ShaderManager;
37 class TextureManager;
38 class MemoryTracker;
39 struct DisallowedFeatures;
41 // A Context Group helps manage multiple GLES2Decoders that share
42 // resources.
43 class GPU_EXPORT ContextGroup : public base::RefCounted<ContextGroup> {
44 public:
45 ContextGroup(
46 MailboxManager* mailbox_manager,
47 MemoryTracker* memory_tracker,
48 ShaderTranslatorCache* shader_translator_cache,
49 FeatureInfo* feature_info,
50 bool bind_generates_resource);
52 // This should only be called by GLES2Decoder. This must be paired with a
53 // call to destroy if it succeeds.
54 bool Initialize(
55 GLES2Decoder* decoder,
56 const DisallowedFeatures& disallowed_features);
58 // Destroys all the resources when called for the last context in the group.
59 // It should only be called by GLES2Decoder.
60 void Destroy(GLES2Decoder* decoder, bool have_context);
62 MailboxManager* mailbox_manager() const {
63 return mailbox_manager_.get();
66 MemoryTracker* memory_tracker() const {
67 return memory_tracker_.get();
70 ShaderTranslatorCache* shader_translator_cache() const {
71 return shader_translator_cache_.get();
74 bool bind_generates_resource() {
75 return bind_generates_resource_;
78 uint32 max_vertex_attribs() const {
79 return max_vertex_attribs_;
82 uint32 max_texture_units() const {
83 return max_texture_units_;
86 uint32 max_texture_image_units() const {
87 return max_texture_image_units_;
90 uint32 max_vertex_texture_image_units() const {
91 return max_vertex_texture_image_units_;
94 uint32 max_fragment_uniform_vectors() const {
95 return max_fragment_uniform_vectors_;
98 uint32 max_varying_vectors() const {
99 return max_varying_vectors_;
102 uint32 max_vertex_uniform_vectors() const {
103 return max_vertex_uniform_vectors_;
106 uint32 max_color_attachments() const {
107 return max_color_attachments_;
110 uint32 max_draw_buffers() const {
111 return max_draw_buffers_;
114 FeatureInfo* feature_info() {
115 return feature_info_.get();
118 BufferManager* buffer_manager() const {
119 return buffer_manager_.get();
122 FramebufferManager* framebuffer_manager() const {
123 return framebuffer_manager_.get();
126 RenderbufferManager* renderbuffer_manager() const {
127 return renderbuffer_manager_.get();
130 TextureManager* texture_manager() const {
131 return texture_manager_.get();
134 ProgramManager* program_manager() const {
135 return program_manager_.get();
138 bool has_program_cache() const {
139 return program_cache_ != NULL;
142 void set_program_cache(ProgramCache* program_cache) {
143 program_cache_ = program_cache;
146 ShaderManager* shader_manager() const {
147 return shader_manager_.get();
150 TransferBufferManagerInterface* transfer_buffer_manager() const {
151 return transfer_buffer_manager_.get();
154 IdAllocatorInterface* GetIdAllocator(unsigned namespace_id);
156 uint32 GetMemRepresented() const;
158 // Loses all the context associated with this group.
159 void LoseContexts(GLenum reset_status);
161 // EXT_draw_buffer related states for backbuffer.
162 GLenum draw_buffer() const {
163 return draw_buffer_;
165 void set_draw_buffer(GLenum buf) {
166 draw_buffer_ = buf;
169 private:
170 friend class base::RefCounted<ContextGroup>;
171 ~ContextGroup();
173 bool CheckGLFeature(GLint min_required, GLint* v);
174 bool CheckGLFeatureU(GLint min_required, uint32* v);
175 bool QueryGLFeature(GLenum pname, GLint min_required, GLint* v);
176 bool QueryGLFeatureU(GLenum pname, GLint min_required, uint32* v);
177 bool HaveContexts();
179 scoped_refptr<MailboxManager> mailbox_manager_;
180 scoped_refptr<MemoryTracker> memory_tracker_;
181 scoped_refptr<ShaderTranslatorCache> shader_translator_cache_;
182 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_;
184 bool enforce_gl_minimums_;
185 bool bind_generates_resource_;
187 uint32 max_vertex_attribs_;
188 uint32 max_texture_units_;
189 uint32 max_texture_image_units_;
190 uint32 max_vertex_texture_image_units_;
191 uint32 max_fragment_uniform_vectors_;
192 uint32 max_varying_vectors_;
193 uint32 max_vertex_uniform_vectors_;
194 uint32 max_color_attachments_;
195 uint32 max_draw_buffers_;
197 ProgramCache* program_cache_;
199 scoped_ptr<BufferManager> buffer_manager_;
201 scoped_ptr<FramebufferManager> framebuffer_manager_;
203 scoped_ptr<RenderbufferManager> renderbuffer_manager_;
205 scoped_ptr<TextureManager> texture_manager_;
207 scoped_ptr<ProgramManager> program_manager_;
209 scoped_ptr<ShaderManager> shader_manager_;
211 linked_ptr<IdAllocatorInterface>
212 id_namespaces_[id_namespaces::kNumIdNamespaces];
214 scoped_refptr<FeatureInfo> feature_info_;
216 std::vector<base::WeakPtr<gles2::GLES2Decoder> > decoders_;
218 GLenum draw_buffer_;
220 DISALLOW_COPY_AND_ASSIGN(ContextGroup);
223 } // namespace gles2
224 } // namespace gpu
226 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_GROUP_H_