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
;
39 class SubscriptionRefSet
;
40 class ValuebufferManager
;
42 struct DisallowedFeatures
;
44 // A Context Group helps manage multiple GLES2Decoders that share
46 class GPU_EXPORT ContextGroup
: public base::RefCounted
<ContextGroup
> {
52 CONTEXT_TYPE_UNDEFINED
55 static ContextType
GetContextType(unsigned webgl_version
);
58 const scoped_refptr
<MailboxManager
>& mailbox_manager
,
59 const scoped_refptr
<MemoryTracker
>& memory_tracker
,
60 const scoped_refptr
<ShaderTranslatorCache
>& shader_translator_cache
,
61 const scoped_refptr
<FeatureInfo
>& feature_info
,
62 const scoped_refptr
<SubscriptionRefSet
>& subscription_ref_set
,
63 const scoped_refptr
<ValueStateMap
>& pending_valuebuffer_state
,
64 bool bind_generates_resource
);
66 // This should only be called by GLES2Decoder. This must be paired with a
67 // call to destroy if it succeeds.
69 GLES2Decoder
* decoder
,
70 ContextType context_type
,
71 const DisallowedFeatures
& disallowed_features
);
73 // Destroys all the resources when called for the last context in the group.
74 // It should only be called by GLES2Decoder.
75 void Destroy(GLES2Decoder
* decoder
, bool have_context
);
77 MailboxManager
* mailbox_manager() const {
78 return mailbox_manager_
.get();
81 MemoryTracker
* memory_tracker() const {
82 return memory_tracker_
.get();
85 ShaderTranslatorCache
* shader_translator_cache() const {
86 return shader_translator_cache_
.get();
89 bool bind_generates_resource() {
90 return bind_generates_resource_
;
93 uint32
max_vertex_attribs() const {
94 return max_vertex_attribs_
;
97 uint32
max_texture_units() const {
98 return max_texture_units_
;
101 uint32
max_texture_image_units() const {
102 return max_texture_image_units_
;
105 uint32
max_vertex_texture_image_units() const {
106 return max_vertex_texture_image_units_
;
109 uint32
max_fragment_uniform_vectors() const {
110 return max_fragment_uniform_vectors_
;
113 uint32
max_varying_vectors() const {
114 return max_varying_vectors_
;
117 uint32
max_vertex_uniform_vectors() const {
118 return max_vertex_uniform_vectors_
;
121 uint32
max_color_attachments() const {
122 return max_color_attachments_
;
125 uint32
max_draw_buffers() const {
126 return max_draw_buffers_
;
129 FeatureInfo
* feature_info() {
130 return feature_info_
.get();
133 BufferManager
* buffer_manager() const {
134 return buffer_manager_
.get();
137 FramebufferManager
* framebuffer_manager() const {
138 return framebuffer_manager_
.get();
141 RenderbufferManager
* renderbuffer_manager() const {
142 return renderbuffer_manager_
.get();
145 ValuebufferManager
* valuebuffer_manager() const {
146 return valuebuffer_manager_
.get();
149 ValueStateMap
* pending_valuebuffer_state() const {
150 return pending_valuebuffer_state_
.get();
153 TextureManager
* texture_manager() const {
154 return texture_manager_
.get();
157 PathManager
* path_manager() const { return path_manager_
.get(); }
159 ProgramManager
* program_manager() const {
160 return program_manager_
.get();
163 bool has_program_cache() const {
164 return program_cache_
!= NULL
;
167 void set_program_cache(ProgramCache
* program_cache
) {
168 program_cache_
= program_cache
;
171 ShaderManager
* shader_manager() const {
172 return shader_manager_
.get();
175 TransferBufferManagerInterface
* transfer_buffer_manager() const {
176 return transfer_buffer_manager_
.get();
179 uint32
GetMemRepresented() const;
181 // Loses all the context associated with this group.
182 void LoseContexts(error::ContextLostReason reason
);
184 // EXT_draw_buffer related states for backbuffer.
185 GLenum
draw_buffer() const {
188 void set_draw_buffer(GLenum buf
) {
192 bool GetBufferServiceId(GLuint client_id
, GLuint
* service_id
) const;
194 void AddSamplerId(GLuint client_id
, GLuint service_id
) {
195 samplers_id_map_
[client_id
] = service_id
;
198 bool GetSamplerServiceId(GLuint client_id
, GLuint
* service_id
) const {
199 base::hash_map
<GLuint
, GLuint
>::const_iterator iter
=
200 samplers_id_map_
.find(client_id
);
201 if (iter
== samplers_id_map_
.end())
204 *service_id
= iter
->second
;
208 void RemoveSamplerId(GLuint client_id
) {
209 samplers_id_map_
.erase(client_id
);
212 void AddTransformFeedbackId(GLuint client_id
, GLuint service_id
) {
213 transformfeedbacks_id_map_
[client_id
] = service_id
;
216 bool GetTransformFeedbackServiceId(
217 GLuint client_id
, GLuint
* service_id
) const {
218 if (client_id
== 0) {
224 base::hash_map
<GLuint
, GLuint
>::const_iterator iter
=
225 transformfeedbacks_id_map_
.find(client_id
);
226 if (iter
== transformfeedbacks_id_map_
.end())
229 *service_id
= iter
->second
;
233 void RemoveTransformFeedbackId(GLuint client_id
) {
234 transformfeedbacks_id_map_
.erase(client_id
);
237 void AddSyncId(GLuint client_id
, GLsync service_id
) {
238 syncs_id_map_
[client_id
] = service_id
;
241 bool GetSyncServiceId(GLuint client_id
, GLsync
* service_id
) const {
242 base::hash_map
<GLuint
, GLsync
>::const_iterator iter
=
243 syncs_id_map_
.find(client_id
);
244 if (iter
== syncs_id_map_
.end())
247 *service_id
= iter
->second
;
251 void RemoveSyncId(GLuint client_id
) {
252 syncs_id_map_
.erase(client_id
);
256 friend class base::RefCounted
<ContextGroup
>;
259 bool CheckGLFeature(GLint min_required
, GLint
* v
);
260 bool CheckGLFeatureU(GLint min_required
, uint32
* v
);
261 bool QueryGLFeature(GLenum pname
, GLint min_required
, GLint
* v
);
262 bool QueryGLFeatureU(GLenum pname
, GLint min_required
, uint32
* v
);
265 ContextType context_type_
;
267 scoped_refptr
<MailboxManager
> mailbox_manager_
;
268 scoped_refptr
<MemoryTracker
> memory_tracker_
;
269 scoped_refptr
<ShaderTranslatorCache
> shader_translator_cache_
;
270 scoped_refptr
<TransferBufferManagerInterface
> transfer_buffer_manager_
;
271 scoped_refptr
<SubscriptionRefSet
> subscription_ref_set_
;
272 scoped_refptr
<ValueStateMap
> pending_valuebuffer_state_
;
274 bool enforce_gl_minimums_
;
275 bool bind_generates_resource_
;
277 uint32 max_vertex_attribs_
;
278 uint32 max_texture_units_
;
279 uint32 max_texture_image_units_
;
280 uint32 max_vertex_texture_image_units_
;
281 uint32 max_fragment_uniform_vectors_
;
282 uint32 max_varying_vectors_
;
283 uint32 max_vertex_uniform_vectors_
;
284 uint32 max_color_attachments_
;
285 uint32 max_draw_buffers_
;
287 ProgramCache
* program_cache_
;
289 scoped_ptr
<BufferManager
> buffer_manager_
;
291 scoped_ptr
<FramebufferManager
> framebuffer_manager_
;
293 scoped_ptr
<RenderbufferManager
> renderbuffer_manager_
;
295 scoped_ptr
<TextureManager
> texture_manager_
;
297 scoped_ptr
<PathManager
> path_manager_
;
299 scoped_ptr
<ProgramManager
> program_manager_
;
301 scoped_ptr
<ShaderManager
> shader_manager_
;
303 scoped_ptr
<ValuebufferManager
> valuebuffer_manager_
;
305 scoped_refptr
<FeatureInfo
> feature_info_
;
307 std::vector
<base::WeakPtr
<gles2::GLES2Decoder
> > decoders_
;
309 // Mappings from client side IDs to service side IDs.
310 base::hash_map
<GLuint
, GLuint
> samplers_id_map_
;
311 base::hash_map
<GLuint
, GLuint
> transformfeedbacks_id_map_
;
312 base::hash_map
<GLuint
, GLsync
> syncs_id_map_
;
316 DISALLOW_COPY_AND_ASSIGN(ContextGroup
);
322 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_GROUP_H_