| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/gpu_process_host.h" | 5 #include "chrome/browser/gpu_process_host.h" |
| 6 | 6 |
| 7 #include "app/app_switches.h" | 7 #include "app/app_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/thread.h" | 9 #include "base/thread.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
| 12 #include "chrome/browser/gpu_process_host_ui_shim.h" | 12 #include "chrome/browser/gpu_process_host_ui_shim.h" |
| 13 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
| 14 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 14 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 15 #include "chrome/browser/renderer_host/resource_message_filter.h" | 15 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/gpu_info.h" | 17 #include "chrome/common/gpu_info.h" |
| 18 #include "chrome/common/gpu_messages.h" | 18 #include "chrome/common/gpu_messages.h" |
| 19 #include "chrome/common/render_messages.h" | 19 #include "chrome/common/render_messages.h" |
| 20 #include "ipc/ipc_channel_handle.h" | 20 #include "ipc/ipc_channel_handle.h" |
| 21 #include "ipc/ipc_switches.h" | 21 #include "ipc/ipc_switches.h" |
| 22 #include "media/base/media_switches.h" | 22 #include "media/base/media_switches.h" |
| 23 | 23 |
| 24 #if defined(OS_LINUX) | 24 #if defined(OS_LINUX) |
| 25 #include <gdk/gdkwindow.h> |
| 26 #include <gdk/gdkx.h> |
| 25 #include "app/x11_util.h" | 27 #include "app/x11_util.h" |
| 26 #include "gfx/gtk_native_view_id_manager.h" | 28 #include "gfx/gtk_native_view_id_manager.h" |
| 27 #endif | 29 #endif |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 // Tasks used by this file | 33 // Tasks used by this file |
| 32 class RouteOnUIThreadTask : public Task { | 34 class RouteOnUIThreadTask : public Task { |
| 33 public: | 35 public: |
| 34 explicit RouteOnUIThreadTask(const IPC::Message& msg) : msg_(msg) { | 36 explicit RouteOnUIThreadTask(const IPC::Message& msg) : msg_(msg) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 GpuProcessHost::SynchronizationRequest::~SynchronizationRequest() {} | 192 GpuProcessHost::SynchronizationRequest::~SynchronizationRequest() {} |
| 191 | 193 |
| 192 void GpuProcessHost::OnControlMessageReceived(const IPC::Message& message) { | 194 void GpuProcessHost::OnControlMessageReceived(const IPC::Message& message) { |
| 193 DCHECK(CalledOnValidThread()); | 195 DCHECK(CalledOnValidThread()); |
| 194 | 196 |
| 195 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) | 197 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) |
| 196 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) | 198 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) |
| 197 IPC_MESSAGE_HANDLER(GpuHostMsg_SynchronizeReply, OnSynchronizeReply) | 199 IPC_MESSAGE_HANDLER(GpuHostMsg_SynchronizeReply, OnSynchronizeReply) |
| 198 #if defined(OS_LINUX) | 200 #if defined(OS_LINUX) |
| 199 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuHostMsg_GetViewXID, OnGetViewXID) | 201 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuHostMsg_GetViewXID, OnGetViewXID) |
| 202 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuHostMsg_ResizeXID, OnResizeXID) |
| 200 #elif defined(OS_MACOSX) | 203 #elif defined(OS_MACOSX) |
| 201 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceSetIOSurface, | 204 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceSetIOSurface, |
| 202 OnAcceleratedSurfaceSetIOSurface) | 205 OnAcceleratedSurfaceSetIOSurface) |
| 203 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, | 206 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
| 204 OnAcceleratedSurfaceBuffersSwapped) | 207 OnAcceleratedSurfaceBuffersSwapped) |
| 205 #endif | 208 #endif |
| 206 // If the IO thread does not handle the message then automatically route it | 209 // If the IO thread does not handle the message then automatically route it |
| 207 // to the UI thread. The UI thread will report an error if it does not | 210 // to the UI thread. The UI thread will report an error if it does not |
| 208 // handle it. | 211 // handle it. |
| 209 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) | 212 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 246 } |
| 244 | 247 |
| 245 GpuHostMsg_GetViewXID::WriteReplyParams(reply_msg, xid); | 248 GpuHostMsg_GetViewXID::WriteReplyParams(reply_msg, xid); |
| 246 | 249 |
| 247 // Have to reply from IO thread. | 250 // Have to reply from IO thread. |
| 248 BrowserThread::PostTask( | 251 BrowserThread::PostTask( |
| 249 BrowserThread::IO, FROM_HERE, | 252 BrowserThread::IO, FROM_HERE, |
| 250 NewRunnableFunction(&SendDelayedReply, reply_msg)); | 253 NewRunnableFunction(&SendDelayedReply, reply_msg)); |
| 251 } | 254 } |
| 252 | 255 |
| 256 void ResizeXIDDispatcher(unsigned long xid, int32 width, int32 height, |
| 257 IPC::Message *reply_msg) { |
| 258 GdkWindow* window = reinterpret_cast<GdkWindow*>(gdk_xid_table_lookup(xid)); |
| 259 if (window) { |
| 260 Display* display = GDK_WINDOW_XDISPLAY(window); |
| 261 gdk_window_resize(window, width, height); |
| 262 XSync(display, False); |
| 263 } |
| 264 |
| 265 GpuHostMsg_ResizeXID::WriteReplyParams(reply_msg, (window != NULL)); |
| 266 |
| 267 // Have to reply from IO thread. |
| 268 BrowserThread::PostTask( |
| 269 BrowserThread::IO, FROM_HERE, |
| 270 NewRunnableFunction(&SendDelayedReply, reply_msg)); |
| 271 } |
| 272 |
| 253 } // namespace | 273 } // namespace |
| 254 | 274 |
| 255 void GpuProcessHost::OnGetViewXID(gfx::NativeViewId id, | 275 void GpuProcessHost::OnGetViewXID(gfx::NativeViewId id, |
| 256 IPC::Message *reply_msg) { | 276 IPC::Message *reply_msg) { |
| 257 // Have to request a permanent XID from UI thread. | 277 // Have to request a permanent XID from UI thread. |
| 258 BrowserThread::PostTask( | 278 BrowserThread::PostTask( |
| 259 BrowserThread::UI, FROM_HERE, | 279 BrowserThread::UI, FROM_HERE, |
| 260 NewRunnableFunction(&GetViewXIDDispatcher, id, reply_msg)); | 280 NewRunnableFunction(&GetViewXIDDispatcher, id, reply_msg)); |
| 261 } | 281 } |
| 262 | 282 |
| 283 void GpuProcessHost::OnResizeXID(unsigned long xid, int32 width, int32 height, |
| 284 IPC::Message *reply_msg) { |
| 285 // Have to resize the window from UI thread. |
| 286 BrowserThread::PostTask( |
| 287 BrowserThread::UI, FROM_HERE, |
| 288 NewRunnableFunction(&ResizeXIDDispatcher, xid, width, height, reply_msg)); |
| 289 } |
| 290 |
| 263 #elif defined(OS_MACOSX) | 291 #elif defined(OS_MACOSX) |
| 264 | 292 |
| 265 namespace { | 293 namespace { |
| 266 | 294 |
| 267 class SetIOSurfaceDispatcher : public Task { | 295 class SetIOSurfaceDispatcher : public Task { |
| 268 public: | 296 public: |
| 269 SetIOSurfaceDispatcher( | 297 SetIOSurfaceDispatcher( |
| 270 const GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params& params) | 298 const GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params& params) |
| 271 : params_(params) { | 299 : params_(params) { |
| 272 } | 300 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 405 |
| 378 bool GpuProcessHost::CanShutdown() { | 406 bool GpuProcessHost::CanShutdown() { |
| 379 return true; | 407 return true; |
| 380 } | 408 } |
| 381 | 409 |
| 382 void GpuProcessHost::OnProcessCrashed() { | 410 void GpuProcessHost::OnProcessCrashed() { |
| 383 // TODO(alokp): Update gpu process crash rate. | 411 // TODO(alokp): Update gpu process crash rate. |
| 384 BrowserChildProcessHost::OnProcessCrashed(); | 412 BrowserChildProcessHost::OnProcessCrashed(); |
| 385 } | 413 } |
| 386 | 414 |
| OLD | NEW |