Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 | 11 |
| 12 namespace gpu { | 12 namespace gpu { |
| 13 namespace gles2 { | 13 namespace gles2 { |
| 14 | 14 |
| 15 namespace { | |
| 16 | |
| 17 // Given a variable name | a[0].b.c[0] |, return |a|. | |
| 18 std::string GetTopVariableName(const std::string& fullname) { | |
| 19 size_t pos = fullname.find_first_of("[."); | |
| 20 if (pos == std::string::npos) | |
| 21 return fullname; | |
| 22 return fullname.substr(0, pos); | |
| 23 } | |
| 24 | |
| 25 } // namespace anonymous | |
| 26 | |
| 15 Shader::Shader(GLuint service_id, GLenum shader_type) | 27 Shader::Shader(GLuint service_id, GLenum shader_type) |
| 16 : use_count_(0), | 28 : use_count_(0), |
| 17 service_id_(service_id), | 29 service_id_(service_id), |
| 18 shader_type_(shader_type), | 30 shader_type_(shader_type), |
| 19 valid_(false) { | 31 valid_(false) { |
| 20 } | 32 } |
| 21 | 33 |
| 22 Shader::~Shader() { | 34 Shader::~Shader() { |
| 23 } | 35 } |
| 24 | 36 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 void Shader::DecUseCount() { | 101 void Shader::DecUseCount() { |
| 90 --use_count_; | 102 --use_count_; |
| 91 DCHECK_GE(use_count_, 0); | 103 DCHECK_GE(use_count_, 0); |
| 92 } | 104 } |
| 93 | 105 |
| 94 void Shader::MarkAsDeleted() { | 106 void Shader::MarkAsDeleted() { |
| 95 DCHECK_NE(service_id_, 0u); | 107 DCHECK_NE(service_id_, 0u); |
| 96 service_id_ = 0; | 108 service_id_ = 0; |
| 97 } | 109 } |
| 98 | 110 |
| 99 const Shader::VariableInfo* Shader::GetAttribInfo( | 111 const sh::Attribute* Shader::GetAttribInfo(const std::string& name) const { |
| 100 const std::string& name) const { | 112 AttributeMap::const_iterator it = attrib_map_.find(GetTopVariableName(name)); |
|
Ken Russell (switch to Gerrit)
2014/10/07 03:35:26
Per comment above: vertex shader inputs can't be a
Zhenyao Mo
2014/10/07 18:23:41
Done.
| |
| 101 VariableMap::const_iterator it = attrib_map_.find(name); | |
| 102 return it != attrib_map_.end() ? &it->second : NULL; | 113 return it != attrib_map_.end() ? &it->second : NULL; |
| 103 } | 114 } |
| 104 | 115 |
| 105 const std::string* Shader::GetAttribMappedName( | 116 const std::string* Shader::GetAttribMappedName( |
| 106 const std::string& original_name) const { | 117 const std::string& original_name) const { |
| 107 for (VariableMap::const_iterator it = attrib_map_.begin(); | 118 for (AttributeMap::const_iterator it = attrib_map_.begin(); |
| 108 it != attrib_map_.end(); ++it) { | 119 it != attrib_map_.end(); ++it) { |
| 109 if (it->second.name == original_name) | 120 if (it->second.name == original_name) |
| 110 return &(it->first); | 121 return &(it->first); |
| 111 } | 122 } |
| 112 return NULL; | 123 return NULL; |
| 113 } | 124 } |
| 114 | 125 |
| 115 const std::string* Shader::GetOriginalNameFromHashedName( | 126 const std::string* Shader::GetOriginalNameFromHashedName( |
| 116 const std::string& hashed_name) const { | 127 const std::string& hashed_name) const { |
| 117 NameMap::const_iterator it = name_map_.find(hashed_name); | 128 NameMap::const_iterator it = name_map_.find(hashed_name); |
| 118 if (it != name_map_.end()) | 129 if (it != name_map_.end()) |
| 119 return &(it->second); | 130 return &(it->second); |
| 120 return NULL; | 131 return NULL; |
| 121 } | 132 } |
| 122 | 133 |
| 123 const Shader::VariableInfo* Shader::GetUniformInfo( | 134 const sh::Uniform* Shader::GetUniformInfo(const std::string& name) const { |
| 124 const std::string& name) const { | 135 UniformMap::const_iterator it = uniform_map_.find(GetTopVariableName(name)); |
| 125 VariableMap::const_iterator it = uniform_map_.find(name); | |
| 126 return it != uniform_map_.end() ? &it->second : NULL; | 136 return it != uniform_map_.end() ? &it->second : NULL; |
| 127 } | 137 } |
| 128 | 138 |
| 129 const Shader::VariableInfo* Shader::GetVaryingInfo( | 139 const sh::Varying* Shader::GetVaryingInfo(const std::string& name) const { |
| 130 const std::string& name) const { | 140 VaryingMap::const_iterator it = varying_map_.find(GetTopVariableName(name)); |
| 131 VariableMap::const_iterator it = varying_map_.find(name); | |
| 132 return it != varying_map_.end() ? &it->second : NULL; | 141 return it != varying_map_.end() ? &it->second : NULL; |
| 133 } | 142 } |
| 134 | 143 |
| 135 ShaderManager::ShaderManager() {} | 144 ShaderManager::ShaderManager() {} |
| 136 | 145 |
| 137 ShaderManager::~ShaderManager() { | 146 ShaderManager::~ShaderManager() { |
| 138 DCHECK(shaders_.empty()); | 147 DCHECK(shaders_.empty()); |
| 139 } | 148 } |
| 140 | 149 |
| 141 void ShaderManager::Destroy(bool have_context) { | 150 void ShaderManager::Destroy(bool have_context) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 DCHECK(shader); | 231 DCHECK(shader); |
| 223 DCHECK(IsOwned(shader)); | 232 DCHECK(IsOwned(shader)); |
| 224 shader->DecUseCount(); | 233 shader->DecUseCount(); |
| 225 RemoveShader(shader); | 234 RemoveShader(shader); |
| 226 } | 235 } |
| 227 | 236 |
| 228 } // namespace gles2 | 237 } // namespace gles2 |
| 229 } // namespace gpu | 238 } // namespace gpu |
| 230 | 239 |
| 231 | 240 |
| OLD | NEW |