| 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->owned_) { | 71 if (!info->IsDeleted() && info->owner_.get() == this) { |
| 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::Ref info(new TextureInfo(service_id)); | 559 TextureInfo* texture_info = new TextureInfo(service_id); |
| 560 std::pair<TextureInfoMap::iterator, bool> result = | 560 texture_info->owner_ = AsWeakPtr(); |
| 561 texture_infos_.insert(std::make_pair(client_id, info)); | 561 AddTextureInfo(feature_info, client_id, texture_info); |
| 562 DCHECK(result.second); | 562 return texture_info; |
| 563 if (!info->CanRender(feature_info)) { | |
| 564 ++num_unrenderable_textures_; | |
| 565 } | |
| 566 return info.get(); | |
| 567 } | 563 } |
| 568 | 564 |
| 569 TextureManager::TextureInfo* TextureManager::GetTextureInfo( | 565 TextureManager::TextureInfo* TextureManager::GetTextureInfo( |
| 570 GLuint client_id) { | 566 GLuint client_id) { |
| 571 TextureInfoMap::iterator it = texture_infos_.find(client_id); | 567 TextureInfoMap::iterator it = texture_infos_.find(client_id); |
| 572 return it != texture_infos_.end() ? it->second : NULL; | 568 return it != texture_infos_.end() ? it->second : NULL; |
| 573 } | 569 } |
| 574 | 570 |
| 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 |
| 575 void TextureManager::RemoveTextureInfo( | 582 void TextureManager::RemoveTextureInfo( |
| 576 const FeatureInfo* feature_info, GLuint client_id) { | 583 const FeatureInfo* feature_info, GLuint client_id) { |
| 577 TextureInfoMap::iterator it = texture_infos_.find(client_id); | 584 TextureInfoMap::iterator it = texture_infos_.find(client_id); |
| 578 if (it != texture_infos_.end()) { | 585 if (it != texture_infos_.end()) { |
| 579 TextureInfo* info = it->second; | 586 TextureInfo* info = it->second; |
| 580 if (!info->CanRender(feature_info)) { | 587 if (!info->CanRender(feature_info)) |
| 581 --num_unrenderable_textures_; | 588 --num_unrenderable_textures_; |
| 582 } | 589 if (info->owner_.get() == this) |
| 583 info->MarkAsDeleted(); | 590 info->MarkAsDeleted(); |
| 584 texture_infos_.erase(it); | 591 texture_infos_.erase(it); |
| 585 } | 592 } |
| 586 } | 593 } |
| 587 | 594 |
| 588 bool TextureManager::GetClientId(GLuint service_id, GLuint* client_id) const { | 595 bool TextureManager::GetClientId(GLuint service_id, GLuint* client_id) const { |
| 589 // This doesn't need to be fast. It's only used during slow queries. | 596 // This doesn't need to be fast. It's only used during slow queries. |
| 590 for (TextureInfoMap::const_iterator it = texture_infos_.begin(); | 597 for (TextureInfoMap::const_iterator it = texture_infos_.begin(); |
| 591 it != texture_infos_.end(); ++it) { | 598 it != texture_infos_.end(); ++it) { |
| 592 if (it->second->service_id() == service_id) { | 599 if (it->second->service_id() == service_id) { |
| 593 *client_id = it->first; | 600 *client_id = it->first; |
| 594 return true; | 601 return true; |
| 595 } | 602 } |
| 596 } | 603 } |
| 597 return false; | 604 return false; |
| 598 } | 605 } |
| 599 | 606 |
| 600 } // namespace gles2 | 607 } // namespace gles2 |
| 601 } // namespace gpu | 608 } // namespace gpu |
| 602 | 609 |
| 603 | 610 |
| OLD | NEW |