Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: gpu/command_buffer/service/mailbox_synchronizer.cc

Issue 180723023: gpu: Mailbox emulation with EGLImage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #include "gpu/command_buffer/service/mailbox_synchronizer.h"
6
7 #include "base/bind.h"
8 #include "gpu/command_buffer/service/mailbox_manager.h"
9 #include "gpu/command_buffer/service/texture_manager.h"
10
11 namespace gpu {
12 namespace gles2 {
13
14 namespace {
15
16 MailboxSynchronizer* g_instance = NULL;
17
18 } // anonymous namespace
19
20 // static
21 bool MailboxSynchronizer::Initialize() {
22 DCHECK(!g_instance);
23 g_instance = new MailboxSynchronizer;
24 return true;
25 }
26
27 // static
28 void MailboxSynchronizer::Terminate() {
29 DCHECK(g_instance);
30 delete g_instance;
31 g_instance = NULL;
32 }
33
34 // static
35 MailboxSynchronizer* MailboxSynchronizer::GetInstance() {
36 return g_instance;
37 }
38
39 MailboxSynchronizer::TargetName::TargetName(unsigned target,
40 const Mailbox& mailbox)
41 : target(target), mailbox(mailbox) {}
42
43 MailboxSynchronizer::MailboxSynchronizer() {}
44
45 MailboxSynchronizer::~MailboxSynchronizer() {
46 }
47
48 Texture* MailboxSynchronizer::CreateTextureFromMailbox(MailboxManager* manager,
49 unsigned target,
50 const Mailbox& mailbox) {
51 base::AutoLock lock(lock_);
52 TargetName target_name(target, mailbox);
53 MailboxMap::const_iterator it = mailboxes_.find(target_name);
54 if (it != mailboxes_.end()) {
55 linked_ptr<GlobalMailbox> info = it->second;
56 DCHECK(find(info->refs.begin(), info->refs.end(), manager) ==
57 info->refs.end());
58 Texture* texture = info->definition.CreateTexture();
59 if (texture)
60 it->second->refs.insert(manager);
61 return texture;
62 }
63
64 return NULL;
65 }
66
67 void MailboxSynchronizer::TextureDeleted(MailboxManager* manager,
68 unsigned target,
69 const Mailbox& mailbox) {
70 base::AutoLock lock(lock_);
71 TargetName target_name(target, mailbox);
72 MailboxMap::iterator it = mailboxes_.find(target_name);
73 if (it != mailboxes_.end()) {
74 size_t count = it->second->refs.erase(manager);
75 DCHECK_EQ(count, 1U);
76 if (it->second->refs.empty())
77 mailboxes_.erase(it);
78 }
79 }
80
81 void MailboxSynchronizer::PushTextureUpdates(MailboxManager* manager) {
82 base::AutoLock lock(lock_);
83 scoped_refptr<SharedGLFence> fence(new SharedGLFence);
84 for (MailboxManager::MailboxToTextureMap::const_iterator texture_it =
85 manager->mailbox_to_textures_.begin();
86 texture_it != manager->mailbox_to_textures_.end();
87 texture_it++) {
88 TargetName target_name(texture_it->first.target, texture_it->first.mailbox);
89 Texture* texture = texture_it->second->first;
90 // TODO(sievers)
91 bool needs_mips = texture->min_filter() != GL_NEAREST &&
92 texture->min_filter() != GL_LINEAR;
93 if (target_name.target != GL_TEXTURE_2D || needs_mips)
94 continue;
95
96 MailboxMap::iterator it = mailboxes_.find(target_name);
97 if (it != mailboxes_.end()) {
98 // TODO: Different texture produced into an existing mailbox needs to
99 // decouple it from updates to previously shared textures in other
100 // contexts.
101 bool texture_has_image =
102 texture->GetLevelImage(texture->target(), 0) != NULL;
103 it->second->definition = TextureDefinition(
104 target_name.target,
105 texture,
106 texture_has_image ? it->second->definition.image() : NULL,
107 fence);
108 it->second->refs.insert(manager);
109 } else {
110 // TODO: If the texture is associated with another mailbox though,
111 // we need to reuse the same EGLImage.
112 mailboxes_[target_name] = make_linked_ptr(new GlobalMailbox(
113 TextureDefinition(target_name.target, texture, NULL, fence)));
114 mailboxes_[target_name]->refs.insert(manager);
115 }
116 }
117 }
118
119 void MailboxSynchronizer::PullTextureUpdates(MailboxManager* manager) {
120 base::AutoLock lock(lock_);
121 for (MailboxManager::MailboxToTextureMap::const_iterator texture_it =
122 manager->mailbox_to_textures_.begin();
123 texture_it != manager->mailbox_to_textures_.end();
124 texture_it++) {
125 TargetName target_name(texture_it->first.target, texture_it->first.mailbox);
126 MailboxMap::iterator it = mailboxes_.find(target_name);
127 if (it != mailboxes_.end()) {
128 it->second->definition.UpdateTexture(texture_it->second->first);
129 }
130 }
131 }
132
133 } // namespace gles2
134 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698