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
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/mailbox_manager_impl.h"
9 #include "gpu/command_buffer/service/texture_manager.h"
14 MailboxManagerImpl::MailboxManagerImpl() {
17 MailboxManagerImpl::~MailboxManagerImpl() {
18 DCHECK(mailbox_to_textures_
.empty());
19 DCHECK(textures_to_mailboxes_
.empty());
22 bool MailboxManagerImpl::UsesSync() {
26 Texture
* MailboxManagerImpl::ConsumeTexture(const Mailbox
& mailbox
) {
27 MailboxToTextureMap::iterator it
=
28 mailbox_to_textures_
.find(mailbox
);
29 if (it
!= mailbox_to_textures_
.end())
30 return it
->second
->first
;
35 void MailboxManagerImpl::ProduceTexture(const Mailbox
& mailbox
,
37 MailboxToTextureMap::iterator it
= mailbox_to_textures_
.find(mailbox
);
38 if (it
!= mailbox_to_textures_
.end()) {
39 if (it
->second
->first
== texture
)
41 TextureToMailboxMap::iterator texture_it
= it
->second
;
42 mailbox_to_textures_
.erase(it
);
43 textures_to_mailboxes_
.erase(texture_it
);
45 InsertTexture(mailbox
, texture
);
48 void MailboxManagerImpl::InsertTexture(const Mailbox
& mailbox
,
50 texture
->SetMailboxManager(this);
51 TextureToMailboxMap::iterator texture_it
=
52 textures_to_mailboxes_
.insert(std::make_pair(texture
, mailbox
));
53 mailbox_to_textures_
.insert(std::make_pair(mailbox
, texture_it
));
54 DCHECK_EQ(mailbox_to_textures_
.size(), textures_to_mailboxes_
.size());
57 void MailboxManagerImpl::TextureDeleted(Texture
* texture
) {
58 std::pair
<TextureToMailboxMap::iterator
,
59 TextureToMailboxMap::iterator
> range
=
60 textures_to_mailboxes_
.equal_range(texture
);
61 for (TextureToMailboxMap::iterator it
= range
.first
;
62 it
!= range
.second
; ++it
) {
63 size_t count
= mailbox_to_textures_
.erase(it
->second
);
66 textures_to_mailboxes_
.erase(range
.first
, range
.second
);
67 DCHECK_EQ(mailbox_to_textures_
.size(), textures_to_mailboxes_
.size());