| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/program_manager.h" | 5 #include "gpu/command_buffer/service/program_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 for (ProgramInfoMap::const_iterator it = program_infos_.begin(); | 447 for (ProgramInfoMap::const_iterator it = program_infos_.begin(); |
| 448 it != program_infos_.end(); ++it) { | 448 it != program_infos_.end(); ++it) { |
| 449 if (it->second->service_id() == service_id) { | 449 if (it->second->service_id() == service_id) { |
| 450 *client_id = it->first; | 450 *client_id = it->first; |
| 451 return true; | 451 return true; |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 return false; | 454 return false; |
| 455 } | 455 } |
| 456 | 456 |
| 457 bool ProgramManager::IsOwned(ProgramManager::ProgramInfo* info) { |
| 458 for (ProgramInfoMap::iterator it = program_infos_.begin(); |
| 459 it != program_infos_.end(); ++it) { |
| 460 if (it->second.get() == info) { |
| 461 return true; |
| 462 } |
| 463 } |
| 464 return false; |
| 465 } |
| 466 |
| 457 void ProgramManager::RemoveProgramInfoIfUnused( | 467 void ProgramManager::RemoveProgramInfoIfUnused( |
| 458 ShaderManager* shader_manager, ProgramInfo* info) { | 468 ShaderManager* shader_manager, ProgramInfo* info) { |
| 459 DCHECK(shader_manager); | 469 DCHECK(shader_manager); |
| 460 DCHECK(info); | 470 DCHECK(info); |
| 471 DCHECK(IsOwned(info)); |
| 461 if (info->IsDeleted() && !info->InUse()) { | 472 if (info->IsDeleted() && !info->InUse()) { |
| 462 info->DetachShaders(shader_manager); | 473 info->DetachShaders(shader_manager); |
| 463 for (ProgramInfoMap::iterator it = program_infos_.begin(); | 474 for (ProgramInfoMap::iterator it = program_infos_.begin(); |
| 464 it != program_infos_.end(); ++it) { | 475 it != program_infos_.end(); ++it) { |
| 465 if (it->second->service_id() == info->service_id()) { | 476 if (it->second.get() == info) { |
| 466 program_infos_.erase(it); | 477 program_infos_.erase(it); |
| 467 return; | 478 return; |
| 468 } | 479 } |
| 469 } | 480 } |
| 470 NOTREACHED(); | 481 NOTREACHED(); |
| 471 } | 482 } |
| 472 } | 483 } |
| 473 | 484 |
| 474 void ProgramManager::MarkAsDeleted( | 485 void ProgramManager::MarkAsDeleted( |
| 475 ShaderManager* shader_manager, | 486 ShaderManager* shader_manager, |
| 476 ProgramManager::ProgramInfo* info) { | 487 ProgramManager::ProgramInfo* info) { |
| 477 DCHECK(shader_manager); | 488 DCHECK(shader_manager); |
| 478 DCHECK(info); | 489 DCHECK(info); |
| 490 DCHECK(IsOwned(info)); |
| 479 info->MarkAsDeleted(); | 491 info->MarkAsDeleted(); |
| 480 RemoveProgramInfoIfUnused(shader_manager, info); | 492 RemoveProgramInfoIfUnused(shader_manager, info); |
| 481 } | 493 } |
| 482 | 494 |
| 483 void ProgramManager::UseProgram(ProgramManager::ProgramInfo* info) { | 495 void ProgramManager::UseProgram(ProgramManager::ProgramInfo* info) { |
| 484 DCHECK(info); | 496 DCHECK(info); |
| 497 DCHECK(IsOwned(info)); |
| 485 info->IncUseCount(); | 498 info->IncUseCount(); |
| 486 } | 499 } |
| 487 | 500 |
| 488 void ProgramManager::UnuseProgram( | 501 void ProgramManager::UnuseProgram( |
| 489 ShaderManager* shader_manager, | 502 ShaderManager* shader_manager, |
| 490 ProgramManager::ProgramInfo* info) { | 503 ProgramManager::ProgramInfo* info) { |
| 491 DCHECK(shader_manager); | 504 DCHECK(shader_manager); |
| 492 DCHECK(info); | 505 DCHECK(info); |
| 506 DCHECK(IsOwned(info)); |
| 493 info->DecUseCount(); | 507 info->DecUseCount(); |
| 494 RemoveProgramInfoIfUnused(shader_manager, info); | 508 RemoveProgramInfoIfUnused(shader_manager, info); |
| 495 } | 509 } |
| 496 | 510 |
| 497 } // namespace gles2 | 511 } // namespace gles2 |
| 498 } // namespace gpu | 512 } // namespace gpu |
| 499 | 513 |
| 500 | 514 |
| OLD | NEW |