| 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/mailbox_manager.h" | 5 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "crypto/random.h" | 9 #include "crypto/random.h" |
| 10 #include "gpu/command_buffer/service/mailbox_synchronizer.h" |
| 10 #include "gpu/command_buffer/service/texture_manager.h" | 11 #include "gpu/command_buffer/service/texture_manager.h" |
| 11 | 12 |
| 12 namespace gpu { | 13 namespace gpu { |
| 13 namespace gles2 { | 14 namespace gles2 { |
| 14 | 15 |
| 15 MailboxManager::MailboxManager() | 16 MailboxManager::MailboxManager() |
| 16 : mailbox_to_textures_(std::ptr_fun(&MailboxManager::TargetNameLess)) { | 17 : mailbox_to_textures_(std::ptr_fun(&MailboxManager::TargetNameLess)), |
| 18 sync_(MailboxSynchronizer::GetInstance()) { |
| 17 } | 19 } |
| 18 | 20 |
| 19 MailboxManager::~MailboxManager() { | 21 MailboxManager::~MailboxManager() { |
| 20 DCHECK(mailbox_to_textures_.empty()); | 22 DCHECK(mailbox_to_textures_.empty()); |
| 21 DCHECK(textures_to_mailboxes_.empty()); | 23 DCHECK(textures_to_mailboxes_.empty()); |
| 22 } | 24 } |
| 23 | 25 |
| 24 Texture* MailboxManager::ConsumeTexture(unsigned target, | 26 Texture* MailboxManager::ConsumeTexture(unsigned target, |
| 25 const Mailbox& mailbox) { | 27 const Mailbox& mailbox) { |
| 28 TargetName target_name(target, mailbox); |
| 26 MailboxToTextureMap::iterator it = | 29 MailboxToTextureMap::iterator it = |
| 27 mailbox_to_textures_.find(TargetName(target, mailbox)); | 30 mailbox_to_textures_.find(target_name); |
| 28 if (it == mailbox_to_textures_.end()) | 31 if (it != mailbox_to_textures_.end()) |
| 29 return NULL; | 32 return it->second->first; |
| 30 | 33 |
| 31 return it->second->first; | 34 if (sync_) { |
| 35 // See if it's visible in another mailbox manager, and if so make it visible |
| 36 // here too. |
| 37 Texture* texture = sync_->CreateTextureFromMailbox(target, mailbox); |
| 38 if (texture) { |
| 39 InsertTexture(target_name, texture); |
| 40 DCHECK_EQ(0U, texture->refs_.size()); // TODO |
| 41 } |
| 42 return texture; |
| 43 } |
| 44 |
| 45 return NULL; |
| 32 } | 46 } |
| 33 | 47 |
| 34 void MailboxManager::ProduceTexture(unsigned target, | 48 void MailboxManager::ProduceTexture(unsigned target, |
| 35 const Mailbox& mailbox, | 49 const Mailbox& mailbox, |
| 36 Texture* texture) { | 50 Texture* texture) { |
| 37 texture->SetMailboxManager(this); | |
| 38 TargetName target_name(target, mailbox); | 51 TargetName target_name(target, mailbox); |
| 39 MailboxToTextureMap::iterator it = mailbox_to_textures_.find(target_name); | 52 MailboxToTextureMap::iterator it = mailbox_to_textures_.find(target_name); |
| 40 if (it != mailbox_to_textures_.end()) { | 53 if (it != mailbox_to_textures_.end()) { |
| 54 if (it->second->first == texture) |
| 55 return; |
| 41 TextureToMailboxMap::iterator texture_it = it->second; | 56 TextureToMailboxMap::iterator texture_it = it->second; |
| 42 mailbox_to_textures_.erase(it); | 57 mailbox_to_textures_.erase(it); |
| 43 textures_to_mailboxes_.erase(texture_it); | 58 textures_to_mailboxes_.erase(texture_it); |
| 44 } | 59 } |
| 60 InsertTexture(target_name, texture); |
| 61 } |
| 62 |
| 63 void MailboxManager::InsertTexture(TargetName target_name, Texture* texture) { |
| 64 texture->SetMailboxManager(this); |
| 45 TextureToMailboxMap::iterator texture_it = | 65 TextureToMailboxMap::iterator texture_it = |
| 46 textures_to_mailboxes_.insert(std::make_pair(texture, target_name)); | 66 textures_to_mailboxes_.insert(std::make_pair(texture, target_name)); |
| 47 mailbox_to_textures_.insert(std::make_pair(target_name, texture_it)); | 67 mailbox_to_textures_.insert(std::make_pair(target_name, texture_it)); |
| 48 DCHECK_EQ(mailbox_to_textures_.size(), textures_to_mailboxes_.size()); | 68 DCHECK_EQ(mailbox_to_textures_.size(), textures_to_mailboxes_.size()); |
| 49 } | 69 } |
| 50 | 70 |
| 51 void MailboxManager::TextureDeleted(Texture* texture) { | 71 void MailboxManager::TextureDeleted(Texture* texture) { |
| 52 std::pair<TextureToMailboxMap::iterator, | 72 std::pair<TextureToMailboxMap::iterator, |
| 53 TextureToMailboxMap::iterator> range = | 73 TextureToMailboxMap::iterator> range = |
| 54 textures_to_mailboxes_.equal_range(texture); | 74 textures_to_mailboxes_.equal_range(texture); |
| 55 for (TextureToMailboxMap::iterator it = range.first; | 75 for (TextureToMailboxMap::iterator it = range.first; |
| 56 it != range.second; ++it) { | 76 it != range.second; ++it) { |
| 57 size_t count = mailbox_to_textures_.erase(it->second); | 77 size_t count = mailbox_to_textures_.erase(it->second); |
| 58 DCHECK(count == 1); | 78 DCHECK(count == 1); |
| 59 } | 79 } |
| 60 textures_to_mailboxes_.erase(range.first, range.second); | 80 textures_to_mailboxes_.erase(range.first, range.second); |
| 61 DCHECK_EQ(mailbox_to_textures_.size(), textures_to_mailboxes_.size()); | 81 DCHECK_EQ(mailbox_to_textures_.size(), textures_to_mailboxes_.size()); |
| 82 |
| 83 if (sync_) |
| 84 sync_->TextureDeleted(texture); |
| 85 } |
| 86 |
| 87 void MailboxManager::PushTextureUpdates() { |
| 88 if (sync_) |
| 89 sync_->PushTextureUpdates(this); |
| 90 } |
| 91 |
| 92 void MailboxManager::PullTextureUpdates() { |
| 93 if (sync_) |
| 94 sync_->PullTextureUpdates(this); |
| 62 } | 95 } |
| 63 | 96 |
| 64 MailboxManager::TargetName::TargetName(unsigned target, const Mailbox& mailbox) | 97 MailboxManager::TargetName::TargetName(unsigned target, const Mailbox& mailbox) |
| 65 : target(target), | 98 : target(target), |
| 66 mailbox(mailbox) { | 99 mailbox(mailbox) { |
| 67 } | 100 } |
| 68 | 101 |
| 69 bool MailboxManager::TargetNameLess(const MailboxManager::TargetName& lhs, | 102 bool MailboxManager::TargetNameLess(const MailboxManager::TargetName& lhs, |
| 70 const MailboxManager::TargetName& rhs) { | 103 const MailboxManager::TargetName& rhs) { |
| 71 return memcmp(&lhs, &rhs, sizeof(lhs)) < 0; | 104 return memcmp(&lhs, &rhs, sizeof(lhs)) < 0; |
| 72 } | 105 } |
| 73 | 106 |
| 74 } // namespace gles2 | 107 } // namespace gles2 |
| 75 } // namespace gpu | 108 } // namespace gpu |
| OLD | NEW |