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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/mailbox_synchronizer.cc
diff --git a/gpu/command_buffer/service/mailbox_synchronizer.cc b/gpu/command_buffer/service/mailbox_synchronizer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..31f3e0181ebeff62835536f2ef4281c712902476
--- /dev/null
+++ b/gpu/command_buffer/service/mailbox_synchronizer.cc
@@ -0,0 +1,188 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gpu/command_buffer/service/mailbox_synchronizer.h"
+
+#include "base/bind.h"
+#include "gpu/command_buffer/service/mailbox_manager.h"
+#include "gpu/command_buffer/service/texture_manager.h"
+
+namespace gpu {
+namespace gles2 {
+
+namespace {
+
+MailboxSynchronizer* g_instance = NULL;
+
+} // anonymous namespace
+
+// static
+bool MailboxSynchronizer::Initialize() {
+ DCHECK(!g_instance);
+ g_instance = new MailboxSynchronizer;
+ return true;
+}
+
+// static
+void MailboxSynchronizer::Terminate() {
+ DCHECK(g_instance);
+ delete g_instance;
+ g_instance = NULL;
+}
+
+// static
+MailboxSynchronizer* MailboxSynchronizer::GetInstance() {
+ return g_instance;
+}
+
+MailboxSynchronizer::TargetName::TargetName(unsigned target,
+ const Mailbox& mailbox)
+ : target(target), mailbox(mailbox) {}
+
+MailboxSynchronizer::TextureGroup::TextureGroup(
+ const TextureDefinition& definition)
+ : definition(definition) {}
+
+MailboxSynchronizer::TextureGroup::~TextureGroup() {}
+
+MailboxSynchronizer::TextureVersion::TextureVersion(
+ linked_ptr<TextureGroup> group)
+ : version(group->definition.version()), group(group) {}
+
+MailboxSynchronizer::TextureVersion::~TextureVersion() {}
+
+MailboxSynchronizer::MailboxSynchronizer() {}
+
+MailboxSynchronizer::~MailboxSynchronizer() {
+ DCHECK_EQ(0U, textures_.size());
+}
+
+void MailboxSynchronizer::ReassociateMailboxLocked(
+ const TargetName& target_name,
+ TextureGroup* group) {
+ lock_.AssertAcquired();
+ for (TextureMap::iterator it = textures_.begin(); it != textures_.end();
+ it++) {
+ std::set<TargetName>::iterator mb_it =
+ it->second.group->mailboxes.find(target_name);
+ if (it->second.group != group &&
+ mb_it != it->second.group->mailboxes.end()) {
+ it->second.group->mailboxes.erase(mb_it);
+ }
+ }
+ group->mailboxes.insert(target_name);
+}
+
+linked_ptr<MailboxSynchronizer::TextureGroup>
+MailboxSynchronizer::GetGroupForMailboxLocked(const TargetName& target_name) {
+ lock_.AssertAcquired();
+ for (TextureMap::iterator it = textures_.begin(); it != textures_.end();
+ it++) {
+ std::set<TargetName>::const_iterator mb_it =
+ it->second.group->mailboxes.find(target_name);
+ if (mb_it != it->second.group->mailboxes.end())
+ return it->second.group;
+ }
+ return make_linked_ptr<MailboxSynchronizer::TextureGroup>(NULL);
+}
+
+Texture* MailboxSynchronizer::CreateTextureFromMailbox(unsigned target,
+ const Mailbox& mailbox) {
+ base::AutoLock lock(lock_);
+ TargetName target_name(target, mailbox);
+ linked_ptr<TextureGroup> group = GetGroupForMailboxLocked(target_name);
+ if (group.get()) {
+ Texture* new_texture = group->definition.CreateTexture();
+ if (new_texture)
+ textures_.insert(std::make_pair(new_texture, TextureVersion(group)));
+ return new_texture;
+ }
+
+ return NULL;
+}
+
+void MailboxSynchronizer::TextureDeleted(Texture* texture) {
+ base::AutoLock lock(lock_);
+ textures_.erase(texture);
+}
+
+void MailboxSynchronizer::PushTextureUpdates(MailboxManager* manager) {
+ base::AutoLock lock(lock_);
+ for (MailboxManager::MailboxToTextureMap::const_iterator texture_it =
+ manager->mailbox_to_textures_.begin();
+ texture_it != manager->mailbox_to_textures_.end();
+ texture_it++) {
+ TargetName target_name(texture_it->first.target, texture_it->first.mailbox);
+ Texture* texture = texture_it->second->first;
+ // TODO(sievers)
piman 2014/03/13 04:41:58 nit: TODO? bug#?
no sievers 2014/03/13 20:50:15 Done.
+ bool needs_mips = texture->min_filter() != GL_NEAREST &&
+ texture->min_filter() != GL_LINEAR;
+ if (target_name.target != GL_TEXTURE_2D || needs_mips)
+ continue;
+
+ TextureMap::iterator it = textures_.find(texture);
+ if (it != textures_.end()) {
+ gfx::GLImage* gl_image = texture->GetLevelImage(texture->target(), 0);
+ 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.
+ std::set<TargetName>::const_iterator mb_it =
+ group->mailboxes.find(target_name);
+ scoped_refptr<NativeImageBuffer> image = group->definition.image();
+ if (mb_it == group->mailboxes.end()) {
+ // We previously did not associate this texture with the given mailbox.
+ // Unlink other texture groups from the mailbox.
+ ReassociateMailboxLocked(target_name, group);
+ }
+
+ // Make sure we don't clobber with an older version
+ 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.
+ continue;
+
+ // Also don't push redundant updates. Note that it would break the
+ // versioning.
+ if (group->definition.Matches(texture))
+ continue;
+
+ if (gl_image && !image->IsClient(gl_image)) {
+ LOG(ERROR) << "MailboxSync: Incompatible attachment";
+ 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
+ }
+
+ group->definition = TextureDefinition(
+ target_name.target,
+ texture,
+ ++it->second.version,
+ gl_image ? image : NULL);
+ } else {
+ linked_ptr<TextureGroup> group = make_linked_ptr(new TextureGroup(
+ TextureDefinition(target_name.target, texture, 1, NULL)));
+
+ // Unlink other textures from this mailbox in case the name is not new.
+ ReassociateMailboxLocked(target_name, group.get());
+ textures_.insert(std::make_pair(texture, TextureVersion(group)));
+ }
+ }
+ // Make sure all write fences are flushed.
+ glFlush();
+}
+
+void MailboxSynchronizer::PullTextureUpdates(MailboxManager* manager) {
+ base::AutoLock lock(lock_);
+ for (MailboxManager::MailboxToTextureMap::const_iterator texture_it =
+ manager->mailbox_to_textures_.begin();
+ texture_it != manager->mailbox_to_textures_.end();
+ texture_it++) {
+ Texture* texture = texture_it->second->first;
+ TextureMap::iterator it = textures_.find(texture);
+ if (it != textures_.end()) {
+ TextureDefinition& definition = it->second.group->definition;
+ if (!definition.IsNewerThan(it->second.version))
+ continue;
+ it->second.version = definition.version();
+ definition.UpdateTexture(texture);
+ }
+ }
+}
+
+} // namespace gles2
+} // namespace gpu

Powered by Google App Engine
This is Rietveld 408576698