vertex_array_manager.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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#include "gpu/command_buffer/service/vertex_array_manager.h"
6#include "base/debug/trace_event.h"
7#include "base/logging.h"
8#include "gpu/command_buffer/common/gles2_cmd_utils.h"
9#include "gpu/command_buffer/service/buffer_manager.h"
10#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
11#include "gpu/command_buffer/service/vertex_attrib_manager.h"
12
13namespace gpu {
14namespace gles2 {
15
16VertexArrayManager::VertexArrayManager()
17    : vertex_attrib_manager_count_(0),
18      have_context_(true) {
19}
20
21VertexArrayManager::~VertexArrayManager() {
22  DCHECK(vertex_attrib_managers_.empty());
23  CHECK_EQ(vertex_attrib_manager_count_, 0u);
24}
25
26void VertexArrayManager::Destroy(bool have_context) {
27  have_context_ = have_context;
28  vertex_attrib_managers_.clear();
29}
30
31void VertexArrayManager::CreateVertexAttribManager(
32    GLuint client_id, GLuint service_id, uint32 num_vertex_attribs) {
33  scoped_refptr<VertexAttribManager> vertex_attrib_manager(
34    new VertexAttribManager(this, service_id, num_vertex_attribs));
35  std::pair<VertexAttribManagerMap::iterator, bool> result =
36      vertex_attrib_managers_.insert(
37      std::make_pair(client_id, vertex_attrib_manager));
38  DCHECK(result.second);
39}
40
41VertexAttribManager* VertexArrayManager::GetVertexAttribManager(
42    GLuint client_id) {
43  VertexAttribManagerMap::iterator it = vertex_attrib_managers_.find(client_id);
44  return it != vertex_attrib_managers_.end() ? it->second : NULL;
45}
46
47void VertexArrayManager::RemoveVertexAttribManager(GLuint client_id) {
48  VertexAttribManagerMap::iterator it = vertex_attrib_managers_.find(client_id);
49  if (it != vertex_attrib_managers_.end()) {
50    VertexAttribManager* vertex_attrib_manager = it->second;
51    vertex_attrib_manager->MarkAsDeleted();
52    vertex_attrib_managers_.erase(it);
53  }
54}
55
56void VertexArrayManager::StartTracking(
57    VertexAttribManager* /* vertex_attrib_manager */) {
58  ++vertex_attrib_manager_count_;
59}
60
61void VertexArrayManager::StopTracking(
62    VertexAttribManager* /* vertex_attrib_manager */) {
63  --vertex_attrib_manager_count_;
64}
65
66bool VertexArrayManager::GetClientId(
67    GLuint service_id, GLuint* client_id) const {
68  // This doesn't need to be fast. It's only used during slow queries.
69  for (VertexAttribManagerMap::const_iterator it =
70      vertex_attrib_managers_.begin();
71      it != vertex_attrib_managers_.end(); ++it) {
72    if (it->second->service_id() == service_id) {
73      *client_id = it->first;
74      return true;
75    }
76  }
77  return false;
78}
79
80}  // namespace gles2
81}  // namespace gpu
82
83
84