| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "content/renderer/gpu/gpu_channel_host.h" | 5 #include "content/renderer/gpu/gpu_channel_host.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" |
| 7 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 8 #include "content/common/child_process.h" | 9 #include "content/common/child_process.h" |
| 9 #include "content/common/gpu/gpu_messages.h" | 10 #include "content/common/gpu/gpu_messages.h" |
| 10 #include "content/renderer/gpu/command_buffer_proxy.h" | 11 #include "content/renderer/gpu/command_buffer_proxy.h" |
| 11 #include "content/renderer/gpu/transport_texture_service.h" | 12 #include "content/renderer/gpu/transport_texture_service.h" |
| 12 #include "content/renderer/render_process.h" | 13 #include "content/renderer/render_process.h" |
| 13 #include "content/renderer/render_thread.h" | 14 #include "content/renderer/render_thread.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 #include "ipc/ipc_sync_message_filter.h" | 16 #include "ipc/ipc_sync_message_filter.h" |
| 16 | 17 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 34 listener_->OnMessageReceived(msg); | 35 listener_->OnMessageReceived(msg); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void GpuChannelHost::Listener::DispatchError() { | 38 void GpuChannelHost::Listener::DispatchError() { |
| 38 if (listener_.get()) | 39 if (listener_.get()) |
| 39 listener_->OnChannelError(); | 40 listener_->OnChannelError(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 GpuChannelHost::MessageFilter::MessageFilter(GpuChannelHost* parent) | 43 GpuChannelHost::MessageFilter::MessageFilter(GpuChannelHost* parent) |
| 43 : parent_(parent) { | 44 : parent_(parent) { |
| 44 DetachFromThread(); | |
| 45 } | 45 } |
| 46 | 46 |
| 47 GpuChannelHost::MessageFilter::~MessageFilter() { | 47 GpuChannelHost::MessageFilter::~MessageFilter() { |
| 48 | 48 |
| 49 } | 49 } |
| 50 | 50 |
| 51 void GpuChannelHost::MessageFilter::AddRoute( | 51 void GpuChannelHost::MessageFilter::AddRoute( |
| 52 int route_id, | 52 int route_id, |
| 53 base::WeakPtr<IPC::Channel::Listener> listener, | 53 base::WeakPtr<IPC::Channel::Listener> listener, |
| 54 scoped_refptr<MessageLoopProxy> loop) { | 54 scoped_refptr<MessageLoopProxy> loop) { |
| 55 DCHECK(CalledOnValidThread()); | 55 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); |
| 56 DCHECK(listeners_.find(route_id) == listeners_.end()); | 56 DCHECK(listeners_.find(route_id) == listeners_.end()); |
| 57 listeners_[route_id] = new GpuChannelHost::Listener(listener, loop); | 57 listeners_[route_id] = new GpuChannelHost::Listener(listener, loop); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void GpuChannelHost::MessageFilter::RemoveRoute(int route_id) { | 60 void GpuChannelHost::MessageFilter::RemoveRoute(int route_id) { |
| 61 DCHECK(CalledOnValidThread()); | 61 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); |
| 62 ListenerMap::iterator it = listeners_.find(route_id); | 62 ListenerMap::iterator it = listeners_.find(route_id); |
| 63 if (it != listeners_.end()) | 63 if (it != listeners_.end()) |
| 64 listeners_.erase(it); | 64 listeners_.erase(it); |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool GpuChannelHost::MessageFilter::OnMessageReceived( | 67 bool GpuChannelHost::MessageFilter::OnMessageReceived( |
| 68 const IPC::Message& message) { | 68 const IPC::Message& message) { |
| 69 DCHECK(CalledOnValidThread()); | 69 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); |
| 70 | |
| 71 // Never handle sync message replies or we will deadlock here. | 70 // Never handle sync message replies or we will deadlock here. |
| 72 if (message.is_reply()) | 71 if (message.is_reply()) |
| 73 return false; | 72 return false; |
| 74 | 73 |
| 75 DCHECK(message.routing_id() != MSG_ROUTING_CONTROL); | 74 DCHECK(message.routing_id() != MSG_ROUTING_CONTROL); |
| 76 | 75 |
| 77 ListenerMap::iterator it = listeners_.find(message.routing_id()); | 76 ListenerMap::iterator it = listeners_.find(message.routing_id()); |
| 78 | 77 |
| 79 if (it != listeners_.end()) { | 78 if (it != listeners_.end()) { |
| 80 const scoped_refptr<GpuChannelHost::Listener>& listener = it->second; | 79 const scoped_refptr<GpuChannelHost::Listener>& listener = it->second; |
| 81 listener->loop()->PostTask( | 80 listener->loop()->PostTask( |
| 82 FROM_HERE, | 81 FROM_HERE, |
| 83 NewRunnableMethod( | 82 NewRunnableMethod( |
| 84 listener.get(), | 83 listener.get(), |
| 85 &GpuChannelHost::Listener::DispatchMessage, | 84 &GpuChannelHost::Listener::DispatchMessage, |
| 86 message)); | 85 message)); |
| 87 } | 86 } |
| 88 | 87 |
| 89 return true; | 88 return true; |
| 90 } | 89 } |
| 91 | 90 |
| 92 void GpuChannelHost::MessageFilter::OnChannelError() { | 91 void GpuChannelHost::MessageFilter::OnChannelError() { |
| 93 DCHECK(CalledOnValidThread()); | 92 DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop()); |
| 94 | |
| 95 // Inform all the proxies that an error has occurred. This will be reported | 93 // Inform all the proxies that an error has occurred. This will be reported |
| 96 // via OpenGL as a lost context. | 94 // via OpenGL as a lost context. |
| 97 for (ListenerMap::iterator it = listeners_.begin(); | 95 for (ListenerMap::iterator it = listeners_.begin(); |
| 98 it != listeners_.end(); | 96 it != listeners_.end(); |
| 99 it++) { | 97 it++) { |
| 100 const scoped_refptr<GpuChannelHost::Listener>& listener = it->second; | 98 const scoped_refptr<GpuChannelHost::Listener>& listener = it->second; |
| 101 listener->loop()->PostTask( | 99 listener->loop()->PostTask( |
| 102 FROM_HERE, | 100 FROM_HERE, |
| 103 NewRunnableMethod( | 101 NewRunnableMethod( |
| 104 listener.get(), | 102 listener.get(), |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 308 } |
| 311 | 309 |
| 312 void GpuChannelHost::RemoveRoute(int route_id) { | 310 void GpuChannelHost::RemoveRoute(int route_id) { |
| 313 MessageLoopProxy* io_loop = RenderProcess::current()->io_message_loop_proxy(); | 311 MessageLoopProxy* io_loop = RenderProcess::current()->io_message_loop_proxy(); |
| 314 io_loop->PostTask(FROM_HERE, | 312 io_loop->PostTask(FROM_HERE, |
| 315 NewRunnableMethod( | 313 NewRunnableMethod( |
| 316 channel_filter_.get(), | 314 channel_filter_.get(), |
| 317 &GpuChannelHost::MessageFilter::RemoveRoute, | 315 &GpuChannelHost::MessageFilter::RemoveRoute, |
| 318 route_id)); | 316 route_id)); |
| 319 } | 317 } |
| OLD | NEW |