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

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::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 if (it->second.group != group)
68 it->second.group->mailboxes.erase(target_name);
69 }
70 group->mailboxes.insert(target_name);
71 }
72
73 linked_ptr<MailboxSynchronizer::TextureGroup>
74 MailboxSynchronizer::GetGroupForMailboxLocked(const TargetName& target_name) {
75 lock_.AssertAcquired();
76 for (TextureMap::iterator it = textures_.begin(); it != textures_.end();
77 it++) {
78 std::set<TargetName>::const_iterator mb_it =
79 it->second.group->mailboxes.find(target_name);
80 if (mb_it != it->second.group->mailboxes.end())
81 return it->second.group;
82 }
83 return make_linked_ptr<MailboxSynchronizer::TextureGroup>(NULL);
84 }
85
86 Texture* MailboxSynchronizer::CreateTextureFromMailbox(unsigned target,
87 const Mailbox& mailbox) {
88 base::AutoLock lock(lock_);
89 TargetName target_name(target, mailbox);
90 linked_ptr<TextureGroup> group = GetGroupForMailboxLocked(target_name);
91 if (group.get()) {
92 Texture* new_texture = group->definition.CreateTexture();
93 if (new_texture)
94 textures_.insert(std::make_pair(new_texture, TextureVersion(group)));
95 return new_texture;
96 }
97
98 return NULL;
99 }
100
101 void MailboxSynchronizer::TextureDeleted(Texture* texture) {
102 base::AutoLock lock(lock_);
103 textures_.erase(texture);
104 }
105
106 void MailboxSynchronizer::PushTextureUpdates(MailboxManager* manager) {
107 base::AutoLock lock(lock_);
108 for (MailboxManager::MailboxToTextureMap::const_iterator texture_it =
109 manager->mailbox_to_textures_.begin();
110 texture_it != manager->mailbox_to_textures_.end();
111 texture_it++) {
112 TargetName target_name(texture_it->first.target, texture_it->first.mailbox);
113 Texture* texture = texture_it->second->first;
114 // TODO(sievers)
115 bool needs_mips = texture->min_filter() != GL_NEAREST &&
116 texture->min_filter() != GL_LINEAR;
117 if (target_name.target != GL_TEXTURE_2D || needs_mips)
118 continue;
119
120 TextureMap::iterator it = textures_.find(texture);
121 if (it != textures_.end()) {
122 gfx::GLImage* gl_image = texture->GetLevelImage(texture->target(), 0);
123 TextureGroup* group = it->second.group.get();
124 std::set<TargetName>::const_iterator mb_it =
125 group->mailboxes.find(target_name);
126 if (mb_it == group->mailboxes.end()) {
127 // We previously did not associate this texture with the given mailbonx.
128 // Unlink other texture groups from the mailbox.
129 ReassociateMailboxLocked(target_name, group);
130 }
131
132 // Make sure we don't clobber with an older version
133 if (group->definition.IsNewerThan(it->second.version))
134 continue;
135
136 // Also don't push redundant updates. Note that it would break the
137 // versioning.
138 if (group->definition.Matches(texture))
139 continue;
140
141 if (gl_image && !group->definition.image()->IsClient(gl_image)) {
142 LOG(ERROR) << "MailboxSync: Incompatible attachment";
143 return;
144 }
145
146 group->definition = TextureDefinition(
147 target_name.target,
148 texture,
149 ++it->second.version,
150 gl_image ? group->definition.image() : NULL);
151 } else {
152 linked_ptr<TextureGroup> group = make_linked_ptr(new TextureGroup(
153 TextureDefinition(target_name.target, texture, 1, NULL)));
154
155 // Unlink other textures from this mailbox in case the name is not new.
156 ReassociateMailboxLocked(target_name, group.get());
157 textures_.insert(std::make_pair(texture, TextureVersion(group)));
158 }
159 }
160 // Make sure all write fences are flushed.
161 glFlush();
162 }
163
164 void MailboxSynchronizer::PullTextureUpdates(MailboxManager* manager) {
165 base::AutoLock lock(lock_);
166 for (MailboxManager::MailboxToTextureMap::const_iterator texture_it =
167 manager->mailbox_to_textures_.begin();
168 texture_it != manager->mailbox_to_textures_.end();
169 texture_it++) {
170 Texture* texture = texture_it->second->first;
171 TextureMap::iterator it = textures_.find(texture);
172 if (it != textures_.end()) {
173 TextureDefinition& definition = it->second.group->definition;
174 if (!definition.IsNewerThan(it->second.version))
175 continue;
176 it->second.version = definition.version();
177 definition.UpdateTexture(texture);
178 }
179 }
180 }
181
182 } // namespace gles2
183 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698