15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef GPU_COMMAND_BUFFER_SERVICE_VERTEX_ARRAY_MANAGER_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GPU_COMMAND_BUFFER_SERVICE_VERTEX_ARRAY_MANAGER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/containers/hash_tables.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "gpu/command_buffer/service/gl_utils.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "gpu/gpu_export.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gpu {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gles2 {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class VertexAttribManager;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class keeps track of the vertex arrays and their sizes so we can do
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// bounds checking.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GPU_EXPORT VertexArrayManager {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VertexArrayManager();
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~VertexArrayManager();
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Must call before destruction.
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Destroy(bool have_context);
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
310de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  // Creates a VertexAttribManager and if client_visible,
320de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  // maps it to the client_id.
330de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  scoped_refptr<VertexAttribManager> CreateVertexAttribManager(
340de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)      GLuint client_id,
350de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)      GLuint service_id,
360de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)      uint32 num_vertex_attribs,
370de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)      bool client_visible);
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets the vertex attrib manager for the given vertex array.
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VertexAttribManager* GetVertexAttribManager(GLuint client_id);
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Removes the vertex attrib manager for the given vertex array.
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RemoveVertexAttribManager(GLuint client_id);
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets a client id for a given service id.
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetClientId(GLuint service_id, GLuint* client_id) const;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class VertexAttribManager;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StartTracking(VertexAttribManager* vertex_attrib_manager);
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StopTracking(VertexAttribManager* vertex_attrib_manager);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Info for each vertex array in the system.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::hash_map<GLuint, scoped_refptr<VertexAttribManager> >
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      VertexAttribManagerMap;
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VertexAttribManagerMap vertex_attrib_managers_;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Counts the number of VertexArrayInfo allocated with 'this' as its manager.
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allows to check no VertexArrayInfo will outlive this.
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned int vertex_attrib_manager_count_;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool have_context_;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(VertexArrayManager);
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace gles2
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace gpu
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // GPU_COMMAND_BUFFER_SERVICE_VERTEX_ARRAY_MANAGER_H_
72