diff options
-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 | ||||
-rw-r--r-- | gpu/command_buffer/service/mailbox_manager.cc | 6 | ||||
-rw-r--r-- | gpu/command_buffer/service/mailbox_manager.h | 5 |
8 files changed, 107 insertions, 3 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 diff --git a/gpu/command_buffer/service/mailbox_manager.cc b/gpu/command_buffer/service/mailbox_manager.cc index 9cdf0bc..ec7ad94 100644 --- a/gpu/command_buffer/service/mailbox_manager.cc +++ b/gpu/command_buffer/service/mailbox_manager.cc @@ -15,9 +15,9 @@ namespace gles2 { MailboxManager::MailboxManager() : hmac_(crypto::HMAC::SHA256), textures_(std::ptr_fun(&MailboxManager::TargetNameLess)) { - unsigned char private_key[GL_MAILBOX_SIZE_CHROMIUM / 2]; - base::RandBytes(private_key, sizeof(private_key)); - bool success = hmac_.Init(private_key, sizeof(private_key)); + base::RandBytes(private_key_, sizeof(private_key_)); + bool success = hmac_.Init( + base::StringPiece(private_key_, sizeof(private_key_))); DCHECK(success); } diff --git a/gpu/command_buffer/service/mailbox_manager.h b/gpu/command_buffer/service/mailbox_manager.h index f9ae588..337998d 100644 --- a/gpu/command_buffer/service/mailbox_manager.h +++ b/gpu/command_buffer/service/mailbox_manager.h @@ -56,6 +56,10 @@ class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> { // manager. void DestroyOwnedTextures(TextureManager* owner, bool have_context); + std::string private_key() { + return std::string(private_key_, sizeof(private_key_)); + } + private: friend class base::RefCounted<MailboxManager>; @@ -86,6 +90,7 @@ class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> { std::pointer_to_binary_function< const TargetName&, const TargetName&, bool> > TextureDefinitionMap; + char private_key_[GL_MAILBOX_SIZE_CHROMIUM / 2]; crypto::HMAC hmac_; TextureDefinitionMap textures_; |