Add ICU message format support
[chromium-blink-merge.git] / gpu / command_buffer / service / context_group.h
blob65a81e4185b680c2b7c4c4c471bd9f3d08167955
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 <vector>
9 #include "base/basictypes.h"
10 #include "base/containers/hash_tables.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "gpu/command_buffer/common/constants.h"
15 #include "gpu/command_buffer/common/gles2_cmd_format.h"
16 #include "gpu/command_buffer/service/feature_info.h"
17 #include "gpu/command_buffer/service/shader_translator_cache.h"
18 #include "gpu/gpu_export.h"
20 namespace gpu {
22 class TransferBufferManagerInterface;
23 class ValueStateMap;
25 namespace gles2 {
27 class ProgramCache;
28 class BufferManager;
29 class GLES2Decoder;
30 class FramebufferManager;
31 class MailboxManager;
32 class RenderbufferManager;
33 class PathManager;
34 class ProgramManager;
35 class ShaderManager;
36 class TextureManager;
37 class SubscriptionRefSet;
38 class ValuebufferManager;
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 enum ContextType {
47 CONTEXT_TYPE_WEBGL1,
48 CONTEXT_TYPE_WEBGL2,
49 CONTEXT_TYPE_OTHER,
50 CONTEXT_TYPE_UNDEFINED
53 static ContextType GetContextType(unsigned webgl_version);
55 ContextGroup(
56 const scoped_refptr<MailboxManager>& mailbox_manager,
57 const scoped_refptr<MemoryTracker>& memory_tracker,
58 const scoped_refptr<ShaderTranslatorCache>& shader_translator_cache,
59 const scoped_refptr<FeatureInfo>& feature_info,
60 const scoped_refptr<SubscriptionRefSet>& subscription_ref_set,
61 const scoped_refptr<ValueStateMap>& pending_valuebuffer_state,
62 bool bind_generates_resource);
64 // This should only be called by GLES2Decoder. This must be paired with a
65 // call to destroy if it succeeds.
66 bool Initialize(
67 GLES2Decoder* decoder,
68 ContextType context_type,
69 const DisallowedFeatures& disallowed_features);
71 // Destroys all the resources when called for the last context in the group.
72 // It should only be called by GLES2Decoder.
73 void Destroy(GLES2Decoder* decoder, bool have_context);
75 MailboxManager* mailbox_manager() const {
76 return mailbox_manager_.get();
79 MemoryTracker* memory_tracker() const {
80 return memory_tracker_.get();
83 ShaderTranslatorCache* shader_translator_cache() const {
84 return shader_translator_cache_.get();
87 bool bind_generates_resource() {
88 return bind_generates_resource_;
91 uint32 max_vertex_attribs() const {
92 return max_vertex_attribs_;
95 uint32 max_texture_units() const {
96 return max_texture_units_;
99 uint32 max_texture_image_units() const {
100 return max_texture_image_units_;
103 uint32 max_vertex_texture_image_units() const {
104 return max_vertex_texture_image_units_;
107 uint32 max_fragment_uniform_vectors() const {
108 return max_fragment_uniform_vectors_;
111 uint32 max_varying_vectors() const {
112 return max_varying_vectors_;
115 uint32 max_vertex_uniform_vectors() const {
116 return max_vertex_uniform_vectors_;
119 uint32 max_color_attachments() const {
120 return max_color_attachments_;
123 uint32 max_draw_buffers() const {
124 return max_draw_buffers_;
127 FeatureInfo* feature_info() {
128 return feature_info_.get();
131 BufferManager* buffer_manager() const {
132 return buffer_manager_.get();
135 FramebufferManager* framebuffer_manager() const {
136 return framebuffer_manager_.get();
139 RenderbufferManager* renderbuffer_manager() const {
140 return renderbuffer_manager_.get();
143 ValuebufferManager* valuebuffer_manager() const {
144 return valuebuffer_manager_.get();
147 ValueStateMap* pending_valuebuffer_state() const {
148 return pending_valuebuffer_state_.get();
151 TextureManager* texture_manager() const {
152 return texture_manager_.get();
155 PathManager* path_manager() const { return path_manager_.get(); }
157 ProgramManager* program_manager() const {
158 return program_manager_.get();
161 bool has_program_cache() const {
162 return program_cache_ != NULL;
165 void set_program_cache(ProgramCache* program_cache) {
166 program_cache_ = program_cache;
169 ShaderManager* shader_manager() const {
170 return shader_manager_.get();
173 TransferBufferManagerInterface* transfer_buffer_manager() const {
174 return transfer_buffer_manager_.get();
177 uint32 GetMemRepresented() const;
179 // Loses all the context associated with this group.
180 void LoseContexts(error::ContextLostReason reason);
182 // EXT_draw_buffer related states for backbuffer.
183 GLenum draw_buffer() const {
184 return draw_buffer_;
186 void set_draw_buffer(GLenum buf) {
187 draw_buffer_ = buf;
190 bool GetBufferServiceId(GLuint client_id, GLuint* service_id) const;
192 void AddSamplerId(GLuint client_id, GLuint service_id) {
193 samplers_id_map_[client_id] = service_id;
196 bool GetSamplerServiceId(GLuint client_id, GLuint* service_id) const {
197 base::hash_map<GLuint, GLuint>::const_iterator iter =
198 samplers_id_map_.find(client_id);
199 if (iter == samplers_id_map_.end())
200 return false;
201 if (service_id)
202 *service_id = iter->second;
203 return true;
206 void RemoveSamplerId(GLuint client_id) {
207 samplers_id_map_.erase(client_id);
210 void AddTransformFeedbackId(GLuint client_id, GLuint service_id) {
211 transformfeedbacks_id_map_[client_id] = service_id;
214 bool GetTransformFeedbackServiceId(
215 GLuint client_id, GLuint* service_id) const {
216 if (client_id == 0) {
217 // Default one.
218 if (service_id)
219 *service_id = 0;
220 return true;
222 base::hash_map<GLuint, GLuint>::const_iterator iter =
223 transformfeedbacks_id_map_.find(client_id);
224 if (iter == transformfeedbacks_id_map_.end())
225 return false;
226 if (service_id)
227 *service_id = iter->second;
228 return true;
231 void RemoveTransformFeedbackId(GLuint client_id) {
232 transformfeedbacks_id_map_.erase(client_id);
235 void AddSyncId(GLuint client_id, GLsync service_id) {
236 syncs_id_map_[client_id] = service_id;
239 bool GetSyncServiceId(GLuint client_id, GLsync* service_id) const {
240 base::hash_map<GLuint, GLsync>::const_iterator iter =
241 syncs_id_map_.find(client_id);
242 if (iter == syncs_id_map_.end())
243 return false;
244 if (service_id)
245 *service_id = iter->second;
246 return true;
249 void RemoveSyncId(GLuint client_id) {
250 syncs_id_map_.erase(client_id);
253 private:
254 friend class base::RefCounted<ContextGroup>;
255 ~ContextGroup();
257 bool CheckGLFeature(GLint min_required, GLint* v);
258 bool CheckGLFeatureU(GLint min_required, uint32* v);
259 bool QueryGLFeature(GLenum pname, GLint min_required, GLint* v);
260 bool QueryGLFeatureU(GLenum pname, GLint min_required, uint32* v);
261 bool HaveContexts();
263 ContextType context_type_;
265 scoped_refptr<MailboxManager> mailbox_manager_;
266 scoped_refptr<MemoryTracker> memory_tracker_;
267 scoped_refptr<ShaderTranslatorCache> shader_translator_cache_;
268 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_;
269 scoped_refptr<SubscriptionRefSet> subscription_ref_set_;
270 scoped_refptr<ValueStateMap> pending_valuebuffer_state_;
272 bool enforce_gl_minimums_;
273 bool bind_generates_resource_;
275 uint32 max_vertex_attribs_;
276 uint32 max_texture_units_;
277 uint32 max_texture_image_units_;
278 uint32 max_vertex_texture_image_units_;
279 uint32 max_fragment_uniform_vectors_;
280 uint32 max_varying_vectors_;
281 uint32 max_vertex_uniform_vectors_;
282 uint32 max_color_attachments_;
283 uint32 max_draw_buffers_;
285 ProgramCache* program_cache_;
287 scoped_ptr<BufferManager> buffer_manager_;
289 scoped_ptr<FramebufferManager> framebuffer_manager_;
291 scoped_ptr<RenderbufferManager> renderbuffer_manager_;
293 scoped_ptr<TextureManager> texture_manager_;
295 scoped_ptr<PathManager> path_manager_;
297 scoped_ptr<ProgramManager> program_manager_;
299 scoped_ptr<ShaderManager> shader_manager_;
301 scoped_ptr<ValuebufferManager> valuebuffer_manager_;
303 scoped_refptr<FeatureInfo> feature_info_;
305 std::vector<base::WeakPtr<gles2::GLES2Decoder> > decoders_;
307 // Mappings from client side IDs to service side IDs.
308 base::hash_map<GLuint, GLuint> samplers_id_map_;
309 base::hash_map<GLuint, GLuint> transformfeedbacks_id_map_;
310 base::hash_map<GLuint, GLsync> syncs_id_map_;
312 GLenum draw_buffer_;
314 DISALLOW_COPY_AND_ASSIGN(ContextGroup);
317 } // namespace gles2
318 } // namespace gpu
320 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_GROUP_H_