Home | History | Annotate | Download | only in service
      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 VertexArrayInfo for the given vertex array.
     32   void CreateVertexAttribManager(GLuint client_id, GLuint service_id,
     33       uint32 num_vertex_attribs);
     34 
     35   // Gets the vertex attrib manager for the given vertex array.
     36   VertexAttribManager* GetVertexAttribManager(GLuint client_id);
     37 
     38   // Removes the vertex attrib manager for the given vertex array.
     39   void RemoveVertexAttribManager(GLuint client_id);
     40 
     41   // Gets a client id for a given service id.
     42   bool GetClientId(GLuint service_id, GLuint* client_id) const;
     43 
     44  private:
     45   friend class VertexAttribManager;
     46 
     47   void StartTracking(VertexAttribManager* vertex_attrib_manager);
     48   void StopTracking(VertexAttribManager* vertex_attrib_manager);
     49 
     50   // Info for each vertex array in the system.
     51   typedef base::hash_map<GLuint, scoped_refptr<VertexAttribManager> >
     52       VertexAttribManagerMap;
     53   VertexAttribManagerMap vertex_attrib_managers_;
     54 
     55   // Counts the number of VertexArrayInfo allocated with 'this' as its manager.
     56   // Allows to check no VertexArrayInfo will outlive this.
     57   unsigned int vertex_attrib_manager_count_;
     58 
     59   bool have_context_;
     60 
     61   DISALLOW_COPY_AND_ASSIGN(VertexArrayManager);
     62 };
     63 
     64 }  // namespace gles2
     65 }  // namespace gpu
     66 
     67 #endif  // GPU_COMMAND_BUFFER_SERVICE_VERTEX_ARRAY_MANAGER_H_
     68