| 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/browser/gpu/gpu_process_host.h" | 5 #include "content/browser/gpu/gpu_process_host.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 12 #include "base/string_piece.h" | 12 #include "base/string_piece.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" | 14 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" |
| 15 #include "content/browser/browser_thread.h" | 15 #include "content/browser/browser_thread.h" |
| 16 #include "content/browser/gpu/gpu_data_manager.h" | 16 #include "content/browser/gpu/gpu_data_manager.h" |
| 17 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 17 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 18 #include "content/browser/renderer_host/render_widget_host.h" | 18 #include "content/browser/renderer_host/render_widget_host.h" |
| 19 #include "content/browser/renderer_host/render_widget_host_view.h" | 19 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 20 #include "content/common/content_switches.h" | 20 #include "content/common/content_switches.h" |
| 21 #include "content/common/gpu/gpu_messages.h" | 21 #include "content/common/gpu/gpu_messages.h" |
| 22 #include "content/gpu/gpu_child_thread.h" | 22 #include "content/gpu/gpu_child_thread.h" |
| 23 #include "content/gpu/gpu_process.h" | 23 #include "content/gpu/gpu_process.h" |
| 24 #include "ipc/ipc_channel_handle.h" | 24 #include "ipc/ipc_channel_handle.h" |
| 25 #include "ipc/ipc_switches.h" | 25 #include "ipc/ipc_switches.h" |
| 26 #include "media/base/media_switches.h" | 26 #include "media/base/media_switches.h" |
| 27 #include "ui/gfx/gl/gl_context.h" | 27 #include "ui/gfx/gl/gl_context.h" |
| 28 #include "ui/gfx/gl/gl_switches.h" | 28 #include "ui/gfx/gl/gl_switches.h" |
| 29 | 29 |
| 30 #if defined(OS_LINUX) | 30 #if defined(TOOLKIT_USES_GTK) |
| 31 #include "ui/gfx/gtk_native_view_id_manager.h" | 31 #include "ui/gfx/gtk_native_view_id_manager.h" |
| 32 #endif // defined(OS_LINUX) | 32 #endif |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 enum GPUProcessLifetimeEvent { | 36 enum GPUProcessLifetimeEvent { |
| 37 LAUNCHED, | 37 LAUNCHED, |
| 38 DIED_FIRST_TIME, | 38 DIED_FIRST_TIME, |
| 39 DIED_SECOND_TIME, | 39 DIED_SECOND_TIME, |
| 40 DIED_THIRD_TIME, | 40 DIED_THIRD_TIME, |
| 41 DIED_FOURTH_TIME, | 41 DIED_FOURTH_TIME, |
| 42 GPU_PROCESS_LIFETIME_EVENT_MAX | 42 GPU_PROCESS_LIFETIME_EVENT_MAX |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // A global map from GPU process host ID to GpuProcessHost. | 45 // A global map from GPU process host ID to GpuProcessHost. |
| 46 static IDMap<GpuProcessHost> g_hosts_by_id; | 46 static IDMap<GpuProcessHost> g_hosts_by_id; |
| 47 | 47 |
| 48 // Number of times the gpu process has crashed in the current browser session. | 48 // Number of times the gpu process has crashed in the current browser session. |
| 49 static int g_gpu_crash_count = 0; | 49 static int g_gpu_crash_count = 0; |
| 50 | 50 |
| 51 // Maximum number of times the gpu process is allowed to crash in a session. | 51 // Maximum number of times the gpu process is allowed to crash in a session. |
| 52 // Once this limit is reached, any request to launch the gpu process will fail. | 52 // Once this limit is reached, any request to launch the gpu process will fail. |
| 53 static const int kGpuMaxCrashCount = 3; | 53 static const int kGpuMaxCrashCount = 3; |
| 54 | 54 |
| 55 int g_last_host_id = 0; | 55 int g_last_host_id = 0; |
| 56 | 56 |
| 57 #if defined(OS_LINUX) | 57 #if defined(TOOLKIT_USES_GTK) |
| 58 | 58 |
| 59 class ReleasePermanentXIDDispatcher: public Task { | 59 class ReleasePermanentXIDDispatcher: public Task { |
| 60 public: | 60 public: |
| 61 explicit ReleasePermanentXIDDispatcher(gfx::PluginWindowHandle surface); | 61 explicit ReleasePermanentXIDDispatcher(gfx::PluginWindowHandle surface); |
| 62 void Run(); | 62 void Run(); |
| 63 private: | 63 private: |
| 64 gfx::PluginWindowHandle surface_; | 64 gfx::PluginWindowHandle surface_; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 ReleasePermanentXIDDispatcher::ReleasePermanentXIDDispatcher( | 67 ReleasePermanentXIDDispatcher::ReleasePermanentXIDDispatcher( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 renderer_id, cause); | 83 renderer_id, cause); |
| 84 if (host) { | 84 if (host) { |
| 85 host->Send(message); | 85 host->Send(message); |
| 86 } else { | 86 } else { |
| 87 delete message; | 87 delete message; |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 } // anonymous namespace | 91 } // anonymous namespace |
| 92 | 92 |
| 93 #if defined(OS_LINUX) && !defined(TOUCH_UI) | 93 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) |
| 94 // Used to put a lock on surfaces so that the window to which the GPU | 94 // Used to put a lock on surfaces so that the window to which the GPU |
| 95 // process is drawing to doesn't disappear while it is drawing when | 95 // process is drawing to doesn't disappear while it is drawing when |
| 96 // a tab is closed. | 96 // a tab is closed. |
| 97 class GpuProcessHost::SurfaceRef { | 97 class GpuProcessHost::SurfaceRef { |
| 98 public: | 98 public: |
| 99 explicit SurfaceRef(gfx::PluginWindowHandle surface); | 99 explicit SurfaceRef(gfx::PluginWindowHandle surface); |
| 100 ~SurfaceRef(); | 100 ~SurfaceRef(); |
| 101 private: | 101 private: |
| 102 gfx::PluginWindowHandle surface_; | 102 gfx::PluginWindowHandle surface_; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 GpuProcessHost::SurfaceRef::SurfaceRef(gfx::PluginWindowHandle surface) | 105 GpuProcessHost::SurfaceRef::SurfaceRef(gfx::PluginWindowHandle surface) |
| 106 : surface_(surface) { | 106 : surface_(surface) { |
| 107 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); | 107 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); |
| 108 if (!manager->AddRefPermanentXID(surface_)) { | 108 if (!manager->AddRefPermanentXID(surface_)) { |
| 109 LOG(ERROR) << "Surface " << surface << " cannot be referenced."; | 109 LOG(ERROR) << "Surface " << surface << " cannot be referenced."; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 GpuProcessHost::SurfaceRef::~SurfaceRef() { | 113 GpuProcessHost::SurfaceRef::~SurfaceRef() { |
| 114 BrowserThread::PostTask(BrowserThread::UI, | 114 BrowserThread::PostTask(BrowserThread::UI, |
| 115 FROM_HERE, | 115 FROM_HERE, |
| 116 new ReleasePermanentXIDDispatcher(surface_)); | 116 new ReleasePermanentXIDDispatcher(surface_)); |
| 117 } | 117 } |
| 118 #endif // defined(OS_LINUX) && !defined(TOUCH_UI) | 118 #endif // defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) |
| 119 | 119 |
| 120 // This class creates a GPU thread (instead of a GPU process), when running | 120 // This class creates a GPU thread (instead of a GPU process), when running |
| 121 // with --in-process-gpu or --single-process. | 121 // with --in-process-gpu or --single-process. |
| 122 class GpuMainThread : public base::Thread { | 122 class GpuMainThread : public base::Thread { |
| 123 public: | 123 public: |
| 124 explicit GpuMainThread(const std::string& channel_id) | 124 explicit GpuMainThread(const std::string& channel_id) |
| 125 : base::Thread("Chrome_InProcGpuThread"), | 125 : base::Thread("Chrome_InProcGpuThread"), |
| 126 channel_id_(channel_id), | 126 channel_id_(channel_id), |
| 127 gpu_process_(NULL), | 127 gpu_process_(NULL), |
| 128 child_thread_(NULL) { | 128 child_thread_(NULL) { |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 371 |
| 372 void GpuProcessHost::CreateViewCommandBuffer( | 372 void GpuProcessHost::CreateViewCommandBuffer( |
| 373 gfx::PluginWindowHandle compositing_surface, | 373 gfx::PluginWindowHandle compositing_surface, |
| 374 int32 render_view_id, | 374 int32 render_view_id, |
| 375 int32 renderer_id, | 375 int32 renderer_id, |
| 376 const GPUCreateCommandBufferConfig& init_params, | 376 const GPUCreateCommandBufferConfig& init_params, |
| 377 CreateCommandBufferCallback* callback) { | 377 CreateCommandBufferCallback* callback) { |
| 378 DCHECK(CalledOnValidThread()); | 378 DCHECK(CalledOnValidThread()); |
| 379 linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); | 379 linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); |
| 380 | 380 |
| 381 #if defined(OS_LINUX) && !defined(TOUCH_UI) | 381 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) |
| 382 ViewID view_id(renderer_id, render_view_id); | 382 ViewID view_id(renderer_id, render_view_id); |
| 383 | 383 |
| 384 // There should only be one such command buffer (for the compositor). In | 384 // There should only be one such command buffer (for the compositor). In |
| 385 // practice, if the GPU process lost a context, GraphicsContext3D with | 385 // practice, if the GPU process lost a context, GraphicsContext3D with |
| 386 // associated command buffer and view surface will not be gone until new | 386 // associated command buffer and view surface will not be gone until new |
| 387 // one is in place and all layers are reattached. | 387 // one is in place and all layers are reattached. |
| 388 linked_ptr<SurfaceRef> surface_ref; | 388 linked_ptr<SurfaceRef> surface_ref; |
| 389 SurfaceRefMap::iterator it = surface_refs_.find(view_id); | 389 SurfaceRefMap::iterator it = surface_refs_.find(view_id); |
| 390 if (it != surface_refs_.end()) | 390 if (it != surface_refs_.end()) |
| 391 surface_ref = (*it).second; | 391 surface_ref = (*it).second; |
| 392 else | 392 else |
| 393 surface_ref.reset(new SurfaceRef(compositing_surface)); | 393 surface_ref.reset(new SurfaceRef(compositing_surface)); |
| 394 #endif // defined(OS_LINUX) && defined(TOUCH_UI) | 394 #endif // defined(TOOLKIT_USES_GTK) && defined(TOUCH_UI) |
| 395 | 395 |
| 396 if (compositing_surface != gfx::kNullPluginWindow && | 396 if (compositing_surface != gfx::kNullPluginWindow && |
| 397 Send(new GpuMsg_CreateViewCommandBuffer( | 397 Send(new GpuMsg_CreateViewCommandBuffer( |
| 398 compositing_surface, render_view_id, renderer_id, init_params))) { | 398 compositing_surface, render_view_id, renderer_id, init_params))) { |
| 399 create_command_buffer_requests_.push(wrapped_callback); | 399 create_command_buffer_requests_.push(wrapped_callback); |
| 400 #if defined(OS_LINUX) && !defined(TOUCH_UI) | 400 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) |
| 401 surface_refs_.insert(std::pair<ViewID, linked_ptr<SurfaceRef> >( | 401 surface_refs_.insert(std::pair<ViewID, linked_ptr<SurfaceRef> >( |
| 402 view_id, surface_ref)); | 402 view_id, surface_ref)); |
| 403 #endif // defined(OS_LINUX) && !defined(TOUCH_UI) | 403 #endif |
| 404 } else { | 404 } else { |
| 405 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); | 405 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); |
| 406 } | 406 } |
| 407 } | 407 } |
| 408 | 408 |
| 409 void GpuProcessHost::OnChannelEstablished( | 409 void GpuProcessHost::OnChannelEstablished( |
| 410 const IPC::ChannelHandle& channel_handle) { | 410 const IPC::ChannelHandle& channel_handle) { |
| 411 // The GPU process should have launched at this point and this object should | 411 // The GPU process should have launched at this point and this object should |
| 412 // have been notified of its process handle. | 412 // have been notified of its process handle. |
| 413 DCHECK(gpu_process_); | 413 DCHECK(gpu_process_); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 if (route_id == MSG_ROUTING_NONE) | 452 if (route_id == MSG_ROUTING_NONE) |
| 453 CreateCommandBufferError(callback.release(), route_id); | 453 CreateCommandBufferError(callback.release(), route_id); |
| 454 else | 454 else |
| 455 callback->Run(route_id); | 455 callback->Run(route_id); |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 void GpuProcessHost::OnDestroyCommandBuffer( | 459 void GpuProcessHost::OnDestroyCommandBuffer( |
| 460 gfx::PluginWindowHandle window, int32 renderer_id, | 460 gfx::PluginWindowHandle window, int32 renderer_id, |
| 461 int32 render_view_id) { | 461 int32 render_view_id) { |
| 462 #if defined(OS_LINUX) && !defined(TOUCH_UI) | 462 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) |
| 463 ViewID view_id(renderer_id, render_view_id); | 463 ViewID view_id(renderer_id, render_view_id); |
| 464 SurfaceRefMap::iterator it = surface_refs_.find(view_id); | 464 SurfaceRefMap::iterator it = surface_refs_.find(view_id); |
| 465 if (it != surface_refs_.end()) | 465 if (it != surface_refs_.end()) |
| 466 surface_refs_.erase(it); | 466 surface_refs_.erase(it); |
| 467 #endif // defined(OS_LINUX) && !defined(TOUCH_UI) | 467 #endif // defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) |
| 468 } | 468 } |
| 469 | 469 |
| 470 void GpuProcessHost::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { | 470 void GpuProcessHost::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { |
| 471 GpuDataManager::GetInstance()->UpdateGpuInfo(gpu_info); | 471 GpuDataManager::GetInstance()->UpdateGpuInfo(gpu_info); |
| 472 } | 472 } |
| 473 | 473 |
| 474 bool GpuProcessHost::CanShutdown() { | 474 bool GpuProcessHost::CanShutdown() { |
| 475 return true; | 475 return true; |
| 476 } | 476 } |
| 477 | 477 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 CreateCommandBufferCallback* callback, int32 route_id) { | 615 CreateCommandBufferCallback* callback, int32 route_id) { |
| 616 scoped_ptr<GpuProcessHost::CreateCommandBufferCallback> | 616 scoped_ptr<GpuProcessHost::CreateCommandBufferCallback> |
| 617 wrapped_callback(callback); | 617 wrapped_callback(callback); |
| 618 callback->Run(route_id); | 618 callback->Run(route_id); |
| 619 } | 619 } |
| 620 | 620 |
| 621 void GpuProcessHost::SynchronizeError(SynchronizeCallback* callback) { | 621 void GpuProcessHost::SynchronizeError(SynchronizeCallback* callback) { |
| 622 scoped_ptr<SynchronizeCallback> wrapped_callback(callback); | 622 scoped_ptr<SynchronizeCallback> wrapped_callback(callback); |
| 623 wrapped_callback->Run(); | 623 wrapped_callback->Run(); |
| 624 } | 624 } |
| OLD | NEW |