| OLD | NEW |
| 1 // Copyright (c) 2011 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/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
| 6 #include "base/bits.h" | 6 #include "base/bits.h" |
| 7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 8 #include "gpu/command_buffer/service/feature_info.h" | 8 #include "gpu/command_buffer/service/feature_info.h" |
| 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 10 #include "gpu/GLES2/gles2_command_buffer.h" | 10 #include "gpu/GLES2/gles2_command_buffer.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 TextureManager::~TextureManager() { | 63 TextureManager::~TextureManager() { |
| 64 DCHECK(texture_infos_.empty()); | 64 DCHECK(texture_infos_.empty()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void TextureManager::Destroy(bool have_context) { | 67 void TextureManager::Destroy(bool have_context) { |
| 68 while (!texture_infos_.empty()) { | 68 while (!texture_infos_.empty()) { |
| 69 if (have_context) { | 69 if (have_context) { |
| 70 TextureInfo* info = texture_infos_.begin()->second; | 70 TextureInfo* info = texture_infos_.begin()->second; |
| 71 if (!info->IsDeleted() && info->owner_.get() == this) { | 71 if (!info->IsDeleted() && info->owned_) { |
| 72 GLuint service_id = info->service_id(); | 72 GLuint service_id = info->service_id(); |
| 73 glDeleteTextures(1, &service_id); | 73 glDeleteTextures(1, &service_id); |
| 74 info->MarkAsDeleted(); | 74 info->MarkAsDeleted(); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 texture_infos_.erase(texture_infos_.begin()); | 77 texture_infos_.erase(texture_infos_.begin()); |
| 78 } | 78 } |
| 79 if (have_context) { | 79 if (have_context) { |
| 80 GLuint ids[] = { | 80 GLuint ids[] = { |
| 81 black_2d_texture_id_, | 81 black_2d_texture_id_, |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 bool result = info->MarkMipmapsGenerated(feature_info); | 549 bool result = info->MarkMipmapsGenerated(feature_info); |
| 550 if (!info->CanRender(feature_info)) { | 550 if (!info->CanRender(feature_info)) { |
| 551 ++num_unrenderable_textures_; | 551 ++num_unrenderable_textures_; |
| 552 } | 552 } |
| 553 return result; | 553 return result; |
| 554 } | 554 } |
| 555 | 555 |
| 556 TextureManager::TextureInfo* TextureManager::CreateTextureInfo( | 556 TextureManager::TextureInfo* TextureManager::CreateTextureInfo( |
| 557 const FeatureInfo* feature_info, | 557 const FeatureInfo* feature_info, |
| 558 GLuint client_id, GLuint service_id) { | 558 GLuint client_id, GLuint service_id) { |
| 559 TextureInfo* texture_info = new TextureInfo(service_id); | 559 TextureInfo::Ref info(new TextureInfo(service_id)); |
| 560 texture_info->owner_ = AsWeakPtr(); | 560 std::pair<TextureInfoMap::iterator, bool> result = |
| 561 AddTextureInfo(feature_info, client_id, texture_info); | 561 texture_infos_.insert(std::make_pair(client_id, info)); |
| 562 return texture_info; | 562 DCHECK(result.second); |
| 563 if (!info->CanRender(feature_info)) { |
| 564 ++num_unrenderable_textures_; |
| 565 } |
| 566 return info.get(); |
| 563 } | 567 } |
| 564 | 568 |
| 565 TextureManager::TextureInfo* TextureManager::GetTextureInfo( | 569 TextureManager::TextureInfo* TextureManager::GetTextureInfo( |
| 566 GLuint client_id) { | 570 GLuint client_id) { |
| 567 TextureInfoMap::iterator it = texture_infos_.find(client_id); | 571 TextureInfoMap::iterator it = texture_infos_.find(client_id); |
| 568 return it != texture_infos_.end() ? it->second : NULL; | 572 return it != texture_infos_.end() ? it->second : NULL; |
| 569 } | 573 } |
| 570 | 574 |
| 571 void TextureManager::AddTextureInfo( | |
| 572 const FeatureInfo* feature_info, | |
| 573 GLuint client_id, TextureInfo* texture_info) { | |
| 574 std::pair<TextureInfoMap::iterator, bool> result = | |
| 575 texture_infos_.insert(std::make_pair(client_id, texture_info)); | |
| 576 DCHECK(result.second); | |
| 577 if (!texture_info->CanRender(feature_info)) { | |
| 578 ++num_unrenderable_textures_; | |
| 579 } | |
| 580 } | |
| 581 | |
| 582 void TextureManager::RemoveTextureInfo( | 575 void TextureManager::RemoveTextureInfo( |
| 583 const FeatureInfo* feature_info, GLuint client_id) { | 576 const FeatureInfo* feature_info, GLuint client_id) { |
| 584 TextureInfoMap::iterator it = texture_infos_.find(client_id); | 577 TextureInfoMap::iterator it = texture_infos_.find(client_id); |
| 585 if (it != texture_infos_.end()) { | 578 if (it != texture_infos_.end()) { |
| 586 TextureInfo* info = it->second; | 579 TextureInfo* info = it->second; |
| 587 if (!info->CanRender(feature_info)) | 580 if (!info->CanRender(feature_info)) { |
| 588 --num_unrenderable_textures_; | 581 --num_unrenderable_textures_; |
| 589 if (info->owner_.get() == this) | 582 } |
| 590 info->MarkAsDeleted(); | 583 info->MarkAsDeleted(); |
| 591 texture_infos_.erase(it); | 584 texture_infos_.erase(it); |
| 592 } | 585 } |
| 593 } | 586 } |
| 594 | 587 |
| 595 bool TextureManager::GetClientId(GLuint service_id, GLuint* client_id) const { | 588 bool TextureManager::GetClientId(GLuint service_id, GLuint* client_id) const { |
| 596 // This doesn't need to be fast. It's only used during slow queries. | 589 // This doesn't need to be fast. It's only used during slow queries. |
| 597 for (TextureInfoMap::const_iterator it = texture_infos_.begin(); | 590 for (TextureInfoMap::const_iterator it = texture_infos_.begin(); |
| 598 it != texture_infos_.end(); ++it) { | 591 it != texture_infos_.end(); ++it) { |
| 599 if (it->second->service_id() == service_id) { | 592 if (it->second->service_id() == service_id) { |
| 600 *client_id = it->first; | 593 *client_id = it->first; |
| 601 return true; | 594 return true; |
| 602 } | 595 } |
| 603 } | 596 } |
| 604 return false; | 597 return false; |
| 605 } | 598 } |
| 606 | 599 |
| 607 } // namespace gles2 | 600 } // namespace gles2 |
| 608 } // namespace gpu | 601 } // namespace gpu |
| 609 | 602 |
| 610 | 603 |
| OLD | NEW |