Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / service / vertex_array_manager.cc
blob0809eda2861e1dd26f17ce31646a6ee3732792bb
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 #include "gpu/command_buffer/service/vertex_array_manager.h"
7 #include "base/logging.h"
8 #include "base/trace_event/trace_event.h"
9 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
10 #include "gpu/command_buffer/service/buffer_manager.h"
11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
12 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
14 namespace gpu {
15 namespace gles2 {
17 VertexArrayManager::VertexArrayManager()
18 : vertex_attrib_manager_count_(0),
19 have_context_(true) {
22 VertexArrayManager::~VertexArrayManager() {
23 DCHECK(vertex_attrib_managers_.empty());
24 CHECK_EQ(vertex_attrib_manager_count_, 0u);
27 void VertexArrayManager::Destroy(bool have_context) {
28 have_context_ = have_context;
29 vertex_attrib_managers_.clear();
32 scoped_refptr<VertexAttribManager>
33 VertexArrayManager::CreateVertexAttribManager(GLuint client_id,
34 GLuint service_id,
35 uint32 num_vertex_attribs,
36 bool client_visible) {
37 scoped_refptr<VertexAttribManager> vertex_attrib_manager(
38 new VertexAttribManager(this, service_id, num_vertex_attribs));
40 if (client_visible) {
41 std::pair<VertexAttribManagerMap::iterator, bool> result =
42 vertex_attrib_managers_.insert(
43 std::make_pair(client_id, vertex_attrib_manager));
44 DCHECK(result.second);
47 return vertex_attrib_manager;
50 VertexAttribManager* VertexArrayManager::GetVertexAttribManager(
51 GLuint client_id) {
52 VertexAttribManagerMap::iterator it = vertex_attrib_managers_.find(client_id);
53 return it != vertex_attrib_managers_.end() ? it->second.get() : NULL;
56 void VertexArrayManager::RemoveVertexAttribManager(GLuint client_id) {
57 VertexAttribManagerMap::iterator it = vertex_attrib_managers_.find(client_id);
58 if (it != vertex_attrib_managers_.end()) {
59 VertexAttribManager* vertex_attrib_manager = it->second.get();
60 vertex_attrib_manager->MarkAsDeleted();
61 vertex_attrib_managers_.erase(it);
65 void VertexArrayManager::StartTracking(
66 VertexAttribManager* /* vertex_attrib_manager */) {
67 ++vertex_attrib_manager_count_;
70 void VertexArrayManager::StopTracking(
71 VertexAttribManager* /* vertex_attrib_manager */) {
72 --vertex_attrib_manager_count_;
75 bool VertexArrayManager::GetClientId(
76 GLuint service_id, GLuint* client_id) const {
77 // This doesn't need to be fast. It's only used during slow queries.
78 for (VertexAttribManagerMap::const_iterator it =
79 vertex_attrib_managers_.begin();
80 it != vertex_attrib_managers_.end(); ++it) {
81 if (it->second->service_id() == service_id) {
82 *client_id = it->first;
83 return true;
86 return false;
89 } // namespace gles2
90 } // namespace gpu