Commit de171202 authored by dcheng@chromium.org's avatar dcheng@chromium.org

Remove custom Task implementations and re-exorcise old callbacks from gpu.

BUG=none
TEST=trybots


Review URL: http://codereview.chromium.org/8887001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113924 0039d316-1c4b-4281-b951-d872f2087c98
parent d051d9a0
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_process_host.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/base_switches.h" #include "base/base_switches.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/debug/trace_event.h" #include "base/debug/trace_event.h"
...@@ -65,22 +67,9 @@ int g_last_host_id = 0; ...@@ -65,22 +67,9 @@ int g_last_host_id = 0;
#if defined(TOOLKIT_USES_GTK) #if defined(TOOLKIT_USES_GTK)
class ReleasePermanentXIDDispatcher: public Task { void ReleasePermanentXIDDispatcher(gfx::PluginWindowHandle surface) {
public:
explicit ReleasePermanentXIDDispatcher(gfx::PluginWindowHandle surface);
void Run();
private:
gfx::PluginWindowHandle surface_;
};
ReleasePermanentXIDDispatcher::ReleasePermanentXIDDispatcher(
gfx::PluginWindowHandle surface)
: surface_(surface) {
}
void ReleasePermanentXIDDispatcher::Run() {
GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance();
manager->ReleasePermanentXID(surface_); manager->ReleasePermanentXID(surface);
} }
#endif #endif
...@@ -122,7 +111,7 @@ GpuProcessHost::SurfaceRef::SurfaceRef(gfx::PluginWindowHandle surface) ...@@ -122,7 +111,7 @@ GpuProcessHost::SurfaceRef::SurfaceRef(gfx::PluginWindowHandle surface)
GpuProcessHost::SurfaceRef::~SurfaceRef() { GpuProcessHost::SurfaceRef::~SurfaceRef() {
BrowserThread::PostTask(BrowserThread::UI, BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE, FROM_HERE,
new ReleasePermanentXIDDispatcher(surface_)); base::Bind(&ReleasePermanentXIDDispatcher, surface_));
} }
#endif // defined(TOOLKIT_USES_GTK) #endif // defined(TOOLKIT_USES_GTK)
...@@ -233,7 +222,7 @@ void GpuProcessHost::SendOnIO(int renderer_id, ...@@ -233,7 +222,7 @@ void GpuProcessHost::SendOnIO(int renderer_id,
IPC::Message* message) { IPC::Message* message) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
NewRunnableFunction( base::Bind(
&SendGpuProcessMessage, renderer_id, cause, message)); &SendGpuProcessMessage, renderer_id, cause, message));
} }
...@@ -275,7 +264,7 @@ GpuProcessHost::GpuProcessHost(int host_id) ...@@ -275,7 +264,7 @@ GpuProcessHost::GpuProcessHost(int host_id)
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, BrowserThread::UI,
FROM_HERE, FROM_HERE,
NewRunnableFunction(&GpuProcessHostUIShim::Create, host_id)); base::Bind(base::IgnoreResult(&GpuProcessHostUIShim::Create), host_id));
} }
GpuProcessHost::~GpuProcessHost() { GpuProcessHost::~GpuProcessHost() {
...@@ -314,8 +303,7 @@ GpuProcessHost::~GpuProcessHost() { ...@@ -314,8 +303,7 @@ GpuProcessHost::~GpuProcessHost() {
BrowserThread::PostTask(BrowserThread::UI, BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE, FROM_HERE,
NewRunnableFunction(GpuProcessHostUIShim::Destroy, base::Bind(&GpuProcessHostUIShim::Destroy, host_id_));
host_id_));
} }
bool GpuProcessHost::Init() { bool GpuProcessHost::Init() {
...@@ -353,7 +341,7 @@ void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { ...@@ -353,7 +341,7 @@ void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, BrowserThread::UI,
FROM_HERE, FROM_HERE,
new RouteToGpuProcessHostUIShimTask(host_id_, message)); base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message));
} }
bool GpuProcessHost::Send(IPC::Message* msg) { bool GpuProcessHost::Send(IPC::Message* msg) {
...@@ -388,24 +376,23 @@ void GpuProcessHost::OnChannelConnected(int32 peer_pid) { ...@@ -388,24 +376,23 @@ void GpuProcessHost::OnChannelConnected(int32 peer_pid) {
void GpuProcessHost::EstablishGpuChannel( void GpuProcessHost::EstablishGpuChannel(
int renderer_id, int renderer_id,
EstablishChannelCallback *callback) { const EstablishChannelCallback& callback) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
TRACE_EVENT0("gpu", "GpuProcessHostUIShim::EstablishGpuChannel"); TRACE_EVENT0("gpu", "GpuProcessHostUIShim::EstablishGpuChannel");
linked_ptr<EstablishChannelCallback> wrapped_callback(callback);
// If GPU features are already blacklisted, no need to establish the channel. // If GPU features are already blacklisted, no need to establish the channel.
if (!GpuDataManager::GetInstance()->GpuAccessAllowed()) { if (!GpuDataManager::GetInstance()->GpuAccessAllowed()) {
EstablishChannelError( EstablishChannelError(
wrapped_callback.release(), IPC::ChannelHandle(), callback, IPC::ChannelHandle(),
base::kNullProcessHandle, content::GPUInfo()); base::kNullProcessHandle, content::GPUInfo());
return; return;
} }
if (Send(new GpuMsg_EstablishChannel(renderer_id))) { if (Send(new GpuMsg_EstablishChannel(renderer_id))) {
channel_requests_.push(wrapped_callback); channel_requests_.push(callback);
} else { } else {
EstablishChannelError( EstablishChannelError(
wrapped_callback.release(), IPC::ChannelHandle(), callback, IPC::ChannelHandle(),
base::kNullProcessHandle, content::GPUInfo()); base::kNullProcessHandle, content::GPUInfo());
} }
} }
...@@ -415,9 +402,8 @@ void GpuProcessHost::CreateViewCommandBuffer( ...@@ -415,9 +402,8 @@ void GpuProcessHost::CreateViewCommandBuffer(
int32 render_view_id, int32 render_view_id,
int32 renderer_id, int32 renderer_id,
const GPUCreateCommandBufferConfig& init_params, const GPUCreateCommandBufferConfig& init_params,
CreateCommandBufferCallback* callback) { const CreateCommandBufferCallback& callback) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback);
#if defined(TOOLKIT_USES_GTK) #if defined(TOOLKIT_USES_GTK)
ViewID view_id(renderer_id, render_view_id); ViewID view_id(renderer_id, render_view_id);
...@@ -437,13 +423,13 @@ void GpuProcessHost::CreateViewCommandBuffer( ...@@ -437,13 +423,13 @@ void GpuProcessHost::CreateViewCommandBuffer(
if (compositing_surface != gfx::kNullPluginWindow && if (compositing_surface != gfx::kNullPluginWindow &&
Send(new GpuMsg_CreateViewCommandBuffer( Send(new GpuMsg_CreateViewCommandBuffer(
compositing_surface, render_view_id, renderer_id, init_params))) { compositing_surface, render_view_id, renderer_id, init_params))) {
create_command_buffer_requests_.push(wrapped_callback); create_command_buffer_requests_.push(callback);
#if defined(TOOLKIT_USES_GTK) #if defined(TOOLKIT_USES_GTK)
surface_refs_.insert(std::pair<ViewID, linked_ptr<SurfaceRef> >( surface_refs_.insert(std::pair<ViewID, linked_ptr<SurfaceRef> >(
view_id, surface_ref)); view_id, surface_ref));
#endif #endif
} else { } else {
CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); CreateCommandBufferError(callback, MSG_ROUTING_NONE);
} }
} }
...@@ -453,7 +439,7 @@ void GpuProcessHost::OnChannelEstablished( ...@@ -453,7 +439,7 @@ void GpuProcessHost::OnChannelEstablished(
// have been notified of its process handle. // have been notified of its process handle.
DCHECK(gpu_process_); DCHECK(gpu_process_);
linked_ptr<EstablishChannelCallback> callback = channel_requests_.front(); EstablishChannelCallback callback = channel_requests_.front();
channel_requests_.pop(); channel_requests_.pop();
// Currently if any of the GPU features are blacklisted, we don't establish a // Currently if any of the GPU features are blacklisted, we don't establish a
...@@ -461,7 +447,7 @@ void GpuProcessHost::OnChannelEstablished( ...@@ -461,7 +447,7 @@ void GpuProcessHost::OnChannelEstablished(
if (!channel_handle.name.empty() && if (!channel_handle.name.empty() &&
!GpuDataManager::GetInstance()->GpuAccessAllowed()) { !GpuDataManager::GetInstance()->GpuAccessAllowed()) {
Send(new GpuMsg_CloseChannel(channel_handle)); Send(new GpuMsg_CloseChannel(channel_handle));
EstablishChannelError(callback.release(), EstablishChannelError(callback,
IPC::ChannelHandle(), IPC::ChannelHandle(),
base::kNullProcessHandle, base::kNullProcessHandle,
content::GPUInfo()); content::GPUInfo());
...@@ -472,19 +458,19 @@ void GpuProcessHost::OnChannelEstablished( ...@@ -472,19 +458,19 @@ void GpuProcessHost::OnChannelEstablished(
return; return;
} }
callback->Run( callback.Run(
channel_handle, gpu_process_, GpuDataManager::GetInstance()->gpu_info()); channel_handle, gpu_process_, GpuDataManager::GetInstance()->gpu_info());
} }
void GpuProcessHost::OnCommandBufferCreated(const int32 route_id) { void GpuProcessHost::OnCommandBufferCreated(const int32 route_id) {
if (!create_command_buffer_requests_.empty()) { if (!create_command_buffer_requests_.empty()) {
linked_ptr<CreateCommandBufferCallback> callback = CreateCommandBufferCallback callback =
create_command_buffer_requests_.front(); create_command_buffer_requests_.front();
create_command_buffer_requests_.pop(); create_command_buffer_requests_.pop();
if (route_id == MSG_ROUTING_NONE) if (route_id == MSG_ROUTING_NONE)
CreateCommandBufferError(callback.release(), route_id); CreateCommandBufferError(callback, route_id);
else else
callback->Run(route_id); callback.Run(route_id);
} }
} }
...@@ -620,9 +606,9 @@ bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { ...@@ -620,9 +606,9 @@ bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) {
void GpuProcessHost::SendOutstandingReplies() { void GpuProcessHost::SendOutstandingReplies() {
// First send empty channel handles for all EstablishChannel requests. // First send empty channel handles for all EstablishChannel requests.
while (!channel_requests_.empty()) { while (!channel_requests_.empty()) {
linked_ptr<EstablishChannelCallback> callback = channel_requests_.front(); EstablishChannelCallback callback = channel_requests_.front();
channel_requests_.pop(); channel_requests_.pop();
EstablishChannelError(callback.release(), EstablishChannelError(callback,
IPC::ChannelHandle(), IPC::ChannelHandle(),
base::kNullProcessHandle, base::kNullProcessHandle,
content::GPUInfo()); content::GPUInfo());
...@@ -630,17 +616,14 @@ void GpuProcessHost::SendOutstandingReplies() { ...@@ -630,17 +616,14 @@ void GpuProcessHost::SendOutstandingReplies() {
} }
void GpuProcessHost::EstablishChannelError( void GpuProcessHost::EstablishChannelError(
EstablishChannelCallback* callback, const EstablishChannelCallback& callback,
const IPC::ChannelHandle& channel_handle, const IPC::ChannelHandle& channel_handle,
base::ProcessHandle renderer_process_for_gpu, base::ProcessHandle renderer_process_for_gpu,
const content::GPUInfo& gpu_info) { const content::GPUInfo& gpu_info) {
scoped_ptr<EstablishChannelCallback> wrapped_callback(callback); callback.Run(channel_handle, renderer_process_for_gpu, gpu_info);
wrapped_callback->Run(channel_handle, renderer_process_for_gpu, gpu_info);
} }
void GpuProcessHost::CreateCommandBufferError( void GpuProcessHost::CreateCommandBufferError(
CreateCommandBufferCallback* callback, int32 route_id) { const CreateCommandBufferCallback& callback, int32 route_id) {
scoped_ptr<GpuProcessHost::CreateCommandBufferCallback> callback.Run(route_id);
wrapped_callback(callback);
callback->Run(route_id);
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <map> #include <map>
#include <queue> #include <queue>
#include "base/callback_old.h" #include "base/callback.h"
#include "base/memory/linked_ptr.h" #include "base/memory/linked_ptr.h"
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "content/browser/browser_child_process_host.h" #include "content/browser/browser_child_process_host.h"
...@@ -58,18 +58,18 @@ class GpuProcessHost : public BrowserChildProcessHost, ...@@ -58,18 +58,18 @@ class GpuProcessHost : public BrowserChildProcessHost,
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
typedef Callback3<const IPC::ChannelHandle&, typedef base::Callback<void(const IPC::ChannelHandle&,
base::ProcessHandle, base::ProcessHandle,
const content::GPUInfo&>::Type const content::GPUInfo&)>
EstablishChannelCallback; EstablishChannelCallback;
// Tells the GPU process to create a new channel for communication with a // Tells the GPU process to create a new channel for communication with a
// renderer. Once the GPU process responds asynchronously with the IPC handle // renderer. Once the GPU process responds asynchronously with the IPC handle
// and GPUInfo, we call the callback. // and GPUInfo, we call the callback.
void EstablishGpuChannel( void EstablishGpuChannel(
int renderer_id, EstablishChannelCallback* callback); int renderer_id, const EstablishChannelCallback& callback);
typedef Callback1<int32>::Type CreateCommandBufferCallback; typedef base::Callback<void(int32)> CreateCommandBufferCallback;
// Tells the GPU process to create a new command buffer that draws into the // Tells the GPU process to create a new command buffer that draws into the
// window associated with the given renderer. // window associated with the given renderer.
...@@ -78,7 +78,7 @@ class GpuProcessHost : public BrowserChildProcessHost, ...@@ -78,7 +78,7 @@ class GpuProcessHost : public BrowserChildProcessHost,
int32 render_view_id, int32 render_view_id,
int32 renderer_id, int32 renderer_id,
const GPUCreateCommandBufferConfig& init_params, const GPUCreateCommandBufferConfig& init_params,
CreateCommandBufferCallback* callback); const CreateCommandBufferCallback& callback);
// Whether this GPU process is set up to use software rendering. // Whether this GPU process is set up to use software rendering.
bool software_rendering(); bool software_rendering();
...@@ -107,11 +107,11 @@ class GpuProcessHost : public BrowserChildProcessHost, ...@@ -107,11 +107,11 @@ class GpuProcessHost : public BrowserChildProcessHost,
void SendOutstandingReplies(); void SendOutstandingReplies();
void EstablishChannelError( void EstablishChannelError(
EstablishChannelCallback* callback, const EstablishChannelCallback& callback,
const IPC::ChannelHandle& channel_handle, const IPC::ChannelHandle& channel_handle,
base::ProcessHandle renderer_process_for_gpu, base::ProcessHandle renderer_process_for_gpu,
const content::GPUInfo& gpu_info); const content::GPUInfo& gpu_info);
void CreateCommandBufferError(CreateCommandBufferCallback* callback, void CreateCommandBufferError(const CreateCommandBufferCallback& callback,
int32 route_id); int32 route_id);
// The serial number of the GpuProcessHost / GpuProcessHostUIShim pair. // The serial number of the GpuProcessHost / GpuProcessHostUIShim pair.
...@@ -119,11 +119,10 @@ class GpuProcessHost : public BrowserChildProcessHost, ...@@ -119,11 +119,10 @@ class GpuProcessHost : public BrowserChildProcessHost,
// These are the channel requests that we have already sent to // These are the channel requests that we have already sent to
// the GPU process, but haven't heard back about yet. // the GPU process, but haven't heard back about yet.
std::queue<linked_ptr<EstablishChannelCallback> > channel_requests_; std::queue<EstablishChannelCallback> channel_requests_;
// The pending create command buffer requests we need to reply to. // The pending create command buffer requests we need to reply to.
std::queue<linked_ptr<CreateCommandBufferCallback> > std::queue<CreateCommandBufferCallback> create_command_buffer_requests_;
create_command_buffer_requests_;
#if defined(TOOLKIT_USES_GTK) #if defined(TOOLKIT_USES_GTK)
typedef std::pair<int32 /* renderer_id */, typedef std::pair<int32 /* renderer_id */,
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include "base/bind.h"
#include "base/debug/trace_event.h" #include "base/debug/trace_event.h"
#include "base/id_map.h" #include "base/id_map.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
...@@ -38,23 +39,13 @@ namespace { ...@@ -38,23 +39,13 @@ namespace {
base::LazyInstance<IDMap<GpuProcessHostUIShim> > g_hosts_by_id = base::LazyInstance<IDMap<GpuProcessHostUIShim> > g_hosts_by_id =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
class SendOnIOThreadTask : public Task { void SendOnIOThreadTask(int host_id, IPC::Message* msg) {
public: GpuProcessHost* host = GpuProcessHost::FromID(host_id);
SendOnIOThreadTask(int host_id, IPC::Message* msg) if (host)
: host_id_(host_id), host->Send(msg);
msg_(msg) { else
} delete msg;
}
private:
void Run() {
GpuProcessHost* host = GpuProcessHost::FromID(host_id_);
if (host)
host->Send(msg_.release());
}
int host_id_;
scoped_ptr<IPC::Message> msg_;
};
class ScopedSendOnIOThread { class ScopedSendOnIOThread {
public: public:
...@@ -68,8 +59,9 @@ class ScopedSendOnIOThread { ...@@ -68,8 +59,9 @@ class ScopedSendOnIOThread {
if (!cancelled_) { if (!cancelled_) {
BrowserThread::PostTask(BrowserThread::IO, BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE, FROM_HERE,
new SendOnIOThreadTask(host_id_, base::Bind(&SendOnIOThreadTask,
msg_.release())); host_id_,
msg_.release()));
} }
} }
...@@ -95,20 +87,10 @@ RenderWidgetHostView* GetRenderWidgetHostViewFromID(int render_process_id, ...@@ -95,20 +87,10 @@ RenderWidgetHostView* GetRenderWidgetHostViewFromID(int render_process_id,
} // namespace } // namespace
RouteToGpuProcessHostUIShimTask::RouteToGpuProcessHostUIShimTask( void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg) {
int host_id, GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id);
const IPC::Message& msg)
: host_id_(host_id),
msg_(msg) {
}
RouteToGpuProcessHostUIShimTask::~RouteToGpuProcessHostUIShimTask() {
}
void RouteToGpuProcessHostUIShimTask::Run() {
GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id_);
if (ui_shim) if (ui_shim)
ui_shim->OnMessageReceived(msg_); ui_shim->OnMessageReceived(msg);
} }
GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id) GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id)
...@@ -156,7 +138,9 @@ bool GpuProcessHostUIShim::Send(IPC::Message* msg) { ...@@ -156,7 +138,9 @@ bool GpuProcessHostUIShim::Send(IPC::Message* msg) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
return BrowserThread::PostTask(BrowserThread::IO, return BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE, FROM_HERE,
new SendOnIOThreadTask(host_id_, msg)); base::Bind(&SendOnIOThreadTask,
host_id_,
msg));
} }
bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) {
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/task.h"
#include "base/memory/linked_ptr.h" #include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
...@@ -36,18 +35,7 @@ namespace IPC { ...@@ -36,18 +35,7 @@ namespace IPC {
class Message; class Message;
} }
// A task that will forward an IPC message to the UI shim. void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg);
class RouteToGpuProcessHostUIShimTask : public Task {
public:
RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg);
virtual ~RouteToGpuProcessHostUIShimTask();
private:
virtual void Run() OVERRIDE;
int host_id_;
IPC::Message msg_;
};
class GpuProcessHostUIShim class GpuProcessHostUIShim
: public IPC::Channel::Listener, : public IPC::Channel::Listener,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "content/browser/renderer_host/gpu_message_filter.h" #include "content/browser/renderer_host/gpu_message_filter.h"
#include "base/callback.h" #include "base/bind.h"
#include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_process_host.h"
#include "content/browser/renderer_host/render_widget_helper.h" #include "content/browser/renderer_host/render_widget_helper.h"
#include "content/common/gpu/gpu_messages.h" #include "content/common/gpu/gpu_messages.h"
...@@ -41,98 +41,11 @@ bool GpuMessageFilter::OnMessageReceived( ...@@ -41,98 +41,11 @@ bool GpuMessageFilter::OnMessageReceived(
return handled; return handled;
} }
// Callbacks used in this file.
namespace {
class EstablishChannelCallback
: public CallbackRunner<Tuple3<const IPC::ChannelHandle&,
base::ProcessHandle,
const content::GPUInfo&> > {
public:
EstablishChannelCallback(GpuMessageFilter* filter, IPC::Message* reply)
: filter_(filter->AsWeakPtr()),
reply_(reply) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
}
virtual void RunWithParams(const TupleType& params) {
DispatchToMethod(this, &EstablishChannelCallback::Send, params);
}
void Send(const IPC::ChannelHandle& channel,
base::ProcessHandle gpu_process_for_browser,
const content::GPUInfo& gpu_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!filter_)
return;
base::ProcessHandle renderer_process_for_gpu;
if (gpu_process_for_browser != 0) {
#if defined(OS_WIN)
// Create a process handle that the renderer process can give to the GPU
// process to give it access to its handles.
DuplicateHandle(base::GetCurrentProcessHandle(),
filter_->peer_handle(),
gpu_process_for_browser,
&renderer_process_for_gpu,
PROCESS_DUP_HANDLE,
FALSE,
0);
#else
renderer_process_for_gpu = filter_->peer_handle();
#endif
} else {
renderer_process_for_gpu = 0;
}
GpuHostMsg_EstablishGpuChannel::WriteReplyParams(reply_,
channel,
renderer_process_for_gpu,
gpu_info);
filter_->Send(reply_);
}
private:
base::WeakPtr<GpuMessageFilter> filter_;
IPC::Message* reply_;
};
class CreateCommandBufferCallback : public CallbackRunner<Tuple1<int32> > {
public:
CreateCommandBufferCallback(GpuMessageFilter* filter,
IPC::Message* reply) :
filter_(filter->AsWeakPtr()),
reply_(reply) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
}
virtual void RunWithParams(const TupleType& params) {
DispatchToMethod(this, &CreateCommandBufferCallback::Send, params);
}
void Send(int32 route_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GpuHostMsg_CreateViewCommandBuffer::WriteReplyParams(reply_, route_id);
if (filter_)
filter_->Send(reply_);
}
private:
base::WeakPtr<GpuMessageFilter> filter_;
IPC::Message* reply_;
};
} // namespace
void GpuMessageFilter::OnEstablishGpuChannel( void GpuMessageFilter::OnEstablishGpuChannel(
content::CauseForGpuLaunch cause_for_gpu_launch, content::CauseForGpuLaunch cause_for_gpu_launch,
IPC::Message* reply) { IPC::Message* reply) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
scoped_ptr<EstablishChannelCallback> callback(
new EstablishChannelCallback(this, reply));
// TODO(apatrick): Eventually, this will return the route ID of a // TODO(apatrick): Eventually, this will return the route ID of a
// GpuProcessStub, from which the renderer process will create a // GpuProcessStub, from which the renderer process will create a
// GpuProcessProxy. The renderer will use the proxy for all subsequent // GpuProcessProxy. The renderer will use the proxy for all subsequent
...@@ -153,7 +66,11 @@ void GpuMessageFilter::OnEstablishGpuChannel( ...@@ -153,7 +66,11 @@ void GpuMessageFilter::OnEstablishGpuChannel(
gpu_host_id_ = host->host_id(); gpu_host_id_ = host->host_id();
} }
host->EstablishGpuChannel(render_process_id_, callback.release()); host->EstablishGpuChannel(
render_process_id_,
base::Bind(&GpuMessageFilter::EstablishChannelCallback,
AsWeakPtr(),
reply));
} }
void GpuMessageFilter::OnCreateViewCommandBuffer( void GpuMessageFilter::OnCreateViewCommandBuffer(
...@@ -181,5 +98,46 @@ void GpuMessageFilter::OnCreateViewCommandBuffer( ...@@ -181,5 +98,46 @@ void GpuMessageFilter::OnCreateViewCommandBuffer(
render_view_id, render_view_id,
render_process_id_, render_process_id_,
init_params, init_params,
new CreateCommandBufferCallback(this, reply)); base::Bind(&GpuMessageFilter::CreateCommandBufferCallback,
AsWeakPtr(),
reply));
}
void GpuMessageFilter::EstablishChannelCallback(
IPC::Message* reply,
const IPC::ChannelHandle& channel,
base::ProcessHandle gpu_process_for_browser,
const content::GPUInfo& gpu_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::ProcessHandle renderer_process_for_gpu;
if (gpu_process_for_browser != 0) {
#if defined(OS_WIN)
// Create a process handle that the renderer process can give to the GPU
// process to give it access to its handles.
DuplicateHandle(base::GetCurrentProcessHandle(),
peer_handle(),
gpu_process_for_browser,
&renderer_process_for_gpu,
PROCESS_DUP_HANDLE,
FALSE,
0);
#else
renderer_process_for_gpu = peer_handle();
#endif
} else {
renderer_process_for_gpu = 0;
}
GpuHostMsg_EstablishGpuChannel::WriteReplyParams(
reply, channel, renderer_process_for_gpu, gpu_info);
Send(reply);
} }
void GpuMessageFilter::CreateCommandBufferCallback(
IPC::Message* reply, int32 route_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GpuHostMsg_CreateViewCommandBuffer::WriteReplyParams(reply, route_id);
Send(reply);
}
...@@ -15,6 +15,10 @@ class GpuProcessHost; ...@@ -15,6 +15,10 @@ class GpuProcessHost;
struct GPUCreateCommandBufferConfig; struct GPUCreateCommandBufferConfig;
class RenderWidgetHelper; class RenderWidgetHelper;
namespace content {
struct GPUInfo;
} // namespace content
// A message filter for messages from the renderer to the GpuProcessHost(UIShim) // A message filter for messages from the renderer to the GpuProcessHost(UIShim)
// in the browser. Such messages are typically destined for the GPU process, // in the browser. Such messages are typically destined for the GPU process,
// but need to be mediated by the browser. // but need to be mediated by the browser.
...@@ -40,6 +44,12 @@ class GpuMessageFilter : public BrowserMessageFilter, ...@@ -40,6 +44,12 @@ class GpuMessageFilter : public BrowserMessageFilter,
int32 render_view_id, int32 render_view_id,
const GPUCreateCommandBufferConfig& init_params, const GPUCreateCommandBufferConfig& init_params,
IPC::Message* reply); IPC::Message* reply);
// Helper callbacks for the message handlers.
void EstablishChannelCallback(IPC::Message* reply,
const IPC::ChannelHandle& channel,
base::ProcessHandle gpu_process_for_browser,
const content::GPUInfo& gpu_info);
void CreateCommandBufferCallback(IPC::Message* reply, int32 route_id);
int gpu_host_id_; int gpu_host_id_;
int render_process_id_; int render_process_id_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment