diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-07 04:45:18 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-07 04:45:18 +0000 |
commit | bba2ff826889c3c06c492281bb34f0a09e0aba68 (patch) | |
tree | a7a7da859cd3e121cbe20d01e751e0c120b14a9d /content | |
parent | be71a04c0b865e679c36c1bc2b7fc315d1dd1aee (diff) | |
download | chromium_src-bba2ff826889c3c06c492281bb34f0a09e0aba68.zip chromium_src-bba2ff826889c3c06c492281bb34f0a09e0aba68.tar.gz chromium_src-bba2ff826889c3c06c492281bb34f0a09e0aba68.tar.bz2 |
IPC to generate mailbox names on the GPU process IO thread.
This allows the browser and renderer processes to get new unique mailbox names without syncing with the GPU process main thread.
Review URL: https://chromiumcodereview.appspot.com/11362053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166351 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/common/gpu/client/command_buffer_proxy_impl.cc | 7 | ||||
-rw-r--r-- | content/common/gpu/client/command_buffer_proxy_impl.h | 6 | ||||
-rw-r--r-- | content/common/gpu/client/gpu_channel_host.cc | 7 | ||||
-rw-r--r-- | content/common/gpu/client/gpu_channel_host.h | 6 | ||||
-rw-r--r-- | content/common/gpu/gpu_channel.cc | 69 | ||||
-rw-r--r-- | content/common/gpu/gpu_messages.h | 4 |
6 files changed, 99 insertions, 0 deletions
diff --git a/content/common/gpu/client/command_buffer_proxy_impl.cc b/content/common/gpu/client/command_buffer_proxy_impl.cc index 5a332a5..c60d84c 100644 --- a/content/common/gpu/client/command_buffer_proxy_impl.cc +++ b/content/common/gpu/client/command_buffer_proxy_impl.cc @@ -461,6 +461,13 @@ bool CommandBufferProxyImpl::SignalSyncPoint(uint32 sync_point, return true; } + +bool CommandBufferProxyImpl::GenerateMailboxNames( + unsigned num, + std::vector<std::string>* names) { + return channel_->GenerateMailboxNames(num, names); +} + bool CommandBufferProxyImpl::SetParent( CommandBufferProxy* parent_command_buffer, uint32 parent_texture_id) { diff --git a/content/common/gpu/client/command_buffer_proxy_impl.h b/content/common/gpu/client/command_buffer_proxy_impl.h index e8fb3f4..38cf2d6 100644 --- a/content/common/gpu/client/command_buffer_proxy_impl.h +++ b/content/common/gpu/client/command_buffer_proxy_impl.h @@ -110,6 +110,12 @@ class CommandBufferProxyImpl bool SignalSyncPoint(uint32 sync_point, const base::Closure& callback); + // Generates n unique mailbox names that can be used with + // GL_texture_mailbox_CHROMIUM. Unlike genMailboxCHROMIUM, this IPC is + // handled only on the GPU process' IO thread, and so is not effectively + // a finish. + bool GenerateMailboxNames(unsigned num, std::vector<std::string>* names); + // Set a task that will be invoked the next time the window becomes invalid // and needs to be repainted. Takes ownership of task. void SetNotifyRepaintTask(const base::Closure& callback); diff --git a/content/common/gpu/client/gpu_channel_host.cc b/content/common/gpu/client/gpu_channel_host.cc index 2677550..294035d 100644 --- a/content/common/gpu/client/gpu_channel_host.cc +++ b/content/common/gpu/client/gpu_channel_host.cc @@ -242,6 +242,13 @@ void GpuChannelHost::RemoveRoute(int route_id) { channel_filter_.get(), route_id)); } +bool GpuChannelHost::GenerateMailboxNames(unsigned num, + std::vector<std::string>* names) { + TRACE_EVENT0("gpu", "GenerateMailboxName"); + AutoLock lock(context_lock_); + return Send(new GpuChannelMsg_GenerateMailboxNames(num, names)); +} + GpuChannelHost::~GpuChannelHost() {} diff --git a/content/common/gpu/client/gpu_channel_host.h b/content/common/gpu/client/gpu_channel_host.h index 38457e0..55454dc 100644 --- a/content/common/gpu/client/gpu_channel_host.h +++ b/content/common/gpu/client/gpu_channel_host.h @@ -152,6 +152,12 @@ class GpuChannelHost : public IPC::Sender, base::ProcessId gpu_pid() const { return channel_->peer_pid(); } int client_id() const { return client_id_; } + // Generates n unique mailbox names that can be used with + // GL_texture_mailbox_CHROMIUM. Unlike genMailboxCHROMIUM, this IPC is + // handled only on the GPU process' IO thread, and so is not effectively + // a finish. + bool GenerateMailboxNames(unsigned num, std::vector<std::string>* names); + private: friend class base::RefCountedThreadSafe<GpuChannelHost>; virtual ~GpuChannelHost(); diff --git a/content/common/gpu/gpu_channel.cc b/content/common/gpu/gpu_channel.cc index 4dc25c9..a2247db 100644 --- a/content/common/gpu/gpu_channel.cc +++ b/content/common/gpu/gpu_channel.cc @@ -13,12 +13,14 @@ #include "base/debug/trace_event.h" #include "base/message_loop_proxy.h" #include "base/process_util.h" +#include "base/rand_util.h" #include "base/string_util.h" #include "content/common/child_process.h" #include "content/common/gpu/gpu_channel_manager.h" #include "content/common/gpu/gpu_messages.h" #include "content/common/gpu/sync_point_manager.h" #include "content/public/common/content_switches.h" +#include "crypto/hmac.h" #include "gpu/command_buffer/service/image_manager.h" #include "gpu/command_buffer/service/mailbox_manager.h" #include "gpu/command_buffer/service/gpu_scheduler.h" @@ -143,6 +145,70 @@ class SyncPointMessageFilter : public IPC::ChannelProxy::MessageFilter { scoped_refptr<gpu::RefCountedCounter> unprocessed_messages_; }; +// Generates mailbox names for clients of the GPU process on the IO thread. +class MailboxMessageFilter : public IPC::ChannelProxy::MessageFilter { + public: + explicit MailboxMessageFilter(const std::string& private_key) + : channel_(NULL), + hmac_(crypto::HMAC::SHA256) { + bool success = hmac_.Init(base::StringPiece(private_key)); + DCHECK(success); + } + + virtual void OnFilterAdded(IPC::Channel* channel) { + DCHECK(!channel_); + channel_ = channel; + } + + virtual void OnFilterRemoved() { + DCHECK(channel_); + channel_ = NULL; + } + + virtual bool OnMessageReceived(const IPC::Message& message) { + DCHECK(channel_); + + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(MailboxMessageFilter, message) + IPC_MESSAGE_HANDLER(GpuChannelMsg_GenerateMailboxNames, + OnGenerateMailboxNames) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled; + } + + bool Send(IPC::Message* message) { + return channel_->Send(message); + } + + private: + ~MailboxMessageFilter() { + } + + // Message handlers. + void OnGenerateMailboxNames(unsigned num, std::vector<std::string>* result) { + TRACE_EVENT1("gpu", "OnGenerateMailboxNames", "num", num); + + result->resize(num); + + for (unsigned i = 0; i < num; ++i) { + char name[GL_MAILBOX_SIZE_CHROMIUM]; + base::RandBytes(name, sizeof(name) / 2); + + bool success = hmac_.Sign( + base::StringPiece(name, sizeof(name) / 2), + reinterpret_cast<unsigned char*>(name) + sizeof(name) / 2, + sizeof(name) / 2); + DCHECK(success); + + (*result)[i].assign(name, sizeof(name)); + } + } + + IPC::Channel* channel_; + crypto::HMAC hmac_; +}; } // anonymous namespace GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager, @@ -198,6 +264,9 @@ bool GpuChannel::Init(base::MessageLoopProxy* io_message_loop, unprocessed_messages_)); channel_->AddFilter(filter); + channel_->AddFilter( + new MailboxMessageFilter(mailbox_manager_->private_key())); + return true; } diff --git a/content/common/gpu/gpu_messages.h b/content/common/gpu/gpu_messages.h index 69e2352..8af0477 100644 --- a/content/common/gpu/gpu_messages.h +++ b/content/common/gpu/gpu_messages.h @@ -414,6 +414,10 @@ IPC_SYNC_MESSAGE_CONTROL2_1(GpuChannelMsg_CreateOffscreenCommandBuffer, IPC_SYNC_MESSAGE_CONTROL1_0(GpuChannelMsg_DestroyCommandBuffer, int32 /* instance_id */) +// Generates n new unique mailbox names. +IPC_SYNC_MESSAGE_CONTROL1_1(GpuChannelMsg_GenerateMailboxNames, + unsigned, /* num */ + std::vector<std::string> /* mailbox_names */) #if defined(OS_ANDROID) // Register the StreamTextureProxy class with the GPU process, so that |