| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/shader_manager.h" | 5 #include "gpu/command_buffer/service/shader_manager.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 | 7 |
| 8 namespace gpu { | 8 namespace gpu { |
| 9 namespace gles2 { | 9 namespace gles2 { |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 shader_infos_.insert(std::make_pair( | 61 shader_infos_.insert(std::make_pair( |
| 62 client_id, ShaderInfo::Ref(new ShaderInfo(service_id, shader_type)))); | 62 client_id, ShaderInfo::Ref(new ShaderInfo(service_id, shader_type)))); |
| 63 DCHECK(result.second); | 63 DCHECK(result.second); |
| 64 } | 64 } |
| 65 | 65 |
| 66 ShaderManager::ShaderInfo* ShaderManager::GetShaderInfo(GLuint client_id) { | 66 ShaderManager::ShaderInfo* ShaderManager::GetShaderInfo(GLuint client_id) { |
| 67 ShaderInfoMap::iterator it = shader_infos_.find(client_id); | 67 ShaderInfoMap::iterator it = shader_infos_.find(client_id); |
| 68 return it != shader_infos_.end() ? it->second : NULL; | 68 return it != shader_infos_.end() ? it->second : NULL; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void ShaderManager::RemoveShaderInfo(GLuint client_id) { | |
| 72 ShaderInfoMap::iterator it = shader_infos_.find(client_id); | |
| 73 if (it != shader_infos_.end()) { | |
| 74 it->second->MarkAsDeleted(); | |
| 75 shader_infos_.erase(it); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 bool ShaderManager::GetClientId(GLuint service_id, GLuint* client_id) const { | 71 bool ShaderManager::GetClientId(GLuint service_id, GLuint* client_id) const { |
| 80 // This doesn't need to be fast. It's only used during slow queries. | 72 // This doesn't need to be fast. It's only used during slow queries. |
| 81 for (ShaderInfoMap::const_iterator it = shader_infos_.begin(); | 73 for (ShaderInfoMap::const_iterator it = shader_infos_.begin(); |
| 82 it != shader_infos_.end(); ++it) { | 74 it != shader_infos_.end(); ++it) { |
| 83 if (it->second->service_id() == service_id) { | 75 if (it->second->service_id() == service_id) { |
| 84 *client_id = it->first; | 76 *client_id = it->first; |
| 85 return true; | 77 return true; |
| 86 } | 78 } |
| 87 } | 79 } |
| 88 return false; | 80 return false; |
| 89 } | 81 } |
| 90 | 82 |
| 83 void ShaderManager::RemoveShaderInfoIfUnused(ShaderManager::ShaderInfo* info) { |
| 84 DCHECK(info); |
| 85 if (info->IsDeleted() && !info->InUse()) { |
| 86 for (ShaderInfoMap::iterator it = shader_infos_.begin(); |
| 87 it != shader_infos_.end(); ++it) { |
| 88 if (it->second->service_id() == info->service_id()) { |
| 89 shader_infos_.erase(it); |
| 90 return; |
| 91 } |
| 92 } |
| 93 NOTREACHED(); |
| 94 } |
| 95 } |
| 96 |
| 97 void ShaderManager::MarkAsDeleted(ShaderManager::ShaderInfo* info) { |
| 98 DCHECK(info); |
| 99 info->MarkAsDeleted(); |
| 100 RemoveShaderInfoIfUnused(info); |
| 101 } |
| 102 |
| 103 void ShaderManager::UseShader(ShaderManager::ShaderInfo* info) { |
| 104 DCHECK(info); |
| 105 info->IncUseCount(); |
| 106 } |
| 107 |
| 108 void ShaderManager::UnuseShader(ShaderManager::ShaderInfo* info) { |
| 109 DCHECK(info); |
| 110 info->DecUseCount(); |
| 111 RemoveShaderInfoIfUnused(info); |
| 112 } |
| 113 |
| 91 } // namespace gles2 | 114 } // namespace gles2 |
| 92 } // namespace gpu | 115 } // namespace gpu |
| 93 | 116 |
| 94 | 117 |
| OLD | NEW |