Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / gpu / command_buffer / service / vertex_array_manager.h
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.
4
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_VERTEX_ARRAY_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_VERTEX_ARRAY_MANAGER_H_
7
8 #include "base/basictypes.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/logging.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "gpu/command_buffer/service/gl_utils.h"
14 #include "gpu/gpu_export.h"
15
16 namespace gpu {
17 namespace gles2 {
18
19 class VertexAttribManager;
20
21 // This class keeps track of the vertex arrays and their sizes so we can do
22 // bounds checking.
23 class GPU_EXPORT VertexArrayManager {
24  public:
25   VertexArrayManager();
26   ~VertexArrayManager();
27
28   // Must call before destruction.
29   void Destroy(bool have_context);
30
31   // Creates a VertexAttribManager and if client_visible,
32   // maps it to the client_id.
33   scoped_refptr<VertexAttribManager> CreateVertexAttribManager(
34       GLuint client_id,
35       GLuint service_id,
36       uint32 num_vertex_attribs,
37       bool client_visible);
38
39   // Gets the vertex attrib manager for the given vertex array.
40   VertexAttribManager* GetVertexAttribManager(GLuint client_id);
41
42   // Removes the vertex attrib manager for the given vertex array.
43   void RemoveVertexAttribManager(GLuint client_id);
44
45   // Gets a client id for a given service id.
46   bool GetClientId(GLuint service_id, GLuint* client_id) const;
47
48  private:
49   friend class VertexAttribManager;
50
51   void StartTracking(VertexAttribManager* vertex_attrib_manager);
52   void StopTracking(VertexAttribManager* vertex_attrib_manager);
53
54   // Info for each vertex array in the system.
55   typedef base::hash_map<GLuint, scoped_refptr<VertexAttribManager> >
56       VertexAttribManagerMap;
57   VertexAttribManagerMap vertex_attrib_managers_;
58
59   // Counts the number of VertexArrayInfo allocated with 'this' as its manager.
60   // Allows to check no VertexArrayInfo will outlive this.
61   unsigned int vertex_attrib_manager_count_;
62
63   bool have_context_;
64
65   DISALLOW_COPY_AND_ASSIGN(VertexArrayManager);
66 };
67
68 }  // namespace gles2
69 }  // namespace gpu
70
71 #endif  // GPU_COMMAND_BUFFER_SERVICE_VERTEX_ARRAY_MANAGER_H_