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