| 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" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 void Shader::IncUseCount() { | 127 void Shader::IncUseCount() { |
| 128 ++use_count_; | 128 ++use_count_; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void Shader::DecUseCount() { | 131 void Shader::DecUseCount() { |
| 132 --use_count_; | 132 --use_count_; |
| 133 DCHECK_GE(use_count_, 0); | 133 DCHECK_GE(use_count_, 0); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void Shader::MarkAsDeleted() { | 136 void Shader::Delete() { |
| 137 if (use_count_ > 0) { |
| 138 // If attached, compile the shader before we delete it. |
| 139 DoCompile(); |
| 140 } |
| 137 DCHECK_NE(service_id_, 0u); | 141 DCHECK_NE(service_id_, 0u); |
| 142 glDeleteShader(service_id_); |
| 138 service_id_ = 0; | 143 service_id_ = 0; |
| 139 } | 144 } |
| 140 | 145 |
| 141 const sh::Attribute* Shader::GetAttribInfo(const std::string& name) const { | 146 const sh::Attribute* Shader::GetAttribInfo(const std::string& name) const { |
| 142 // Vertex attributes can't be arrays or structs (GLSL ES 3.00.4, section | 147 // Vertex attributes can't be arrays or structs (GLSL ES 3.00.4, section |
| 143 // 4.3.4, "Input Variables"), so |name| is the top level name used as | 148 // 4.3.4, "Input Variables"), so |name| is the top level name used as |
| 144 // the AttributeMap key. | 149 // the AttributeMap key. |
| 145 AttributeMap::const_iterator it = attrib_map_.find(name); | 150 AttributeMap::const_iterator it = attrib_map_.find(name); |
| 146 return it != attrib_map_.end() ? &it->second : NULL; | 151 return it != attrib_map_.end() ? &it->second : NULL; |
| 147 } | 152 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 178 | 183 |
| 179 ShaderManager::~ShaderManager() { | 184 ShaderManager::~ShaderManager() { |
| 180 DCHECK(shaders_.empty()); | 185 DCHECK(shaders_.empty()); |
| 181 } | 186 } |
| 182 | 187 |
| 183 void ShaderManager::Destroy(bool have_context) { | 188 void ShaderManager::Destroy(bool have_context) { |
| 184 while (!shaders_.empty()) { | 189 while (!shaders_.empty()) { |
| 185 if (have_context) { | 190 if (have_context) { |
| 186 Shader* shader = shaders_.begin()->second.get(); | 191 Shader* shader = shaders_.begin()->second.get(); |
| 187 if (!shader->IsDeleted()) { | 192 if (!shader->IsDeleted()) { |
| 188 glDeleteShader(shader->service_id()); | 193 shader->Delete(); |
| 189 shader->MarkAsDeleted(); | |
| 190 } | 194 } |
| 191 } | 195 } |
| 192 shaders_.erase(shaders_.begin()); | 196 shaders_.erase(shaders_.begin()); |
| 193 } | 197 } |
| 194 } | 198 } |
| 195 | 199 |
| 196 Shader* ShaderManager::CreateShader( | 200 Shader* ShaderManager::CreateShader( |
| 197 GLuint client_id, | 201 GLuint client_id, |
| 198 GLuint service_id, | 202 GLuint service_id, |
| 199 GLenum shader_type) { | 203 GLenum shader_type) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 it != shaders_.end(); ++it) { | 244 it != shaders_.end(); ++it) { |
| 241 if (it->second.get() == shader) { | 245 if (it->second.get() == shader) { |
| 242 shaders_.erase(it); | 246 shaders_.erase(it); |
| 243 return; | 247 return; |
| 244 } | 248 } |
| 245 } | 249 } |
| 246 NOTREACHED(); | 250 NOTREACHED(); |
| 247 } | 251 } |
| 248 } | 252 } |
| 249 | 253 |
| 250 void ShaderManager::MarkAsDeleted(Shader* shader) { | 254 void ShaderManager::Delete(Shader* shader) { |
| 251 DCHECK(shader); | 255 DCHECK(shader); |
| 252 DCHECK(IsOwned(shader)); | 256 DCHECK(IsOwned(shader)); |
| 253 shader->MarkAsDeleted(); | 257 shader->Delete(); |
| 254 RemoveShader(shader); | 258 RemoveShader(shader); |
| 255 } | 259 } |
| 256 | 260 |
| 257 void ShaderManager::UseShader(Shader* shader) { | 261 void ShaderManager::UseShader(Shader* shader) { |
| 258 DCHECK(shader); | 262 DCHECK(shader); |
| 259 DCHECK(IsOwned(shader)); | 263 DCHECK(IsOwned(shader)); |
| 260 shader->IncUseCount(); | 264 shader->IncUseCount(); |
| 261 } | 265 } |
| 262 | 266 |
| 263 void ShaderManager::UnuseShader(Shader* shader) { | 267 void ShaderManager::UnuseShader(Shader* shader) { |
| 264 DCHECK(shader); | 268 DCHECK(shader); |
| 265 DCHECK(IsOwned(shader)); | 269 DCHECK(IsOwned(shader)); |
| 266 shader->DecUseCount(); | 270 shader->DecUseCount(); |
| 267 RemoveShader(shader); | 271 RemoveShader(shader); |
| 268 } | 272 } |
| 269 | 273 |
| 270 } // namespace gles2 | 274 } // namespace gles2 |
| 271 } // namespace gpu | 275 } // namespace gpu |
| 272 | |
| 273 | |
| OLD | NEW |