Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / gpu / command_buffer / service / mailbox_manager_impl.cc
blobdb7b4c20fafbda98c06f1c7b8ea97cac1e385449
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"
7 #include <algorithm>
9 #include "gpu/command_buffer/service/texture_manager.h"
11 namespace gpu {
12 namespace gles2 {
14 MailboxManagerImpl::MailboxManagerImpl() {
17 MailboxManagerImpl::~MailboxManagerImpl() {
18 DCHECK(mailbox_to_textures_.empty());
19 DCHECK(textures_to_mailboxes_.empty());
22 bool MailboxManagerImpl::UsesSync() {
23 return false;
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;
32 return NULL;
35 void MailboxManagerImpl::ProduceTexture(const Mailbox& mailbox,
36 Texture* texture) {
37 MailboxToTextureMap::iterator it = mailbox_to_textures_.find(mailbox);
38 if (it != mailbox_to_textures_.end()) {
39 if (it->second->first == texture)
40 return;
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,
49 Texture* texture) {
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);
64 DCHECK(count == 1);
66 textures_to_mailboxes_.erase(range.first, range.second);
67 DCHECK_EQ(mailbox_to_textures_.size(), textures_to_mailboxes_.size());
70 } // namespace gles2
71 } // namespace gpu