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 31scoped_refptr<VertexAttribManager> 32VertexArrayManager::CreateVertexAttribManager(GLuint client_id, 33 GLuint service_id, 34 uint32 num_vertex_attribs, 35 bool client_visible) { 36 scoped_refptr<VertexAttribManager> vertex_attrib_manager( 37 new VertexAttribManager(this, service_id, num_vertex_attribs)); 38 39 if (client_visible) { 40 std::pair<VertexAttribManagerMap::iterator, bool> result = 41 vertex_attrib_managers_.insert( 42 std::make_pair(client_id, vertex_attrib_manager)); 43 DCHECK(result.second); 44 } 45 46 return vertex_attrib_manager; 47} 48 49VertexAttribManager* VertexArrayManager::GetVertexAttribManager( 50 GLuint client_id) { 51 VertexAttribManagerMap::iterator it = vertex_attrib_managers_.find(client_id); 52 return it != vertex_attrib_managers_.end() ? it->second.get() : NULL; 53} 54 55void VertexArrayManager::RemoveVertexAttribManager(GLuint client_id) { 56 VertexAttribManagerMap::iterator it = vertex_attrib_managers_.find(client_id); 57 if (it != vertex_attrib_managers_.end()) { 58 VertexAttribManager* vertex_attrib_manager = it->second.get(); 59 vertex_attrib_manager->MarkAsDeleted(); 60 vertex_attrib_managers_.erase(it); 61 } 62} 63 64void VertexArrayManager::StartTracking( 65 VertexAttribManager* /* vertex_attrib_manager */) { 66 ++vertex_attrib_manager_count_; 67} 68 69void VertexArrayManager::StopTracking( 70 VertexAttribManager* /* vertex_attrib_manager */) { 71 --vertex_attrib_manager_count_; 72} 73 74bool VertexArrayManager::GetClientId( 75 GLuint service_id, GLuint* client_id) const { 76 // This doesn't need to be fast. It's only used during slow queries. 77 for (VertexAttribManagerMap::const_iterator it = 78 vertex_attrib_managers_.begin(); 79 it != vertex_attrib_managers_.end(); ++it) { 80 if (it->second->service_id() == service_id) { 81 *client_id = it->first; 82 return true; 83 } 84 } 85 return false; 86} 87 88} // namespace gles2 89} // namespace gpu 90 91 92