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 // Vertex attributes can't be arrays or structs (GLSL ES 3.00.4, section |
101 VariableMap::const_iterator it = attrib_map_.find(name); | 113 // 4.3.4, "Input Variables"), so |name| is the top level name used as |
| 114 // the AttributeMap key. |
| 115 AttributeMap::const_iterator it = attrib_map_.find(name); |
102 return it != attrib_map_.end() ? &it->second : NULL; | 116 return it != attrib_map_.end() ? &it->second : NULL; |
103 } | 117 } |
104 | 118 |
105 const std::string* Shader::GetAttribMappedName( | 119 const std::string* Shader::GetAttribMappedName( |
106 const std::string& original_name) const { | 120 const std::string& original_name) const { |
107 for (VariableMap::const_iterator it = attrib_map_.begin(); | 121 for (AttributeMap::const_iterator it = attrib_map_.begin(); |
108 it != attrib_map_.end(); ++it) { | 122 it != attrib_map_.end(); ++it) { |
109 if (it->second.name == original_name) | 123 if (it->second.name == original_name) |
110 return &(it->first); | 124 return &(it->first); |
111 } | 125 } |
112 return NULL; | 126 return NULL; |
113 } | 127 } |
114 | 128 |
115 const std::string* Shader::GetOriginalNameFromHashedName( | 129 const std::string* Shader::GetOriginalNameFromHashedName( |
116 const std::string& hashed_name) const { | 130 const std::string& hashed_name) const { |
117 NameMap::const_iterator it = name_map_.find(hashed_name); | 131 NameMap::const_iterator it = name_map_.find(hashed_name); |
118 if (it != name_map_.end()) | 132 if (it != name_map_.end()) |
119 return &(it->second); | 133 return &(it->second); |
120 return NULL; | 134 return NULL; |
121 } | 135 } |
122 | 136 |
123 const Shader::VariableInfo* Shader::GetUniformInfo( | 137 const sh::Uniform* Shader::GetUniformInfo(const std::string& name) const { |
124 const std::string& name) const { | 138 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; | 139 return it != uniform_map_.end() ? &it->second : NULL; |
127 } | 140 } |
128 | 141 |
129 const Shader::VariableInfo* Shader::GetVaryingInfo( | 142 const sh::Varying* Shader::GetVaryingInfo(const std::string& name) const { |
130 const std::string& name) const { | 143 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; | 144 return it != varying_map_.end() ? &it->second : NULL; |
133 } | 145 } |
134 | 146 |
135 ShaderManager::ShaderManager() {} | 147 ShaderManager::ShaderManager() {} |
136 | 148 |
137 ShaderManager::~ShaderManager() { | 149 ShaderManager::~ShaderManager() { |
138 DCHECK(shaders_.empty()); | 150 DCHECK(shaders_.empty()); |
139 } | 151 } |
140 | 152 |
141 void ShaderManager::Destroy(bool have_context) { | 153 void ShaderManager::Destroy(bool have_context) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 DCHECK(shader); | 234 DCHECK(shader); |
223 DCHECK(IsOwned(shader)); | 235 DCHECK(IsOwned(shader)); |
224 shader->DecUseCount(); | 236 shader->DecUseCount(); |
225 RemoveShader(shader); | 237 RemoveShader(shader); |
226 } | 238 } |
227 | 239 |
228 } // namespace gles2 | 240 } // namespace gles2 |
229 } // namespace gpu | 241 } // namespace gpu |
230 | 242 |
231 | 243 |
OLD | NEW |