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_
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"
24 class IdAllocatorInterface
;
25 class TransferBufferManagerInterface
;
32 class FramebufferManager
;
35 class RenderbufferManager
;
40 struct DisallowedFeatures
;
42 // A Context Group helps manage multiple GLES2Decoders that share
44 class GPU_EXPORT ContextGroup
: public base::RefCounted
<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.
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 {
171 void set_draw_buffer(GLenum buf
) {
176 friend class base::RefCounted
<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
);
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_
;
227 DISALLOW_COPY_AND_ASSIGN(ContextGroup
);
233 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_GROUP_H_