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