| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "gpu/command_buffer/service/progress_reporter.h" |
| 13 | 14 |
| 14 namespace gpu { | 15 namespace gpu { |
| 15 namespace gles2 { | 16 namespace gles2 { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // Given a variable name | a[0].b.c[0] |, return |a|. | 20 // Given a variable name | a[0].b.c[0] |, return |a|. |
| 20 std::string GetTopVariableName(const std::string& fullname) { | 21 std::string GetTopVariableName(const std::string& fullname) { |
| 21 size_t pos = fullname.find_first_of("[."); | 22 size_t pos = fullname.find_first_of("[."); |
| 22 if (pos == std::string::npos) | 23 if (pos == std::string::npos) |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 std::string mapped_name = GetTopVariableName(name); | 261 std::string mapped_name = GetTopVariableName(name); |
| 261 // Number of output variables is expected to be so low that | 262 // Number of output variables is expected to be so low that |
| 262 // a linear search of a list should be faster than using a map. | 263 // a linear search of a list should be faster than using a map. |
| 263 for (const auto& value : output_variable_list_) { | 264 for (const auto& value : output_variable_list_) { |
| 264 if (value.mappedName == mapped_name) | 265 if (value.mappedName == mapped_name) |
| 265 return &value; | 266 return &value; |
| 266 } | 267 } |
| 267 return nullptr; | 268 return nullptr; |
| 268 } | 269 } |
| 269 | 270 |
| 270 ShaderManager::ShaderManager() {} | 271 ShaderManager::ShaderManager(ProgressReporter* progress_reporter) |
| 272 : progress_reporter_(progress_reporter) { |
| 273 DCHECK(progress_reporter_); |
| 274 } |
| 271 | 275 |
| 272 ShaderManager::~ShaderManager() { | 276 ShaderManager::~ShaderManager() { |
| 273 DCHECK(shaders_.empty()); | 277 DCHECK(shaders_.empty()); |
| 274 } | 278 } |
| 275 | 279 |
| 276 void ShaderManager::Destroy(bool have_context) { | 280 void ShaderManager::Destroy(bool have_context) { |
| 277 while (!shaders_.empty()) { | 281 while (!shaders_.empty()) { |
| 278 if (have_context) { | 282 if (have_context) { |
| 279 Shader* shader = shaders_.begin()->second.get(); | 283 Shader* shader = shaders_.begin()->second.get(); |
| 280 shader->Destroy(); | 284 shader->Destroy(); |
| 281 } | 285 } |
| 282 shaders_.erase(shaders_.begin()); | 286 shaders_.erase(shaders_.begin()); |
| 287 progress_reporter_->ReportProgress(); |
| 283 } | 288 } |
| 284 } | 289 } |
| 285 | 290 |
| 286 Shader* ShaderManager::CreateShader( | 291 Shader* ShaderManager::CreateShader( |
| 287 GLuint client_id, | 292 GLuint client_id, |
| 288 GLuint service_id, | 293 GLuint service_id, |
| 289 GLenum shader_type) { | 294 GLenum shader_type) { |
| 290 std::pair<ShaderMap::iterator, bool> result = | 295 std::pair<ShaderMap::iterator, bool> result = |
| 291 shaders_.insert(std::make_pair( | 296 shaders_.insert(std::make_pair( |
| 292 client_id, scoped_refptr<Shader>( | 297 client_id, scoped_refptr<Shader>( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 357 |
| 353 void ShaderManager::UnuseShader(Shader* shader) { | 358 void ShaderManager::UnuseShader(Shader* shader) { |
| 354 DCHECK(shader); | 359 DCHECK(shader); |
| 355 DCHECK(IsOwned(shader)); | 360 DCHECK(IsOwned(shader)); |
| 356 shader->DecUseCount(); | 361 shader->DecUseCount(); |
| 357 RemoveShader(shader); | 362 RemoveShader(shader); |
| 358 } | 363 } |
| 359 | 364 |
| 360 } // namespace gles2 | 365 } // namespace gles2 |
| 361 } // namespace gpu | 366 } // namespace gpu |
| OLD | NEW |