| 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/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 // Number of times the gpu process has crashed in the current browser session. | 53 // Number of times the gpu process has crashed in the current browser session. |
| 54 static int g_gpu_crash_count = 0; | 54 static int g_gpu_crash_count = 0; |
| 55 | 55 |
| 56 // Maximum number of times the gpu process is allowed to crash in a session. | 56 // Maximum number of times the gpu process is allowed to crash in a session. |
| 57 // Once this limit is reached, any request to launch the gpu process will fail. | 57 // Once this limit is reached, any request to launch the gpu process will fail. |
| 58 static const int kGpuMaxCrashCount = 3; | 58 static const int kGpuMaxCrashCount = 3; |
| 59 | 59 |
| 60 int g_last_host_id = 0; | 60 int g_last_host_id = 0; |
| 61 | 61 |
| 62 #if defined(TOOLKIT_USES_GTK) | 62 #if defined(TOOLKIT_USES_GTK) && !defined(USE_AURA) |
| 63 | 63 |
| 64 class ReleasePermanentXIDDispatcher: public Task { | 64 class ReleasePermanentXIDDispatcher: public Task { |
| 65 public: | 65 public: |
| 66 explicit ReleasePermanentXIDDispatcher(gfx::PluginWindowHandle surface); | 66 explicit ReleasePermanentXIDDispatcher(gfx::PluginWindowHandle surface); |
| 67 void Run(); | 67 void Run(); |
| 68 private: | 68 private: |
| 69 gfx::PluginWindowHandle surface_; | 69 gfx::PluginWindowHandle surface_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 ReleasePermanentXIDDispatcher::ReleasePermanentXIDDispatcher( | 72 ReleasePermanentXIDDispatcher::ReleasePermanentXIDDispatcher( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 88 renderer_id, cause); | 88 renderer_id, cause); |
| 89 if (host) { | 89 if (host) { |
| 90 host->Send(message); | 90 host->Send(message); |
| 91 } else { | 91 } else { |
| 92 delete message; | 92 delete message; |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // anonymous namespace | 96 } // anonymous namespace |
| 97 | 97 |
| 98 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 98 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) && !defined(USE_AURA) |
| 99 // Used to put a lock on surfaces so that the window to which the GPU | 99 // Used to put a lock on surfaces so that the window to which the GPU |
| 100 // process is drawing to doesn't disappear while it is drawing when | 100 // process is drawing to doesn't disappear while it is drawing when |
| 101 // a tab is closed. | 101 // a tab is closed. |
| 102 class GpuProcessHost::SurfaceRef { | 102 class GpuProcessHost::SurfaceRef { |
| 103 public: | 103 public: |
| 104 explicit SurfaceRef(gfx::PluginWindowHandle surface); | 104 explicit SurfaceRef(gfx::PluginWindowHandle surface); |
| 105 ~SurfaceRef(); | 105 ~SurfaceRef(); |
| 106 private: | 106 private: |
| 107 gfx::PluginWindowHandle surface_; | 107 gfx::PluginWindowHandle surface_; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 GpuProcessHost::SurfaceRef::SurfaceRef(gfx::PluginWindowHandle surface) | 110 GpuProcessHost::SurfaceRef::SurfaceRef(gfx::PluginWindowHandle surface) |
| 111 : surface_(surface) { | 111 : surface_(surface) { |
| 112 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); | 112 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); |
| 113 if (!manager->AddRefPermanentXID(surface_)) { | 113 if (!manager->AddRefPermanentXID(surface_)) { |
| 114 LOG(ERROR) << "Surface " << surface << " cannot be referenced."; | 114 LOG(ERROR) << "Surface " << surface << " cannot be referenced."; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 GpuProcessHost::SurfaceRef::~SurfaceRef() { | 118 GpuProcessHost::SurfaceRef::~SurfaceRef() { |
| 119 BrowserThread::PostTask(BrowserThread::UI, | 119 BrowserThread::PostTask(BrowserThread::UI, |
| 120 FROM_HERE, | 120 FROM_HERE, |
| 121 new ReleasePermanentXIDDispatcher(surface_)); | 121 new ReleasePermanentXIDDispatcher(surface_)); |
| 122 } | 122 } |
| 123 #endif // defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 123 #endif // defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) && !defined(USE_AURA) |
| 124 | 124 |
| 125 // This class creates a GPU thread (instead of a GPU process), when running | 125 // This class creates a GPU thread (instead of a GPU process), when running |
| 126 // with --in-process-gpu or --single-process. | 126 // with --in-process-gpu or --single-process. |
| 127 class GpuMainThread : public base::Thread { | 127 class GpuMainThread : public base::Thread { |
| 128 public: | 128 public: |
| 129 explicit GpuMainThread(const std::string& channel_id) | 129 explicit GpuMainThread(const std::string& channel_id) |
| 130 : base::Thread("Chrome_InProcGpuThread"), | 130 : base::Thread("Chrome_InProcGpuThread"), |
| 131 channel_id_(channel_id), | 131 channel_id_(channel_id), |
| 132 gpu_process_(NULL), | 132 gpu_process_(NULL), |
| 133 child_thread_(NULL) { | 133 child_thread_(NULL) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 364 |
| 365 void GpuProcessHost::CreateViewCommandBuffer( | 365 void GpuProcessHost::CreateViewCommandBuffer( |
| 366 gfx::PluginWindowHandle compositing_surface, | 366 gfx::PluginWindowHandle compositing_surface, |
| 367 int32 render_view_id, | 367 int32 render_view_id, |
| 368 int32 renderer_id, | 368 int32 renderer_id, |
| 369 const GPUCreateCommandBufferConfig& init_params, | 369 const GPUCreateCommandBufferConfig& init_params, |
| 370 CreateCommandBufferCallback* callback) { | 370 CreateCommandBufferCallback* callback) { |
| 371 DCHECK(CalledOnValidThread()); | 371 DCHECK(CalledOnValidThread()); |
| 372 linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); | 372 linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); |
| 373 | 373 |
| 374 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 374 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) && !defined(USE_AURA) |
| 375 ViewID view_id(renderer_id, render_view_id); | 375 ViewID view_id(renderer_id, render_view_id); |
| 376 | 376 |
| 377 // There should only be one such command buffer (for the compositor). In | 377 // There should only be one such command buffer (for the compositor). In |
| 378 // practice, if the GPU process lost a context, GraphicsContext3D with | 378 // practice, if the GPU process lost a context, GraphicsContext3D with |
| 379 // associated command buffer and view surface will not be gone until new | 379 // associated command buffer and view surface will not be gone until new |
| 380 // one is in place and all layers are reattached. | 380 // one is in place and all layers are reattached. |
| 381 linked_ptr<SurfaceRef> surface_ref; | 381 linked_ptr<SurfaceRef> surface_ref; |
| 382 SurfaceRefMap::iterator it = surface_refs_.find(view_id); | 382 SurfaceRefMap::iterator it = surface_refs_.find(view_id); |
| 383 if (it != surface_refs_.end()) | 383 if (it != surface_refs_.end()) |
| 384 surface_ref = (*it).second; | 384 surface_ref = (*it).second; |
| 385 else | 385 else |
| 386 surface_ref.reset(new SurfaceRef(compositing_surface)); | 386 surface_ref.reset(new SurfaceRef(compositing_surface)); |
| 387 #endif // defined(TOOLKIT_USES_GTK) && defined(TOUCH_UI) | 387 #endif // defined(TOOLKIT_USES_GTK) && defined(TOUCH_UI) && !defined(USE_AURA) |
| 388 | 388 |
| 389 if (compositing_surface != gfx::kNullPluginWindow && | 389 if (compositing_surface != gfx::kNullPluginWindow && |
| 390 Send(new GpuMsg_CreateViewCommandBuffer( | 390 Send(new GpuMsg_CreateViewCommandBuffer( |
| 391 compositing_surface, render_view_id, renderer_id, init_params))) { | 391 compositing_surface, render_view_id, renderer_id, init_params))) { |
| 392 create_command_buffer_requests_.push(wrapped_callback); | 392 create_command_buffer_requests_.push(wrapped_callback); |
| 393 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 393 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) && !defined(USE_AURA) |
| 394 surface_refs_.insert(std::pair<ViewID, linked_ptr<SurfaceRef> >( | 394 surface_refs_.insert(std::pair<ViewID, linked_ptr<SurfaceRef> >( |
| 395 view_id, surface_ref)); | 395 view_id, surface_ref)); |
| 396 #endif | 396 #endif |
| 397 } else { | 397 } else { |
| 398 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); | 398 CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 void GpuProcessHost::OnChannelEstablished( | 402 void GpuProcessHost::OnChannelEstablished( |
| 403 const IPC::ChannelHandle& channel_handle) { | 403 const IPC::ChannelHandle& channel_handle) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 if (route_id == MSG_ROUTING_NONE) | 436 if (route_id == MSG_ROUTING_NONE) |
| 437 CreateCommandBufferError(callback.release(), route_id); | 437 CreateCommandBufferError(callback.release(), route_id); |
| 438 else | 438 else |
| 439 callback->Run(route_id); | 439 callback->Run(route_id); |
| 440 } | 440 } |
| 441 } | 441 } |
| 442 | 442 |
| 443 void GpuProcessHost::OnDestroyCommandBuffer( | 443 void GpuProcessHost::OnDestroyCommandBuffer( |
| 444 gfx::PluginWindowHandle window, int32 renderer_id, | 444 gfx::PluginWindowHandle window, int32 renderer_id, |
| 445 int32 render_view_id) { | 445 int32 render_view_id) { |
| 446 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 446 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) && !defined(USE_AURA) |
| 447 ViewID view_id(renderer_id, render_view_id); | 447 ViewID view_id(renderer_id, render_view_id); |
| 448 SurfaceRefMap::iterator it = surface_refs_.find(view_id); | 448 SurfaceRefMap::iterator it = surface_refs_.find(view_id); |
| 449 if (it != surface_refs_.end()) | 449 if (it != surface_refs_.end()) |
| 450 surface_refs_.erase(it); | 450 surface_refs_.erase(it); |
| 451 #endif // defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) | 451 #endif // defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) && !defined(USE_AURA) |
| 452 } | 452 } |
| 453 | 453 |
| 454 void GpuProcessHost::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { | 454 void GpuProcessHost::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { |
| 455 GpuDataManager::GetInstance()->UpdateGpuInfo(gpu_info); | 455 GpuDataManager::GetInstance()->UpdateGpuInfo(gpu_info); |
| 456 } | 456 } |
| 457 | 457 |
| 458 bool GpuProcessHost::CanShutdown() { | 458 bool GpuProcessHost::CanShutdown() { |
| 459 return true; | 459 return true; |
| 460 } | 460 } |
| 461 | 461 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 scoped_ptr<EstablishChannelCallback> wrapped_callback(callback); | 610 scoped_ptr<EstablishChannelCallback> wrapped_callback(callback); |
| 611 wrapped_callback->Run(channel_handle, renderer_process_for_gpu, gpu_info); | 611 wrapped_callback->Run(channel_handle, renderer_process_for_gpu, gpu_info); |
| 612 } | 612 } |
| 613 | 613 |
| 614 void GpuProcessHost::CreateCommandBufferError( | 614 void GpuProcessHost::CreateCommandBufferError( |
| 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 } |
| OLD | NEW |