OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if defined(OS_WIN) | 5 #if defined(OS_WIN) |
6 #include <windows.h> | 6 #include <windows.h> |
7 #endif | 7 #endif |
8 | 8 |
9 #include "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
| 16 #include "base/rand_util.h" |
16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
17 #include "content/common/child_process.h" | 18 #include "content/common/child_process.h" |
18 #include "content/common/gpu/gpu_channel_manager.h" | 19 #include "content/common/gpu/gpu_channel_manager.h" |
19 #include "content/common/gpu/gpu_messages.h" | 20 #include "content/common/gpu/gpu_messages.h" |
20 #include "content/common/gpu/sync_point_manager.h" | 21 #include "content/common/gpu/sync_point_manager.h" |
21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 23 #include "crypto/hmac.h" |
22 #include "gpu/command_buffer/service/image_manager.h" | 24 #include "gpu/command_buffer/service/image_manager.h" |
23 #include "gpu/command_buffer/service/mailbox_manager.h" | 25 #include "gpu/command_buffer/service/mailbox_manager.h" |
24 #include "gpu/command_buffer/service/gpu_scheduler.h" | 26 #include "gpu/command_buffer/service/gpu_scheduler.h" |
25 #include "ipc/ipc_channel.h" | 27 #include "ipc/ipc_channel.h" |
26 #include "ipc/ipc_channel_proxy.h" | 28 #include "ipc/ipc_channel_proxy.h" |
27 #include "ui/gl/gl_context.h" | 29 #include "ui/gl/gl_context.h" |
28 #include "ui/gl/gl_image.h" | 30 #include "ui/gl/gl_image.h" |
29 #include "ui/gl/gl_surface.h" | 31 #include "ui/gl/gl_surface.h" |
30 | 32 |
31 #if defined(OS_POSIX) | 33 #if defined(OS_POSIX) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // NOTE: this is a pointer to a weak pointer. It is never dereferenced on the | 138 // NOTE: this is a pointer to a weak pointer. It is never dereferenced on the |
137 // IO thread, it's only passed through - therefore the WeakPtr assumptions are | 139 // IO thread, it's only passed through - therefore the WeakPtr assumptions are |
138 // respected. | 140 // respected. |
139 base::WeakPtr<GpuChannel>* gpu_channel_; | 141 base::WeakPtr<GpuChannel>* gpu_channel_; |
140 IPC::Channel* channel_; | 142 IPC::Channel* channel_; |
141 scoped_refptr<SyncPointManager> sync_point_manager_; | 143 scoped_refptr<SyncPointManager> sync_point_manager_; |
142 scoped_refptr<base::MessageLoopProxy> message_loop_; | 144 scoped_refptr<base::MessageLoopProxy> message_loop_; |
143 scoped_refptr<gpu::RefCountedCounter> unprocessed_messages_; | 145 scoped_refptr<gpu::RefCountedCounter> unprocessed_messages_; |
144 }; | 146 }; |
145 | 147 |
| 148 // Generates mailbox names for clients of the GPU process on the IO thread. |
| 149 class MailboxMessageFilter : public IPC::ChannelProxy::MessageFilter { |
| 150 public: |
| 151 explicit MailboxMessageFilter(const std::string& private_key) |
| 152 : channel_(NULL), |
| 153 hmac_(crypto::HMAC::SHA256) { |
| 154 bool success = hmac_.Init(base::StringPiece(private_key)); |
| 155 DCHECK(success); |
| 156 } |
| 157 |
| 158 virtual void OnFilterAdded(IPC::Channel* channel) { |
| 159 DCHECK(!channel_); |
| 160 channel_ = channel; |
| 161 } |
| 162 |
| 163 virtual void OnFilterRemoved() { |
| 164 DCHECK(channel_); |
| 165 channel_ = NULL; |
| 166 } |
| 167 |
| 168 virtual bool OnMessageReceived(const IPC::Message& message) { |
| 169 DCHECK(channel_); |
| 170 |
| 171 bool handled = true; |
| 172 IPC_BEGIN_MESSAGE_MAP(MailboxMessageFilter, message) |
| 173 IPC_MESSAGE_HANDLER(GpuChannelMsg_GenerateMailboxNames, |
| 174 OnGenerateMailboxNames) |
| 175 IPC_MESSAGE_UNHANDLED(handled = false) |
| 176 IPC_END_MESSAGE_MAP() |
| 177 |
| 178 return handled; |
| 179 } |
| 180 |
| 181 bool Send(IPC::Message* message) { |
| 182 return channel_->Send(message); |
| 183 } |
| 184 |
| 185 private: |
| 186 ~MailboxMessageFilter() { |
| 187 } |
| 188 |
| 189 // Message handlers. |
| 190 void OnGenerateMailboxNames(unsigned num, std::vector<std::string>* result) { |
| 191 TRACE_EVENT1("gpu", "OnGenerateMailboxNames", "num", num); |
| 192 |
| 193 result->resize(num); |
| 194 |
| 195 for (unsigned i = 0; i < num; ++i) { |
| 196 char name[GL_MAILBOX_SIZE_CHROMIUM]; |
| 197 base::RandBytes(name, sizeof(name) / 2); |
| 198 |
| 199 bool success = hmac_.Sign( |
| 200 base::StringPiece(name, sizeof(name) / 2), |
| 201 reinterpret_cast<unsigned char*>(name) + sizeof(name) / 2, |
| 202 sizeof(name) / 2); |
| 203 DCHECK(success); |
| 204 |
| 205 (*result)[i].assign(name, sizeof(name)); |
| 206 } |
| 207 } |
| 208 |
| 209 IPC::Channel* channel_; |
| 210 crypto::HMAC hmac_; |
| 211 }; |
146 } // anonymous namespace | 212 } // anonymous namespace |
147 | 213 |
148 GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager, | 214 GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager, |
149 GpuWatchdog* watchdog, | 215 GpuWatchdog* watchdog, |
150 gfx::GLShareGroup* share_group, | 216 gfx::GLShareGroup* share_group, |
151 gpu::gles2::MailboxManager* mailbox, | 217 gpu::gles2::MailboxManager* mailbox, |
152 int client_id, | 218 int client_id, |
153 bool software) | 219 bool software) |
154 : gpu_channel_manager_(gpu_channel_manager), | 220 : gpu_channel_manager_(gpu_channel_manager), |
155 unprocessed_messages_(new gpu::RefCountedCounter), | 221 unprocessed_messages_(new gpu::RefCountedCounter), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 257 |
192 base::WeakPtr<GpuChannel>* weak_ptr(new base::WeakPtr<GpuChannel>( | 258 base::WeakPtr<GpuChannel>* weak_ptr(new base::WeakPtr<GpuChannel>( |
193 weak_factory_.GetWeakPtr())); | 259 weak_factory_.GetWeakPtr())); |
194 scoped_refptr<SyncPointMessageFilter> filter(new SyncPointMessageFilter( | 260 scoped_refptr<SyncPointMessageFilter> filter(new SyncPointMessageFilter( |
195 weak_ptr, | 261 weak_ptr, |
196 gpu_channel_manager_->sync_point_manager(), | 262 gpu_channel_manager_->sync_point_manager(), |
197 base::MessageLoopProxy::current(), | 263 base::MessageLoopProxy::current(), |
198 unprocessed_messages_)); | 264 unprocessed_messages_)); |
199 channel_->AddFilter(filter); | 265 channel_->AddFilter(filter); |
200 | 266 |
| 267 channel_->AddFilter( |
| 268 new MailboxMessageFilter(mailbox_manager_->private_key())); |
| 269 |
201 return true; | 270 return true; |
202 } | 271 } |
203 | 272 |
204 std::string GpuChannel::GetChannelName() { | 273 std::string GpuChannel::GetChannelName() { |
205 return channel_id_; | 274 return channel_id_; |
206 } | 275 } |
207 | 276 |
208 #if defined(OS_POSIX) | 277 #if defined(OS_POSIX) |
209 int GpuChannel::TakeRendererFileDescriptor() { | 278 int GpuChannel::TakeRendererFileDescriptor() { |
210 if (!channel_.get()) { | 279 if (!channel_.get()) { |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 } | 672 } |
604 } | 673 } |
605 | 674 |
606 GpuChannelMsg_CollectRenderingStatsForSurface::WriteReplyParams( | 675 GpuChannelMsg_CollectRenderingStatsForSurface::WriteReplyParams( |
607 reply_message, | 676 reply_message, |
608 stats); | 677 stats); |
609 Send(reply_message); | 678 Send(reply_message); |
610 } | 679 } |
611 | 680 |
612 } // namespace content | 681 } // namespace content |
OLD | NEW |