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 TransferBufferManagerInterface
;
32 class FramebufferManager
;
34 class RenderbufferManager
;
38 class SubscriptionRefSet
;
39 class ValuebufferManager
;
41 struct DisallowedFeatures
;
43 // A Context Group helps manage multiple GLES2Decoders that share
45 class GPU_EXPORT ContextGroup
: public base::RefCounted
<ContextGroup
> {
48 const scoped_refptr
<MailboxManager
>& mailbox_manager
,
49 const scoped_refptr
<MemoryTracker
>& memory_tracker
,
50 const scoped_refptr
<ShaderTranslatorCache
>& shader_translator_cache
,
51 const scoped_refptr
<FeatureInfo
>& feature_info
,
52 const scoped_refptr
<SubscriptionRefSet
>& subscription_ref_set
,
53 const scoped_refptr
<ValueStateMap
>& pending_valuebuffer_state
,
54 bool bind_generates_resource
);
56 // This should only be called by GLES2Decoder. This must be paired with a
57 // call to destroy if it succeeds.
59 GLES2Decoder
* decoder
,
60 const DisallowedFeatures
& disallowed_features
);
62 // Destroys all the resources when called for the last context in the group.
63 // It should only be called by GLES2Decoder.
64 void Destroy(GLES2Decoder
* decoder
, bool have_context
);
66 MailboxManager
* mailbox_manager() const {
67 return mailbox_manager_
.get();
70 MemoryTracker
* memory_tracker() const {
71 return memory_tracker_
.get();
74 ShaderTranslatorCache
* shader_translator_cache() const {
75 return shader_translator_cache_
.get();
78 bool bind_generates_resource() {
79 return bind_generates_resource_
;
82 uint32
max_vertex_attribs() const {
83 return max_vertex_attribs_
;
86 uint32
max_texture_units() const {
87 return max_texture_units_
;
90 uint32
max_texture_image_units() const {
91 return max_texture_image_units_
;
94 uint32
max_vertex_texture_image_units() const {
95 return max_vertex_texture_image_units_
;
98 uint32
max_fragment_uniform_vectors() const {
99 return max_fragment_uniform_vectors_
;
102 uint32
max_varying_vectors() const {
103 return max_varying_vectors_
;
106 uint32
max_vertex_uniform_vectors() const {
107 return max_vertex_uniform_vectors_
;
110 uint32
max_color_attachments() const {
111 return max_color_attachments_
;
114 uint32
max_draw_buffers() const {
115 return max_draw_buffers_
;
118 FeatureInfo
* feature_info() {
119 return feature_info_
.get();
122 BufferManager
* buffer_manager() const {
123 return buffer_manager_
.get();
126 FramebufferManager
* framebuffer_manager() const {
127 return framebuffer_manager_
.get();
130 RenderbufferManager
* renderbuffer_manager() const {
131 return renderbuffer_manager_
.get();
134 ValuebufferManager
* valuebuffer_manager() const {
135 return valuebuffer_manager_
.get();
138 ValueStateMap
* pending_valuebuffer_state() const {
139 return pending_valuebuffer_state_
.get();
142 TextureManager
* texture_manager() const {
143 return texture_manager_
.get();
146 ProgramManager
* program_manager() const {
147 return program_manager_
.get();
150 bool has_program_cache() const {
151 return program_cache_
!= NULL
;
154 void set_program_cache(ProgramCache
* program_cache
) {
155 program_cache_
= program_cache
;
158 ShaderManager
* shader_manager() const {
159 return shader_manager_
.get();
162 TransferBufferManagerInterface
* transfer_buffer_manager() const {
163 return transfer_buffer_manager_
.get();
166 uint32
GetMemRepresented() const;
168 // Loses all the context associated with this group.
169 void LoseContexts(GLenum reset_status
);
171 // EXT_draw_buffer related states for backbuffer.
172 GLenum
draw_buffer() const {
175 void set_draw_buffer(GLenum buf
) {
179 bool GetBufferServiceId(GLuint client_id
, GLuint
* service_id
) const;
181 void AddSamplerId(GLuint client_id
, GLuint service_id
) {
182 samplers_id_map_
[client_id
] = service_id
;
185 bool GetSamplerServiceId(GLuint client_id
, GLuint
* service_id
) const {
186 base::hash_map
<GLuint
, GLuint
>::const_iterator iter
=
187 samplers_id_map_
.find(client_id
);
188 if (iter
== samplers_id_map_
.end())
191 *service_id
= iter
->second
;
195 void RemoveSamplerId(GLuint client_id
) {
196 samplers_id_map_
.erase(client_id
);
199 void AddTransformFeedbackId(GLuint client_id
, GLuint service_id
) {
200 transformfeedbacks_id_map_
[client_id
] = service_id
;
203 bool GetTransformFeedbackServiceId(
204 GLuint client_id
, GLuint
* service_id
) const {
205 base::hash_map
<GLuint
, GLuint
>::const_iterator iter
=
206 transformfeedbacks_id_map_
.find(client_id
);
207 if (iter
== transformfeedbacks_id_map_
.end())
210 *service_id
= iter
->second
;
214 void RemoveTransformFeedbackId(GLuint client_id
) {
215 transformfeedbacks_id_map_
.erase(client_id
);
218 void AddSyncId(GLuint client_id
, GLsync service_id
) {
219 syncs_id_map_
[client_id
] = service_id
;
222 bool GetSyncServiceId(GLuint client_id
, GLsync
* service_id
) const {
223 base::hash_map
<GLuint
, GLsync
>::const_iterator iter
=
224 syncs_id_map_
.find(client_id
);
225 if (iter
== syncs_id_map_
.end())
228 *service_id
= iter
->second
;
232 void RemoveSyncId(GLuint client_id
) {
233 syncs_id_map_
.erase(client_id
);
237 friend class base::RefCounted
<ContextGroup
>;
240 bool CheckGLFeature(GLint min_required
, GLint
* v
);
241 bool CheckGLFeatureU(GLint min_required
, uint32
* v
);
242 bool QueryGLFeature(GLenum pname
, GLint min_required
, GLint
* v
);
243 bool QueryGLFeatureU(GLenum pname
, GLint min_required
, uint32
* v
);
246 scoped_refptr
<MailboxManager
> mailbox_manager_
;
247 scoped_refptr
<MemoryTracker
> memory_tracker_
;
248 scoped_refptr
<ShaderTranslatorCache
> shader_translator_cache_
;
249 scoped_ptr
<TransferBufferManagerInterface
> transfer_buffer_manager_
;
250 scoped_refptr
<SubscriptionRefSet
> subscription_ref_set_
;
251 scoped_refptr
<ValueStateMap
> pending_valuebuffer_state_
;
253 bool enforce_gl_minimums_
;
254 bool bind_generates_resource_
;
256 uint32 max_vertex_attribs_
;
257 uint32 max_texture_units_
;
258 uint32 max_texture_image_units_
;
259 uint32 max_vertex_texture_image_units_
;
260 uint32 max_fragment_uniform_vectors_
;
261 uint32 max_varying_vectors_
;
262 uint32 max_vertex_uniform_vectors_
;
263 uint32 max_color_attachments_
;
264 uint32 max_draw_buffers_
;
266 ProgramCache
* program_cache_
;
268 scoped_ptr
<BufferManager
> buffer_manager_
;
270 scoped_ptr
<FramebufferManager
> framebuffer_manager_
;
272 scoped_ptr
<RenderbufferManager
> renderbuffer_manager_
;
274 scoped_ptr
<TextureManager
> texture_manager_
;
276 scoped_ptr
<ProgramManager
> program_manager_
;
278 scoped_ptr
<ShaderManager
> shader_manager_
;
280 scoped_ptr
<ValuebufferManager
> valuebuffer_manager_
;
282 scoped_refptr
<FeatureInfo
> feature_info_
;
284 std::vector
<base::WeakPtr
<gles2::GLES2Decoder
> > decoders_
;
286 // Mappings from client side IDs to service side IDs.
287 base::hash_map
<GLuint
, GLuint
> samplers_id_map_
;
288 base::hash_map
<GLuint
, GLuint
> transformfeedbacks_id_map_
;
289 base::hash_map
<GLuint
, GLsync
> syncs_id_map_
;
293 DISALLOW_COPY_AND_ASSIGN(ContextGroup
);
299 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_GROUP_H_