OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_impl.h" | 5 #include "gpu/command_buffer/service/mailbox_manager_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "gpu/command_buffer/service/texture_manager.h" | 11 #include "gpu/command_buffer/service/texture_manager.h" |
12 | 12 |
13 namespace gpu { | 13 namespace gpu { |
14 namespace gles2 { | 14 namespace gles2 { |
15 | 15 |
16 MailboxManagerImpl::MailboxManagerImpl() { | 16 MailboxManagerImpl::MailboxManagerImpl() { |
17 } | 17 } |
18 | 18 |
19 MailboxManagerImpl::~MailboxManagerImpl() { | 19 MailboxManagerImpl::~MailboxManagerImpl() { |
20 DCHECK(mailbox_to_textures_.empty()); | 20 DCHECK(mailbox_to_textures_.empty()); |
21 DCHECK(textures_to_mailboxes_.empty()); | 21 DCHECK(textures_to_mailboxes_.empty()); |
22 } | 22 } |
23 | 23 |
24 bool MailboxManagerImpl::UsesSync() { | 24 bool MailboxManagerImpl::UsesSync() { |
25 return false; | 25 return false; |
26 } | 26 } |
27 | 27 |
28 Texture* MailboxManagerImpl::ConsumeTexture(const Mailbox& mailbox) { | 28 TextureBase* MailboxManagerImpl::ConsumeTexture(const Mailbox& mailbox) { |
29 MailboxToTextureMap::iterator it = | 29 MailboxToTextureMap::iterator it = |
30 mailbox_to_textures_.find(mailbox); | 30 mailbox_to_textures_.find(mailbox); |
31 if (it != mailbox_to_textures_.end()) | 31 if (it != mailbox_to_textures_.end()) |
32 return it->second->first; | 32 return it->second->first; |
33 | 33 |
34 return NULL; | 34 return NULL; |
35 } | 35 } |
36 | 36 |
37 void MailboxManagerImpl::ProduceTexture(const Mailbox& mailbox, | 37 void MailboxManagerImpl::ProduceTexture(const Mailbox& mailbox, |
38 Texture* texture) { | 38 TextureBase* texture) { |
39 MailboxToTextureMap::iterator it = mailbox_to_textures_.find(mailbox); | 39 MailboxToTextureMap::iterator it = mailbox_to_textures_.find(mailbox); |
40 if (it != mailbox_to_textures_.end()) { | 40 if (it != mailbox_to_textures_.end()) { |
41 if (it->second->first == texture) | 41 if (it->second->first == texture) |
42 return; | 42 return; |
43 TextureToMailboxMap::iterator texture_it = it->second; | 43 TextureToMailboxMap::iterator texture_it = it->second; |
44 mailbox_to_textures_.erase(it); | 44 mailbox_to_textures_.erase(it); |
45 textures_to_mailboxes_.erase(texture_it); | 45 textures_to_mailboxes_.erase(texture_it); |
46 } | 46 } |
47 if (texture) | 47 if (texture) |
48 InsertTexture(mailbox, texture); | 48 InsertTexture(mailbox, texture); |
49 } | 49 } |
50 | 50 |
51 void MailboxManagerImpl::InsertTexture(const Mailbox& mailbox, | 51 void MailboxManagerImpl::InsertTexture(const Mailbox& mailbox, |
52 Texture* texture) { | 52 TextureBase* texture) { |
53 texture->SetMailboxManager(this); | 53 texture->SetMailboxManager(this); |
54 TextureToMailboxMap::iterator texture_it = | 54 TextureToMailboxMap::iterator texture_it = |
55 textures_to_mailboxes_.insert(std::make_pair(texture, mailbox)); | 55 textures_to_mailboxes_.insert(std::make_pair(texture, mailbox)); |
56 mailbox_to_textures_.insert(std::make_pair(mailbox, texture_it)); | 56 mailbox_to_textures_.insert(std::make_pair(mailbox, texture_it)); |
57 DCHECK_EQ(mailbox_to_textures_.size(), textures_to_mailboxes_.size()); | 57 DCHECK_EQ(mailbox_to_textures_.size(), textures_to_mailboxes_.size()); |
58 } | 58 } |
59 | 59 |
60 void MailboxManagerImpl::TextureDeleted(Texture* texture) { | 60 void MailboxManagerImpl::TextureDeleted(TextureBase* texture) { |
61 std::pair<TextureToMailboxMap::iterator, | 61 std::pair<TextureToMailboxMap::iterator, |
62 TextureToMailboxMap::iterator> range = | 62 TextureToMailboxMap::iterator> range = |
63 textures_to_mailboxes_.equal_range(texture); | 63 textures_to_mailboxes_.equal_range(texture); |
64 for (TextureToMailboxMap::iterator it = range.first; | 64 for (TextureToMailboxMap::iterator it = range.first; |
65 it != range.second; ++it) { | 65 it != range.second; ++it) { |
66 size_t count = mailbox_to_textures_.erase(it->second); | 66 size_t count = mailbox_to_textures_.erase(it->second); |
67 DCHECK(count == 1); | 67 DCHECK(count == 1); |
68 } | 68 } |
69 textures_to_mailboxes_.erase(range.first, range.second); | 69 textures_to_mailboxes_.erase(range.first, range.second); |
70 DCHECK_EQ(mailbox_to_textures_.size(), textures_to_mailboxes_.size()); | 70 DCHECK_EQ(mailbox_to_textures_.size(), textures_to_mailboxes_.size()); |
71 } | 71 } |
72 | 72 |
73 } // namespace gles2 | 73 } // namespace gles2 |
74 } // namespace gpu | 74 } // namespace gpu |
OLD | NEW |