Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / service / context_group.h
blobea62823bd1be44c14aab5707697a21f33ae2e6de
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 bool GetBufferServiceId(GLuint client_id, GLuint* service_id) const;
184 void AddSamplerId(GLuint client_id, GLuint service_id) {
185 samplers_id_map_[client_id] = service_id;
188 bool GetSamplerServiceId(GLuint client_id, GLuint* service_id) const {
189 base::hash_map<GLuint, GLuint>::const_iterator iter =
190 samplers_id_map_.find(client_id);
191 if (iter == samplers_id_map_.end())
192 return false;
193 if (service_id)
194 *service_id = iter->second;
195 return true;
198 void RemoveSamplerId(GLuint client_id) {
199 samplers_id_map_.erase(client_id);
202 void AddTransformFeedbackId(GLuint client_id, GLuint service_id) {
203 transformfeedbacks_id_map_[client_id] = service_id;
206 bool GetTransformFeedbackServiceId(
207 GLuint client_id, GLuint* service_id) const {
208 if (client_id == 0) {
209 // Default one.
210 if (service_id)
211 *service_id = 0;
212 return true;
214 base::hash_map<GLuint, GLuint>::const_iterator iter =
215 transformfeedbacks_id_map_.find(client_id);
216 if (iter == transformfeedbacks_id_map_.end())
217 return false;
218 if (service_id)
219 *service_id = iter->second;
220 return true;
223 void RemoveTransformFeedbackId(GLuint client_id) {
224 transformfeedbacks_id_map_.erase(client_id);
227 void AddSyncId(GLuint client_id, GLsync service_id) {
228 syncs_id_map_[client_id] = service_id;
231 bool GetSyncServiceId(GLuint client_id, GLsync* service_id) const {
232 base::hash_map<GLuint, GLsync>::const_iterator iter =
233 syncs_id_map_.find(client_id);
234 if (iter == syncs_id_map_.end())
235 return false;
236 if (service_id)
237 *service_id = iter->second;
238 return true;
241 void RemoveSyncId(GLuint client_id) {
242 syncs_id_map_.erase(client_id);
245 private:
246 friend class base::RefCounted<ContextGroup>;
247 ~ContextGroup();
249 bool CheckGLFeature(GLint min_required, GLint* v);
250 bool CheckGLFeatureU(GLint min_required, uint32* v);
251 bool QueryGLFeature(GLenum pname, GLint min_required, GLint* v);
252 bool QueryGLFeatureU(GLenum pname, GLint min_required, uint32* v);
253 bool HaveContexts();
255 ContextType context_type_;
257 scoped_refptr<MailboxManager> mailbox_manager_;
258 scoped_refptr<MemoryTracker> memory_tracker_;
259 scoped_refptr<ShaderTranslatorCache> shader_translator_cache_;
260 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_;
261 scoped_refptr<SubscriptionRefSet> subscription_ref_set_;
262 scoped_refptr<ValueStateMap> pending_valuebuffer_state_;
264 bool enforce_gl_minimums_;
265 bool bind_generates_resource_;
267 uint32 max_vertex_attribs_;
268 uint32 max_texture_units_;
269 uint32 max_texture_image_units_;
270 uint32 max_vertex_texture_image_units_;
271 uint32 max_fragment_uniform_vectors_;
272 uint32 max_varying_vectors_;
273 uint32 max_vertex_uniform_vectors_;
274 uint32 max_color_attachments_;
275 uint32 max_draw_buffers_;
277 ProgramCache* program_cache_;
279 scoped_ptr<BufferManager> buffer_manager_;
281 scoped_ptr<FramebufferManager> framebuffer_manager_;
283 scoped_ptr<RenderbufferManager> renderbuffer_manager_;
285 scoped_ptr<TextureManager> texture_manager_;
287 scoped_ptr<PathManager> path_manager_;
289 scoped_ptr<ProgramManager> program_manager_;
291 scoped_ptr<ShaderManager> shader_manager_;
293 scoped_ptr<ValuebufferManager> valuebuffer_manager_;
295 scoped_refptr<FeatureInfo> feature_info_;
297 std::vector<base::WeakPtr<gles2::GLES2Decoder> > decoders_;
299 // Mappings from client side IDs to service side IDs.
300 base::hash_map<GLuint, GLuint> samplers_id_map_;
301 base::hash_map<GLuint, GLuint> transformfeedbacks_id_map_;
302 base::hash_map<GLuint, GLsync> syncs_id_map_;
304 DISALLOW_COPY_AND_ASSIGN(ContextGroup);
307 } // namespace gles2
308 } // namespace gpu
310 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_GROUP_H_