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

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: oops 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::TextureGroup::TextureGroup(
44 const TextureDefinition& definition)
45 : definition(definition) {}
46
47 MailboxSynchronizer::TextureGroup::~TextureGroup() {}
48
49 MailboxSynchronizer::TextureVersion::TextureVersion(
50 linked_ptr<TextureGroup> group)
51 : version(group->definition.version()), group(group) {}
52
53 MailboxSynchronizer::TextureVersion::~TextureVersion() {}
54
55 MailboxSynchronizer::MailboxSynchronizer() {}
56
57 MailboxSynchronizer::~MailboxSynchronizer() {
58 DCHECK_EQ(0U, textures_.size());
59 }
60
61 void MailboxSynchronizer::ReassociateMailboxLocked(
62 const TargetName& target_name,
63 TextureGroup* group) {
64 lock_.AssertAcquired();
65 for (TextureMap::iterator it = textures_.begin(); it != textures_.end();
66 it++) {
67 std::set<TargetName>::iterator mb_it =
68 it->second.group->mailboxes.find(target_name);
69 if (it->second.group != group &&
70 mb_it != it->second.group->mailboxes.end()) {
71 it->second.group->mailboxes.erase(mb_it);
72 }
73 }
74 group->mailboxes.insert(target_name);
75 }
76
77 linked_ptr<MailboxSynchronizer::TextureGroup>
78 MailboxSynchronizer::GetGroupForMailboxLocked(const TargetName& target_name) {
79 lock_.AssertAcquired();
80 for (TextureMap::iterator it = textures_.begin(); it != textures_.end();
81 it++) {
82 std::set<TargetName>::const_iterator mb_it =
83 it->second.group->mailboxes.find(target_name);
84 if (mb_it != it->second.group->mailboxes.end())
85 return it->second.group;
86 }
87 return make_linked_ptr<MailboxSynchronizer::TextureGroup>(NULL);
88 }
89
90 Texture* MailboxSynchronizer::CreateTextureFromMailbox(unsigned target,
91 const Mailbox& mailbox) {
92 base::AutoLock lock(lock_);
93 TargetName target_name(target, mailbox);
94 linked_ptr<TextureGroup> group = GetGroupForMailboxLocked(target_name);
95 if (group.get()) {
96 Texture* new_texture = group->definition.CreateTexture();
97 if (new_texture)
98 textures_.insert(std::make_pair(new_texture, TextureVersion(group)));
99 return new_texture;
100 }
101
102 return NULL;
103 }
104
105 void MailboxSynchronizer::TextureDeleted(Texture* texture) {
106 base::AutoLock lock(lock_);
107 textures_.erase(texture);
108 }
109
110 void MailboxSynchronizer::PushTextureUpdates(MailboxManager* manager) {
111 base::AutoLock lock(lock_);
112 for (MailboxManager::MailboxToTextureMap::const_iterator texture_it =
113 manager->mailbox_to_textures_.begin();
114 texture_it != manager->mailbox_to_textures_.end();
115 texture_it++) {
116 TargetName target_name(texture_it->first.target, texture_it->first.mailbox);
117 Texture* texture = texture_it->second->first;
118 // TODO(sievers)
piman 2014/03/13 04:41:58 nit: TODO? bug#?
no sievers 2014/03/13 20:50:15 Done.
119 bool needs_mips = texture->min_filter() != GL_NEAREST &&
120 texture->min_filter() != GL_LINEAR;
121 if (target_name.target != GL_TEXTURE_2D || needs_mips)
122 continue;
123
124 TextureMap::iterator it = textures_.find(texture);
125 if (it != textures_.end()) {
126 gfx::GLImage* gl_image = texture->GetLevelImage(texture->target(), 0);
127 TextureGroup* group = it->second.group.get();
piman 2014/03/13 04:41:58 nit: it would be nice to give a name to it->second
no sievers 2014/03/13 20:50:15 Done.
128 std::set<TargetName>::const_iterator mb_it =
129 group->mailboxes.find(target_name);
130 scoped_refptr<NativeImageBuffer> image = group->definition.image();
131 if (mb_it == group->mailboxes.end()) {
132 // We previously did not associate this texture with the given mailbox.
133 // Unlink other texture groups from the mailbox.
134 ReassociateMailboxLocked(target_name, group);
135 }
136
137 // Make sure we don't clobber with an older version
138 if (group->definition.IsNewerThan(it->second.version))
piman 2014/03/13 04:41:58 Do we want IsNewerOrEqual? If versions are equal,
no sievers 2014/03/13 20:50:15 Good point. Done.
139 continue;
140
141 // Also don't push redundant updates. Note that it would break the
142 // versioning.
143 if (group->definition.Matches(texture))
144 continue;
145
146 if (gl_image && !image->IsClient(gl_image)) {
147 LOG(ERROR) << "MailboxSync: Incompatible attachment";
148 return;
piman 2014/03/13 04:41:58 What are the conditions under which this would hap
no sievers 2014/03/13 20:50:15 Oops, thanks. The 'return' is a total typo, it sho
149 }
150
151 group->definition = TextureDefinition(
152 target_name.target,
153 texture,
154 ++it->second.version,
155 gl_image ? image : NULL);
156 } else {
157 linked_ptr<TextureGroup> group = make_linked_ptr(new TextureGroup(
158 TextureDefinition(target_name.target, texture, 1, NULL)));
159
160 // Unlink other textures from this mailbox in case the name is not new.
161 ReassociateMailboxLocked(target_name, group.get());
162 textures_.insert(std::make_pair(texture, TextureVersion(group)));
163 }
164 }
165 // Make sure all write fences are flushed.
166 glFlush();
167 }
168
169 void MailboxSynchronizer::PullTextureUpdates(MailboxManager* manager) {
170 base::AutoLock lock(lock_);
171 for (MailboxManager::MailboxToTextureMap::const_iterator texture_it =
172 manager->mailbox_to_textures_.begin();
173 texture_it != manager->mailbox_to_textures_.end();
174 texture_it++) {
175 Texture* texture = texture_it->second->first;
176 TextureMap::iterator it = textures_.find(texture);
177 if (it != textures_.end()) {
178 TextureDefinition& definition = it->second.group->definition;
179 if (!definition.IsNewerThan(it->second.version))
180 continue;
181 it->second.version = definition.version();
182 definition.UpdateTexture(texture);
183 }
184 }
185 }
186
187 } // namespace gles2
188 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698